Lenovo cnos vrf (#54188)

* Adding module cnos_vrf to manage VRF Configurations.

* Update cnos_vrf.py

* Adding Functional Tests, Unit Tests and Bug Fixes.

* Fixing discrepancy in description against sample

* Review comments incorporated

* Review comments 2 Done

* Update basic.yaml

* Update test_cnos_vrf.py

* Review comments 3
This commit is contained in:
Anil Kumar Muraleedharan
2019-03-28 19:19:37 +05:30
committed by Sumit Jaiswal
parent c007422d05
commit 82d26c8c93
17 changed files with 889 additions and 7 deletions

View File

@@ -10,5 +10,5 @@
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_command]
[cnos_command_sample]
10.241.107.39 ansible_network_os=cnos ansible_ssh_user=<username> ansible_ssh_pass=<password> deviceType=g8272_cnos

View File

@@ -10,5 +10,5 @@
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_config]
[cnos_config_sample]
10.241.107.39 ansible_network_os=cnos ansible_ssh_user=<username> ansible_ssh_pass=<password> deviceType=g8272_cnos

View File

@@ -10,5 +10,5 @@
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_facts]
[cnos_facts_sample]
10.241.107.39 ansible_network_os=cnos ansible_ssh_user=<username> ansible_ssh_pass=<password> deviceType=g8272_cnos

View File

@@ -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_lldp_sample] tag
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_lldp_sample]
10.241.107.39 ansible_network_os=cnos ansible_ssh_user=<username> ansible_ssh_pass=<password> deviceType=g8272_cnos

View File

@@ -6,7 +6,7 @@
# - 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_logging_sample] tag
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.

View File

@@ -6,7 +6,7 @@
# - 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_facts_sample] tag
# In the /etc/ansible/hosts file u have to enter [cnos_showrun_sample] tag
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.

View File

@@ -10,5 +10,5 @@
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_sample_sample]
[cnos_user_sample]
10.241.107.39 ansible_network_os=cnos ansible_ssh_user=admin ansible_ssh_pass=admin

View File

@@ -10,5 +10,5 @@
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos]
[cnos_vlan_sample]
10.241.107.39 ansible_network_os=cnos ansible_ssh_user=<username> ansible_ssh_pass=<password>

View File

@@ -0,0 +1,2 @@
# No Lenovo Switch simulator yet, so not enabled
unsupported

View File

@@ -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_vrf_sample] tag
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_vrf_sample]
10.241.107.39 ansible_network_os=cnos ansible_ssh_user=<username> ansible_ssh_pass=<password> test_interface=ethernet1/33 test_interface2=ethernet1/44

View File

@@ -0,0 +1,3 @@
---
testcase: "*"
test_items: []

View 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 cases (connection=network_cli)
include: "{{ test_case_to_run }} ansible_connection=network_cli"
with_items: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run

View File

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

View File

