From 1d342ef0377abfb563d7692cdb3eb7356b03da3c Mon Sep 17 00:00:00 2001 From: Till Maas Date: Sun, 26 May 2019 09:46:14 +0200 Subject: [PATCH] tests: Test volatile state changes --- tests/ensure_non_running_provider.py | 2 +- tests/playbooks/tasks | 1 + tests/playbooks/tests_states.yml | 49 ++++++++++++++++++++++++++++ tests/tests_states.yml | 11 +++++++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 120000 tests/playbooks/tasks create mode 100644 tests/playbooks/tests_states.yml create mode 100644 tests/tests_states.yml diff --git a/tests/ensure_non_running_provider.py b/tests/ensure_non_running_provider.py index c6a6eef..0925797 100755 --- a/tests/ensure_non_running_provider.py +++ b/tests/ensure_non_running_provider.py @@ -13,7 +13,7 @@ import yaml OTHER_PROVIDER_SUFFIX = "_other_provider.yml" -IGNORE = ["tests_unit.yml", "tests_helpers-and-asserts.yml"] +IGNORE = ["tests_unit.yml", "tests_helpers-and-asserts.yml", "tests_states.yml"] OTHER_PLAYBOOK = """ # SPDX-License-Identifier: BSD-3-Clause diff --git a/tests/playbooks/tasks b/tests/playbooks/tasks new file mode 120000 index 0000000..93c76d6 --- /dev/null +++ b/tests/playbooks/tasks @@ -0,0 +1 @@ +../tasks/ \ No newline at end of file diff --git a/tests/playbooks/tests_states.yml b/tests/playbooks/tests_states.yml new file mode 100644 index 0000000..7a1e207 --- /dev/null +++ b/tests/playbooks/tests_states.yml @@ -0,0 +1,49 @@ +# SPDX-License-Identifier: BSD-3-Clause +--- +- hosts: all + vars: + interface: statebr + profile: "{{ interface }}" + network_provider: nm + tasks: + - debug: + msg: Inside states tests + - include_tasks: tasks/show-interfaces.yml + - include_tasks: tasks/assert-device_absent.yml + + # create test profile + - include_role: + name: linux-system-roles.network + vars: + network_connections: + - name: statebr + state: up + type: bridge + ip: + dhcp4: false + auto6: false + - include_tasks: tasks/assert-device_present.yml + - include_tasks: tasks/assert-profile_present.yml + + # test case (remove profile but keep it up) + # I can remove a profile but keep the configuration active. + - include_role: + name: linux-system-roles.network + vars: + network_connections: + - name: statebr + persistent_state: absent + - include_tasks: tasks/assert-device_present.yml + - include_tasks: tasks/assert-profile_absent.yml + + # test case + # I can set a profile down that is up and absent. + - name: Set down + include_role: + name: linux-system-roles.network + vars: + network_connections: + - name: statebr + state: down + - include_tasks: tasks/assert-device_absent.yml + - include_tasks: tasks/assert-profile_absent.yml diff --git a/tests/tests_states.yml b/tests/tests_states.yml new file mode 100644 index 0000000..eff3436 --- /dev/null +++ b/tests/tests_states.yml @@ -0,0 +1,11 @@ +--- +# empty playbook to gather facts for import_playbook when clause +- hosts: all + +# workaround for: https://github.com/ansible/ansible/issues/27973 +# There is no way in Ansible to abort a playbook hosts with specific OS +# releases Therefore we include the playbook with the tests only if the hosts +# would support it. +# The test requires NetworkManager, therefore it cannot run on RHEL 6 or CentOS 6. +- import_playbook: playbooks/tests_states.yml + when: ansible_distribution_major_version != '6'