mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-22 03:53:59 -07:00
Platform agnostic net_system module (#24953)
* Platform agnostic net_system module Also refactor the action network plugins for better code re-use Still more refactoring to do once the connection plugin work is complete * Replace importlib for imp importlib is not available on 2.6, so we need to stick to imp * Load action plugin via module metadata * Better error message if no implementation is found Now the plugin will show the module name and the network OS in the error message * Fix typo on documentation author line * Fix pep8 issues * Add missing options key on doc string and stringify version * Return None in case module has no metadata * Read module metadata only if it's a python module Check for module suffix, if it's .py then read metadata. Otherwise this fails on non-python modules, like Windows PS for example. * Read metadata variable only if it's a python module Fix referencing a variable before assignment * Add action_handler to validate_modules metadata schema * Pull metadata with plugin_docs get_docstring Using load_source from PluginLoader is troublesome, it is not guaranteed a module may be importable at the controller, e.g. if a module depends on module_utils functions it won't work, because module_utils is not in the sys path. Rather than putting that module dependencies introspection, just use plain parsing like plugin_docs get_docstring does as we only care about reading ANSIBLE_METADATA. * Add platform agnostic group of groups for integration tests This will be the target for platform agnostic integration tests. * Add integration tests for net_system * Switch to action plugin inheritance from metadata driven action handler As the metadata action driven action handler work is being worked on on its standalone proposal+PR, let's just go back to have one action handler per platform agnostic module. Those action plugins will inherit from net_base. * Add blank line to fix pep8 * Add aliases file to net_system integration test This will avoid CI failure * Fix integration tests for net_system * Give more precedence to task network_os over inventory network_os
This commit is contained in:
parent
2ee2c8c1ab
commit
64add28657
20 changed files with 674 additions and 6 deletions
|
@ -5,27 +5,27 @@ ansible_python_interpreter=python
|
|||
|
||||
[eos]
|
||||
#veos-dut-01
|
||||
veos01
|
||||
veos01 ansible_network_os=eos
|
||||
|
||||
|
||||
[nxos]
|
||||
nxos01
|
||||
nxos01 ansible_network_os=nxos
|
||||
|
||||
[iosxr]
|
||||
iosxr01
|
||||
iosxr01 ansible_network_os=iosxr
|
||||
|
||||
[ios]
|
||||
ios01
|
||||
ios01 ansible_network_os=ios
|
||||
#csr01
|
||||
|
||||
[junos]
|
||||
vsrx01
|
||||
vsrx01 ansible_network_os=junos
|
||||
|
||||
[cumulus]
|
||||
clvx01
|
||||
|
||||
[vyos]
|
||||
vyos-dut-01
|
||||
vyos01 ansible_network_os=vyos
|
||||
|
||||
[ops]
|
||||
ops01
|
||||
|
@ -33,4 +33,12 @@ ops01
|
|||
[asa]
|
||||
asa01
|
||||
|
||||
[platform_agnostic:children]
|
||||
ios
|
||||
iosxr
|
||||
eos
|
||||
junos
|
||||
vyos
|
||||
nxos
|
||||
|
||||
# vim: nospell filetype=dosini
|
||||
|
|
11
test/integration/platform_agnostic.yaml
Normal file
11
test/integration/platform_agnostic.yaml
Normal file
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
- hosts: platform_agnostic
|
||||
gather_facts: no
|
||||
connection: local
|
||||
|
||||
vars:
|
||||
limit_to: "*"
|
||||
debug: false
|
||||
|
||||
roles:
|
||||
- { role: net_system, when: "limit_to in ['*', 'net_system']" }
|
2
test/integration/targets/net_system/aliases
Normal file
2
test/integration/targets/net_system/aliases
Normal file
|
@ -0,0 +1,2 @@
|
|||
network/ci
|
||||
skip/python3
|
2
test/integration/targets/net_system/defaults/main.yaml
Normal file
2
test/integration/targets/net_system/defaults/main.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
testcase: "*"
|
16
test/integration/targets/net_system/tasks/cli.yaml
Normal file
16
test/integration/targets/net_system/tasks/cli.yaml
Normal file
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
- name: collect all cli test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/cli"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
register: test_cases
|
||||
delegate_to: localhost
|
||||
|
||||
- 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
|
2
test/integration/targets/net_system/tasks/main.yaml
Normal file
2
test/integration/targets/net_system/tasks/main.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
- debug: msg="START cli/set_name_servers.yaml"
|
||||
|
||||
- include: "{{ role_path }}/tests/ios/set_name_servers.yaml"
|
||||
when: hostvars[inventory_hostname]['ansible_network_os'] == 'ios'
|
||||
|
||||
- include: "{{ role_path }}/tests/iosxr/set_name_servers.yaml"
|
||||
when: hostvars[inventory_hostname]['ansible_network_os'] == 'iosxr'
|
||||
|
||||
- include: "{{ role_path }}/tests/nxos/set_name_servers.yaml"
|
||||
when: hostvars[inventory_hostname]['ansible_network_os'] == 'nxos'
|
||||
|
||||
- include: "{{ role_path }}/tests/eos/set_name_servers.yaml"
|
||||
when: hostvars[inventory_hostname]['ansible_network_os'] == 'eos'
|
||||
|
||||
- debug: msg="END cli/set_name_servers.yaml"
|
|
@ -0,0 +1,64 @@
|
|||
---
|
||||
- debug: msg="START eos/set_name_servers.yaml"
|
||||
|
||||
- name: setup
|
||||
eos_config:
|
||||
lines:
|
||||
- no ip name-server
|
||||
- vrf definition ansible
|
||||
match: none
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- name: configure name_servers
|
||||
net_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
|
||||
net_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: remove one
|
||||
net_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 eos/set_name_servers.yaml"
|
|
@ -0,0 +1,67 @@
|
|||
---
|
||||
- debug: msg="START ios/set_name_servers.yaml"
|
||||
|
||||
- name: setup
|
||||
ios_config:
|
||||
lines:
|
||||
- no ip name-server
|
||||
match: none
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- name: configure name_servers
|
||||
net_system:
|
||||
name_servers:
|
||||
- 1.1.1.1
|
||||
- 2.2.2.2
|
||||
- 3.3.3.3
|
||||
authorize: yes
|
||||
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
|
||||
net_system:
|
||||
name_servers:
|
||||
- 1.1.1.1
|
||||
- 2.2.2.2
|
||||
- 3.3.3.3
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
|
||||
- name: remove one
|
||||
net_system:
|
||||
name_servers:
|
||||
- 1.1.1.1
|
||||
- 2.2.2.2
|
||||
authorize: yes
|
||||
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
|
||||
ios_config:
|
||||
lines:
|
||||
- no ip domain lookup source-interface
|
||||
match: none
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- debug: msg="END ios/set_name_servers.yaml"
|
|
@ -0,0 +1,59 @@
|
|||
---
|
||||
- debug: msg="START iosxr/set_name_servers.yaml"
|
||||
|
||||
- name: setup
|
||||
iosxr_config:
|
||||
lines:
|
||||
- no ip name-server 1.1.1.1
|
||||
- no ip name-server 2.2.2.2
|
||||
- no ip name-server 3.3.3.3
|
||||
match: none
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- name: configure name_servers
|
||||
net_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
|
||||
- "'domain name-server 1.1.1.1' in result.commands"
|
||||
- "'domain name-server 2.2.2.2' in result.commands"
|
||||
- "'domain name-server 3.3.3.3' in result.commands"
|
||||
|
||||
- name: verify name_servers
|
||||
net_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: remove one
|
||||
net_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 domain name-server 3.3.3.3' in result.commands"
|
||||
|
||||
# FIXME: No teardown
|
||||
#
|
||||
- debug: msg="END iosxr/set_name_servers.yaml"
|
|
@ -0,0 +1,66 @@
|
|||
---
|
||||
- debug: msg="START nxos/set_name_servers.yaml"
|
||||
|
||||
- name: setup
|
||||
nxos_config:
|
||||
lines:
|
||||
- no ip name-server 1.1.1.1
|
||||
- no ip name-server 2.2.2.2
|
||||
- no ip name-server 3.3.3.3
|
||||
match: none
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- name: configure name_servers
|
||||
nxos_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
|
||||
nxos_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: remove one
|
||||
nxos_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
|
||||
nxos_config:
|
||||
lines:
|
||||
- no ip lookup source-interface
|
||||
match: none
|
||||
provider: "{{ cli }}"
|
||||
ignore_errors: yes
|
||||
# FIXME Copied from iosxr, not sure what we need here
|
||||
|
||||
- debug: msg="END nxos/set_name_servers.yaml"
|
Loading…
Add table
Add a link
Reference in a new issue