Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: add tests #52

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Test
on:
pull_request:
push:
branches:
- master

jobs:

test:
name: Test
runs-on: ubuntu-latest

steps:
- name: Check out the codebase.
uses: actions/checkout@v2

- name: Set up Python 3.7.
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install test dependencies.
run: pip3 install molecule docker

- name: Run tests.
run: |
cd roles/download && molecule test
cd ../prereq && molecule test
cd ../reset && molecule test
9 changes: 9 additions & 0 deletions roles/download/molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Converge
hosts: all
vars_files:
- vars.yml
tasks:
- name: Include download
include_role:
name: download
58 changes: 58 additions & 0 deletions roles/download/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: debian-10
image: docker.io/geerlingguy/docker-debian10-ansible
pre_build_image: true
- name: ubuntu-1804
image: docker.io/geerlingguy/docker-ubuntu1804-ansible
pre_build_image: true
- name: centos-8
image: docker.io/geerlingguy/docker-centos8-ansible
pre_build_image: true
provisioner:
name: ansible
# log: true
verifier:
name: ansible
scenario:
name: default
create_sequence:
- dependency
- create
- prepare
check_sequence:
- dependency
- cleanup
- destroy
- create
- prepare
- converge
- check
- destroy
converge_sequence:
- dependency
- create
- prepare
- converge
destroy_sequence:
- dependency
- cleanup
- destroy
test_sequence:
- lint
- dependency
- cleanup
- destroy
- syntax
- create
- prepare
- converge
# - idempotence # deleting existing files before download cause this to fail.
- side_effect
- verify
- cleanup
- destroy
2 changes: 2 additions & 0 deletions roles/download/molecule/default/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
k3s_version: v1.17.5+k3s1
12 changes: 12 additions & 0 deletions roles/download/molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: Verify
hosts: all
tasks:
- name: Check for /usr/local/bin/k3s
stat:
path: /usr/local/bin/k3s
register: file

- name: Verify binary exists
assert:
that: file.stat.exists
10 changes: 10 additions & 0 deletions roles/k3s/master/molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Converge
hosts: all
vars_files:
- vars.yml
tasks:
- import_tasks: ../../../../download/tasks/main.yml
- name: Include master
include_role:
name: master
76 changes: 76 additions & 0 deletions roles/k3s/master/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: master-debian-10
image: docker.io/geerlingguy/docker-debian10-ansible
command: ""
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: true
groups:
- master
- name: master-ubuntu-1804
image: docker.io/geerlingguy/docker-ubuntu1804-ansible
command: ""
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: true
groups:
- master
- name: master-centos-8
image: docker.io/geerlingguy/docker-centos8-ansible
command: ""
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: true
groups:
- master
provisioner:
name: ansible
# log: true
verifier:
name: ansible
scenario:
name: default
create_sequence:
- dependency
- create
- prepare
check_sequence:
- dependency
- cleanup
- destroy
- create
- prepare
- converge
- check
- destroy
converge_sequence:
- dependency
- create
- prepare
- converge
destroy_sequence:
- dependency
- cleanup
- destroy
test_sequence:
- lint
- dependency
- cleanup
- destroy
- syntax
- create
- prepare
- converge
# - idempotence # deleting existing files before download cause this to fail.
- side_effect
- verify
- cleanup
- destroy
5 changes: 5 additions & 0 deletions roles/k3s/master/molecule/default/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
k3s_version: v1.17.5+k3s1
ansible_user: root
systemd_dir: /etc/systemd/system
master_ip: "{{ hostvars[groups['master'][0]]['ansible_host'] | default(groups['master'][0]) }}"
14 changes: 14 additions & 0 deletions roles/k3s/master/molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- name: Verify
hosts: all
tasks:
- name: Populate service facts
service_facts:

- name: Verify ansible k3s service is enabled
assert:
that: ansible_facts.services['k3s.service'].status == 'enabled'

- name: Verify ansible k3s service is running
assert:
that: ansible_facts.services['k3s.service'].state == 'running'
9 changes: 9 additions & 0 deletions roles/k3s/molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Converge
hosts: all
vars_files:
- vars.yml
tasks:

- import_playbook: ../../master/tasks/main.yml
- import_playbook: ../../node/tasks/main.yml
65 changes: 65 additions & 0 deletions roles/k3s/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: master-debian-10
image: docker.io/geerlingguy/docker-debian10-ansible
command: ""
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: true
groups:
- master
- name: master-ubuntu-1804
image: docker.io/geerlingguy/docker-ubuntu1804-ansible
command: ""
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: true
groups:
- master
- name: master-centos-8
image: docker.io/geerlingguy/docker-centos8-ansible
command: ""
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: true
groups:
- master
- name: node-debian-10
image: docker.io/geerlingguy/docker-debian10-ansible
command: ""
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: true
groups:
- node
- name: node-ubuntu-1804
image: docker.io/geerlingguy/docker-ubuntu1804-ansible
command: ""
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: true
groups:
- node
- name: node-centos-8
image: docker.io/geerlingguy/docker-centos8-ansible
command: ""
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: true
groups:
- node
provisioner:
name: ansible
# log: true
verifier:
name: ansible
6 changes: 6 additions & 0 deletions roles/k3s/molecule/default/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
k3s_version: v1.17.5+k3s1
ansible_user: root
systemd_dir: /etc/systemd/system
master_ip: "{{ hostvars[groups['master'][0]]['ansible_host'] | default(groups['master'][0]) }}"
extra_server_args: ""
8 changes: 8 additions & 0 deletions roles/k3s/molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Verify
hosts:
- master-debian-10
- master-ubuntu-1804
- master-centos-8
tasks:
# Todo - Verify the integration between master and node / Verify that there is one node available in the cluster with `kubectl get nodes`
7 changes: 7 additions & 0 deletions roles/prereq/molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Converge
hosts: all
tasks:
- name: Include prereq
include_role:
name: prereq
23 changes: 23 additions & 0 deletions roles/prereq/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
# - name: debian-10
# image: docker.io/geerlingguy/docker-debian10-ansible
# privileged: true
# pre_build_image: true
- name: ubuntu-1804
image: docker.io/geerlingguy/docker-ubuntu1804-ansible
privileged: true
pre_build_image: true
# - name: centos-8
# image: docker.io/geerlingguy/docker-centos8-ansible
# privileged: true
# pre_build_image: true
provisioner:
name: ansible
# log: true
verifier:
name: ansible
23 changes: 23 additions & 0 deletions roles/prereq/molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
- name: Verify
hosts: all
tasks:
- name: Check if /etc/sysctl.conf contains "net.ipv4.ip_forward=1"
command: grep -Fxq "net.ipv4.ip_forward=1" /etc/sysctl.conf
register: sysctl_ipv4_forward
tags:
- skip_ansible_lint

- name: Check if /etc/sysctl.conf contains "net.ipv6.conf.all.forwarding=1"
command: grep -Fxq "net.ipv6.conf.all.forwarding=1" /etc/sysctl.conf
register: sysctl_ipv6_forward
tags:
- skip_ansible_lint

- name: Verify that sysctl ipv4 forwarding is enabled
assert:
that: sysctl_ipv4_forward.rc == 0

- name: Verify that sysctl ipv6 forwarding is enabled
assert:
that: sysctl_ipv6_forward.rc == 0
9 changes: 9 additions & 0 deletions roles/reset/molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Converge
hosts: all
vars_files:
- vars.yml
tasks:
- name: Include reset
include_role:
name: reset
Loading