From 3874d7d2e0ebcebcce926b8a68d53fbabe8107e8 Mon Sep 17 00:00:00 2001 From: Vibhu Tripathi Date: Mon, 29 May 2023 16:16:15 +0530 Subject: [PATCH 01/19] Test: Adding integration test for cv_device_v3 (move_device) --- .../cvp/molecule/cv_device_v3/converge.yml | 3 + .../cvp/molecule/cv_device_v3/molecule.yml | 25 ++++++++ .../cv_device_v3/test_cv_device_v3.yaml | 62 +++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 ansible_collections/arista/cvp/molecule/cv_device_v3/converge.yml create mode 100644 ansible_collections/arista/cvp/molecule/cv_device_v3/molecule.yml create mode 100644 ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/converge.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/converge.yml new file mode 100644 index 000000000..b98f8b875 --- /dev/null +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/converge.yml @@ -0,0 +1,3 @@ +--- +- name: Run cv_device_v3 + import_playbook: test_cv_device_v3.yaml diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/molecule.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/molecule.yml new file mode 100644 index 000000000..79248ffed --- /dev/null +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/molecule.yml @@ -0,0 +1,25 @@ +--- +scenario: + test_sequence: + - converge +driver: + name: delegated +platforms: + - name: dummy + managed: false +provisioner: + name: ansible + config_options: + defaults: + jinja2_extensions: 'jinja2.ext.loopcontrols,jinja2.ext.do,jinja2.ext.i18n' + gathering: explicit + command_warnings: False + remote_tmp: /tmp/.ansible-${USER}/tmp + stdout_callback: yaml + playbooks: + converge: converge.yml + ansible_args: + - --inventory + - ${MOLECULE_SCENARIO_DIRECTORY}/../../examples/inventory.yml +verifier: + name: ansible diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml new file mode 100644 index 000000000..a43c59767 --- /dev/null +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml @@ -0,0 +1,62 @@ +--- +- name: Test cv_device_v3 + hosts: CloudVision + connection: local + gather_facts: no + vars: + CVP_DEVICES_MOVE_DEVICE: + - fqdn: leaf1 + parentContainerName: "Spine" + + CVP_DEVICES_PARENT_CONTAINER_NONE: + - fqdn: leaf1 + parentContainerName: None + + CVP_DEVICES_PARENT_CONTAINER_SAME: + - fqdn: leaf1 + parentContainerName: "Spine" + tasks: + +##################################### +# MOVE DEVICE # +##################################### + + - name: Run CV_DEVICE_V3 To Move Device + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_MOVE_DEVICE}}' + state: present + register: MOVE_DEVICE_RUN + - assert: + that: + - "MOVE_DEVICE_RUN.devices_moved.changed == true" + - "MOVE_DEVICE_RUN.devices_moved.devices_moved_count == 1" + - "MOVE_DEVICE_RUN.devices_moved.devices_moved_list == ['leaf1_to_Spine']" + - "MOVE_DEVICE_RUN.devices_moved.success == true" + - "MOVE_DEVICE_RUN.failed == false" + + - name: Run CV_DEVICE_V3 To Move Device With Parent Container None + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_PARENT_CONTAINER_NONE}}' + state: present + ignore_errors: yes # ignoring errors so assertions can be done + register: MOVE_DEVICE_NONE + - assert: + that: + - MOVE_DEVICE_NONE.msg == "The target container 'None' for the device 'leaf1' does not exist on CVP." + - MOVE_DEVICE_NONE.changed == false + - MOVE_DEVICE_NONE.failed == true + + - name: Run CV_DEVICE_V3 To Move Device With Parent Container Same + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_PARENT_CONTAINER_SAME}}' + state: present + ignore_errors: yes # ignoring errors so assertions can be done + register: MOVE_DEVICE + - assert: + that: + - MOVE_DEVICE.devices_moved.changed == false + - MOVE_DEVICE.devices_moved.devices_moved_count == 0 + - MOVE_DEVICE.devices_moved.devices_moved_list == [] + - MOVE_DEVICE.devices_moved.success == false + - MOVE_DEVICE.failed == false + - MOVE_DEVICE.taskIds: [] From 3a7a02ba124a746dfb54fee5cf9a1c72db1f4f34 Mon Sep 17 00:00:00 2001 From: Shivani-chourasiya Date: Mon, 29 May 2023 17:27:19 +0530 Subject: [PATCH 02/19] Adding tests for state absent (decommission_device) --- .../cv_device_v3/test_cv_device_v3.yaml | 35 ++++++++++++++++++- .../cvp/plugins/module_utils/device_tools.py | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml index a43c59767..f3e189829 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml @@ -15,8 +15,11 @@ CVP_DEVICES_PARENT_CONTAINER_SAME: - fqdn: leaf1 parentContainerName: "Spine" - tasks: + CVP_DEVICES_STATE_ABSENT: + - fqdn: leaf2 + parentContainerName: "" + tasks: ##################################### # MOVE DEVICE # ##################################### @@ -60,3 +63,33 @@ - MOVE_DEVICE.devices_moved.success == false - MOVE_DEVICE.failed == false - MOVE_DEVICE.taskIds: [] + +##################################### +# STATE ABSENT # +##################################### + - name: Run CV_DEVICE_V3 With State Absent + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_STATE_ABSENT}}' + state: absent + # ignore_errors: yes # ignoring errors so assertions can be done + register: DECOMMISSION_DEVICE + - assert: + that: + - DECOMMISSION_DEVICE.devices_decommissioned.changed == true + - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_count == 0 + - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_list == ['leaf2_delete'] + - DECOMMISSION_DEVICE.devices_decommissioned.success == true + - DECOMMISSION_DEVICE.devices_decommissioned.taskIds == [] + - DECOMMISSION_DEVICE.failed == false + + - name: Run CV_DEVICE_V3 With State Absent + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_STATE_ABSENT}}' + state: absent + ignore_errors: yes # ignoring errors so assertions can be done + register: DECOMMISSION_DEVICE_ABSENT + - assert: + that: + - DECOMMISSION_DEVICE_ABSENT.changed == false + - DECOMMISSION_DEVICE_ABSENT.failed == true + - DECOMMISSION_DEVICE_ABSENT.msg == "Error - the following devices do not exist in CVP ['leaf2'] but are defined in the playbook. Make sure that the devices are provisioned and defined with the full fqdn name (including the domain name) if needed." diff --git a/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py b/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py index 709814d1f..ae9875c99 100644 --- a/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py +++ b/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py @@ -619,7 +619,7 @@ def __check_devices_exist(self, user_inventory: DeviceInventory): ) if list_non_existing_devices is not None and len(list_non_existing_devices) > 0: error_message = "Error - the following devices do not exist in CVP {0} but are defined in the playbook. \ - \nMake sure that the devices are provisioned and defined with the full fqdn name \ + Make sure that the devices are provisioned and defined with the full fqdn name \ (including the domain name) if needed.".format( str(list_non_existing_devices) ) From d346824e7dd8b716d3011c78d914351fe29b7202 Mon Sep 17 00:00:00 2001 From: Shivani-chourasiya Date: Fri, 2 Jun 2023 14:32:44 +0530 Subject: [PATCH 03/19] Addressing review comments --- .../arista/cvp/examples/inventory.yml | 17 ----------------- .../cv_device_v3/test_cv_device_v3.yaml | 8 ++++---- 2 files changed, 4 insertions(+), 21 deletions(-) delete mode 100644 ansible_collections/arista/cvp/examples/inventory.yml diff --git a/ansible_collections/arista/cvp/examples/inventory.yml b/ansible_collections/arista/cvp/examples/inventory.yml deleted file mode 100644 index 1ffaad3b9..000000000 --- a/ansible_collections/arista/cvp/examples/inventory.yml +++ /dev/null @@ -1,17 +0,0 @@ ---- -all: - children: - CVP: - hosts: - CloudVision: - ansible_httpapi_host: 192.168.0.5 - ansible_host: 192.168.0.5 - ansible_user: arista - ansible_password: "{{ lookup('env', 'LABPASSPHRASE') }}" # lab credential password - ansible_connection: httpapi - ansible_httpapi_use_ssl: True - ansible_httpapi_validate_certs: False - ansible_network_os: eos - ansible_httpapi_port: 443 - # Configuration to get Virtual Env information - ansible_python_interpreter: $(which python3) diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml index f3e189829..5a8961692 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml @@ -6,7 +6,7 @@ vars: CVP_DEVICES_MOVE_DEVICE: - fqdn: leaf1 - parentContainerName: "Spine" + parentContainerName: "Leaf" CVP_DEVICES_PARENT_CONTAINER_NONE: - fqdn: leaf1 @@ -14,7 +14,8 @@ CVP_DEVICES_PARENT_CONTAINER_SAME: - fqdn: leaf1 - parentContainerName: "Spine" + parentContainerName: "Leaf" + CVP_DEVICES_STATE_ABSENT: - fqdn: leaf2 parentContainerName: "" @@ -33,7 +34,7 @@ that: - "MOVE_DEVICE_RUN.devices_moved.changed == true" - "MOVE_DEVICE_RUN.devices_moved.devices_moved_count == 1" - - "MOVE_DEVICE_RUN.devices_moved.devices_moved_list == ['leaf1_to_Spine']" + - "MOVE_DEVICE_RUN.devices_moved.devices_moved_list == ['leaf1_to_Leaf']" - "MOVE_DEVICE_RUN.devices_moved.success == true" - "MOVE_DEVICE_RUN.failed == false" @@ -71,7 +72,6 @@ arista.cvp.cv_device_v3: devices: '{{CVP_DEVICES_STATE_ABSENT}}' state: absent - # ignore_errors: yes # ignoring errors so assertions can be done register: DECOMMISSION_DEVICE - assert: that: From 7abdaeac5e70ee377d3be6a68e76c3587364f049 Mon Sep 17 00:00:00 2001 From: Shivani-chourasiya Date: Tue, 6 Jun 2023 17:47:33 +0530 Subject: [PATCH 04/19] Added tests for factory_reset and provisioning_reset --- .../cv_device_v3/test_cv_device_v3.yaml | 62 +++++++++++++++++-- .../cvp/plugins/module_utils/device_tools.py | 4 +- 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml index 5a8961692..6a7da68e7 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml @@ -20,9 +20,17 @@ - fqdn: leaf2 parentContainerName: "" + CVP_DEVICES_FACT0RY_RESET: + - fqdn: leaf2 + parentContainerName: "" + + CVP_DEVICES_PROVISIONING_RESET: + - fqdn: leaf3 + parentContainerName: "" + tasks: ##################################### -# MOVE DEVICE # +## MOVE DEVICE ## ##################################### - name: Run CV_DEVICE_V3 To Move Device @@ -65,9 +73,9 @@ - MOVE_DEVICE.failed == false - MOVE_DEVICE.taskIds: [] -##################################### -# STATE ABSENT # -##################################### +###################################### +## STATE ABSENT ## +###################################### - name: Run CV_DEVICE_V3 With State Absent arista.cvp.cv_device_v3: devices: '{{CVP_DEVICES_STATE_ABSENT}}' @@ -82,7 +90,7 @@ - DECOMMISSION_DEVICE.devices_decommissioned.taskIds == [] - DECOMMISSION_DEVICE.failed == false - - name: Run CV_DEVICE_V3 With State Absent + - name: Run CV_DEVICE_V3 With State Absent # when device does not exist in CVP arista.cvp.cv_device_v3: devices: '{{CVP_DEVICES_STATE_ABSENT}}' state: absent @@ -93,3 +101,47 @@ - DECOMMISSION_DEVICE_ABSENT.changed == false - DECOMMISSION_DEVICE_ABSENT.failed == true - DECOMMISSION_DEVICE_ABSENT.msg == "Error - the following devices do not exist in CVP ['leaf2'] but are defined in the playbook. Make sure that the devices are provisioned and defined with the full fqdn name (including the domain name) if needed." + +###################################### +## STATE FACTORY RESET ## +###################################### + - name: Run CV_DEVICE_V3 With State Factory reset + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_FACT0RY_RESET}}' + state: factory_reset + register: FACTORY_RESET_RESULT + + - assert: + that: + - FACTORY_RESET_RESULT.devices_reset.changed == true + - FACTORY_RESET_RESULT.devices_reset.devices_reset_count == 1 + - FACTORY_RESET_RESULT.devices_reset.devices_reset_list == ['leaf2_reset'] + - FACTORY_RESET_RESULT.devices_reset.success == true + - FACTORY_RESET_RESULT.devices_reset.taskIds is defined + - FACTORY_RESET_RESULT.failed == false + - FACTORY_RESET_RESULT.success == true + +# it is not moving device to undefined container, just creating a task on CVP + +###################################### +## STATE PROVISIONING RESET ## +###################################### + + - name: Run CV_DEVICE_V3 With State Provisioning Reset + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_PROVISIONING_RESET}}' + state: provisioning_reset + register: PROVISIONING_RESET_RESULT + + - name: check provisioning reset + assert: + that: + - PROVISIONING_RESET_RESULT.devices_removed.changed == true + - PROVISIONING_RESET_RESULT.devices_removed.devices_removed_count == 1 + - PROVISIONING_RESET_RESULT.devices_removed. devices_removed_list == ['leaf3_delete'] + - PROVISIONING_RESET_RESULT.devices_removed.success == true + - PROVISIONING_RESET_RESULT.devices_removed.taskIds is defined + - PROVISIONING_RESET_RESULT.failed == false + - PROVISIONING_RESET_RESULT.success == true + +# if we try to delete the same device again(already in undefined container), it does not raises any error and gives the same result diff --git a/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py b/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py index ae9875c99..2b3c91835 100644 --- a/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py +++ b/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py @@ -2209,9 +2209,7 @@ def reset_device(self, user_inventory: DeviceInventory): result_data.changed = True result_data.success = True result_data.taskIds = resp["data"][Api.task.TASK_IDS] - result_data.add_entry( - "{} resets {}".format(device.fqdn, *device.configlets) - ) + result_data.add_entry(f"{device.fqdn} resets {device.configlets}") results.append(result_data) return results From 4f3b39837ac0c82cfec58849d46aee0033d6f68b Mon Sep 17 00:00:00 2001 From: Vibhu Tripathi Date: Thu, 8 Jun 2023 17:04:47 +0530 Subject: [PATCH 05/19] Added tests for attach and detach bundle and fixed counters for bundle_attached/bundle_detached --- .../cv_device_v3/test_cv_device_v3.yaml | 269 +++++++++++------- .../cvp/plugins/module_utils/device_tools.py | 2 + 2 files changed, 165 insertions(+), 106 deletions(-) diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml index 6a7da68e7..b730971ba 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml @@ -28,120 +28,177 @@ - fqdn: leaf3 parentContainerName: "" + CVP_DEVICES_BUNDLE_ATTACHED: + - serialNumber: JPE504a004ea054 + parentContainerName: L2_Leaf + configlets: + - 'AVD_Ipmi3' + imageBundle: leaf_bundle + + CVP_DEVICES_BUNDLE_DETACHED: + - serialNumber: JPE504a004ea054 + parentContainerName: L2_Leaf + configlets: + - 'AVD_Ipmi3' + tasks: ##################################### ## MOVE DEVICE ## ##################################### - - name: Run CV_DEVICE_V3 To Move Device - arista.cvp.cv_device_v3: + - name: Run CV_DEVICE_V3 To Move Device + arista.cvp.cv_device_v3: devices: '{{CVP_DEVICES_MOVE_DEVICE}}' state: present - register: MOVE_DEVICE_RUN - - assert: - that: - - "MOVE_DEVICE_RUN.devices_moved.changed == true" - - "MOVE_DEVICE_RUN.devices_moved.devices_moved_count == 1" - - "MOVE_DEVICE_RUN.devices_moved.devices_moved_list == ['leaf1_to_Leaf']" - - "MOVE_DEVICE_RUN.devices_moved.success == true" - - "MOVE_DEVICE_RUN.failed == false" - - - name: Run CV_DEVICE_V3 To Move Device With Parent Container None - arista.cvp.cv_device_v3: + register: MOVE_DEVICE_RUN + + - name: Check Move Device + assert: + that: + - "MOVE_DEVICE_RUN.devices_moved.changed == true" + - "MOVE_DEVICE_RUN.devices_moved.devices_moved_count == 1" + - "MOVE_DEVICE_RUN.devices_moved.devices_moved_list == ['leaf1_to_Leaf']" + - "MOVE_DEVICE_RUN.devices_moved.success == true" + - "MOVE_DEVICE_RUN.failed == false" + + - name: Run CV_DEVICE_V3 To Move Device With Parent Container None + arista.cvp.cv_device_v3: devices: '{{CVP_DEVICES_PARENT_CONTAINER_NONE}}' state: present - ignore_errors: yes # ignoring errors so assertions can be done - register: MOVE_DEVICE_NONE - - assert: - that: - - MOVE_DEVICE_NONE.msg == "The target container 'None' for the device 'leaf1' does not exist on CVP." - - MOVE_DEVICE_NONE.changed == false - - MOVE_DEVICE_NONE.failed == true - - - name: Run CV_DEVICE_V3 To Move Device With Parent Container Same - arista.cvp.cv_device_v3: + ignore_errors: yes + register: MOVE_DEVICE_NONE + + - name: Negative Test Check Move Device With Parent Container None + assert: + that: + - MOVE_DEVICE_NONE.msg == "The target container 'None' for the device 'leaf1' does not exist on CVP." + - MOVE_DEVICE_NONE.changed == false + - MOVE_DEVICE_NONE.failed == true + + - name: Run CV_DEVICE_V3 To Move Device With Parent Container Same + arista.cvp.cv_device_v3: devices: '{{CVP_DEVICES_PARENT_CONTAINER_SAME}}' state: present - ignore_errors: yes # ignoring errors so assertions can be done - register: MOVE_DEVICE - - assert: - that: - - MOVE_DEVICE.devices_moved.changed == false - - MOVE_DEVICE.devices_moved.devices_moved_count == 0 - - MOVE_DEVICE.devices_moved.devices_moved_list == [] - - MOVE_DEVICE.devices_moved.success == false - - MOVE_DEVICE.failed == false - - MOVE_DEVICE.taskIds: [] - -###################################### -## STATE ABSENT ## -###################################### - - name: Run CV_DEVICE_V3 With State Absent - arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_STATE_ABSENT}}' - state: absent - register: DECOMMISSION_DEVICE - - assert: - that: - - DECOMMISSION_DEVICE.devices_decommissioned.changed == true - - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_count == 0 - - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_list == ['leaf2_delete'] - - DECOMMISSION_DEVICE.devices_decommissioned.success == true - - DECOMMISSION_DEVICE.devices_decommissioned.taskIds == [] - - DECOMMISSION_DEVICE.failed == false - - - name: Run CV_DEVICE_V3 With State Absent # when device does not exist in CVP - arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_STATE_ABSENT}}' - state: absent - ignore_errors: yes # ignoring errors so assertions can be done - register: DECOMMISSION_DEVICE_ABSENT - - assert: - that: - - DECOMMISSION_DEVICE_ABSENT.changed == false - - DECOMMISSION_DEVICE_ABSENT.failed == true - - DECOMMISSION_DEVICE_ABSENT.msg == "Error - the following devices do not exist in CVP ['leaf2'] but are defined in the playbook. Make sure that the devices are provisioned and defined with the full fqdn name (including the domain name) if needed." - -###################################### -## STATE FACTORY RESET ## -###################################### - - name: Run CV_DEVICE_V3 With State Factory reset - arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_FACT0RY_RESET}}' - state: factory_reset - register: FACTORY_RESET_RESULT - - - assert: - that: - - FACTORY_RESET_RESULT.devices_reset.changed == true - - FACTORY_RESET_RESULT.devices_reset.devices_reset_count == 1 - - FACTORY_RESET_RESULT.devices_reset.devices_reset_list == ['leaf2_reset'] - - FACTORY_RESET_RESULT.devices_reset.success == true - - FACTORY_RESET_RESULT.devices_reset.taskIds is defined - - FACTORY_RESET_RESULT.failed == false - - FACTORY_RESET_RESULT.success == true - -# it is not moving device to undefined container, just creating a task on CVP - -###################################### -## STATE PROVISIONING RESET ## -###################################### - - - name: Run CV_DEVICE_V3 With State Provisioning Reset - arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_PROVISIONING_RESET}}' - state: provisioning_reset - register: PROVISIONING_RESET_RESULT - - - name: check provisioning reset - assert: - that: - - PROVISIONING_RESET_RESULT.devices_removed.changed == true - - PROVISIONING_RESET_RESULT.devices_removed.devices_removed_count == 1 - - PROVISIONING_RESET_RESULT.devices_removed. devices_removed_list == ['leaf3_delete'] - - PROVISIONING_RESET_RESULT.devices_removed.success == true - - PROVISIONING_RESET_RESULT.devices_removed.taskIds is defined - - PROVISIONING_RESET_RESULT.failed == false - - PROVISIONING_RESET_RESULT.success == true - -# if we try to delete the same device again(already in undefined container), it does not raises any error and gives the same result + ignore_errors: yes + register: MOVE_DEVICE + + - name: Negative Test Check Move Device With With Parent Container Same + assert: + that: + - MOVE_DEVICE.devices_moved.changed == false + - MOVE_DEVICE.devices_moved.devices_moved_count == 0 + - MOVE_DEVICE.devices_moved.devices_moved_list == [] + - MOVE_DEVICE.devices_moved.success == false + - MOVE_DEVICE.failed == false + - MOVE_DEVICE.taskIds: [] + + ###################################### + ## STATE ABSENT ## + ###################################### + - name: Run CV_DEVICE_V3 With State Absent + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_STATE_ABSENT}}' + state: absent + register: DECOMMISSION_DEVICE + - assert: + that: + - DECOMMISSION_DEVICE.devices_decommissioned.changed == true + - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_count == 0 + - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_list == ['leaf2_delete'] + - DECOMMISSION_DEVICE.devices_decommissioned.success == true + - DECOMMISSION_DEVICE.devices_decommissioned.taskIds == [] + - DECOMMISSION_DEVICE.failed == false + + - name: Run CV_DEVICE_V3 With State Absent # when device does not exist in CVP + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_STATE_ABSENT}}' + state: absent + ignore_errors: yes + register: DECOMMISSION_DEVICE_ABSENT + - assert: + that: + - DECOMMISSION_DEVICE_ABSENT.changed == false + - DECOMMISSION_DEVICE_ABSENT.failed == true + - DECOMMISSION_DEVICE_ABSENT.msg == "Error - the following devices do not exist in CVP ['leaf2'] but are defined in the playbook. Make sure that the devices are provisioned and defined with the full fqdn name (including the domain name) if needed." + + ###################################### + ## STATE FACTORY RESET ## + ###################################### + - name: Run CV_DEVICE_V3 With State Factory reset + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_FACT0RY_RESET}}' + state: factory_reset + register: FACTORY_RESET_RESULT + + # it does not move device to undefined container, just creates a task on CVP + + - name: Check State Factory reset + assert: + that: + - FACTORY_RESET_RESULT.devices_reset.changed == true + - FACTORY_RESET_RESULT.devices_reset.devices_reset_count == 1 + - FACTORY_RESET_RESULT.devices_reset.devices_reset_list == ['leaf2_reset'] + - FACTORY_RESET_RESULT.devices_reset.success == true + - FACTORY_RESET_RESULT.devices_reset.taskIds is defined + - FACTORY_RESET_RESULT.failed == false + - FACTORY_RESET_RESULT.success == true + + ###################################### + ## STATE PROVISIONING RESET ## + ###################################### + + - name: Run CV_DEVICE_V3 With State Provisioning Reset + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_PROVISIONING_RESET}}' + state: provisioning_reset + register: PROVISIONING_RESET_RESULT + + # if we try to delete the same device again(already in undefined container), it does not raise any error and gives the same result + + - name: check provisioning reset + assert: + that: + - PROVISIONING_RESET_RESULT.devices_removed.changed == true + - PROVISIONING_RESET_RESULT.devices_removed.devices_removed_count == 1 + - PROVISIONING_RESET_RESULT.devices_removed. devices_removed_list == ['leaf3_delete'] + - PROVISIONING_RESET_RESULT.devices_removed.success == true + - PROVISIONING_RESET_RESULT.devices_removed.taskIds is defined + - PROVISIONING_RESET_RESULT.failed == false + - PROVISIONING_RESET_RESULT.success == true + + ################################# + ## ASSIGN/REMOVE BUNDLE ## + ################################# + + - name: "Attach bundle on {{inventory_hostname}}" + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_BUNDLE_ATTACHED}}' + state: present + search_key: serialNumber + apply_mode: strict + register: ATTACH_BUNDLE + + - name: "Check attach bundle" + assert: + that: + - ATTACH_BUNDLE.bundle_attached.changed == true + - ATTACH_BUNDLE.bundle_attached.bundle_attached_count == 1 + - ATTACH_BUNDLE.bundle_attached.bundle_attached_list != [] + - ATTACH_BUNDLE.bundle_attached.success == true + - ATTACH_BUNDLE.bundle_attached.taskIds != [] + + - name: "Detach bundle on {{inventory_hostname}}" + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_BUNDLE_DETACHED}}' + state: present + search_key: serialNumber + apply_mode: strict + register: DETACH_BUNDLE + + - name: "Check detach bundle" + assert: + that: + - DETACH_BUNDLE.bundle_detached.changed == true + - DETACH_BUNDLE.bundle_detached.bundle_detached_count == 1 + - DETACH_BUNDLE.bundle_detached.bundle_detached_list != [] + - DETACH_BUNDLE.bundle_detached.success == true diff --git a/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py b/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py index 2b3c91835..3529d7071 100644 --- a/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py +++ b/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py @@ -1588,6 +1588,7 @@ def apply_bundle(self, user_inventory: DeviceInventory): result_data.changed = True result_data.success = True result_data.taskIds = resp["data"][Api.task.TASK_IDS] + result_data.add_entry(f"{device.image_bundle} apply to {device.fqdn}") results.append(result_data) @@ -1691,6 +1692,7 @@ def detach_bundle(self, user_inventory: DeviceInventory): result_data.changed = True result_data.success = True result_data.taskIds = resp["data"][Api.task.TASK_IDS] + result_data.add_entry(f"{device.image_bundle} detach from {device.fqdn}") results.append(result_data) From 968316063912dcdcd80bfd519acad962870e42ac Mon Sep 17 00:00:00 2001 From: Shivani-chourasiya Date: Mon, 19 Jun 2023 12:20:43 +0530 Subject: [PATCH 06/19] Added tests for apply/detach configlets --- .../cv_device_v3/test_cv_device_v3.yaml | 91 ++++++++++++++++++- .../cvp/plugins/module_utils/device_tools.py | 24 ++--- 2 files changed, 97 insertions(+), 18 deletions(-) diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml index b730971ba..6a22090b6 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml @@ -41,10 +41,25 @@ configlets: - 'AVD_Ipmi3' + CVP_CONFIGLETS: + configlet1: '! This is first configlet' + configlet2: '! This is second configlet' + + CVP_DEVICES_APPLY_CONFIGLET: + - fqdn: leaf3.atd.lab + parentContainerName: ATD_SPINES + configlets: + - 'configlet1' + - 'configlet2' + + CVP_DEVICES_DETACH_CONFIGLET: + - fqdn: leaf3.atd.lab + parentContainerName: ATD_SPINES + tasks: -##################################### -## MOVE DEVICE ## -##################################### + ##################################### + ## MOVE DEVICE ## + ##################################### - name: Run CV_DEVICE_V3 To Move Device arista.cvp.cv_device_v3: @@ -93,7 +108,7 @@ - MOVE_DEVICE.taskIds: [] ###################################### - ## STATE ABSENT ## + ## STATE ABSENT (DECOMMISSION) ## ###################################### - name: Run CV_DEVICE_V3 With State Absent arista.cvp.cv_device_v3: @@ -202,3 +217,71 @@ - DETACH_BUNDLE.bundle_detached.bundle_detached_count == 1 - DETACH_BUNDLE.bundle_detached.bundle_detached_list != [] - DETACH_BUNDLE.bundle_detached.success == true + + ################################# + ## APPLY/DETACH CONFIGLET ## + ################################# + + - name: "Push config" + arista.cvp.cv_configlet_v3: + configlets: "{{CVP_CONFIGLETS}}" + state: present + register: CV_CONFIGLET + + - name: "Configure devices on {{inventory_hostname}}" + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_APPLY_CONFIGLET}}' + state: present + search_key: fqdn + register: CV_DEVICE_V3_RESULT + + - name: "Check apply_configlet with apply_mode loose" + assert: + that: + - CV_DEVICE_V3_RESULT.changed == true + - CV_DEVICE_V3_RESULT.configlets_attached.changed == true + - CV_DEVICE_V3_RESULT.configlets_attached.configlets_attached_count == 2 + - CV_DEVICE_V3_RESULT.configlets_attached.configlets_attached_list == ["leaf3.atd.lab_configlet_attached"] + - CV_DEVICE_V3_RESULT.configlets_attached.success == true + - CV_DEVICE_V3_RESULT.configlets_attached.taskIds != [] + + - name: "Applying same configlet again on {{inventory_hostname}}" + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_APPLY_CONFIGLET}}' + state: present + search_key: fqdn + register: CV_DEVICE_V3_RESULT + + - name: "Check apply_configlet with same configlets" + assert: + that: + - CV_DEVICE_V3_RESULT.changed == false + - CV_DEVICE_V3_RESULT.configlets_attached.changed == false + - CV_DEVICE_V3_RESULT.configlets_attached.configlets_attached_count == 0 + - CV_DEVICE_V3_RESULT.configlets_attached.configlets_attached_list == [] + - CV_DEVICE_V3_RESULT.configlets_attached.success == false + - CV_DEVICE_V3_RESULT.configlets_attached.taskIds == [] + + - name: "Configure devices on {{inventory_hostname}}" + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_DETACH_CONFIGLET}}' + state: present + search_key: fqdn + apply_mode: strict + register: CV_DEVICE_V3_RESULT + + - name: "Check detach_configlet with apply_mode strict" + assert: + that: + - CV_DEVICE_V3_RESULT.changed == true + - CV_DEVICE_V3_RESULT.configlets_detached.changed == true + - CV_DEVICE_V3_RESULT.configlets_detached.configlets_detached_count == 2 + - CV_DEVICE_V3_RESULT.configlets_detached.configlets_detached_list == ["leaf3.atd.lab_configlet_removed - configlet1 - configlet2"] + - CV_DEVICE_V3_RESULT.configlets_detached.success == true + - CV_DEVICE_V3_RESULT.configlets_detached.taskIds != [] + + - name: "Delete config" + arista.cvp.cv_configlet_v3: + configlets: "{{CVP_CONFIGLETS}}" + state: absent + register: DELETE_CONFIGLET_RESULT diff --git a/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py b/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py index 3529d7071..65cabf3d0 100644 --- a/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py +++ b/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py @@ -1816,16 +1816,14 @@ def apply_configlets(self, user_inventory: DeviceInventory): result_data.changed = True result_data.success = True result_data.taskIds = resp["data"][Api.task.TASK_IDS] - result_data.add_entry( - "{0} adds {1}".format(device.fqdn, *device.configlets) - ) + for configlet in device.configlets: + result_data.add_entry( + "{0} adds {1}".format(device.fqdn, configlet) + ) MODULE_LOGGER.debug("CVP response is: %s", str(resp)) MODULE_LOGGER.info( "Reponse data is: %s", str(result_data.results) ) - result_data.add_entry( - "{0} to {1}".format(device.fqdn, *device.container) - ) else: result_data.name = result_data.name + " - nothing attached" results.append(result_data) @@ -1900,21 +1898,19 @@ def detach_configlets(self, user_inventory: DeviceInventory): str(catch_error), ) self.__ansible.fail_json( - msg="Error detaching configlets from device " - + device.fqdn - + ": " - + catch_error + msg=f"Error detaching configlets from device {device.fqdn}: {catch_error}" ) else: if resp["data"]["status"] == "success": result_data.changed = True result_data.success = True result_data.taskIds = resp["data"][Api.task.TASK_IDS] - result_data.add_entry( - "{} removes {}".format( - device.fqdn, *device.configlets + for configlet in configlets_to_remove: + result_data.add_entry( + "{} removes {}".format( + device.fqdn, configlet + ) ) - ) else: result_data.name = result_data.name + " - nothing detached" results.append(result_data) From 060a98047c08c03c720480f26e4bfd47880d9da1 Mon Sep 17 00:00:00 2001 From: Shivani-chourasiya Date: Mon, 19 Jun 2023 13:08:18 +0530 Subject: [PATCH 07/19] Added test for deploy_device --- .../cv_device_v3/test_cv_device_v3.yaml | 44 ++++++++++++++----- .../cvp/plugins/module_utils/device_tools.py | 4 +- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml index 6a22090b6..511442e8a 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml @@ -46,15 +46,19 @@ configlet2: '! This is second configlet' CVP_DEVICES_APPLY_CONFIGLET: - - fqdn: leaf3.atd.lab - parentContainerName: ATD_SPINES + - fqdn: leaf1 + parentContainerName: "Leaf" configlets: - 'configlet1' - 'configlet2' CVP_DEVICES_DETACH_CONFIGLET: - - fqdn: leaf3.atd.lab - parentContainerName: ATD_SPINES + - fqdn: leaf1 + parentContainerName: "Leaf" + + CVP_DEVICES_DEPLOY: + - fqdn: leaf3 # leaf1 must be in undefined container + parentContainerName: "pod2" tasks: ##################################### @@ -228,7 +232,7 @@ state: present register: CV_CONFIGLET - - name: "Configure devices on {{inventory_hostname}}" + - name: "Apply configlet on {{inventory_hostname}}" arista.cvp.cv_device_v3: devices: '{{CVP_DEVICES_APPLY_CONFIGLET}}' state: present @@ -241,15 +245,14 @@ - CV_DEVICE_V3_RESULT.changed == true - CV_DEVICE_V3_RESULT.configlets_attached.changed == true - CV_DEVICE_V3_RESULT.configlets_attached.configlets_attached_count == 2 - - CV_DEVICE_V3_RESULT.configlets_attached.configlets_attached_list == ["leaf3.atd.lab_configlet_attached"] + - CV_DEVICE_V3_RESULT.configlets_attached.configlets_attached_list == ["leaf1_configlet_attached"] - CV_DEVICE_V3_RESULT.configlets_attached.success == true - CV_DEVICE_V3_RESULT.configlets_attached.taskIds != [] - - name: "Applying same configlet again on {{inventory_hostname}}" + - name: "Apply same configlet again on {{inventory_hostname}}" arista.cvp.cv_device_v3: devices: '{{CVP_DEVICES_APPLY_CONFIGLET}}' state: present - search_key: fqdn register: CV_DEVICE_V3_RESULT - name: "Check apply_configlet with same configlets" @@ -262,11 +265,10 @@ - CV_DEVICE_V3_RESULT.configlets_attached.success == false - CV_DEVICE_V3_RESULT.configlets_attached.taskIds == [] - - name: "Configure devices on {{inventory_hostname}}" + - name: "Detach configlet from {{inventory_hostname}}" arista.cvp.cv_device_v3: devices: '{{CVP_DEVICES_DETACH_CONFIGLET}}' state: present - search_key: fqdn apply_mode: strict register: CV_DEVICE_V3_RESULT @@ -276,7 +278,7 @@ - CV_DEVICE_V3_RESULT.changed == true - CV_DEVICE_V3_RESULT.configlets_detached.changed == true - CV_DEVICE_V3_RESULT.configlets_detached.configlets_detached_count == 2 - - CV_DEVICE_V3_RESULT.configlets_detached.configlets_detached_list == ["leaf3.atd.lab_configlet_removed - configlet1 - configlet2"] + - CV_DEVICE_V3_RESULT.configlets_detached.configlets_detached_list == ["leaf1_configlet_removed - configlet1 - configlet2"] - CV_DEVICE_V3_RESULT.configlets_detached.success == true - CV_DEVICE_V3_RESULT.configlets_detached.taskIds != [] @@ -285,3 +287,23 @@ configlets: "{{CVP_CONFIGLETS}}" state: absent register: DELETE_CONFIGLET_RESULT + + ################################# + ## DEPLOY DEVICE ## + ################################# + + - name: "Deploy device on {{inventory_hostname}}" + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_DEPLOY}}' + state: present + register: CV_DEVICE_V3_RESULT + + - name: "Check deploy_device" + assert: + that: + - CV_DEVICE_V3_RESULT.changed == true + - CV_DEVICE_V3_RESULT.devices_deployed.changed == true + - CV_DEVICE_V3_RESULT.devices_deployed.devices_deployed_count == 1 + - CV_DEVICE_V3_RESULT.devices_deployed.devices_deployed_list == ["leaf3_deployed"] + - CV_DEVICE_V3_RESULT.devices_deployed.success == true + - CV_DEVICE_V3_RESULT.devices_deployed.taskIds != [] diff --git a/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py b/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py index 65cabf3d0..76ee37ae4 100644 --- a/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py +++ b/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py @@ -2053,12 +2053,12 @@ def deploy_device(self, user_inventory: DeviceInventory): except CvpApiError as error: self.__ansible.fail_json( msg="Error to deploy device {} to container {}".format( - device.fqdn, *device.container + device.fqdn, device.container ) ) MODULE_LOGGER.critical( "Error deploying device {} : {}".format( - device.fqdn, *error + device.fqdn, error ) ) else: From a3155fb4008a0058a46d99563d50617d881fbd07 Mon Sep 17 00:00:00 2001 From: Shivani-chourasiya Date: Mon, 19 Jun 2023 18:07:26 +0530 Subject: [PATCH 08/19] Fixing pylint issues --- .../arista/cvp/plugins/module_utils/device_tools.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py b/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py index 76ee37ae4..b3d9718e6 100644 --- a/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py +++ b/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py @@ -1907,7 +1907,7 @@ def detach_configlets(self, user_inventory: DeviceInventory): result_data.taskIds = resp["data"][Api.task.TASK_IDS] for configlet in configlets_to_remove: result_data.add_entry( - "{} removes {}".format( + "{0} removes {1}".format( device.fqdn, configlet ) ) @@ -2052,12 +2052,10 @@ def deploy_device(self, user_inventory: DeviceInventory): ) except CvpApiError as error: self.__ansible.fail_json( - msg="Error to deploy device {} to container {}".format( - device.fqdn, device.container - ) + msg=f"Error to deploy device {device.fqdn} to container {device.container}" ) MODULE_LOGGER.critical( - "Error deploying device {} : {}".format( + "Error deploying device {0} : {1}".format( device.fqdn, error ) ) From 0968b78e5f8f053829d35814d556ff2f26c90526 Mon Sep 17 00:00:00 2001 From: Sugetha Chandhrasekar Date: Tue, 25 Jul 2023 16:00:28 -0700 Subject: [PATCH 09/19] added back inventory file; revert of d346824e7dd8b716d3011c78d914351fe29b7202 --- .../arista/cvp/examples/inventory.yml | 17 +++++++++++++++++ .../cv_device_v3/test_cv_device_v3.yaml | 5 ++--- 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 ansible_collections/arista/cvp/examples/inventory.yml diff --git a/ansible_collections/arista/cvp/examples/inventory.yml b/ansible_collections/arista/cvp/examples/inventory.yml new file mode 100644 index 000000000..1ffaad3b9 --- /dev/null +++ b/ansible_collections/arista/cvp/examples/inventory.yml @@ -0,0 +1,17 @@ +--- +all: + children: + CVP: + hosts: + CloudVision: + ansible_httpapi_host: 192.168.0.5 + ansible_host: 192.168.0.5 + ansible_user: arista + ansible_password: "{{ lookup('env', 'LABPASSPHRASE') }}" # lab credential password + ansible_connection: httpapi + ansible_httpapi_use_ssl: True + ansible_httpapi_validate_certs: False + ansible_network_os: eos + ansible_httpapi_port: 443 + # Configuration to get Virtual Env information + ansible_python_interpreter: $(which python3) diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml index 511442e8a..abda17a0b 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml @@ -6,7 +6,7 @@ vars: CVP_DEVICES_MOVE_DEVICE: - fqdn: leaf1 - parentContainerName: "Leaf" + parentContainerName: "Spine" CVP_DEVICES_PARENT_CONTAINER_NONE: - fqdn: leaf1 @@ -14,8 +14,7 @@ CVP_DEVICES_PARENT_CONTAINER_SAME: - fqdn: leaf1 - parentContainerName: "Leaf" - + parentContainerName: "Spine" CVP_DEVICES_STATE_ABSENT: - fqdn: leaf2 parentContainerName: "" From 3db220d89a3f63cfa3506818ee94b179417e8f5a Mon Sep 17 00:00:00 2001 From: Sugetha Chandhrasekar Date: Tue, 25 Jul 2023 16:05:23 -0700 Subject: [PATCH 10/19] reapplying partial changes from d346824e7dd8b716d3011c78d914351fe29b7202 --- .../arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml index abda17a0b..6cfabcdf7 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml @@ -6,7 +6,7 @@ vars: CVP_DEVICES_MOVE_DEVICE: - fqdn: leaf1 - parentContainerName: "Spine" + parentContainerName: "Leaf" CVP_DEVICES_PARENT_CONTAINER_NONE: - fqdn: leaf1 @@ -14,7 +14,7 @@ CVP_DEVICES_PARENT_CONTAINER_SAME: - fqdn: leaf1 - parentContainerName: "Spine" + parentContainerName: "Leaf" CVP_DEVICES_STATE_ABSENT: - fqdn: leaf2 parentContainerName: "" From 20e2d6a9330588195eabcc5e7fba9a64925641ce Mon Sep 17 00:00:00 2001 From: Shivani-chourasiya Date: Fri, 28 Jul 2023 18:48:44 +0530 Subject: [PATCH 11/19] Separating files and fixing review comments --- .../cvp/molecule/cv_device_v3/converge.yml | 13 +- .../cv_device_v3/test_apply_detach_bundle.yml | 59 +++++++++ .../test_apply_detach_configlet.yml | 83 +++++++++++++ ...ssion_factory_reset_provisioning_reset.yml | 89 ++++++++++++++ .../test_move_and_deploy_device.yml | 116 ++++++++++++++++++ 5 files changed, 358 insertions(+), 2 deletions(-) create mode 100644 ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml create mode 100644 ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_configlet.yml create mode 100644 ansible_collections/arista/cvp/molecule/cv_device_v3/test_decommission_factory_reset_provisioning_reset.yml create mode 100644 ansible_collections/arista/cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/converge.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/converge.yml index b98f8b875..96b50f1c3 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/converge.yml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/converge.yml @@ -1,3 +1,12 @@ --- -- name: Run cv_device_v3 - import_playbook: test_cv_device_v3.yaml +- name: Test cv_device_v3 module + import_playbook: test_move_and_deploy_device.yml + +- name: Test cv_device_v3 module + import_playbook: test_apply_detach_configlet.yml + +- name: Test cv_device_v3 module + import_playbook: test_decommission_factory_reset_provisioning_reset.yml + +- name: Test cv_device_v3 module + import_playbook: test_apply_detach_bundle.yml diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml new file mode 100644 index 000000000..e38865752 --- /dev/null +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml @@ -0,0 +1,59 @@ +--- +- name: Test cv_device_v3 + hosts: CloudVision + connection: local + gather_facts: no + vars: + CVP_CONFIGLETS: + configlet1: '! This is first configlet' + + CVP_DEVICES_BUNDLE_ATTACHED: + - serialNumber: JPE504a004ea054 + parentContainerName: L2_Leaf + configlets: + - 'AVD_Ipmi3' + imageBundle: leaf_bundle + + CVP_DEVICES_BUNDLE_DETACHED: + - serialNumber: JPE504a004ea054 + parentContainerName: L2_Leaf + configlets: + - 'AVD_Ipmi3' + tasks: + - name: "Push config" + arista.cvp.cv_configlet_v3: + configlets: "{{CVP_CONFIGLETS}}" + state: present + + - name: "Attach bundle on {{inventory_hostname}}" + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_BUNDLE_ATTACHED}}' + state: present + search_key: serialNumber + apply_mode: strict + register: ATTACH_BUNDLE + + - name: "Check attach bundle" + assert: + that: + - ATTACH_BUNDLE.bundle_attached.changed == true + - ATTACH_BUNDLE.bundle_attached.bundle_attached_count == 1 + - ATTACH_BUNDLE.bundle_attached.bundle_attached_list != [] + - ATTACH_BUNDLE.bundle_attached.success == true + - ATTACH_BUNDLE.bundle_attached.taskIds != [] + + - name: "Detach bundle on {{inventory_hostname}}" + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_BUNDLE_DETACHED}}' + state: present + search_key: serialNumber + apply_mode: strict + register: DETACH_BUNDLE + + - name: "Check detach bundle" + assert: + that: + - DETACH_BUNDLE.bundle_detached.changed == true + - DETACH_BUNDLE.bundle_detached.bundle_detached_count == 1 + - DETACH_BUNDLE.bundle_detached.bundle_detached_list != [] + - DETACH_BUNDLE.bundle_detached.success == true diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_configlet.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_configlet.yml new file mode 100644 index 000000000..499dc94c0 --- /dev/null +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_configlet.yml @@ -0,0 +1,83 @@ +--- +- name: Test cv_device_v3 + hosts: CloudVision + connection: local + gather_facts: no + vars: + CVP_CONFIGLETS: + configlet1: '! This is first configlet' + configlet2: '! This is second configlet' + + CVP_DEVICES_APPLY_CONFIGLET: + - fqdn: leaf1.atd.lab + parentContainerName: "pod1" + configlets: + - 'configlet1' + - 'configlet2' + + CVP_DEVICES_DETACH_CONFIGLET: + - fqdn: leaf1.atd.lab + parentContainerName: "pod1" + + tasks: + - name: "Push config" + arista.cvp.cv_configlet_v3: + configlets: "{{CVP_CONFIGLETS}}" + state: present + register: CV_CONFIGLET + + - name: "Apply configlet on {{inventory_hostname}}" + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_APPLY_CONFIGLET}}' + state: present + search_key: fqdn + register: CV_DEVICE_V3_RESULT + + - name: "Check apply_configlet with apply_mode loose" + assert: + that: + - CV_DEVICE_V3_RESULT.changed == true + - CV_DEVICE_V3_RESULT.configlets_attached.changed == true + - CV_DEVICE_V3_RESULT.configlets_attached.configlets_attached_count == 2 + - CV_DEVICE_V3_RESULT.configlets_attached.configlets_attached_list == ["leaf1_configlet_attached"] + - CV_DEVICE_V3_RESULT.configlets_attached.success == true + - CV_DEVICE_V3_RESULT.configlets_attached.taskIds != [] + + - name: "Apply same configlet again on {{inventory_hostname}}" + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_APPLY_CONFIGLET}}' + state: present + register: CV_DEVICE_V3_RESULT + + - name: "Check apply_configlet with same configlets" + assert: + that: + - CV_DEVICE_V3_RESULT.changed == false + - CV_DEVICE_V3_RESULT.configlets_attached.changed == false + - CV_DEVICE_V3_RESULT.configlets_attached.configlets_attached_count == 0 + - CV_DEVICE_V3_RESULT.configlets_attached.configlets_attached_list == [] + - CV_DEVICE_V3_RESULT.configlets_attached.success == false + - CV_DEVICE_V3_RESULT.configlets_attached.taskIds == [] + + - name: "Detach configlet from {{inventory_hostname}}" + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_DETACH_CONFIGLET}}' + state: present + apply_mode: strict + register: CV_DEVICE_V3_RESULT + + - name: "Check detach_configlet with apply_mode strict" + assert: + that: + - CV_DEVICE_V3_RESULT.changed == true + - CV_DEVICE_V3_RESULT.configlets_detached.changed == true + - CV_DEVICE_V3_RESULT.configlets_detached.configlets_detached_count == 2 + - CV_DEVICE_V3_RESULT.configlets_detached.configlets_detached_list == ["leaf1_configlet_removed - configlet1 - configlet2"] + - CV_DEVICE_V3_RESULT.configlets_detached.success == true + - CV_DEVICE_V3_RESULT.configlets_detached.taskIds != [] + + - name: "Delete config" + arista.cvp.cv_configlet_v3: + configlets: "{{CVP_CONFIGLETS}}" + state: absent + register: DELETE_CONFIGLET_RESULT diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_decommission_factory_reset_provisioning_reset.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_decommission_factory_reset_provisioning_reset.yml new file mode 100644 index 000000000..55746ceee --- /dev/null +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_decommission_factory_reset_provisioning_reset.yml @@ -0,0 +1,89 @@ +--- +- name: Test cv_device_v3 + hosts: CloudVision + connection: local + gather_facts: no + vars: + CVP_DEVICES_STATE_ABSENT: + - fqdn: leaf1 + parentContainerName: "" + CVP_DEVICES_FACT0RY_RESET: + - fqdn: leaf1 + parentContainerName: "" + CVP_DEVICES_PROVISIONING_RESET: + - fqdn: leaf2 + parentContainerName: "" + tasks: + ###################################### + ## STATE ABSENT (DECOMMISSION) ## + ###################################### + - name: Run CV_DEVICE_V3 With State Absent + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_STATE_ABSENT}}' + state: absent + register: DECOMMISSION_DEVICE + - assert: + that: + - DECOMMISSION_DEVICE.devices_decommissioned.changed == true + - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_count == 0 + - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_list == ['leaf2_delete'] + - DECOMMISSION_DEVICE.devices_decommissioned.success == true + - DECOMMISSION_DEVICE.devices_decommissioned.taskIds == [] + - DECOMMISSION_DEVICE.failed == false + + - name: Run CV_DEVICE_V3 With State Absent # when device does not exist in CVP + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_STATE_ABSENT}}' + state: absent + ignore_errors: yes + register: DECOMMISSION_DEVICE_ABSENT + - assert: + that: + - DECOMMISSION_DEVICE_ABSENT.changed == false + - DECOMMISSION_DEVICE_ABSENT.failed == true + - DECOMMISSION_DEVICE_ABSENT.msg == "Error - the following devices do not exist in CVP ['leaf2'] but are defined in the playbook. Make sure that the devices are provisioned and defined with the full fqdn name (including the domain name) if needed." + + ###################################### + ## STATE FACTORY RESET ## + ###################################### + - name: Run CV_DEVICE_V3 With State Factory reset + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_FACT0RY_RESET}}' + state: factory_reset + register: FACTORY_RESET_RESULT + + # it does not move device to undefined container, just creates a task on CVP + + - name: Check State Factory reset + assert: + that: + - FACTORY_RESET_RESULT.devices_reset.changed == true + - FACTORY_RESET_RESULT.devices_reset.devices_reset_count == 1 + - FACTORY_RESET_RESULT.devices_reset.devices_reset_list == ['leaf2_reset'] + - FACTORY_RESET_RESULT.devices_reset.success == true + - FACTORY_RESET_RESULT.devices_reset.taskIds is defined + - FACTORY_RESET_RESULT.failed == false + - FACTORY_RESET_RESULT.success == true + + ###################################### + ## STATE PROVISIONING RESET ## + ###################################### + + - name: Run CV_DEVICE_V3 With State Provisioning Reset + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_PROVISIONING_RESET}}' + state: provisioning_reset + register: PROVISIONING_RESET_RESULT + + # if we try to delete the same device again(already in undefined container), it does not raise any error and gives the same result + + - name: check provisioning reset + assert: + that: + - PROVISIONING_RESET_RESULT.devices_removed.changed == true + - PROVISIONING_RESET_RESULT.devices_removed.devices_removed_count == 1 + - PROVISIONING_RESET_RESULT.devices_removed. devices_removed_list == ['leaf3_delete'] + - PROVISIONING_RESET_RESULT.devices_removed.success == true + - PROVISIONING_RESET_RESULT.devices_removed.taskIds is defined + - PROVISIONING_RESET_RESULT.failed == false + - PROVISIONING_RESET_RESULT.success == true diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml new file mode 100644 index 000000000..15fe5b66b --- /dev/null +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml @@ -0,0 +1,116 @@ +--- +- name: Test cv_device_v3 + hosts: CloudVision + connection: local + gather_facts: no + vars: + DEVICE_NAME: leaf1 + + CONTAINER: + Test_Leafs: + parentContainerName: Tenant + + CVP_DEVICES_MOVE_DEVICE: + - fqdn: "{{DEVICE_NAME}}" + parentContainerName: "Test_Leafs" + + CVP_DEVICES_PARENT_CONTAINER_NONE: + - fqdn: "{{DEVICE_NAME}}" + parentContainerName: None + + CVP_DEVICES_DEPLOY: + - fqdn: leaf1.atd.lab # leaf1 must be in undefined container + parentContainerName: "Test_Leafs" + + tasks: + # Creating a container + - name: Build Container On {{inventory_hostname}} + arista.cvp.cv_container_v3: + topology: '{{CONTAINER}}' + + - name: Collect devices facts from {{inventory_hostname}} + arista.cvp.cv_facts_v3: + facts: + - devices + regexp_filter: "{{DEVICE_NAME}}" + register: CV_FACTS_V3_RESULT + + - name: Run CV_DEVICE_V3 To Move Device + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_MOVE_DEVICE}}' + state: present + register: MOVE_DEVICE_RUN + + - name: Check Move Device + assert: + that: + - "MOVE_DEVICE_RUN.devices_moved.changed == true" + - "MOVE_DEVICE_RUN.devices_moved.devices_moved_count == 1" + - "MOVE_DEVICE_RUN.devices_moved.devices_moved_list == ['leaf1_to_Test_Leafs']" + - "MOVE_DEVICE_RUN.devices_moved.success == true" + - "MOVE_DEVICE_RUN.failed == false" + + - name: Run CV_DEVICE_V3 To Move Device With Parent Container None + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_PARENT_CONTAINER_NONE}}' + state: present + ignore_errors: yes + register: MOVE_DEVICE_NONE + + - name: Negative Test Check Move Device With Parent Container None + assert: + that: + - MOVE_DEVICE_NONE.msg == "The target container 'None' for the device 'leaf1' does not exist on CVP." + - MOVE_DEVICE_NONE.changed == false + - MOVE_DEVICE_NONE.failed == true + + - name: Run CV_DEVICE_V3 To Move Device With Parent Container Same + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_MOVE_DEVICE}}' + state: present + ignore_errors: yes + register: MOVE_DEVICE + + - name: Negative Test Check Move Device With Same Parent Container + assert: + that: + - MOVE_DEVICE.devices_moved.changed == false + - MOVE_DEVICE.devices_moved.devices_moved_count == 0 + - MOVE_DEVICE.devices_moved.devices_moved_list == [] + - MOVE_DEVICE.devices_moved.success == false + - MOVE_DEVICE.failed == false + - MOVE_DEVICE.taskIds: [] + + - name: Move Device Back TO Original Container + vars: + CVP_DEVICES_MOVE_BACK_DEVICE: + - fqdn: "{{DEVICE_NAME}}" + parentContainerName: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].parentContainerName}}" + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_MOVE_BACK_DEVICE}}' + state: present + + ################################# + ## DEPLOY DEVICE ## + ################################# + + - name: "Deploy device on {{inventory_hostname}}" + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_DEPLOY}}' + state: present + register: CV_DEVICE_V3_RESULT + + - name: "Check deploy_device" + assert: + that: + - CV_DEVICE_V3_RESULT.changed == true + - CV_DEVICE_V3_RESULT.devices_deployed.changed == true + - CV_DEVICE_V3_RESULT.devices_deployed.devices_deployed_count == 1 + - CV_DEVICE_V3_RESULT.devices_deployed.devices_deployed_list == ["leaf3_deployed"] + - CV_DEVICE_V3_RESULT.devices_deployed.success == true + - CV_DEVICE_V3_RESULT.devices_deployed.taskIds != [] + + - name: Remove Container + arista.cvp.cv_container_v3: + topology: '{{CONTAINER}}' + state: absent From 3bbb64881fddbee9a8a7497c4c5ac05d9c7a93ba Mon Sep 17 00:00:00 2001 From: Shivani-chourasiya Date: Mon, 31 Jul 2023 16:58:50 +0530 Subject: [PATCH 12/19] Updating tests Some minor fix Updated tests --- .../cvp/molecule/cv_device_v3/converge.yml | 12 +- .../cv_device_v3/test_apply_detach_bundle.yml | 75 ++++- .../test_apply_detach_configlet.yml | 7 +- .../cv_device_v3/test_cv_device_v3.yaml | 308 ------------------ .../test_move_and_deploy_device.yml | 75 +++-- 5 files changed, 125 insertions(+), 352 deletions(-) delete mode 100644 ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/converge.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/converge.yml index 96b50f1c3..992cadf21 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/converge.yml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/converge.yml @@ -2,11 +2,11 @@ - name: Test cv_device_v3 module import_playbook: test_move_and_deploy_device.yml -- name: Test cv_device_v3 module - import_playbook: test_apply_detach_configlet.yml +#- name: Test cv_device_v3 module +# import_playbook: test_apply_detach_configlet.yml -- name: Test cv_device_v3 module - import_playbook: test_decommission_factory_reset_provisioning_reset.yml +#- name: Test cv_device_v3 module +# import_playbook: test_apply_detach_bundle.yml -- name: Test cv_device_v3 module - import_playbook: test_apply_detach_bundle.yml +#- name: Test cv_device_v3 module +# import_playbook: test_decommission_factory_reset_provisioning_reset.yml diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml index e38865752..2d9eb2357 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml @@ -4,32 +4,59 @@ connection: local gather_facts: no vars: + ansible_command_timeout: 1200 + ansible_connect_timeout: 600 + + DEVICE_NAME: leaf3 + CVP_CONFIGLETS: configlet1: '! This is first configlet' + IMAGE_NAME: "vEOS-lab.swi" + + BUNDLE_NAME: "Test_bundle" + CVP_DEVICES_BUNDLE_ATTACHED: - - serialNumber: JPE504a004ea054 - parentContainerName: L2_Leaf + - fqdn: "{{DEVICE_NAME}}" + parentContainerName: "pod2" configlets: - - 'AVD_Ipmi3' - imageBundle: leaf_bundle + - 'configlet1' + imageBundle: Test_bundle CVP_DEVICES_BUNDLE_DETACHED: - - serialNumber: JPE504a004ea054 - parentContainerName: L2_Leaf + - fqdn: "{{DEVICE_NAME}}" + parentContainerName: "pod2" configlets: - - 'AVD_Ipmi3' + - 'configlet1' + + CVP_DEVICES_DETACH_CONFIGLET: + - fqdn: "{{DEVICE_NAME}}" + parentContainerName: "pod2" + tasks: - name: "Push config" arista.cvp.cv_configlet_v3: configlets: "{{CVP_CONFIGLETS}}" state: present + - name: "Upload EOS image to {{inventory_hostname}}" + arista.cvp.cv_image_v3: + mode: image + action: add + image: "{{IMAGE_NAME}}" + + - name: "Create bundle {{inventory_hostname}}" + arista.cvp.cv_image_v3: + mode: bundle + action: add + bundle_name: "{{BUNDLE_NAME}}" + image_list: + - "{{IMAGE_NAME}}" + - name: "Attach bundle on {{inventory_hostname}}" arista.cvp.cv_device_v3: devices: '{{CVP_DEVICES_BUNDLE_ATTACHED}}' state: present - search_key: serialNumber apply_mode: strict register: ATTACH_BUNDLE @@ -42,11 +69,16 @@ - ATTACH_BUNDLE.bundle_attached.success == true - ATTACH_BUNDLE.bundle_attached.taskIds != [] + - name: Execute Task for attach_bundle + arista.cvp.cv_task_v3: + tasks: + - "{{item}}" + loop: "{{ATTACH_BUNDLE.taskIds}}" + - name: "Detach bundle on {{inventory_hostname}}" arista.cvp.cv_device_v3: devices: '{{CVP_DEVICES_BUNDLE_DETACHED}}' state: present - search_key: serialNumber apply_mode: strict register: DETACH_BUNDLE @@ -57,3 +89,28 @@ - DETACH_BUNDLE.bundle_detached.bundle_detached_count == 1 - DETACH_BUNDLE.bundle_detached.bundle_detached_list != [] - DETACH_BUNDLE.bundle_detached.success == true + + - name: "Delete bundle {{inventory_hostname}}" + arista.cvp.cv_image_v3: + mode: bundle + action: remove + bundle_name: "{{BUNDLE_NAME}}" + image_list: + - "{{IMAGE_NAME}}" + + - name: "Detach configlet from {{inventory_hostname}}" + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_DETACH_CONFIGLET}}' + state: present + apply_mode: strict + register: DETACH_CONFIGLET + + - name: Execute Task for attach_bundle + arista.cvp.cv_task_v3: + tasks: + - "{{DETACH_CONFIGLET.taskIds[0]}}" + + - name: "Delete configlet" + arista.cvp.cv_configlet_v3: + configlets: "{{CVP_CONFIGLETS}}" + state: absent diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_configlet.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_configlet.yml index 499dc94c0..79514d4b1 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_configlet.yml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_configlet.yml @@ -9,14 +9,14 @@ configlet2: '! This is second configlet' CVP_DEVICES_APPLY_CONFIGLET: - - fqdn: leaf1.atd.lab + - fqdn: leaf1 parentContainerName: "pod1" configlets: - 'configlet1' - 'configlet2' CVP_DEVICES_DETACH_CONFIGLET: - - fqdn: leaf1.atd.lab + - fqdn: leaf1 parentContainerName: "pod1" tasks: @@ -24,13 +24,11 @@ arista.cvp.cv_configlet_v3: configlets: "{{CVP_CONFIGLETS}}" state: present - register: CV_CONFIGLET - name: "Apply configlet on {{inventory_hostname}}" arista.cvp.cv_device_v3: devices: '{{CVP_DEVICES_APPLY_CONFIGLET}}' state: present - search_key: fqdn register: CV_DEVICE_V3_RESULT - name: "Check apply_configlet with apply_mode loose" @@ -80,4 +78,3 @@ arista.cvp.cv_configlet_v3: configlets: "{{CVP_CONFIGLETS}}" state: absent - register: DELETE_CONFIGLET_RESULT diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml deleted file mode 100644 index 6cfabcdf7..000000000 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_cv_device_v3.yaml +++ /dev/null @@ -1,308 +0,0 @@ ---- -- name: Test cv_device_v3 - hosts: CloudVision - connection: local - gather_facts: no - vars: - CVP_DEVICES_MOVE_DEVICE: - - fqdn: leaf1 - parentContainerName: "Leaf" - - CVP_DEVICES_PARENT_CONTAINER_NONE: - - fqdn: leaf1 - parentContainerName: None - - CVP_DEVICES_PARENT_CONTAINER_SAME: - - fqdn: leaf1 - parentContainerName: "Leaf" - CVP_DEVICES_STATE_ABSENT: - - fqdn: leaf2 - parentContainerName: "" - - CVP_DEVICES_FACT0RY_RESET: - - fqdn: leaf2 - parentContainerName: "" - - CVP_DEVICES_PROVISIONING_RESET: - - fqdn: leaf3 - parentContainerName: "" - - CVP_DEVICES_BUNDLE_ATTACHED: - - serialNumber: JPE504a004ea054 - parentContainerName: L2_Leaf - configlets: - - 'AVD_Ipmi3' - imageBundle: leaf_bundle - - CVP_DEVICES_BUNDLE_DETACHED: - - serialNumber: JPE504a004ea054 - parentContainerName: L2_Leaf - configlets: - - 'AVD_Ipmi3' - - CVP_CONFIGLETS: - configlet1: '! This is first configlet' - configlet2: '! This is second configlet' - - CVP_DEVICES_APPLY_CONFIGLET: - - fqdn: leaf1 - parentContainerName: "Leaf" - configlets: - - 'configlet1' - - 'configlet2' - - CVP_DEVICES_DETACH_CONFIGLET: - - fqdn: leaf1 - parentContainerName: "Leaf" - - CVP_DEVICES_DEPLOY: - - fqdn: leaf3 # leaf1 must be in undefined container - parentContainerName: "pod2" - - tasks: - ##################################### - ## MOVE DEVICE ## - ##################################### - - - name: Run CV_DEVICE_V3 To Move Device - arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_MOVE_DEVICE}}' - state: present - register: MOVE_DEVICE_RUN - - - name: Check Move Device - assert: - that: - - "MOVE_DEVICE_RUN.devices_moved.changed == true" - - "MOVE_DEVICE_RUN.devices_moved.devices_moved_count == 1" - - "MOVE_DEVICE_RUN.devices_moved.devices_moved_list == ['leaf1_to_Leaf']" - - "MOVE_DEVICE_RUN.devices_moved.success == true" - - "MOVE_DEVICE_RUN.failed == false" - - - name: Run CV_DEVICE_V3 To Move Device With Parent Container None - arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_PARENT_CONTAINER_NONE}}' - state: present - ignore_errors: yes - register: MOVE_DEVICE_NONE - - - name: Negative Test Check Move Device With Parent Container None - assert: - that: - - MOVE_DEVICE_NONE.msg == "The target container 'None' for the device 'leaf1' does not exist on CVP." - - MOVE_DEVICE_NONE.changed == false - - MOVE_DEVICE_NONE.failed == true - - - name: Run CV_DEVICE_V3 To Move Device With Parent Container Same - arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_PARENT_CONTAINER_SAME}}' - state: present - ignore_errors: yes - register: MOVE_DEVICE - - - name: Negative Test Check Move Device With With Parent Container Same - assert: - that: - - MOVE_DEVICE.devices_moved.changed == false - - MOVE_DEVICE.devices_moved.devices_moved_count == 0 - - MOVE_DEVICE.devices_moved.devices_moved_list == [] - - MOVE_DEVICE.devices_moved.success == false - - MOVE_DEVICE.failed == false - - MOVE_DEVICE.taskIds: [] - - ###################################### - ## STATE ABSENT (DECOMMISSION) ## - ###################################### - - name: Run CV_DEVICE_V3 With State Absent - arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_STATE_ABSENT}}' - state: absent - register: DECOMMISSION_DEVICE - - assert: - that: - - DECOMMISSION_DEVICE.devices_decommissioned.changed == true - - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_count == 0 - - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_list == ['leaf2_delete'] - - DECOMMISSION_DEVICE.devices_decommissioned.success == true - - DECOMMISSION_DEVICE.devices_decommissioned.taskIds == [] - - DECOMMISSION_DEVICE.failed == false - - - name: Run CV_DEVICE_V3 With State Absent # when device does not exist in CVP - arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_STATE_ABSENT}}' - state: absent - ignore_errors: yes - register: DECOMMISSION_DEVICE_ABSENT - - assert: - that: - - DECOMMISSION_DEVICE_ABSENT.changed == false - - DECOMMISSION_DEVICE_ABSENT.failed == true - - DECOMMISSION_DEVICE_ABSENT.msg == "Error - the following devices do not exist in CVP ['leaf2'] but are defined in the playbook. Make sure that the devices are provisioned and defined with the full fqdn name (including the domain name) if needed." - - ###################################### - ## STATE FACTORY RESET ## - ###################################### - - name: Run CV_DEVICE_V3 With State Factory reset - arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_FACT0RY_RESET}}' - state: factory_reset - register: FACTORY_RESET_RESULT - - # it does not move device to undefined container, just creates a task on CVP - - - name: Check State Factory reset - assert: - that: - - FACTORY_RESET_RESULT.devices_reset.changed == true - - FACTORY_RESET_RESULT.devices_reset.devices_reset_count == 1 - - FACTORY_RESET_RESULT.devices_reset.devices_reset_list == ['leaf2_reset'] - - FACTORY_RESET_RESULT.devices_reset.success == true - - FACTORY_RESET_RESULT.devices_reset.taskIds is defined - - FACTORY_RESET_RESULT.failed == false - - FACTORY_RESET_RESULT.success == true - - ###################################### - ## STATE PROVISIONING RESET ## - ###################################### - - - name: Run CV_DEVICE_V3 With State Provisioning Reset - arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_PROVISIONING_RESET}}' - state: provisioning_reset - register: PROVISIONING_RESET_RESULT - - # if we try to delete the same device again(already in undefined container), it does not raise any error and gives the same result - - - name: check provisioning reset - assert: - that: - - PROVISIONING_RESET_RESULT.devices_removed.changed == true - - PROVISIONING_RESET_RESULT.devices_removed.devices_removed_count == 1 - - PROVISIONING_RESET_RESULT.devices_removed. devices_removed_list == ['leaf3_delete'] - - PROVISIONING_RESET_RESULT.devices_removed.success == true - - PROVISIONING_RESET_RESULT.devices_removed.taskIds is defined - - PROVISIONING_RESET_RESULT.failed == false - - PROVISIONING_RESET_RESULT.success == true - - ################################# - ## ASSIGN/REMOVE BUNDLE ## - ################################# - - - name: "Attach bundle on {{inventory_hostname}}" - arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_BUNDLE_ATTACHED}}' - state: present - search_key: serialNumber - apply_mode: strict - register: ATTACH_BUNDLE - - - name: "Check attach bundle" - assert: - that: - - ATTACH_BUNDLE.bundle_attached.changed == true - - ATTACH_BUNDLE.bundle_attached.bundle_attached_count == 1 - - ATTACH_BUNDLE.bundle_attached.bundle_attached_list != [] - - ATTACH_BUNDLE.bundle_attached.success == true - - ATTACH_BUNDLE.bundle_attached.taskIds != [] - - - name: "Detach bundle on {{inventory_hostname}}" - arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_BUNDLE_DETACHED}}' - state: present - search_key: serialNumber - apply_mode: strict - register: DETACH_BUNDLE - - - name: "Check detach bundle" - assert: - that: - - DETACH_BUNDLE.bundle_detached.changed == true - - DETACH_BUNDLE.bundle_detached.bundle_detached_count == 1 - - DETACH_BUNDLE.bundle_detached.bundle_detached_list != [] - - DETACH_BUNDLE.bundle_detached.success == true - - ################################# - ## APPLY/DETACH CONFIGLET ## - ################################# - - - name: "Push config" - arista.cvp.cv_configlet_v3: - configlets: "{{CVP_CONFIGLETS}}" - state: present - register: CV_CONFIGLET - - - name: "Apply configlet on {{inventory_hostname}}" - arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_APPLY_CONFIGLET}}' - state: present - search_key: fqdn - register: CV_DEVICE_V3_RESULT - - - name: "Check apply_configlet with apply_mode loose" - assert: - that: - - CV_DEVICE_V3_RESULT.changed == true - - CV_DEVICE_V3_RESULT.configlets_attached.changed == true - - CV_DEVICE_V3_RESULT.configlets_attached.configlets_attached_count == 2 - - CV_DEVICE_V3_RESULT.configlets_attached.configlets_attached_list == ["leaf1_configlet_attached"] - - CV_DEVICE_V3_RESULT.configlets_attached.success == true - - CV_DEVICE_V3_RESULT.configlets_attached.taskIds != [] - - - name: "Apply same configlet again on {{inventory_hostname}}" - arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_APPLY_CONFIGLET}}' - state: present - register: CV_DEVICE_V3_RESULT - - - name: "Check apply_configlet with same configlets" - assert: - that: - - CV_DEVICE_V3_RESULT.changed == false - - CV_DEVICE_V3_RESULT.configlets_attached.changed == false - - CV_DEVICE_V3_RESULT.configlets_attached.configlets_attached_count == 0 - - CV_DEVICE_V3_RESULT.configlets_attached.configlets_attached_list == [] - - CV_DEVICE_V3_RESULT.configlets_attached.success == false - - CV_DEVICE_V3_RESULT.configlets_attached.taskIds == [] - - - name: "Detach configlet from {{inventory_hostname}}" - arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_DETACH_CONFIGLET}}' - state: present - apply_mode: strict - register: CV_DEVICE_V3_RESULT - - - name: "Check detach_configlet with apply_mode strict" - assert: - that: - - CV_DEVICE_V3_RESULT.changed == true - - CV_DEVICE_V3_RESULT.configlets_detached.changed == true - - CV_DEVICE_V3_RESULT.configlets_detached.configlets_detached_count == 2 - - CV_DEVICE_V3_RESULT.configlets_detached.configlets_detached_list == ["leaf1_configlet_removed - configlet1 - configlet2"] - - CV_DEVICE_V3_RESULT.configlets_detached.success == true - - CV_DEVICE_V3_RESULT.configlets_detached.taskIds != [] - - - name: "Delete config" - arista.cvp.cv_configlet_v3: - configlets: "{{CVP_CONFIGLETS}}" - state: absent - register: DELETE_CONFIGLET_RESULT - - ################################# - ## DEPLOY DEVICE ## - ################################# - - - name: "Deploy device on {{inventory_hostname}}" - arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_DEPLOY}}' - state: present - register: CV_DEVICE_V3_RESULT - - - name: "Check deploy_device" - assert: - that: - - CV_DEVICE_V3_RESULT.changed == true - - CV_DEVICE_V3_RESULT.devices_deployed.changed == true - - CV_DEVICE_V3_RESULT.devices_deployed.devices_deployed_count == 1 - - CV_DEVICE_V3_RESULT.devices_deployed.devices_deployed_list == ["leaf3_deployed"] - - CV_DEVICE_V3_RESULT.devices_deployed.success == true - - CV_DEVICE_V3_RESULT.devices_deployed.taskIds != [] diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml index 15fe5b66b..7ed3dc89c 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml @@ -4,23 +4,40 @@ connection: local gather_facts: no vars: + ansible_command_timeout: 1200 + ansible_connect_timeout: 600 + DEVICE_NAME: leaf1 CONTAINER: - Test_Leafs: + Test_Leaf: parentContainerName: Tenant CVP_DEVICES_MOVE_DEVICE: - fqdn: "{{DEVICE_NAME}}" - parentContainerName: "Test_Leafs" + parentContainerName: "Test_Leaf" CVP_DEVICES_PARENT_CONTAINER_NONE: - fqdn: "{{DEVICE_NAME}}" parentContainerName: None + CVP_DEVICES_PROVISIONING_RESET: + - fqdn: "{{DEVICE_NAME}}" + parentContainerName: "Test_Leaf" + + CVP_DEVICES_VALIDATE_CONFIG: + - device_name: "{{DEVICE_NAME}}" + search_type: serialNumber + cvp_configlets: ['ATD-INFRA', 'BaseIPv4_Leaf4'] #"{{CV_FACTS_V3_RESULT.data.cvp_devices[0].configlets}}" + CVP_DEVICES_DEPLOY: - - fqdn: leaf1.atd.lab # leaf1 must be in undefined container - parentContainerName: "Test_Leafs" + - fqdn: "{{DEVICE_NAME}}" # device must be in undefined container + parentContainerName: "pod1" #"{{CV_FACTS_V3_RESULT.data.cvp_devices[0].parentContainerName}}" + configlets: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].configlets}}" + + CVP_DEVICES_DETACH_CONFIGLET: + - fqdn: "{{DEVICE_NAME}}" + parentContainerName: "pod1" tasks: # Creating a container @@ -46,7 +63,7 @@ that: - "MOVE_DEVICE_RUN.devices_moved.changed == true" - "MOVE_DEVICE_RUN.devices_moved.devices_moved_count == 1" - - "MOVE_DEVICE_RUN.devices_moved.devices_moved_list == ['leaf1_to_Test_Leafs']" + - "MOVE_DEVICE_RUN.devices_moved.devices_moved_list == ['leaf1_to_Test_Leaf']" - "MOVE_DEVICE_RUN.devices_moved.success == true" - "MOVE_DEVICE_RUN.failed == false" @@ -81,18 +98,22 @@ - MOVE_DEVICE.failed == false - MOVE_DEVICE.taskIds: [] - - name: Move Device Back TO Original Container - vars: - CVP_DEVICES_MOVE_BACK_DEVICE: - - fqdn: "{{DEVICE_NAME}}" - parentContainerName: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].parentContainerName}}" + ################################ + # DEPLOY DEVICE ## + ################################ + + # moving device to undefined container + - name: Run CV_DEVICE_V3 With State Provisioning Reset arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_MOVE_BACK_DEVICE}}' - state: present + devices: '{{CVP_DEVICES_PROVISIONING_RESET}}' + state: provisioning_reset + register: PROVISIONING_RESET_RESULT - ################################# - ## DEPLOY DEVICE ## - ################################# + - name: Validate configurations + arista.cvp.cv_validate_v3: + devices: "{{CVP_DEVICES_VALIDATE_CONFIG}}" + validate_mode: stop_on_error + register: CVP_DEVICES_RESULTS - name: "Deploy device on {{inventory_hostname}}" arista.cvp.cv_device_v3: @@ -100,15 +121,21 @@ state: present register: CV_DEVICE_V3_RESULT - - name: "Check deploy_device" - assert: - that: - - CV_DEVICE_V3_RESULT.changed == true - - CV_DEVICE_V3_RESULT.devices_deployed.changed == true - - CV_DEVICE_V3_RESULT.devices_deployed.devices_deployed_count == 1 - - CV_DEVICE_V3_RESULT.devices_deployed.devices_deployed_list == ["leaf3_deployed"] - - CV_DEVICE_V3_RESULT.devices_deployed.success == true - - CV_DEVICE_V3_RESULT.devices_deployed.taskIds != [] + - name: "Check deploy_device" + assert: + that: + - CV_DEVICE_V3_RESULT.changed == true + - CV_DEVICE_V3_RESULT.devices_deployed.changed == true + - CV_DEVICE_V3_RESULT.devices_deployed.devices_deployed_count == 1 + - CV_DEVICE_V3_RESULT.devices_deployed.devices_deployed_list == ["leaf1_deployed"] + - CV_DEVICE_V3_RESULT.devices_deployed.success == true + - CV_DEVICE_V3_RESULT.devices_deployed.taskIds != [] + + - name: Execute Task for deploy_Device + arista.cvp.cv_task_v3: + tasks: + - "{{CV_DEVICE_V3_RESULT.devices_deployed.taskIds[0]}}" + when: CVP_DEVICES_RESULTS.success is true - name: Remove Container arista.cvp.cv_container_v3: From 3ba57804a8fae9d346cee36fe7ca14915d312497 Mon Sep 17 00:00:00 2001 From: Shivani-chourasiya Date: Thu, 3 Aug 2023 00:15:44 +0530 Subject: [PATCH 13/19] Fixing to clean up lab --- .../cvp/molecule/cv_device_v3/converge.yml | 12 +- .../cv_device_v3/test_apply_detach_bundle.yml | 18 ++- .../test_apply_detach_configlet.yml | 23 +++- ...ssion_factory_reset_provisioning_reset.yml | 125 ++++++++++++------ .../test_move_and_deploy_device.yml | 23 +++- 5 files changed, 140 insertions(+), 61 deletions(-) diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/converge.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/converge.yml index 992cadf21..4a25bb4b7 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/converge.yml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/converge.yml @@ -2,11 +2,11 @@ - name: Test cv_device_v3 module import_playbook: test_move_and_deploy_device.yml -#- name: Test cv_device_v3 module -# import_playbook: test_apply_detach_configlet.yml +- name: Test cv_device_v3 module + import_playbook: test_apply_detach_configlet.yml -#- name: Test cv_device_v3 module -# import_playbook: test_apply_detach_bundle.yml +- name: Test cv_device_v3 module + import_playbook: test_apply_detach_bundle.yml -#- name: Test cv_device_v3 module -# import_playbook: test_decommission_factory_reset_provisioning_reset.yml +- name: Test cv_device_v3 module + import_playbook: test_decommission_factory_reset_provisioning_reset.yml diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml index 2d9eb2357..bb7f48188 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml @@ -7,7 +7,7 @@ ansible_command_timeout: 1200 ansible_connect_timeout: 600 - DEVICE_NAME: leaf3 + DEVICE_NAME: leaf1 CVP_CONFIGLETS: configlet1: '! This is first configlet' @@ -18,22 +18,30 @@ CVP_DEVICES_BUNDLE_ATTACHED: - fqdn: "{{DEVICE_NAME}}" - parentContainerName: "pod2" + parentContainerName: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].parentContainerName}}" configlets: - 'configlet1' imageBundle: Test_bundle CVP_DEVICES_BUNDLE_DETACHED: - fqdn: "{{DEVICE_NAME}}" - parentContainerName: "pod2" + parentContainerName: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].parentContainerName}}" configlets: - 'configlet1' CVP_DEVICES_DETACH_CONFIGLET: - fqdn: "{{DEVICE_NAME}}" - parentContainerName: "pod2" + parentContainerName: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].parentContainerName}}" + configlets: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].configlets}}" tasks: + - name: Collect devices facts from {{inventory_hostname}} + arista.cvp.cv_facts_v3: + facts: + - devices + regexp_filter: "{{DEVICE_NAME}}" + register: CV_FACTS_V3_RESULT + - name: "Push config" arista.cvp.cv_configlet_v3: configlets: "{{CVP_CONFIGLETS}}" @@ -105,7 +113,7 @@ apply_mode: strict register: DETACH_CONFIGLET - - name: Execute Task for attach_bundle + - name: Execute Task for detach configlet arista.cvp.cv_task_v3: tasks: - "{{DETACH_CONFIGLET.taskIds[0]}}" diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_configlet.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_configlet.yml index 79514d4b1..1c8d4dea1 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_configlet.yml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_configlet.yml @@ -4,22 +4,32 @@ connection: local gather_facts: no vars: + DEVICE_NAME: leaf1 + CVP_CONFIGLETS: configlet1: '! This is first configlet' configlet2: '! This is second configlet' CVP_DEVICES_APPLY_CONFIGLET: - - fqdn: leaf1 - parentContainerName: "pod1" + - fqdn: "{{DEVICE_NAME}}" + parentContainerName: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].parentContainerName}}" configlets: - 'configlet1' - 'configlet2' CVP_DEVICES_DETACH_CONFIGLET: - - fqdn: leaf1 - parentContainerName: "pod1" + - fqdn: "{{DEVICE_NAME}}" + parentContainerName: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].parentContainerName}}" + configlets: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].configlets}}" tasks: + - name: Collect devices facts from {{inventory_hostname}} + arista.cvp.cv_facts_v3: + facts: + - devices + regexp_filter: "{{DEVICE_NAME}}" + register: CV_FACTS_V3_RESULT + - name: "Push config" arista.cvp.cv_configlet_v3: configlets: "{{CVP_CONFIGLETS}}" @@ -64,6 +74,11 @@ apply_mode: strict register: CV_DEVICE_V3_RESULT + - name: Execute Task for detach configlet + arista.cvp.cv_task_v3: + tasks: + - "{{CV_DEVICE_V3_RESULT.taskIds[0]}}" + - name: "Check detach_configlet with apply_mode strict" assert: that: diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_decommission_factory_reset_provisioning_reset.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_decommission_factory_reset_provisioning_reset.yml index 55746ceee..4c32ab967 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_decommission_factory_reset_provisioning_reset.yml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_decommission_factory_reset_provisioning_reset.yml @@ -4,44 +4,77 @@ connection: local gather_facts: no vars: + DEVICE_NAME: leaf1 + CVP_DEVICES_STATE_ABSENT: - - fqdn: leaf1 + - fqdn: "{{DEVICE_NAME}}" parentContainerName: "" + CVP_DEVICES_FACT0RY_RESET: - - fqdn: leaf1 + - fqdn: "{{DEVICE_NAME}}" parentContainerName: "" + CVP_DEVICES_PROVISIONING_RESET: - - fqdn: leaf2 + - fqdn: "{{DEVICE_NAME}}" parentContainerName: "" + + CVP_DEVICES_VALIDATE_CONFIG: + - device_name: "{{DEVICE_NAME}}" + search_type: serialNumber + cvp_configlets: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].configlets}}" + + CVP_DEVICES_DEPLOY: + - fqdn: "{{DEVICE_NAME}}" + parentContainerName: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].parentContainerName}}" + configlets: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].configlets}}" + tasks: ###################################### - ## STATE ABSENT (DECOMMISSION) ## + ## STATE PROVISIONING RESET ## ###################################### - - name: Run CV_DEVICE_V3 With State Absent + - name: Collect devices facts from {{inventory_hostname}} + arista.cvp.cv_facts_v3: + facts: + - devices + regexp_filter: "{{DEVICE_NAME}}" + register: CV_FACTS_V3_RESULT + + - name: Run CV_DEVICE_V3 With State Provisioning Reset arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_STATE_ABSENT}}' - state: absent - register: DECOMMISSION_DEVICE - - assert: + devices: '{{CVP_DEVICES_PROVISIONING_RESET}}' + state: provisioning_reset + register: PROVISIONING_RESET_RESULT + + # if we try to delete the same device again(already in undefined container), it does not raise any error and gives the same result + + - name: check provisioning reset + assert: that: - - DECOMMISSION_DEVICE.devices_decommissioned.changed == true - - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_count == 0 - - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_list == ['leaf2_delete'] - - DECOMMISSION_DEVICE.devices_decommissioned.success == true - - DECOMMISSION_DEVICE.devices_decommissioned.taskIds == [] - - DECOMMISSION_DEVICE.failed == false + - PROVISIONING_RESET_RESULT.devices_removed.changed == true + - PROVISIONING_RESET_RESULT.devices_removed.devices_removed_count == 1 + - PROVISIONING_RESET_RESULT.devices_removed. devices_removed_list == ['leaf1_delete'] + - PROVISIONING_RESET_RESULT.devices_removed.success == true + - PROVISIONING_RESET_RESULT.devices_removed.taskIds is defined + - PROVISIONING_RESET_RESULT.failed == false + - PROVISIONING_RESET_RESULT.success == true - - name: Run CV_DEVICE_V3 With State Absent # when device does not exist in CVP + - name: Validate configurations + arista.cvp.cv_validate_v3: + devices: "{{CVP_DEVICES_VALIDATE_CONFIG}}" + validate_mode: stop_on_error + register: CVP_DEVICES_RESULTS + + - name: "Deploy device on {{inventory_hostname}}" arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_STATE_ABSENT}}' - state: absent - ignore_errors: yes - register: DECOMMISSION_DEVICE_ABSENT - - assert: - that: - - DECOMMISSION_DEVICE_ABSENT.changed == false - - DECOMMISSION_DEVICE_ABSENT.failed == true - - DECOMMISSION_DEVICE_ABSENT.msg == "Error - the following devices do not exist in CVP ['leaf2'] but are defined in the playbook. Make sure that the devices are provisioned and defined with the full fqdn name (including the domain name) if needed." + devices: '{{CVP_DEVICES_DEPLOY}}' + state: present + register: CV_DEVICE_V3_RESULT + + - name: Execute Task for deploy_Device + arista.cvp.cv_task_v3: + tasks: + - "{{CV_DEVICE_V3_RESULT.devices_deployed.taskIds[0]}}" + when: CVP_DEVICES_RESULTS.success is true ###################################### ## STATE FACTORY RESET ## @@ -59,31 +92,37 @@ that: - FACTORY_RESET_RESULT.devices_reset.changed == true - FACTORY_RESET_RESULT.devices_reset.devices_reset_count == 1 - - FACTORY_RESET_RESULT.devices_reset.devices_reset_list == ['leaf2_reset'] + - FACTORY_RESET_RESULT.devices_reset.devices_reset_list == ['leaf1_reset'] - FACTORY_RESET_RESULT.devices_reset.success == true - FACTORY_RESET_RESULT.devices_reset.taskIds is defined - FACTORY_RESET_RESULT.failed == false - FACTORY_RESET_RESULT.success == true ###################################### - ## STATE PROVISIONING RESET ## + ## STATE ABSENT (DECOMMISSION) ## ###################################### - - - name: Run CV_DEVICE_V3 With State Provisioning Reset + - name: Run CV_DEVICE_V3 With State Absent arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_PROVISIONING_RESET}}' - state: provisioning_reset - register: PROVISIONING_RESET_RESULT - - # if we try to delete the same device again(already in undefined container), it does not raise any error and gives the same result + devices: '{{CVP_DEVICES_STATE_ABSENT}}' + state: absent + register: DECOMMISSION_DEVICE + - assert: + that: + - DECOMMISSION_DEVICE.devices_decommissioned.changed == true + - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_count == 0 + - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_list == ['leaf1_delete'] + - DECOMMISSION_DEVICE.devices_decommissioned.success == true + - DECOMMISSION_DEVICE.devices_decommissioned.taskIds == [] + - DECOMMISSION_DEVICE.failed == false - - name: check provisioning reset - assert: + - name: Run CV_DEVICE_V3 With State Absent # when device does not exist in CVP + arista.cvp.cv_device_v3: + devices: '{{CVP_DEVICES_STATE_ABSENT}}' + state: absent + ignore_errors: yes + register: DECOMMISSION_DEVICE_ABSENT + - assert: that: - - PROVISIONING_RESET_RESULT.devices_removed.changed == true - - PROVISIONING_RESET_RESULT.devices_removed.devices_removed_count == 1 - - PROVISIONING_RESET_RESULT.devices_removed. devices_removed_list == ['leaf3_delete'] - - PROVISIONING_RESET_RESULT.devices_removed.success == true - - PROVISIONING_RESET_RESULT.devices_removed.taskIds is defined - - PROVISIONING_RESET_RESULT.failed == false - - PROVISIONING_RESET_RESULT.success == true + - DECOMMISSION_DEVICE_ABSENT.changed == false + - DECOMMISSION_DEVICE_ABSENT.failed == true + - DECOMMISSION_DEVICE_ABSENT.msg == "Error - the following devices do not exist in CVP ['leaf1'] but are defined in the playbook. Make sure that the devices are provisioned and defined with the full fqdn name (including the domain name) if needed." diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml index 7ed3dc89c..c216ca0f5 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml @@ -25,19 +25,24 @@ - fqdn: "{{DEVICE_NAME}}" parentContainerName: "Test_Leaf" + CVP_DEVICES_APPLY_CONFIGLET: + - fqdn: "{{DEVICE_NAME}}" + parentContainerName: "Undefined" + configlets: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].configlets}}" + CVP_DEVICES_VALIDATE_CONFIG: - device_name: "{{DEVICE_NAME}}" search_type: serialNumber - cvp_configlets: ['ATD-INFRA', 'BaseIPv4_Leaf4'] #"{{CV_FACTS_V3_RESULT.data.cvp_devices[0].configlets}}" + cvp_configlets: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].configlets}}" CVP_DEVICES_DEPLOY: - fqdn: "{{DEVICE_NAME}}" # device must be in undefined container - parentContainerName: "pod1" #"{{CV_FACTS_V3_RESULT.data.cvp_devices[0].parentContainerName}}" + parentContainerName: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].parentContainerName}}" configlets: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].configlets}}" CVP_DEVICES_DETACH_CONFIGLET: - fqdn: "{{DEVICE_NAME}}" - parentContainerName: "pod1" + parentContainerName: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].parentContainerName}}" tasks: # Creating a container @@ -58,6 +63,14 @@ state: present register: MOVE_DEVICE_RUN + - name: Pause for 10 seconds to Execute Task + ansible.builtin.pause: + seconds: 10 + + - name: Execute Task for deploy_Device + arista.cvp.cv_task_v3: + tasks: "{{MOVE_DEVICE_RUN.taskIds}}" + - name: Check Move Device assert: that: @@ -109,6 +122,10 @@ state: provisioning_reset register: PROVISIONING_RESET_RESULT + - name: Pause for 10 seconds to Execute Task + ansible.builtin.pause: + seconds: 10 + - name: Validate configurations arista.cvp.cv_validate_v3: devices: "{{CVP_DEVICES_VALIDATE_CONFIG}}" From 87d3c829bc7ce3a8ad4f29fd1faa4c048ee2a760 Mon Sep 17 00:00:00 2001 From: Shivani-chourasiya Date: Thu, 3 Aug 2023 16:37:07 +0530 Subject: [PATCH 14/19] Changing for dual_dc topology --- .../cv_device_v3/test_apply_detach_bundle.yml | 2 +- .../cv_device_v3/test_apply_detach_configlet.yml | 6 +++--- ...mmission_factory_reset_provisioning_reset.yml | 16 +++++++++++----- .../cv_device_v3/test_move_and_deploy_device.yml | 8 ++++---- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml index bb7f48188..959d92a28 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml @@ -7,7 +7,7 @@ ansible_command_timeout: 1200 ansible_connect_timeout: 600 - DEVICE_NAME: leaf1 + DEVICE_NAME: s1-leaf1 CVP_CONFIGLETS: configlet1: '! This is first configlet' diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_configlet.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_configlet.yml index 1c8d4dea1..417913b1c 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_configlet.yml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_configlet.yml @@ -4,7 +4,7 @@ connection: local gather_facts: no vars: - DEVICE_NAME: leaf1 + DEVICE_NAME: s1-leaf1 CVP_CONFIGLETS: configlet1: '! This is first configlet' @@ -47,7 +47,7 @@ - CV_DEVICE_V3_RESULT.changed == true - CV_DEVICE_V3_RESULT.configlets_attached.changed == true - CV_DEVICE_V3_RESULT.configlets_attached.configlets_attached_count == 2 - - CV_DEVICE_V3_RESULT.configlets_attached.configlets_attached_list == ["leaf1_configlet_attached"] + - CV_DEVICE_V3_RESULT.configlets_attached.configlets_attached_list == ["s1-leaf1_configlet_attached"] - CV_DEVICE_V3_RESULT.configlets_attached.success == true - CV_DEVICE_V3_RESULT.configlets_attached.taskIds != [] @@ -85,7 +85,7 @@ - CV_DEVICE_V3_RESULT.changed == true - CV_DEVICE_V3_RESULT.configlets_detached.changed == true - CV_DEVICE_V3_RESULT.configlets_detached.configlets_detached_count == 2 - - CV_DEVICE_V3_RESULT.configlets_detached.configlets_detached_list == ["leaf1_configlet_removed - configlet1 - configlet2"] + - CV_DEVICE_V3_RESULT.configlets_detached.configlets_detached_list == ["s1-leaf1_configlet_removed - configlet1 - configlet2"] - CV_DEVICE_V3_RESULT.configlets_detached.success == true - CV_DEVICE_V3_RESULT.configlets_detached.taskIds != [] diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_decommission_factory_reset_provisioning_reset.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_decommission_factory_reset_provisioning_reset.yml index 4c32ab967..1fe39b20c 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_decommission_factory_reset_provisioning_reset.yml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_decommission_factory_reset_provisioning_reset.yml @@ -4,7 +4,7 @@ connection: local gather_facts: no vars: - DEVICE_NAME: leaf1 + DEVICE_NAME: s1-leaf1 CVP_DEVICES_STATE_ABSENT: - fqdn: "{{DEVICE_NAME}}" @@ -52,7 +52,7 @@ that: - PROVISIONING_RESET_RESULT.devices_removed.changed == true - PROVISIONING_RESET_RESULT.devices_removed.devices_removed_count == 1 - - PROVISIONING_RESET_RESULT.devices_removed. devices_removed_list == ['leaf1_delete'] + - PROVISIONING_RESET_RESULT.devices_removed. devices_removed_list == ['s1-leaf1_delete'] - PROVISIONING_RESET_RESULT.devices_removed.success == true - PROVISIONING_RESET_RESULT.devices_removed.taskIds is defined - PROVISIONING_RESET_RESULT.failed == false @@ -92,12 +92,18 @@ that: - FACTORY_RESET_RESULT.devices_reset.changed == true - FACTORY_RESET_RESULT.devices_reset.devices_reset_count == 1 - - FACTORY_RESET_RESULT.devices_reset.devices_reset_list == ['leaf1_reset'] + - FACTORY_RESET_RESULT.devices_reset.devices_reset_list == ['s1-leaf1_reset'] - FACTORY_RESET_RESULT.devices_reset.success == true - FACTORY_RESET_RESULT.devices_reset.taskIds is defined - FACTORY_RESET_RESULT.failed == false - FACTORY_RESET_RESULT.success == true + - name: Execute Task for deploy_Device + arista.cvp.cv_task_v3: + tasks: + - "{{FACTORY_RESET_RESULT.taskIds[0]}}" + state: cancelled + ###################################### ## STATE ABSENT (DECOMMISSION) ## ###################################### @@ -110,7 +116,7 @@ that: - DECOMMISSION_DEVICE.devices_decommissioned.changed == true - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_count == 0 - - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_list == ['leaf1_delete'] + - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_list == ['s1-leaf1_delete'] - DECOMMISSION_DEVICE.devices_decommissioned.success == true - DECOMMISSION_DEVICE.devices_decommissioned.taskIds == [] - DECOMMISSION_DEVICE.failed == false @@ -125,4 +131,4 @@ that: - DECOMMISSION_DEVICE_ABSENT.changed == false - DECOMMISSION_DEVICE_ABSENT.failed == true - - DECOMMISSION_DEVICE_ABSENT.msg == "Error - the following devices do not exist in CVP ['leaf1'] but are defined in the playbook. Make sure that the devices are provisioned and defined with the full fqdn name (including the domain name) if needed." + - DECOMMISSION_DEVICE_ABSENT.msg == "Error - the following devices do not exist in CVP ['s1-leaf1'] but are defined in the playbook. Make sure that the devices are provisioned and defined with the full fqdn name (including the domain name) if needed." diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml index c216ca0f5..114427799 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml @@ -7,7 +7,7 @@ ansible_command_timeout: 1200 ansible_connect_timeout: 600 - DEVICE_NAME: leaf1 + DEVICE_NAME: s1-leaf1 CONTAINER: Test_Leaf: @@ -76,7 +76,7 @@ that: - "MOVE_DEVICE_RUN.devices_moved.changed == true" - "MOVE_DEVICE_RUN.devices_moved.devices_moved_count == 1" - - "MOVE_DEVICE_RUN.devices_moved.devices_moved_list == ['leaf1_to_Test_Leaf']" + - "MOVE_DEVICE_RUN.devices_moved.devices_moved_list == ['s1-leaf1_to_Test_Leaf']" - "MOVE_DEVICE_RUN.devices_moved.success == true" - "MOVE_DEVICE_RUN.failed == false" @@ -90,7 +90,7 @@ - name: Negative Test Check Move Device With Parent Container None assert: that: - - MOVE_DEVICE_NONE.msg == "The target container 'None' for the device 'leaf1' does not exist on CVP." + - MOVE_DEVICE_NONE.msg == "The target container 'None' for the device 's1-leaf1' does not exist on CVP." - MOVE_DEVICE_NONE.changed == false - MOVE_DEVICE_NONE.failed == true @@ -144,7 +144,7 @@ - CV_DEVICE_V3_RESULT.changed == true - CV_DEVICE_V3_RESULT.devices_deployed.changed == true - CV_DEVICE_V3_RESULT.devices_deployed.devices_deployed_count == 1 - - CV_DEVICE_V3_RESULT.devices_deployed.devices_deployed_list == ["leaf1_deployed"] + - CV_DEVICE_V3_RESULT.devices_deployed.devices_deployed_list == ["s1-leaf1_deployed"] - CV_DEVICE_V3_RESULT.devices_deployed.success == true - CV_DEVICE_V3_RESULT.devices_deployed.taskIds != [] From 9da93f4606ecc6bff11456e64de263686b783f2c Mon Sep 17 00:00:00 2001 From: Sugetha Chandhrasekar Date: Thu, 3 Aug 2023 10:53:00 -0700 Subject: [PATCH 15/19] minor nit --- .../cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml index 114427799..19e2e8c33 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_move_and_deploy_device.yml @@ -115,7 +115,7 @@ # DEPLOY DEVICE ## ################################ - # moving device to undefined container + # moving device to undefined container - name: Run CV_DEVICE_V3 With State Provisioning Reset arista.cvp.cv_device_v3: devices: '{{CVP_DEVICES_PROVISIONING_RESET}}' From 79b1a3f3bc6fb2508829938d83c4a66bad10c8a2 Mon Sep 17 00:00:00 2001 From: Shivani-chourasiya Date: Fri, 4 Aug 2023 12:23:47 +0530 Subject: [PATCH 16/19] Adding terninattr for image bundle --- .../molecule/cv_device_v3/test_apply_detach_bundle.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml index 959d92a28..9f6d9103a 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml @@ -14,6 +14,8 @@ IMAGE_NAME: "vEOS-lab.swi" + EXTENSION_NAME: "TerminAttr-1.25.1-1.swix" + BUNDLE_NAME: "Test_bundle" CVP_DEVICES_BUNDLE_ATTACHED: @@ -53,6 +55,12 @@ action: add image: "{{IMAGE_NAME}}" + - name: "Upload TerminAttr image to {{inventory_hostname}}" + arista.cvp.cv_image_v3: + mode: image + action: add + image: "{{EXTENSION_NAME}}" + - name: "Create bundle {{inventory_hostname}}" arista.cvp.cv_image_v3: mode: bundle @@ -60,6 +68,7 @@ bundle_name: "{{BUNDLE_NAME}}" image_list: - "{{IMAGE_NAME}}" + - "{{EXTENSION_NAME}}" - name: "Attach bundle on {{inventory_hostname}}" arista.cvp.cv_device_v3: @@ -105,6 +114,7 @@ bundle_name: "{{BUNDLE_NAME}}" image_list: - "{{IMAGE_NAME}}" + - "{{EXTENSION_NAME}}" - name: "Detach configlet from {{inventory_hostname}}" arista.cvp.cv_device_v3: From 4f6aa67a32a2ab8b3e93ed66d83ec539f973aff8 Mon Sep 17 00:00:00 2001 From: Shivani-chourasiya Date: Tue, 8 Aug 2023 15:32:07 +0530 Subject: [PATCH 17/19] Minor fixes while testing PR --- .../cv_device_v3/test_apply_detach_bundle.yml | 8 +++ ...ssion_factory_reset_provisioning_reset.yml | 62 ++++++++++--------- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml index 9f6d9103a..1f3394065 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml @@ -92,6 +92,10 @@ - "{{item}}" loop: "{{ATTACH_BUNDLE.taskIds}}" + - name: Pause for 20 seconds to Execute Task + ansible.builtin.pause: + seconds: 20 + - name: "Detach bundle on {{inventory_hostname}}" arista.cvp.cv_device_v3: devices: '{{CVP_DEVICES_BUNDLE_DETACHED}}' @@ -128,6 +132,10 @@ tasks: - "{{DETACH_CONFIGLET.taskIds[0]}}" + - name: Pause for 20 seconds to Execute Task + ansible.builtin.pause: + seconds: 20 + - name: "Delete configlet" arista.cvp.cv_configlet_v3: configlets: "{{CVP_CONFIGLETS}}" diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_decommission_factory_reset_provisioning_reset.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_decommission_factory_reset_provisioning_reset.yml index 1fe39b20c..64b933061 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_decommission_factory_reset_provisioning_reset.yml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_decommission_factory_reset_provisioning_reset.yml @@ -4,7 +4,7 @@ connection: local gather_facts: no vars: - DEVICE_NAME: s1-leaf1 + DEVICE_NAME: s1-leaf2 CVP_DEVICES_STATE_ABSENT: - fqdn: "{{DEVICE_NAME}}" @@ -52,7 +52,7 @@ that: - PROVISIONING_RESET_RESULT.devices_removed.changed == true - PROVISIONING_RESET_RESULT.devices_removed.devices_removed_count == 1 - - PROVISIONING_RESET_RESULT.devices_removed. devices_removed_list == ['s1-leaf1_delete'] + - PROVISIONING_RESET_RESULT.devices_removed. devices_removed_list == ['s1-leaf2_delete'] - PROVISIONING_RESET_RESULT.devices_removed.success == true - PROVISIONING_RESET_RESULT.devices_removed.taskIds is defined - PROVISIONING_RESET_RESULT.failed == false @@ -76,33 +76,37 @@ - "{{CV_DEVICE_V3_RESULT.devices_deployed.taskIds[0]}}" when: CVP_DEVICES_RESULTS.success is true + - name: Pause for 20 seconds to Execute Task + ansible.builtin.pause: + seconds: 20 + ###################################### ## STATE FACTORY RESET ## ###################################### - - name: Run CV_DEVICE_V3 With State Factory reset - arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_FACT0RY_RESET}}' - state: factory_reset - register: FACTORY_RESET_RESULT - - # it does not move device to undefined container, just creates a task on CVP - - - name: Check State Factory reset - assert: - that: - - FACTORY_RESET_RESULT.devices_reset.changed == true - - FACTORY_RESET_RESULT.devices_reset.devices_reset_count == 1 - - FACTORY_RESET_RESULT.devices_reset.devices_reset_list == ['s1-leaf1_reset'] - - FACTORY_RESET_RESULT.devices_reset.success == true - - FACTORY_RESET_RESULT.devices_reset.taskIds is defined - - FACTORY_RESET_RESULT.failed == false - - FACTORY_RESET_RESULT.success == true - - - name: Execute Task for deploy_Device - arista.cvp.cv_task_v3: - tasks: - - "{{FACTORY_RESET_RESULT.taskIds[0]}}" - state: cancelled +# - name: Run CV_DEVICE_V3 With State Factory reset +# arista.cvp.cv_device_v3: +# devices: '{{CVP_DEVICES_FACT0RY_RESET}}' +# state: factory_reset +# register: FACTORY_RESET_RESULT +# +# # it does not move device to undefined container, just creates a task on CVP +# +# - name: Check State Factory reset +# assert: +# that: +# - FACTORY_RESET_RESULT.devices_reset.changed == true +# - FACTORY_RESET_RESULT.devices_reset.devices_reset_count == 1 +# - FACTORY_RESET_RESULT.devices_reset.devices_reset_list == ['s1-leaf1_reset'] +# - FACTORY_RESET_RESULT.devices_reset.success == true +# - FACTORY_RESET_RESULT.devices_reset.taskIds is defined +# - FACTORY_RESET_RESULT.failed == false +# - FACTORY_RESET_RESULT.success == true +# +# - name: Execute Task for deploy_Device +# arista.cvp.cv_task_v3: +# tasks: +# - "{{FACTORY_RESET_RESULT.taskIds[0]}}" +# state: cancelled ###################################### ## STATE ABSENT (DECOMMISSION) ## @@ -115,8 +119,8 @@ - assert: that: - DECOMMISSION_DEVICE.devices_decommissioned.changed == true - - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_count == 0 - - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_list == ['s1-leaf1_delete'] + - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_count == 1 + - DECOMMISSION_DEVICE.devices_decommissioned.devices_decommissioned_list == ['s1-leaf2_delete'] - DECOMMISSION_DEVICE.devices_decommissioned.success == true - DECOMMISSION_DEVICE.devices_decommissioned.taskIds == [] - DECOMMISSION_DEVICE.failed == false @@ -131,4 +135,4 @@ that: - DECOMMISSION_DEVICE_ABSENT.changed == false - DECOMMISSION_DEVICE_ABSENT.failed == true - - DECOMMISSION_DEVICE_ABSENT.msg == "Error - the following devices do not exist in CVP ['s1-leaf1'] but are defined in the playbook. Make sure that the devices are provisioned and defined with the full fqdn name (including the domain name) if needed." + - DECOMMISSION_DEVICE_ABSENT.msg == "Error - the following devices do not exist in CVP ['s1-leaf2'] but are defined in the playbook. Make sure that the devices are provisioned and defined with the full fqdn name (including the domain name) if needed." From a10ac4fec8c957750555d8dbde48edb1833d307a Mon Sep 17 00:00:00 2001 From: Shivani-chourasiya Date: Thu, 10 Aug 2023 11:51:57 +0530 Subject: [PATCH 18/19] Removing configlets from bundle playbook --- .../cv_device_v3/test_apply_detach_bundle.yml | 38 ------------------- 1 file changed, 38 deletions(-) diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml index 1f3394065..62387cdc6 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_apply_detach_bundle.yml @@ -9,9 +9,6 @@ DEVICE_NAME: s1-leaf1 - CVP_CONFIGLETS: - configlet1: '! This is first configlet' - IMAGE_NAME: "vEOS-lab.swi" EXTENSION_NAME: "TerminAttr-1.25.1-1.swix" @@ -21,20 +18,11 @@ CVP_DEVICES_BUNDLE_ATTACHED: - fqdn: "{{DEVICE_NAME}}" parentContainerName: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].parentContainerName}}" - configlets: - - 'configlet1' imageBundle: Test_bundle CVP_DEVICES_BUNDLE_DETACHED: - fqdn: "{{DEVICE_NAME}}" parentContainerName: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].parentContainerName}}" - configlets: - - 'configlet1' - - CVP_DEVICES_DETACH_CONFIGLET: - - fqdn: "{{DEVICE_NAME}}" - parentContainerName: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].parentContainerName}}" - configlets: "{{CV_FACTS_V3_RESULT.data.cvp_devices[0].configlets}}" tasks: - name: Collect devices facts from {{inventory_hostname}} @@ -44,11 +32,6 @@ regexp_filter: "{{DEVICE_NAME}}" register: CV_FACTS_V3_RESULT - - name: "Push config" - arista.cvp.cv_configlet_v3: - configlets: "{{CVP_CONFIGLETS}}" - state: present - - name: "Upload EOS image to {{inventory_hostname}}" arista.cvp.cv_image_v3: mode: image @@ -119,24 +102,3 @@ image_list: - "{{IMAGE_NAME}}" - "{{EXTENSION_NAME}}" - - - name: "Detach configlet from {{inventory_hostname}}" - arista.cvp.cv_device_v3: - devices: '{{CVP_DEVICES_DETACH_CONFIGLET}}' - state: present - apply_mode: strict - register: DETACH_CONFIGLET - - - name: Execute Task for detach configlet - arista.cvp.cv_task_v3: - tasks: - - "{{DETACH_CONFIGLET.taskIds[0]}}" - - - name: Pause for 20 seconds to Execute Task - ansible.builtin.pause: - seconds: 20 - - - name: "Delete configlet" - arista.cvp.cv_configlet_v3: - configlets: "{{CVP_CONFIGLETS}}" - state: absent From 6e040e4020ecc9bb2f8baab86999d7122d79ee68 Mon Sep 17 00:00:00 2001 From: Sugetha Chandhrasekar Date: Thu, 10 Aug 2023 13:38:18 -0700 Subject: [PATCH 19/19] Added comments --- .../test_decommission_factory_reset_provisioning_reset.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_decommission_factory_reset_provisioning_reset.yml b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_decommission_factory_reset_provisioning_reset.yml index 64b933061..45478ea61 100644 --- a/ansible_collections/arista/cvp/molecule/cv_device_v3/test_decommission_factory_reset_provisioning_reset.yml +++ b/ansible_collections/arista/cvp/molecule/cv_device_v3/test_decommission_factory_reset_provisioning_reset.yml @@ -83,6 +83,7 @@ ###################################### ## STATE FACTORY RESET ## ###################################### +# XXX: This test will fail with cEOS devices. Uncomment if running on vEOS devices # - name: Run CV_DEVICE_V3 With State Factory reset # arista.cvp.cv_device_v3: # devices: '{{CVP_DEVICES_FACT0RY_RESET}}'