-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add module tests for CVP compatibility
- Loading branch information
1 parent
5654a36
commit 9097ecb
Showing
9 changed files
with
570 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
! Configured from Ansible Playbook device.demo | ||
! | ||
hostname CTL1-EXT-PRDSW-001 | ||
! | ||
ip routing | ||
! | ||
! Build Management VRF if not default | ||
vrf definition MGMNT | ||
description ManagementVRF | ||
rd 64900:00001 | ||
exit | ||
! | ||
no ip routing vrf MGMNT | ||
ip route vrf MGMNT 0.0.0.0/0 192.168.30.1 | ||
! | ||
! Build Management Config | ||
! | ||
management api http-commands | ||
protocol unix-socket | ||
cors allowed-origin all | ||
no shutdown | ||
vrf MGMNT | ||
no shutdown | ||
exit | ||
! | ||
interface Management 1 | ||
description CTL1-EXT-PRDSW-001-MGMNT | ||
vrf forwarding MGMNT | ||
ip address 192.168.30.117/24 | ||
exit | ||
! | ||
! Create Spanning Tree Config | ||
! Configure SpanningTree from the start in case of loops | ||
spanning-tree mode MSTP | ||
spanning-tree portfast bpduguard default | ||
spanning-tree priority 49152 | ||
! | ||
! Virtual MAC for vARP | ||
ip virtual-router mac-address 00:1C:73:ee:01:01 | ||
! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
! This is a dynamic test configlet for cvpserver-1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
! This is a dynamic test configlet for cvpserver-2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
- name: Test cv_configlet_v2 | ||
hosts: cvp_servers | ||
connection: local | ||
gather_facts: no | ||
collections: | ||
- arista.cvp | ||
vars: | ||
configlet_list: | ||
ansible_Test_Configlet: "! This is a Very First Testing Configlet\n! it has no affect on the Device \n!\ninterface loopback 999\n description Test Interface_1\n ip address 192.168.99.99/32\n no shutdown\nexit" | ||
# New_Configlet_2: "! This is a Testing Configlet\n! it has no affect on the Device\n!\ninterface loopback 998\n description Test Interface_2\n ip address 192.168.99.98/32\n no shutdown\nexit" | ||
ansible_Test_DYNAMIC_Configlet: "{{ lookup('file', 'templates/ansible_Configlet_'+inventory_hostname+'.txt') }}" | ||
|
||
change_configlet_list: | ||
ansible_Test_Configlet: "! This is a Very First Testing Configlet\n! it has no affect on the Device but has been changed again\n!\ninterface loopback 999\n description Test Interface_1.1\n ip address 192.168.99.98/32\n no shutdown\nexit" | ||
# New_Configlet_2: "! This is a Testing Configlet\n! it has no affect on the Device\n!\ninterface loopback 998\n description Test Interface_2\n ip address 192.168.99.98/32\n no shutdown\nexit" | ||
|
||
tasks: | ||
- name: 'Collecting facts from CVP {{inventory_hostname}}.' | ||
tags: | ||
- always | ||
cv_facts: | ||
register: cvp_facts | ||
|
||
- name: 'Create configlets on CVP {{inventory_hostname}}.' | ||
tags: | ||
- provision | ||
cv_configlet: | ||
cvp_facts: "{{cvp_facts.ansible_facts}}" | ||
configlets: "{{configlet_list}}" | ||
configlet_filter: ["New", "ansible"] | ||
register: cvp_configlet | ||
|
||
- name: 'Change configlets on CVP {{inventory_hostname}}.' | ||
tags: | ||
- change | ||
cv_configlet: | ||
cvp_facts: "{{cvp_facts.ansible_facts}}" | ||
configlets: "{{change_configlet_list}}" | ||
configlet_filter: ["ansible"] | ||
register: cvp_configlet | ||
|
||
- name: 'Delete configlets on CVP {{inventory_hostname}}.' | ||
tags: | ||
- delete | ||
cv_configlet: | ||
cvp_facts: "{{cvp_facts.ansible_facts}}" | ||
configlets: "{{configlet_list}}" | ||
configlet_filter: ["ansible"] | ||
state: "absent" | ||
register: cvp_configlet | ||
|
||
- name: 'CVP configlets status on {{inventory_hostname}}' | ||
tags: | ||
- provision | ||
- change | ||
- delete | ||
debug: | ||
var: cvp_configlet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
--- | ||
- name: Playbook to validate and demonstrate cv_container module. | ||
debugger: on_failed | ||
hosts: cvp_servers | ||
connection: local | ||
gather_facts: no | ||
collections: | ||
- arista.cvp | ||
vars: | ||
verbose: False | ||
containers_cleanup: | ||
CTL1_TempTest: | ||
parent_container: Arista_CTL1 | ||
staging: | ||
parent_container: CTL1_TempTest | ||
devices: | ||
- CTL1-EXT-PRDSW-001 | ||
|
||
containers_provision: | ||
CTL1_TempTest: | ||
parent_container: Arista_CTL1 | ||
Fabric: | ||
parent_container: CTL1_TempTest | ||
Spines: | ||
parent_container: Fabric | ||
Leaves: | ||
parent_container: Fabric | ||
configlets: | ||
- ansible_Configlet_1 | ||
devices: | ||
- CTL1-EXT-PRDSW-001 | ||
|
||
ROOM02: | ||
parent_container: CTL1_TempTest | ||
ROOM02_Spines: | ||
parent_container: ROOM02 | ||
configlets: | ||
- ansible_Configlet_2 | ||
ROOM02_Leaves: | ||
parent_container: ROOM02 | ||
|
||
container_delete: | ||
CTL1_TempTest: | ||
parent_container: Arista_CTL1 | ||
ROOM02: | ||
parent_container: CTL1_TempTest | ||
ROOM02_Spines: | ||
parent_container: ROOM02 | ||
ROOM02_Leaves: | ||
parent_container: ROOM02 | ||
|
||
tasks: | ||
- name: "Gather CVP facts from {{inventory_hostname}}" | ||
cv_facts: | ||
register: cvp_facts | ||
tags: | ||
- always | ||
|
||
- name: "RUN01 - Build Container topology on {{inventory_hostname}}" | ||
tags: | ||
- provision | ||
- never | ||
cv_container: | ||
topology: '{{containers_provision}}' | ||
cvp_facts: '{{cvp_facts.ansible_facts}}' | ||
#save_topology: true | ||
mode: 'merge' | ||
register: cv_container | ||
|
||
- name: "RUN01 - Display cv_container outputs" | ||
tags: | ||
- provision | ||
- never | ||
debug: | ||
msg: "{{cv_container}}" | ||
|
||
- name: "RUN01 - Check if Leaves container exists" | ||
tags: | ||
- provision | ||
- never | ||
cv_facts: | ||
register: cvp_facts | ||
|
||
- name: "RUN01 - Check if Leaves container exists" | ||
tags: | ||
- provision | ||
assert: | ||
that: | ||
- "cvp_facts.ansible_facts['containers'] | selectattr(search_key,'equalto',search_val) | list | count > 0" | ||
fail_msg: "Leaves container has not been found in facts" | ||
success_msg: "Leaves container has been found as expected" | ||
vars: | ||
search_key: name | ||
search_val: Leaves | ||
|
||
- name: "RUN02 - Delete Container topology on {{inventory_hostname}}" | ||
tags: | ||
- delete | ||
cv_container: | ||
topology: '{{container_delete}}' | ||
cvp_facts: '{{cvp_facts.ansible_facts}}' | ||
mode: 'delete' | ||
#save_topology: true | ||
register: cv_container | ||
|
||
- name: "RUN02 - Check if ROOM02 container exists" | ||
tags: | ||
- delete | ||
- never | ||
cv_facts: | ||
register: cvp_facts_delete | ||
|
||
- name: "RUN02 - Check if ROOM02 container exists" | ||
tags: | ||
- delete | ||
- never | ||
assert: | ||
that: | ||
- "cvp_facts_delete.ansible_facts['containers'] | selectattr(search_key,'equalto',search_val) | list | count < 0" | ||
success_msg: "ROOM02 container has not been found in facts as expected" | ||
fail_msg: "ROOM02 container has been found in facts" | ||
vars: | ||
search_key: name | ||
search_val: ROOM02 | ||
|
||
- name: "RUN03 - Cleanup Container topology on {{inventory_hostname}}" | ||
tags: | ||
- never | ||
- cleanup | ||
cv_container: | ||
topology: '{{containers_cleanup}}' | ||
cvp_facts: '{{cvp_facts.ansible_facts}}' | ||
mode: 'override' | ||
register: cv_container | ||
|
||
- name: "RUN03 - Display cv_container outputs" | ||
tags: | ||
- cleanup | ||
debug: | ||
msg: "{{cv_container}}" | ||
|
||
|
||
- name: "RUN03 - Gather CVP facts from {{inventory_hostname}}" | ||
cv_facts: | ||
register: cvp_facts | ||
tags: | ||
- never | ||
- cleanup | ||
|
||
- name: "RUN03 - Check if Leaves container has been removed" | ||
tags: | ||
- never | ||
- cleanup | ||
assert: | ||
that: | ||
- "cvp_facts.ansible_facts['containers'] | selectattr(search_key,'equalto',search_val) | list | count == 0" | ||
fail_msg: "Leaves container has been found in facts" | ||
success_msg: "Leaves container has not been found as expected" | ||
vars: | ||
search_key: name | ||
search_val: Leaves |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
- name: Test cv_device | ||
hosts: cvp_servers | ||
connection: local | ||
gather_facts: no | ||
collections: | ||
- arista.cvp | ||
vars: | ||
configlet_list: | ||
ansible_device_test01: "alias a{{ 999 | random }} show version" | ||
ansible_device_test02: "alias a{{ 999 | random }} show version" | ||
CTL1-EXT-PRDSW-001_base-ansible: "{{ lookup('file', 'templates/CTL1-EXT-PRDSW-001_base-ansible.txt') }}" | ||
# Device inventory for provision activity: bind configlet | ||
devices_inventory: | ||
CTL1-EXT-PRDSW-001: | ||
name: CTL1-EXT-PRDSW-001 | ||
configlets: | ||
- ansible_device_test01 | ||
- CTL1-EXT-PRDSW-001_base-ansible | ||
parentContainerName: "provision" | ||
imageBundle: "" | ||
# Device inventory for rollback activity: unbind configlet | ||
devices_inventory_rollback: | ||
CTL1-EXT-PRDSW-001: | ||
name: CTL1-EXT-PRDSW-001 | ||
configlets: | ||
- CTL1-EXT-PRDSW-001_base-ansible | ||
|
||
tasks: | ||
# Collect CVP Facts as init process | ||
- name: "Gather CVP facts from {{inventory_hostname}}" | ||
cv_facts: | ||
register: cvp_facts | ||
tags: | ||
- always | ||
|
||
################################################### | ||
### Provision | ||
################################################### | ||
|
||
- name: 'Create configlets on CVP {{inventory_hostname}}.' | ||
tags: | ||
- provision | ||
cv_configlet: | ||
cvp_facts: "{{cvp_facts.ansible_facts}}" | ||
configlets: "{{configlet_list}}" | ||
configlet_filter: ["ansible"] | ||
register: cvp_configlet | ||
|
||
- name: "Configure devices on {{inventory_hostname}}" | ||
tags: | ||
- provision | ||
cv_device: | ||
devices: "{{devices_inventory}}" | ||
cvp_facts: '{{cvp_facts.ansible_facts}}' | ||
device_filter: ['PRDSW'] | ||
register: cvp_device | ||
|
||
################################################### | ||
### Cleanup | ||
################################################### | ||
|
||
- name: "Rollback configlet on devices on {{inventory_hostname}}" | ||
tags: | ||
- cleanup | ||
cv_device: | ||
devices: "{{devices_inventory_rollback}}" | ||
cvp_facts: '{{cvp_facts.ansible_facts}}' | ||
device_filter: ['PRDSW'] | ||
register: cvp_device | ||
|
||
################################################### | ||
### Reset | ||
################################################### | ||
|
||
- name: "Reset devices on {{inventory_hostname}}" | ||
tags: | ||
- reset | ||
cv_device: | ||
devices: "{{devices_inventory_rollback}}" | ||
cvp_facts: '{{cvp_facts.ansible_facts}}' | ||
device_filter: ['PRDSW'] | ||
state: "absent" | ||
register: cvp_device | ||
|
||
################################################### | ||
### Show Result | ||
################################################### | ||
|
||
- name: Display cv_device | ||
tags: | ||
- always | ||
debug: | ||
msg: "{{cvp_device}}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
- name: Get devices for cv_facts module. | ||
hosts: cvp_servers | ||
connection: local | ||
gather_facts: no | ||
collections: | ||
- arista.cvp | ||
vars: | ||
- verbose: False | ||
- deviceFilter: "CTL1-EXT-PRDSW-001" | ||
tasks: | ||
- name: "Gather CVP facts {{inventory_hostname}}" | ||
cv_facts: | ||
facts: | ||
devices | ||
register: cv_facts_devices | ||
|
||
- name: "Print out facts from CVP" | ||
debug: | ||
msg: "{{item}}" | ||
with_items: | ||
- "{{cv_facts_devices.ansible_facts}}" | ||
|
Oops, something went wrong.