diff --git a/lib/ansible/modules/network/eos/eos_system.py b/lib/ansible/modules/network/eos/eos_system.py index 3f9cd04667a..b1d1cd88c3c 100644 --- a/lib/ansible/modules/network/eos/eos_system.py +++ b/lib/ansible/modules/network/eos/eos_system.py @@ -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) diff --git a/test/integration/eos.yaml b/test/integration/eos.yaml index 9658a853d45..71aaa274e7a 100644 --- a/test/integration/eos.yaml +++ b/test/integration/eos.yaml @@ -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']" } diff --git a/test/integration/targets/eos_system/meta/main.yml b/test/integration/targets/eos_system/meta/main.yml new file mode 100644 index 00000000000..e5c8cd02f04 --- /dev/null +++ b/test/integration/targets/eos_system/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - prepare_eos_tests diff --git a/test/integration/targets/eos_system/tasks/cli.yaml b/test/integration/targets/eos_system/tasks/cli.yaml new file mode 100644 index 00000000000..d675462dd02 --- /dev/null +++ b/test/integration/targets/eos_system/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_system/tasks/eapi.yaml b/test/integration/targets/eos_system/tasks/eapi.yaml new file mode 100644 index 00000000000..26c247320b2 --- /dev/null +++ b/test/integration/targets/eos_system/tasks/eapi.yaml @@ -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 }}" diff --git a/test/integration/targets/eos_system/tasks/main.yaml b/test/integration/targets/eos_system/tasks/main.yaml new file mode 100644 index 00000000000..970e74171ea --- /dev/null +++ b/test/integration/targets/eos_system/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- { include: cli.yaml, tags: ['cli'] } +- { include: eapi.yaml, tags: ['eapi'] } diff --git a/test/integration/targets/eos_system/tests/cli/set_domain_list.yaml b/test/integration/targets/eos_system/tests/cli/set_domain_list.yaml new file mode 100644 index 00000000000..b605c3097f6 --- /dev/null +++ b/test/integration/targets/eos_system/tests/cli/set_domain_list.yaml @@ -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" diff --git a/test/integration/targets/eos_system/tests/cli/set_domain_name.yaml b/test/integration/targets/eos_system/tests/cli/set_domain_name.yaml new file mode 100644 index 00000000000..ecaa4668a61 --- /dev/null +++ b/test/integration/targets/eos_system/tests/cli/set_domain_name.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" diff --git a/test/integration/targets/eos_system/tests/cli/set_hostname.yaml b/test/integration/targets/eos_system/tests/cli/set_hostname.yaml new file mode 100644 index 00000000000..db80a97b3c9 --- /dev/null +++ b/test/integration/targets/eos_system/tests/cli/set_hostname.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" diff --git a/test/integration/targets/eos_system/tests/cli/set_lookup_source.yaml b/test/integration/targets/eos_system/tests/cli/set_lookup_source.yaml new file mode 100644 index 00000000000..9e653677262 --- /dev/null +++ b/test/integration/targets/eos_system/tests/cli/set_lookup_source.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" diff --git a/test/integration/targets/eos_system/tests/cli/set_name_servers.yaml b/test/integration/targets/eos_system/tests/cli/set_name_servers.yaml new file mode 100644 index 00000000000..bdd3d17c487 --- /dev/null +++ b/test/integration/targets/eos_system/tests/cli/set_name_servers.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" diff --git a/test/integration/targets/eos_system/tests/eapi/set_domain_list.yaml b/test/integration/targets/eos_system/tests/eapi/set_domain_list.yaml new file mode 100644 index 00000000000..80020c34352 --- /dev/null +++ b/test/integration/targets/eos_system/tests/eapi/set_domain_list.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" diff --git a/test/integration/targets/eos_system/tests/eapi/set_domain_name.yaml b/test/integration/targets/eos_system/tests/eapi/set_domain_name.yaml new file mode 100644 index 00000000000..fedd674e4d9 --- /dev/null +++ b/test/integration/targets/eos_system/tests/eapi/set_domain_name.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" diff --git a/test/integration/targets/eos_system/tests/eapi/set_hostname.yaml b/test/integration/targets/eos_system/tests/eapi/set_hostname.yaml new file mode 100644 index 00000000000..d26d9105b8f --- /dev/null +++ b/test/integration/targets/eos_system/tests/eapi/set_hostname.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" diff --git a/test/integration/targets/eos_system/tests/eapi/set_lookup_source.yaml b/test/integration/targets/eos_system/tests/eapi/set_lookup_source.yaml new file mode 100644 index 00000000000..57399004dfd --- /dev/null +++ b/test/integration/targets/eos_system/tests/eapi/set_lookup_source.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" diff --git a/test/integration/targets/eos_system/tests/eapi/set_name_servers.yaml b/test/integration/targets/eos_system/tests/eapi/set_name_servers.yaml new file mode 100644 index 00000000000..19822591c55 --- /dev/null +++ b/test/integration/targets/eos_system/tests/eapi/set_name_servers.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" diff --git a/test/units/modules/network/eos/test_eos_system.py b/test/units/modules/network/eos/test_eos_system.py index 80937aa362f..1c832ca8962 100644 --- a/test/units/modules/network/eos/test_eos_system.py +++ b/test/units/modules/network/eos/test_eos_system.py @@ -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'))