-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tox tests for consul maintenance cooldown
- Loading branch information
Showing
5 changed files
with
152 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
- name: Converge | ||
hosts: molecule_consul_service | ||
become: yes | ||
|
||
vars: | ||
consul_node_role: bootstrap | ||
consul_group_name: molecule_consul_service | ||
consul_service_cooldown_maintenance: true | ||
consul_service_name: nginx | ||
consul_service_url4: test.local | ||
consul_service_tags: | ||
- testtag | ||
- published | ||
|
||
pre_tasks: | ||
- name: Update apt cache | ||
apt: | ||
update_cache: yes | ||
when: ansible_pkg_mgr == 'apt' | ||
tags: molecule-idempotence-notest | ||
|
||
- name: Check Nginx configuration directory | ||
stat: | ||
path: /etc/nginx | ||
register: consul_service_nginx_configuration_directory | ||
changed_when: False | ||
|
||
- name: Install nginx so default consul service health check is fine | ||
include_role: | ||
name: nginxinc.nginx | ||
when: not consul_service_nginx_configuration_directory.stat.exists | ||
|
||
roles: | ||
- role: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
dependency: | ||
name: galaxy | ||
options: | ||
force: False | ||
driver: | ||
name: docker | ||
lint: | | ||
set -e | ||
yamllint . | ||
ansible-lint . | ||
flake8 | ||
platforms: | ||
- name: molecule-consul-service-debian11 | ||
image: jrei/systemd-debian:11 | ||
privileged: True | ||
volumes: | ||
- "/sys/fs/cgroup:/sys/fs/cgroup:rw" | ||
cgroupns_mode: host | ||
command: /lib/systemd/systemd | ||
groups: | ||
- molecule_consul_service | ||
provisioner: | ||
name: ansible | ||
log: true | ||
# https://molecule.readthedocs.io/en/latest/configuration.html#molecule.scenario.Scenario | ||
scenario: | ||
converge_sequence: | ||
- dependency | ||
- create | ||
- prepare | ||
- converge | ||
- converge # add a 2nd converge step so we can check if there's 2 maintenances on/off in Consul log | ||
test_sequence: | ||
- dependency | ||
- lint | ||
- cleanup | ||
- destroy | ||
- syntax | ||
- create | ||
- prepare | ||
- converge | ||
- idempotence | ||
- converge # add a 2nd converge step so we can check if there's 2 maintenances on/off in Consul log | ||
- side_effect | ||
- verify | ||
- cleanup | ||
- destroy | ||
verifier: | ||
name: testinfra | ||
options: | ||
tb: short |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
- src: https://github.com/wazo-platform/ansible-role-metadata.git | ||
scm: git | ||
name: wazo.metadata | ||
|
||
- role: brianshumate.consul | ||
- role: nginxinc.nginx |
55 changes: 55 additions & 0 deletions
55
molecule/cooldown_maintenance/tests/test_consul-service.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import os | ||
import pytest | ||
import testinfra.utils.ansible_runner | ||
|
||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( | ||
os.environ["MOLECULE_INVENTORY_FILE"] | ||
).get_hosts("all") | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"name", ["procps"], | ||
) | ||
def test_packages(host, name): | ||
item = host.package(name) | ||
assert item.is_installed | ||
|
||
|
||
def test_user(host): | ||
u = host.user("consul") | ||
assert u.exists | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"path", | ||
[ | ||
"/etc/consul/.consul_bootstrapped", | ||
"/etc/consul/consul.d/nginx.service.json", | ||
"/etc/systemd/system/consul-maint-before-shutdown.service", | ||
], | ||
) | ||
def test_files(host, path): | ||
with host.sudo(): | ||
item = host.file(path) | ||
assert item.exists | ||
|
||
|
||
@pytest.mark.parametrize("name", ["consul"]) | ||
def test_services(host, name): | ||
item = host.service(name) | ||
assert item.is_running | ||
assert item.is_enabled | ||
|
||
|
||
def test_service_file_content(host): | ||
with host.sudo(): | ||
service = host.file( | ||
"/etc/consul/consul.d/nginx.service.json" | ||
).content_string | ||
assert "testtag" in service | ||
assert "published" in service | ||
assert '"URL"' in service | ||
assert '"URL2"' not in service | ||
assert '"URL3"' not in service | ||
assert '"URL4"' in service | ||
assert '"URL5"' not in service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters