mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
Lenovo cnos system module (#53764)
* Adding cnos_system module to Ansible. * Adding UT, Functional test required for cnos_system. Bugs came up are fixed * Adding more files to the cnos_system suit.
This commit is contained in:
committed by
Nathaniel Case
parent
e4a1473a8f
commit
7a24ecde86
@@ -6,9 +6,9 @@
|
||||
# - You can enter hostnames or ip Addresses
|
||||
# - A hostname/ip can be a member of multiple groups
|
||||
#
|
||||
# In the /etc/ansible/hosts file u have to enter [cnos_portchannel_sample] tag
|
||||
# In the /etc/ansible/hosts file u have to enter [cnos_linkagg_sample] tag
|
||||
# Following you should specify IP Addresses details
|
||||
# Please change <username> and <password> with appropriate value for your switch.
|
||||
|
||||
[cnos_linkagg_sample]
|
||||
10.241.107.39 ansible_network_os=cnos ansible_ssh_user=<username> ansible_ssh_pass=<password>
|
||||
10.241.107.39 ansible_network_os=cnos ansible_ssh_user=<username> ansible_ssh_pass=<password>
|
||||
|
||||
2
test/integration/targets/cnos_system/aliases
Normal file
2
test/integration/targets/cnos_system/aliases
Normal file
@@ -0,0 +1,2 @@
|
||||
# No Lenovo Switch simulator yet, so not enabled
|
||||
unsupported
|
||||
@@ -0,0 +1,14 @@
|
||||
# You have to paste this dummy information in /etc/ansible/hosts
|
||||
# Notes:
|
||||
# - Comments begin with the '#' character
|
||||
# - Blank lines are ignored
|
||||
# - Groups of hosts are delimited by [header] elements
|
||||
# - You can enter hostnames or ip Addresses
|
||||
# - A hostname/ip can be a member of multiple groups
|
||||
#
|
||||
# In the /etc/ansible/hosts file u have to enter [cnos_system_sample] tag
|
||||
# Following you should specify IP Addresses details
|
||||
# Please change <username> and <password> with appropriate value for your switch.
|
||||
|
||||
[cnos_system_sample]
|
||||
<ip address> ansible_network_os=cnos ansible_ssh_user=<username> ansible_ssh_pass=<password>
|
||||
2
test/integration/targets/cnos_system/defaults/main.yaml
Normal file
2
test/integration/targets/cnos_system/defaults/main.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
testcase: "*"
|
||||
33
test/integration/targets/cnos_system/tasks/cli.yaml
Normal file
33
test/integration/targets/cnos_system/tasks/cli.yaml
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
- name: collect common test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/common"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
connection: local
|
||||
register: test_cases
|
||||
|
||||
- name: collect cli test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/cli"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
connection: local
|
||||
register: cli_cases
|
||||
|
||||
- set_fact:
|
||||
test_cases:
|
||||
files: "{{ test_cases.files }} + {{ cli_cases.files }}"
|
||||
|
||||
- name: set test_items
|
||||
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
|
||||
|
||||
- name: run test cases (connection=network_cli)
|
||||
include: "{{ test_case_to_run }} ansible_connection=network_cli connection={{ cli }}"
|
||||
with_items: "{{ test_items }}"
|
||||
loop_control:
|
||||
loop_var: test_case_to_run
|
||||
|
||||
- name: run test case (connection=local)
|
||||
include: "{{ test_case_to_run }} ansible_connection=local"
|
||||
with_first_found: "{{ test_items }}"
|
||||
loop_control:
|
||||
loop_var: test_case_to_run
|
||||
2
test/integration/targets/cnos_system/tasks/main.yaml
Normal file
2
test/integration/targets/cnos_system/tasks/main.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
||||
@@ -0,0 +1,34 @@
|
||||
---
|
||||
- debug: msg="START cnos cli/net_system.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
# Add minimal testcase to check args are passed correctly to
|
||||
# implementation module and module run is successful.
|
||||
|
||||
- name: setup
|
||||
cnos_config:
|
||||
lines:
|
||||
- no ip domain-list ansible.com vrf default
|
||||
- no ip domain-list redhat.com vrf default
|
||||
match: none
|
||||
|
||||
- name: configure domain_list using platform agnostic module
|
||||
net_system:
|
||||
domain_search:
|
||||
- ansible.com
|
||||
- redhat.com
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- "'ip domain-list ansible.com vrf default' in result.commands"
|
||||
- "'ip domain-list redhat.com vrf default' in result.commands"
|
||||
|
||||
- name: setup
|
||||
cnos_config:
|
||||
lines:
|
||||
- no ip domain-list ansible.com vrf default
|
||||
- no ip domain-list redhat.com vrf default
|
||||
match: none
|
||||
|
||||
- debug: msg="END cnos cli/net_system.yaml on connection={{ ansible_connection }}"
|
||||
@@ -0,0 +1,111 @@
|
||||
---
|
||||
- debug: msg="START cli/set_domain_list.yaml"
|
||||
|
||||
- name: setup
|
||||
cnos_config:
|
||||
lines:
|
||||
- no ip domain-list ansible.com vrf default
|
||||
- no ip domain-list redhat.com vrf default
|
||||
match: none
|
||||
|
||||
- name: configure domain_list
|
||||
cnos_system:
|
||||
domain_search:
|
||||
- ansible.com
|
||||
- redhat.com
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- "'ip domain-list ansible.com vrf default' in result.commands"
|
||||
- "'ip domain-list redhat.com vrf default' in result.commands"
|
||||
|
||||
- name: verify domain_list
|
||||
cnos_system:
|
||||
domain_search:
|
||||
- ansible.com
|
||||
- redhat.com
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
|
||||
- name: remove one entry
|
||||
cnos_system:
|
||||
domain_search:
|
||||
- ansible.com
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- "'no ip domain-list redhat.com vrf default' in result.commands"
|
||||
|
||||
- name: verify remove one entry
|
||||
cnos_system:
|
||||
domain_search:
|
||||
- ansible.com
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
|
||||
- name: add one entry
|
||||
cnos_system:
|
||||
domain_search:
|
||||
- ansible.com
|
||||
- redhat.com
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- "'ip domain-list redhat.com vrf default' in result.commands"
|
||||
|
||||
- name: verify add one entry
|
||||
cnos_system:
|
||||
domain_search:
|
||||
- ansible.com
|
||||
- redhat.com
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
|
||||
- name: add and remove one entry
|
||||
cnos_system:
|
||||
domain_search:
|
||||
- ansible.com
|
||||
- eng.ansible.com
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- "'no ip domain-list redhat.com vrf default' in result.commands"
|
||||
- "'ip domain-list eng.ansible.com vrf default' in result.commands"
|
||||
|
||||
- name: verify add and remove one entry
|
||||
cnos_system:
|
||||
domain_search:
|
||||
- ansible.com
|
||||
- eng.ansible.com
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
|
||||
- name: teardown
|
||||
cnos_config:
|
||||
lines:
|
||||
- no ip domain-list ansible.com vrf default
|
||||
- no ip domain-list redhat.com vrf default
|
||||
- no ip domain-list eng.ansible.com vrf default
|
||||
match: none
|
||||
|
||||
- debug: msg="END cli/set_domain_search.yaml"
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
- debug: msg="START cli/set_domain_name.yaml"
|
||||
|
||||
- name: setup
|
||||
cnos_config:
|
||||
lines: no ip domain-name eng.ansible.com vrf default
|
||||
match: none
|
||||
|
||||
- name: configure domain_name
|
||||
cnos_system:
|
||||
domain_name: eng.ansible.com
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: verify domain_name
|
||||
cnos_system:
|
||||
domain_name: eng.ansible.com
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: teardown
|
||||
cnos_config:
|
||||
lines: no ip domain-name eng.ansible.com vrf default
|
||||
match: none
|
||||
|
||||
- debug: msg="END cli/set_domain_name.yaml"
|
||||
@@ -0,0 +1,73 @@
|
||||
---
|
||||
- debug: msg="START cli/set_name_servers.yaml"
|
||||
|
||||
- name: setup
|
||||
cnos_config: &reset
|
||||
lines:
|
||||
- no ip name-server 10.241.107.1 vrf default
|
||||
- no ip name-server 10.241.107.2 vrf default
|
||||
- no ip name-server 10.241.107.3 vrf default
|
||||
match: none
|
||||
|
||||
- name: configure name_servers
|
||||
cnos_system:
|
||||
name_servers:
|
||||
- 10.241.107.1
|
||||
- 10.241.107.2
|
||||
- 10.241.107.3
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- "'ip name-server 10.241.107.1 vrf default' in result.commands"
|
||||
- "'ip name-server 10.241.107.2 vrf default' in result.commands"
|
||||
- "'ip name-server 10.241.107.3 vrf default' in result.commands"
|
||||
|
||||
- name: verify name_servers
|
||||
cnos_system:
|
||||
name_servers:
|
||||
- 10.241.107.1
|
||||
- 10.241.107.2
|
||||
- 10.241.107.3
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
|
||||
- name: remove one
|
||||
cnos_system:
|
||||
name_servers:
|
||||
- 10.241.107.1
|
||||
- 10.241.107.2
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
# - result.commands|length == 1
|
||||
- "'no ip name-server 10.241.107.3 vrf default' in result.commands"
|
||||
|
||||
- name: default name server
|
||||
cnos_system: &defns
|
||||
name_servers: default
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
|
||||
- name: Idempotent check
|
||||
cnos_system: *defns
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
|
||||
- name: teardown
|
||||
cnos_config: *reset
|
||||
ignore_errors: yes
|
||||
|
||||
- debug: msg="END cli/set_name_servers.yaml"
|
||||
122
test/integration/targets/cnos_system/tests/common/sanity.yaml
Normal file
122
test/integration/targets/cnos_system/tests/common/sanity.yaml
Normal file
@@ -0,0 +1,122 @@
|
||||
---
|
||||
- debug: msg="START connection={{ ansible_connection }}/sanity.yaml"
|
||||
- debug: msg="Using provider={{ connection.transport }}"
|
||||
when: ansible_connection == "local"
|
||||
|
||||
- block:
|
||||
- name: remove configuration
|
||||
cnos_system: &remove
|
||||
state: absent
|
||||
register: result
|
||||
ignore_errors: yes
|
||||
|
||||
- name: configure lookup_enabled
|
||||
cnos_system: &dlo
|
||||
lookup_enabled: true
|
||||
state: present
|
||||
register: result
|
||||
|
||||
- name: configure hostname and domain-name
|
||||
cnos_system: &hostname
|
||||
hostname: switch
|
||||
domain_name: test.example.com
|
||||
register: result
|
||||
|
||||
- assert: &true
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: Idempotence check
|
||||
cnos_system: *hostname
|
||||
register: result
|
||||
|
||||
- assert: &false
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: configure name servers
|
||||
cnos_system: &ns
|
||||
name_servers:
|
||||
- 8.8.8.8
|
||||
- 8.8.4.4
|
||||
register: result
|
||||
|
||||
- assert: *true
|
||||
|
||||
- name: Idempotence check
|
||||
cnos_system: *ns
|
||||
register: result
|
||||
|
||||
- assert: *false
|
||||
|
||||
- name: configure name servers with VRF support
|
||||
cnos_system: &nsv
|
||||
name_servers:
|
||||
- { server: 8.8.8.8, vrf: management }
|
||||
- { server: 8.8.4.4, vrf: management }
|
||||
register: result
|
||||
|
||||
- assert: *true
|
||||
|
||||
- name: Idempotence check
|
||||
cnos_system: *nsv
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- name: configure lookup_enabled1
|
||||
cnos_system: &ndlo
|
||||
lookup_enabled: false
|
||||
register: result
|
||||
|
||||
- assert: *true
|
||||
|
||||
- name: Idempotence check
|
||||
cnos_system: *ndlo
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- name: configure lookup_enabled2
|
||||
cnos_system: *dlo
|
||||
register: result
|
||||
|
||||
- assert: *true
|
||||
|
||||
- name: Idempotence check
|
||||
cnos_system: *dlo
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- name: default configuration
|
||||
cnos_system: &default
|
||||
hostname: default
|
||||
domain_name: default
|
||||
name_servers: default
|
||||
register: result
|
||||
|
||||
- assert: *true
|
||||
|
||||
- name: Idempotence check
|
||||
cnos_system: *default
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
always:
|
||||
- name: remove configuration
|
||||
cnos_system: *remove
|
||||
|
||||
- name: Re-configure hostname
|
||||
cnos_system: *hostname
|
||||
|
||||
- debug: msg="END connection={{ ansible_connection }}/sanity.yaml"
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
- debug: msg="START connection={{ ansible_connection }}/set_hostname.yaml"
|
||||
- debug: msg="Using provider={{ connection.transport }}"
|
||||
when: ansible_connection == "local"
|
||||
|
||||
- block:
|
||||
- name: setup
|
||||
cnos_config:
|
||||
lines: "hostname switch"
|
||||
match: none
|
||||
|
||||
- name: configure hostname
|
||||
cnos_system:
|
||||
hostname: foo
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: verify hostname
|
||||
cnos_system:
|
||||
hostname: foo
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
always:
|
||||
- name: teardown
|
||||
cnos_config:
|
||||
lines: "hostname switch"
|
||||
match: none
|
||||
|
||||
- debug: msg="END connection={{ ansible_connection }}/set_hostname.yaml"
|
||||
Reference in New Issue
Block a user