Moved HA testing to a new scenario

This commit is contained in:
Xan Manning 2020-01-12 12:50:03 +00:00
parent 09fc37e6ec
commit 7e7cf2b97d
20 changed files with 160 additions and 22 deletions

View File

@ -8,6 +8,7 @@ services: docker
env:
global:
- ROLE_NAME: k3s
- MOLECULE_SCENARIO: default
matrix:
- MOLECULE_DISTRO: geerlingguy/docker-centos8-ansible:latest
- MOLECULE_DISTRO: geerlingguy/docker-centos7-ansible:latest
@ -36,7 +37,7 @@ env:
# Test multiple masters in control plane with PostgreSQL
- MOLECULE_DISTRO: geerlingguy/docker-centos8-ansible:latest
MOLECULE_PLAYBOOK: playbook-ha-postgres.yml
MOLECULE_SCENATIO: highavailability
install:
# Install test dependencies.
@ -45,12 +46,12 @@ install:
before_script:
# Use actual Ansible Galaxy role name for the project directory.
- cd ../
- mv ansible-role-$ROLE_NAME xanmanning.$ROLE_NAME
- cd xanmanning.$ROLE_NAME
- mv ansible-role-${ROLE_NAME} xanmanning.${ROLE_NAME}
- cd xanmanning.${ROLE_NAME}
script:
# Run tests.
- molecule test
- molecule test --scenario-name "${MOLECULE_SCENARIO}"
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View File

@ -34,14 +34,6 @@ platforms:
pre_build_image: ${MOLECULE_PREBUILT:-true}
networks:
- name: k3snet
- name: database
image: postgres:11-alpine
pre_build_image: true
command: "postgres"
env:
POSTGRES_PASSWORD: "verybadpass"
networks:
- name: k3snet
provisioner:
name: ansible
options:

View File

@ -1,6 +1,6 @@
---
- name: Converge
hosts: node*
hosts: all
become: true
vars:
molecule_is_test: true

View File

@ -1,6 +1,6 @@
---
- name: Converge
hosts: node*
hosts: all
become: true
vars:
molecule_is_test: true

View File

@ -1,6 +1,6 @@
---
- name: Converge
hosts: node*
hosts: all
become: true
vars:
molecule_is_test: true

View File

@ -1,6 +1,6 @@
---
- name: Converge
hosts: node*
hosts: all
become: true
vars:
molecule_is_test: true

View File

@ -1,6 +1,6 @@
---
- name: Converge
hosts: node*
hosts: all
become: true
vars:
molecule_is_test: true

View File

@ -1,6 +1,6 @@
---
- name: Converge
hosts: node*
hosts: all
become: true
vars:
molecule_is_test: true

View File

@ -1,6 +1,6 @@
---
- name: Converge
hosts: node*
hosts: all
become: true
vars:
molecule_is_test: true

View File

@ -1,6 +1,6 @@
---
- name: Converge
hosts: node*
hosts: all
become: true
vars:
molecule_is_test: true

View File

@ -1,6 +1,6 @@
---
- name: Converge
hosts: node*
hosts: all
become: true
vars:
molecule_is_test: true

View File

@ -1,6 +1,6 @@
---
- name: Prepare
hosts: node*
hosts: all
tasks:
- name: Debug Message
debug:

View File

@ -0,0 +1,14 @@
# Molecule managed
{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi

View File

@ -0,0 +1,22 @@
*******
Docker driver installation guide
*******
Requirements
============
* Docker Engine
Install
=======
Please refer to the `Virtual environment`_ documentation for installation best
practices. If not using a virtual environment, please consider passing the
widely recommended `'--user' flag`_ when invoking ``pip``.
.. _Virtual environment: https://virtualenv.pypa.io/en/latest/
.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site
.. code-block:: bash
$ pip install 'molecule[docker]'

View File

@ -0,0 +1,67 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
platforms:
- name: node1
image: "${MOLECULE_DISTRO:-geerlingguy/docker-centos8-ansible:latest}"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: ${MOLECULE_PREBUILT:-true}
networks:
- name: k3snet
- name: node2
image: "${MOLECULE_DISTRO:-geerlingguy/docker-centos8-ansible:latest}"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: ${MOLECULE_PREBUILT:-true}
networks:
- name: k3snet
- name: node3
image: "${MOLECULE_DISTRO:-geerlingguy/docker-centos8-ansible:latest}"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: ${MOLECULE_PREBUILT:-true}
networks:
- name: k3snet
- name: database
image: postgres:11-alpine
pre_build_image: true
command: "postgres"
env:
POSTGRES_PASSWORD: "verybadpass"
networks:
- name: k3snet
- name: loadbalancer
image: nginx:1.16-alpine
pre_build_image: true
ports:
- "6443:6443"
volumes:
- ${MOLECULE_SCENARIO_DIRECTORY}/nginx-loadbalancer.conf:/etc/nginx/nginx.conf:ro
command: "nginx -g 'daemon off;'"
networks:
- name: k3snet
provisioner:
name: ansible
options:
verbose: true
lint:
name: ansible-lint
playbooks:
prepare: ${MOLECULE_PREPARE_PLAYBOOK:-prepare.yml}
converge: ${MOLECULE_PLAYBOOK:-playbook.yml}
verifier:
name: testinfra
lint:
name: flake8

View File

@ -0,0 +1,20 @@
events { }
http {
# Set up our upstream of control (master) nodes. The default load balancing
# algorithm for nginx is to round-robin. Perfect!
upstream control_plane {
server node2:6443;
server node3:6443;
}
# Listen on port 6443, this is our default control plane port, then pass
# all traffic to one of the control (master) nodes.
server {
listen 6443;
location / {
proxy_pass http://control_plane;
}
}
}

View File

@ -4,6 +4,7 @@
become: true
vars:
molecule_is_test: true
k3s_control_node_address: loadbalancer
k3s_datastore_endpoint: "postgres://postgres:verybadpass@database:5432/postgres?sslmode=disable"
pre_tasks:
- name: Set each node to be a control node

View File

@ -0,0 +1,7 @@
---
- name: Prepare
hosts: node*
tasks:
- name: Debug Message
debug:
msg: No prepare steps required

View File

@ -0,0 +1,14 @@
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def test_hosts_file(host):
f = host.file('/etc/hosts')
assert f.exists
assert f.user == 'root'
assert f.group == 'root'

Binary file not shown.