From 5dac2ee00cb04cd55667dcb266a76fafbacc60d5 Mon Sep 17 00:00:00 2001 From: John R Barker Date: Fri, 10 Mar 2017 15:20:09 +0000 Subject: [PATCH] Test eos_banner (#22201) * eos_banner docs improvements * run eos_banner tests * basic eos_banner tests * remove trailing newlines * remove hack * Various eos_banner fixes No unicode tests, as the device doesn't support it Correctly set provider result.command should be empty list if no changes * test eos_banner over eapi * revert docs changes, moved to separate PR --- test/integration/eos.yaml | 1 + .../targets/eos_banner/defaults/main.yaml | 2 + .../targets/eos_banner/meta/main.yml | 2 + .../targets/eos_banner/tasks/cli.yaml | 15 +++++ .../targets/eos_banner/tasks/main.yaml | 3 + .../eos_banner/tests/cli/basic-login.yaml | 55 +++++++++++++++++++ .../eos_banner/tests/cli/basic-motd.yaml | 54 ++++++++++++++++++ .../eos_banner/tests/cli/basic-no-login.yaml | 48 ++++++++++++++++ 8 files changed, 180 insertions(+) create mode 100644 test/integration/targets/eos_banner/defaults/main.yaml create mode 100644 test/integration/targets/eos_banner/meta/main.yml create mode 100644 test/integration/targets/eos_banner/tasks/cli.yaml create mode 100644 test/integration/targets/eos_banner/tasks/main.yaml create mode 100644 test/integration/targets/eos_banner/tests/cli/basic-login.yaml create mode 100644 test/integration/targets/eos_banner/tests/cli/basic-motd.yaml create mode 100644 test/integration/targets/eos_banner/tests/cli/basic-no-login.yaml diff --git a/test/integration/eos.yaml b/test/integration/eos.yaml index 71aaa274e7..21d7d6a6c5 100644 --- a/test/integration/eos.yaml +++ b/test/integration/eos.yaml @@ -8,6 +8,7 @@ debug: false roles: + - { role: eos_banner, when: "limit_to in ['*', 'eos_banner']" } - { role: eos_command, when: "limit_to in ['*', 'eos_command']" } - { role: eos_config, when: "limit_to in ['*', 'eos_config']" } - { role: eos_template, when: "limit_to in ['*', 'eos_template']" } diff --git a/test/integration/targets/eos_banner/defaults/main.yaml b/test/integration/targets/eos_banner/defaults/main.yaml new file mode 100644 index 0000000000..5f709c5aac --- /dev/null +++ b/test/integration/targets/eos_banner/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: "*" diff --git a/test/integration/targets/eos_banner/meta/main.yml b/test/integration/targets/eos_banner/meta/main.yml new file mode 100644 index 0000000000..e5c8cd02f0 --- /dev/null +++ b/test/integration/targets/eos_banner/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - prepare_eos_tests diff --git a/test/integration/targets/eos_banner/tasks/cli.yaml b/test/integration/targets/eos_banner/tasks/cli.yaml new file mode 100644 index 0000000000..d675462dd0 --- /dev/null +++ b/test/integration/targets/eos_banner/tasks/cli.yaml @@ -0,0 +1,15 @@ +--- +- name: collect all cli test cases + find: + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" + register: test_cases + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test case + include: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/eos_banner/tasks/main.yaml b/test/integration/targets/eos_banner/tasks/main.yaml new file mode 100644 index 0000000000..970e74171e --- /dev/null +++ b/test/integration/targets/eos_banner/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- { include: cli.yaml, tags: ['cli'] } +- { include: eapi.yaml, tags: ['eapi'] } diff --git a/test/integration/targets/eos_banner/tests/cli/basic-login.yaml b/test/integration/targets/eos_banner/tests/cli/basic-login.yaml new file mode 100644 index 0000000000..670e09574b --- /dev/null +++ b/test/integration/targets/eos_banner/tests/cli/basic-login.yaml @@ -0,0 +1,55 @@ +--- + +- name: setup - remove login + eos_banner: + banner: login + state: absent + authorize: yes + provider: "{{ cli }}" + +- name: Set login + eos_banner: + banner: login + text: | + this is my login banner + that has a multiline + string + state: present + authorize: yes + provider: "{{ cli }}" + register: result + +- debug: + msg: "{{ result }}" + +- assert: + that: + - "result.changed == true" + - "'this is my login banner' in result.commands" + - "'that has a multiline' in result.commands" + # Ensure sessions contains epoc. Will fail after 18th May 2033 + - "'ansible_1' in result.session_name" + +- name: Set login again (idempotent) + eos_banner: + banner: login + text: | + this is my login banner + that has a multiline + string + state: present + authorize: yes + provider: "{{ cli }}" + register: result + +- assert: + that: + - "result.changed == false" + - "result.commands | length == 0" + # Ensure sessions contains epoc. Will fail after 18th May 2033 + - "result.session_name is not defined" + + +# FIXME add in tests for everything defined in docs +# FIXME Test state:absent + test: +# FIXME Without powers ensure "privileged mode required" diff --git a/test/integration/targets/eos_banner/tests/cli/basic-motd.yaml b/test/integration/targets/eos_banner/tests/cli/basic-motd.yaml new file mode 100644 index 0000000000..fab2d26ff6 --- /dev/null +++ b/test/integration/targets/eos_banner/tests/cli/basic-motd.yaml @@ -0,0 +1,54 @@ +--- + +- name: setup - remove motd + eos_banner: + banner: motd + state: absent + authorize: yes + +- name: Set motd + eos_banner: + banner: motd + text: | + this is my motd banner + that has a multiline + string + state: present + authorize: yes + provider: "{{ cli }}" + register: result + +- debug: + msg: "{{ result }}" + +- assert: + that: + - "result.changed == true" + - "'this is my motd banner' in result.commands" + - "'that has a multiline' in result.commands" + # Ensure sessions contains epoc. Will fail after 18th May 2033 + - "'ansible_1' in result.session_name" + +- name: Set motd again (idempotent) + eos_banner: + banner: motd + text: | + this is my motd banner + that has a multiline + string + state: present + authorize: yes + provider: "{{ cli }}" + register: result + +- assert: + that: + - "result.changed == false" + - "result.commands | length == 0" + # Ensure sessions contains epoc. Will fail after 18th May 2033 + - "result.session_name is not defined" + + +# FIXME add in tests for everything defined in docs +# FIXME Test state:absent + test: +# FIXME Without powers ensure "privileged mode required" diff --git a/test/integration/targets/eos_banner/tests/cli/basic-no-login.yaml b/test/integration/targets/eos_banner/tests/cli/basic-no-login.yaml new file mode 100644 index 0000000000..c34afb7d9d --- /dev/null +++ b/test/integration/targets/eos_banner/tests/cli/basic-no-login.yaml @@ -0,0 +1,48 @@ +--- +- name: Setup + eos_banner: + banner: login + text: | + Junk login banner + over multiple lines + state: present + authorize: yes + provider: "{{ cli }}" + +- name: remove login + eos_banner: + banner: login + state: absent + authorize: yes + provider: "{{ cli }}" + register: result + +- debug: + msg: "{{ result }}" + +- assert: + that: + - "result.changed == true" + - "'no banner login' in result.commands" # does this break due to "contains?" + # Ensure sessions contains epoc. Will fail after 18th May 2033 + - "'ansible_1' in result.session_name" + +- name: remove login (idempotent) + eos_banner: + banner: login + state: absent + authorize: yes + provider: "{{ cli }}" + register: result + +- assert: + that: + - "result.changed == false" + - "result.commands | length == 0" + # Ensure sessions contains epoc. Will fail after 18th May 2033 + - "result.session_name is not defined" + + +# FIXME add in tests for everything defined in docs +# FIXME Test state:absent + test: +# FIXME Without powers ensure "privileged mode required"