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
This commit is contained in:
John R Barker 2017-03-10 15:20:09 +00:00 committed by GitHub
parent 9173a7727c
commit 5dac2ee00c
8 changed files with 180 additions and 0 deletions

View file

@ -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']" }

View file

@ -0,0 +1,2 @@
---
testcase: "*"

View file

@ -0,0 +1,2 @@
dependencies:
- prepare_eos_tests

View file

@ -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

View file

@ -0,0 +1,3 @@
---
- { include: cli.yaml, tags: ['cli'] }
- { include: eapi.yaml, tags: ['eapi'] }

View file

@ -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"

View file

@ -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"

View file

@ -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"