Skip to content

Commit

Permalink
Added tests for attach and detach bundle and fixed counters for bundl…
Browse files Browse the repository at this point in the history
…e_attached/bundle_detached
  • Loading branch information
Vibhu-gslab committed Jun 8, 2023
1 parent b6513b1 commit c8f51ef
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit c8f51ef

Please sign in to comment.