@@ -0,0 +1,250 @@
---
- name: setup - remove vrf
cnos_vrf:
name: "{{ item }}"
state: absent
become: yes
with_items:
- test
- test1
- test2
- test3
- test4
- test5
- name: Create vrf
cnos_vrf:
name: test
rd: 1:200
state: present
become: yes
register: result
- assert:
that:
- "result.changed == true"
- "'vrf context test' in result.commands"
- "'rd 1:200' in result.commands"
- name: Create vrf again (idempotent)
cnos_vrf:
name: test
rd: 1:200
state: present
become: yes
register: result
- assert:
that:
- "result.changed == false"
- "result.commands | length == 0"
- name: Modify rd
cnos_vrf:
name: test
rd: 1:201
state: present
become: yes
register: result
- assert:
that:
- "result.changed == true"
- "'vrf context test' in result.commands"
- "'rd 1:201' in result.commands"
- name: Modify rd again (idempotent)
cnos_vrf:
name: test
rd: 1:201
state: present
become: yes
register: result
- assert:
that:
- "result.changed == false"
- "result.commands | length == 0"
- name: Add Ethernet1/33 to vrf and check interface assigned state
cnos_vrf:
name: test
rd: 1:201
state: present
interfaces:
- Ethernet1/33
associated_interfaces:
- Ethernet1/33
become: yes
register: result
- assert:
that:
- "result.changed == true"
- "'interface ethernet1/33' in result.commands"
- "'vrf member test' in result.commands"
- name: Add Ethernet1/33 to vrf again (idempotent)
cnos_vrf:
name: test
rd: 1:201
state: present
interfaces:
- ethernet 1/33 # interface name modified to test case insensitive and space scenario
become: yes
register: result
- assert:
that:
- "result.changed == false"
- "result.commands | length == 0"
- name: Add multiple interfaces to vrf
cnos_vrf:
name: test1
rd: 1:202
state: present
interfaces:
- loopback 1
- loopback 2
- loopback 3
- loopback 4
- loopback 5
- loopback 6
become: yes
register: result
- assert:
that:
- "result.changed == true"
- "'interface loopback1' in result.commands"
- "'vrf member test1' in result.commands"
- "'interface loopback2' in result.commands"
- "'vrf member test1' in result.commands"
- "'interface loopback3' in result.commands"
- "'vrf member test1' in result.commands"
- "'interface loopback4' in result.commands"
- "'vrf member test1' in result.commands"
- "'interface loopback5' in result.commands"
- "'vrf member test1' in result.commands"
- "'interface loopback6' in result.commands"
- "'vrf member test1' in result.commands"
- name: Add multiple interfaces to vrf (idempotent)
cnos_vrf:
name: test1
rd: 1:202
state: present
interfaces:
- loopback 1
- loopback 2
- loopback 3
- loopback 4
- loopback 5
- loopback 6
become: yes
register: result
- assert:
that:
- "result.changed == false"
- "result.commands | length == 0"
- name: setup - remove vrf
cnos_vrf:
name: "{{ item }}"
state: absent
become: yes
with_items:
- test1
- test2
- test3
- name: Create aggregate of VRFs
cnos_vrf:
aggregate:
- { name: test2, rd: "1:202" }
- { name: test3, rd: "1:203" }
state: present
register: result
- assert:
that:
- "result.changed == true"
- "'vrf context test2' in result.commands"
- "'rd 1:202' in result.commands"
- "'vrf context test3' in result.commands"
- "'rd 1:203' in result.commands"
- name: Create aggregate of VRFs again (idempotent)
cnos_vrf:
aggregate:
- { name: test2, rd: "1:202" }
- { name: test3, rd: "1:203" }
state: present
become: yes
register: result
- assert:
that:
- "result.changed == false"
- "result.commands | length == 0"
- name: Create aggregate of VRFs with purge
cnos_vrf:
aggregate:
- { name: test4, rd: "1:204" }
- { name: test5, rd: "1:205" }
state: present
purge: yes
become: yes
register: result
- assert:
that:
- "result.changed == true"
- "'vrf context test4' in result.commands"
- "'rd 1:204' in result.commands"
- "'vrf context test5' in result.commands"
- "'rd 1:205' in result.commands"
- "'no vrf context test' in result.commands"
- "'no vrf context test2' in result.commands"
- "'no vrf context test3' in result.commands"
- name: Delete VRFs
cnos_vrf:
name: test
state: absent
become: yes
- name: Delete VRFs again (idempotent)
cnos_vrf:
name: test
state: absent
become: yes
- name: Delete aggregate of VRFs
cnos_vrf:
aggregate:
- { name: test1 }
- { name: test2 }
- { name: test3 }
- { name: test4 }
- { name: test5 }
state: absent
become: yes
- name: Delete VRFs again (idempotent)
cnos_vrf:
aggregate:
- { name: test1 }
- { name: test2 }
- { name: test3 }
- { name: test4 }
- { name: test5 }
state: absent
become: yes
- assert:
that:
- "result.changed == true"