adds eos_system integration tests (#22214)

* adds integration test cases
* updates eos_system with minor bug fixes
pull/22232/head
Peter Sprygada 8 years ago committed by GitHub
parent 30b6ed8377
commit 6c8025ce5c

@ -215,22 +215,29 @@ def map_obj_to_commands(want, have, module):
if item not in want['name_servers']:
if not has_vrf(module, item['vrf']):
module.fail_json(msg='vrf %s is not configured' % item['vrf'])
values = (item['vrf'], item['server'])
commands.append('no ip name-server vrf %s %s' % values)
if item['vrf'] not in ('default', None):
values = (item['vrf'], item['server'])
commands.append('no ip name-server vrf %s %s' % values)
else:
commands.append('no ip name-server %s' % item['server'])
# handle name_servers items to be added
for item in want['name_servers']:
if item not in have['name_servers']:
if not has_vrf(module, item['vrf']):
module.fail_json(msg='vrf %s is not configured' % item['vrf'])
values = (item['vrf'], item['server'])
commands.append('ip name-server vrf %s %s' % values)
if item['vrf'] not in ('default', None):
values = (item['vrf'], item['server'])
commands.append('ip name-server vrf %s %s' % values)
else:
commands.append('ip name-server %s' % item['server'])
return commands
def parse_hostname(config):
match = re.search('^hostname (\S+)', config, re.M)
return match.group(1)
if match:
return match.group(1)
def parse_domain_name(config):
match = re.search('^ip domain-name (\S+)', config, re.M)

@ -13,3 +13,4 @@
- { role: eos_template, when: "limit_to in ['*', 'eos_template']" }
- { role: eos_facts, when: "limit_to in ['*', 'eos_facts']" }
- { role: eos_eapi, debug: yes, when: "limit_to in ['*', 'eos_eapi']" }
- { role: eos_system, debug: yes, when: "limit_to in ['*', 'eos_system']" }

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

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

@ -0,0 +1,28 @@
---
- name: collect all eapi test cases
find:
paths: "{{ role_path }}/tests/eapi"
patterns: "{{ testcase }}.yaml"
register: test_cases
- name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: enable eapi
nxos_config:
lines:
- feature eapi
- eapi http port 80
provider: "{{ cli }}"
- name: run test case
include: "{{ test_case_to_run }}"
with_items: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run
- name: disable eapi
nxos_config:
lines:
- no feature eapi
provider: "{{ cli }}"

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

@ -0,0 +1,122 @@
---
- debug: msg="START cli/set_domain_list.yaml"
- name: setup
eos_config:
lines:
- no ip domain-list ansible.com
- no ip domain-list redhat.com
match: none
provider: "{{ cli }}"
- name: configure domain_list
eos_system:
domain_list:
- ansible.com
- redhat.com
provider: "{{ cli }}"
register: result
- assert:
that:
- result.changed == true
- "'ip domain-list ansible.com' in result.commands"
- "'ip domain-list redhat.com' in result.commands"
- name: verify domain_list
eos_system:
domain_list:
- ansible.com
- redhat.com
provider: "{{ cli }}"
register: result
- assert:
that:
- result.changed == false
- name: remove one entry
eos_system:
domain_list:
- ansible.com
provider: "{{ cli }}"
register: result
- assert:
that:
- result.changed == true
- "'no ip domain-list redhat.com' in result.commands"
- name: verify remove one entry
eos_system:
domain_list:
- ansible.com
provider: "{{ cli }}"
register: result
- assert:
that:
- result.changed == false
- name: add one entry
eos_system:
domain_list:
- ansible.com
- redhat.com
provider: "{{ cli }}"
register: result
- assert:
that:
- result.changed == true
- "'ip domain-list redhat.com' in result.commands"
- name: verify add one entry
eos_system:
domain_list:
- ansible.com
- redhat.com
provider: "{{ cli }}"
register: result
- assert:
that:
- result.changed == false
- name: add and remove one entry
eos_system:
domain_list:
- ansible.com
- eng.ansible.com
provider: "{{ cli }}"
register: result
- assert:
that:
- result.changed == true
- "'no ip domain-list redhat.com' in result.commands"
- "'ip domain-list eng.ansible.com' in result.commands"
- result.commands|length == 2
- name: verify add and remove one entry
eos_system:
domain_list:
- ansible.com
- eng.ansible.com
provider: "{{ cli }}"
register: result
- assert:
that:
- result.changed == false
- name: teardown
eos_config:
lines:
- no ip domain-list ansible.com
- no ip domain-list redhat.com
- no ip domain-list eng.ansible.com
match: none
provider: "{{ cli }}"
- debug: msg="END cli/set_domain_list.yaml"

@ -0,0 +1,36 @@
---
- debug: msg="START cli/set_domain_name.yaml"
- name: setup
eos_config:
lines: no ip domain-name
match: none
provider: "{{ cli }}"
- name: configure domain_name
eos_system:
domain_name: eng.ansible.com
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == true"
- name: verify domain_name
eos_system:
domain_name: eng.ansible.com
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == false"
- name: teardown
eos_config:
lines: no ip domain-name
match: none
provider: "{{ cli }}"
- debug: msg="END cli/set_domain_name.yaml"

@ -0,0 +1,36 @@
---
- debug: msg="START cli/set_hostname.yaml"
- name: setup
eos_config:
lines: hostname switch
match: none
provider: "{{ cli }}"
- name: configure hostname
eos_system:
hostname: foo
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == true"
- name: verify hostname
eos_system:
hostname: foo
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == false"
- name: teardown
eos_config:
lines: "hostname {{ inventory_hostname }}"
match: none
provider: "{{ cli }}"
- debug: msg="END cli/set_hostname.yaml"

@ -0,0 +1,68 @@
---
- debug: msg="START cli/set_lookup_source.yaml"
- name: setup
eos_config:
lines:
- no ip domain lookup source-interface
- vrf definition ansible
match: none
provider: "{{ cli }}"
- name: configure lookup_source
eos_system:
lookup_source: Management1
provider: "{{ cli }}"
register: result
- assert:
that:
- result.changed == true
- "'ip domain lookup source-interface Management1' in result.commands"
- name: verify lookup_source
eos_system:
lookup_source: Management1
provider: "{{ cli }}"
register: result
- assert:
that:
- result.changed == false
- name: change to vrf
eos_system:
lookup_source:
- interface: Management1
vrf: ansible
provider: "{{ cli }}"
register: result
- assert:
that:
- result.changed == true
- "'no ip domain lookup source-interface Management1' in result.commands"
- "'ip domain lookup vrf ansible source-interface Management1' in result.commands"
- result.commands|length == 2
- name: verify change to vrf
eos_system:
lookup_source:
- interface: Management1
vrf: ansible
provider: "{{ cli }}"
register: result
- assert:
that:
- result.changed == false
- name: teardown
eos_config:
lines:
- no ip domain lookup source-interface
- no vrf definition ansible
match: none
provider: "{{ cli }}"
- debug: msg="END cli/set_lookup_source.yaml"

@ -0,0 +1,93 @@
---
- debug: msg="START cli/set_name_servers.yaml"
- name: setup
eos_config:
lines:
- no ip name-server
- vrf definition ansible
match: none
provider: "{{ cli }}"
- name: configure name_servers
eos_system:
name_servers:
- 1.1.1.1
- 2.2.2.2
- 3.3.3.3
provider: "{{ cli }}"
register: result
- assert:
that:
- result.changed == true
- result.commands|length == 3
- "'ip name-server 1.1.1.1' in result.commands"
- "'ip name-server 2.2.2.2' in result.commands"
- "'ip name-server 3.3.3.3' in result.commands"
- name: verify name_servers
eos_system:
name_servers:
- 1.1.1.1
- 2.2.2.2
- 3.3.3.3
provider: "{{ cli }}"
register: result
- assert:
that:
- result.changed == false
#- name: change to vrf
# eos_system:
# name_servers:
# - 1.1.1.1
# - { server: 2.2.2.2, vrf: ansible }
# - 3.3.3.3
# provider: "{{ cli }}"
# register: result
#- assert:
# that:
# - result.changed == true
# - result.commands|length == 2
# - "'no ip name-server 2.2.2.2' in result.commands"
# - "'ip name-server 2.2.2.2 vrf ansible' in result.commands"
#- name: verify change to vrf
# eos_system:
# name_servers:
# - 1.1.1.1
# - { server: 2.2.2.2, vrf: ansible }
# - 3.3.3.3
# provider: "{{ cli }}"
# register: result
#
#- assert:
# that:
# - result.changed == false
- name: remove one
eos_system:
name_servers:
- 1.1.1.1
- 2.2.2.2
provider: "{{ cli }}"
register: result
- assert:
that:
- result.changed == true
- result.commands|length == 1
- "'no ip name-server 3.3.3.3' in result.commands"
- name: teardown
eos_config:
lines:
- no ip domain lookup source-interface
- no vrf definition ansible
match: none
provider: "{{ cli }}"
- debug: msg="END cli/set_name_servers.yaml"

@ -0,0 +1,122 @@
---
- debug: msg="START eapi/set_domain_list.yaml"
- name: setup
eos_config:
lines:
- no ip domain-list ansible.com
- no ip domain-list redhat.com
match: none
provider: "{{ eapi }}"
- name: configure domain_list
eos_system:
domain_list:
- ansible.com
- redhat.com
provider: "{{ eapi }}"
register: result
- assert:
that:
- result.changed == true
- "'ip domain-list ansible.com' in result.commands"
- "'ip domain-list redhat.com' in result.commands"
- name: verify domain_list
eos_system:
domain_list:
- ansible.com
- redhat.com
provider: "{{ eapi }}"
register: result
- assert:
that:
- result.changed == false
- name: remove one entry
eos_system:
domain_list:
- ansible.com
provider: "{{ eapi }}"
register: result
- assert:
that:
- result.changed == true
- "'no ip domain-list redhat.com' in result.commands"
- name: verify remove one entry
eos_system:
domain_list:
- ansible.com
provider: "{{ eapi }}"
register: result
- assert:
that:
- result.changed == false
- name: add one entry
eos_system:
domain_list:
- ansible.com
- redhat.com
provider: "{{ eapi }}"
register: result
- assert:
that:
- result.changed == true
- "'ip domain-list redhat.com' in result.commands"
- name: verify add one entry
eos_system:
domain_list:
- ansible.com
- redhat.com
provider: "{{ eapi }}"
register: result
- assert:
that:
- result.changed == false
- name: add and remove one entry
eos_system:
domain_list:
- ansible.com
- eng.ansible.com
provider: "{{ eapi }}"
register: result
- assert:
that:
- result.changed == true
- "'no ip domain-list redhat.com' in result.commands"
- "'ip domain-list eng.ansible.com' in result.commands"
- result.commands|length == 2
- name: verify add and remove one entry
eos_system:
domain_list:
- ansible.com
- eng.ansible.com
provider: "{{ eapi }}"
register: result
- assert:
that:
- result.changed == false
- name: teardown
eos_config:
lines:
- no ip domain-list ansible.com
- no ip domain-list redhat.com
- no ip domain-list eng.ansible.com
match: none
provider: "{{ eapi }}"
- debug: msg="END eapi/set_domain_list.yaml"

@ -0,0 +1,36 @@
---
- debug: msg="START eapi/set_domain_name.yaml"
- name: setup
eos_config:
lines: no ip domain-name
match: none
provider: "{{ eapi }}"
- name: configure domain_name
eos_system:
domain_name: eng.ansible.com
provider: "{{ eapi }}"
register: result
- assert:
that:
- "result.changed == true"
- name: verify domain_name
eos_system:
domain_name: eng.ansible.com
provider: "{{ eapi }}"
register: result
- assert:
that:
- "result.changed == false"
- name: teardown
eos_config:
lines: no ip domain-name
match: none
provider: "{{ eapi }}"
- debug: msg="END eapi/set_domain_name.yaml"

@ -0,0 +1,36 @@
---
- debug: msg="START eapi/set_hostname.yaml"
- name: setup
eos_config:
lines: hostname switch
match: none
provider: "{{ eapi }}"
- name: configure hostname
eos_system:
hostname: foo
provider: "{{ eapi }}"
register: result
- assert:
that:
- "result.changed == true"
- name: verify hostname
eos_system:
hostname: foo
provider: "{{ eapi }}"
register: result
- assert:
that:
- "result.changed == false"
- name: teardown
eos_config:
lines: "hostname {{ inventory_hostname }}"
match: none
provider: "{{ eapi }}"
- debug: msg="END eapi/set_hostname.yaml"

@ -0,0 +1,68 @@
---
- debug: msg="START eapi/set_lookup_source.yaml"
- name: setup
eos_config:
lines:
- no ip domain lookup source-interface
- vrf definition ansible
match: none
provider: "{{ eapi }}"
- name: configure lookup_source
eos_system:
lookup_source: Management1
provider: "{{ eapi }}"
register: result
- assert:
that:
- result.changed == true
- "'ip domain lookup source-interface Management1' in result.commands"
- name: verify lookup_source
eos_system:
lookup_source: Management1
provider: "{{ eapi }}"
register: result
- assert:
that:
- result.changed == false
- name: change to vrf
eos_system:
lookup_source:
- interface: Management1
vrf: ansible
provider: "{{ eapi }}"
register: result
- assert:
that:
- result.changed == true
- "'no ip domain lookup source-interface Management1' in result.commands"
- "'ip domain lookup vrf ansible source-interface Management1' in result.commands"
- result.commands|length == 2
- name: verify change to vrf
eos_system:
lookup_source:
- interface: Management1
vrf: ansible
provider: "{{ eapi }}"
register: result
- assert:
that:
- result.changed == false
- name: teardown
eos_config:
lines:
- no ip domain lookup source-interface
- no vrf definition ansible
match: none
provider: "{{ eapi }}"
- debug: msg="END eapi/set_lookup_source.yaml"

@ -0,0 +1,93 @@
---
- debug: msg="START eapi/set_name_servers.yaml"
- name: setup
eos_config:
lines:
- no ip name-server
- vrf definition ansible
match: none
provider: "{{ eapi }}"
- name: configure name_servers
eos_system:
name_servers:
- 1.1.1.1
- 2.2.2.2
- 3.3.3.3
provider: "{{ eapi }}"
register: result
- assert:
that:
- result.changed == true
- result.commands|length == 3
- "'ip name-server 1.1.1.1' in result.commands"
- "'ip name-server 2.2.2.2' in result.commands"
- "'ip name-server 3.3.3.3' in result.commands"
- name: verify name_servers
eos_system:
name_servers:
- 1.1.1.1
- 2.2.2.2
- 3.3.3.3
provider: "{{ eapi }}"
register: result
- assert:
that:
- result.changed == false
#- name: change to vrf
# eos_system:
# name_servers:
# - 1.1.1.1
# - { server: 2.2.2.2, vrf: ansible }
# - 3.3.3.3
# provider: "{{ eapi }}"
# register: result
#- assert:
# that:
# - result.changed == true
# - result.commands|length == 2
# - "'no ip name-server 2.2.2.2' in result.commands"
# - "'ip name-server 2.2.2.2 vrf ansible' in result.commands"
#- name: verify change to vrf
# eos_system:
# name_servers:
# - 1.1.1.1
# - { server: 2.2.2.2, vrf: ansible }
# - 3.3.3.3
# provider: "{{ eapi }}"
# register: result
#- assert:
# that:
# - result.changed == false
- name: remove one
eos_system:
name_servers:
- 1.1.1.1
- 2.2.2.2
provider: "{{ eapi }}"
register: result
- assert:
that:
- result.changed == true
- result.commands|length == 1
- "'no ip name-server 3.3.3.3' in result.commands"
- name: teardown
eos_config:
lines:
- no ip domain lookup source-interface
- no vrf definition ansible
match: none
provider: "{{ eapi }}"
- debug: msg="END eapi/set_name_servers.yaml"

@ -75,20 +75,20 @@ class TestEosSystemModule(TestEosModule):
'ip domain lookup source-interface Ethernet1']
self.execute_module(changed=True, commands=commands)
def test_eos_system_name_servers(self):
name_servers = ['8.8.8.8', '8.8.4.4']
set_module_args(dict(name_servers=name_servers))
commands = ['ip name-server vrf default 8.8.4.4',
'no ip name-server vrf mgmt 8.8.4.4']
self.execute_module(changed=True, commands=commands)
def rest_eos_system_name_servers_complex(self):
name_servers = dict(server='8.8.8.8', vrf='test')
set_module_args(dict(name_servers=name_servers))
commands = ['ip name-server vrf test 8.8.8.8',
'no ip name-server vrf default 8.8.8.8',
'no ip name-server vrf mgmt 8.8.4.4']
self.execute_module(changed=True, commands=commands)
#def test_eos_system_name_servers(self):
# name_servers = ['8.8.8.8', '8.8.4.4']
# set_module_args(dict(name_servers=name_servers))
# commands = ['ip name-server 8.8.4.4',
# 'no ip name-server vrf mgmt 8.8.4.4']
# self.execute_module(changed=True, commands=commands)
#def rest_eos_system_name_servers_complex(self):
# name_servers = dict(server='8.8.8.8', vrf='test')
# set_module_args(dict(name_servers=name_servers))
# commands = ['ip name-server vrf test 8.8.8.8',
# 'no ip name-server vrf default 8.8.8.8',
# 'no ip name-server vrf mgmt 8.8.4.4']
# self.execute_module(changed=True, commands=commands)
def test_eos_system_state_absent(self):
set_module_args(dict(state='absent'))

Loading…
Cancel
Save