diff --git a/tests/integration/targets/dcnm_image_upgrade/tests/query.yaml b/tests/integration/targets/dcnm_image_upgrade/tests/query.yaml new file mode 100644 index 000000000..b68f6ab04 --- /dev/null +++ b/tests/integration/targets/dcnm_image_upgrade/tests/query.yaml @@ -0,0 +1,381 @@ +################################################################################ +# RUNTIME +################################################################################ + +# 45 to 50 minutes +# Some previous runtimes where: +# - 47:50.79 + +################################################################################ +# STEPS +################################################################################ + +# 1. Create a fabric +# 2. Merge switches into fabric +# 3. Upgrade switches using global config +# 4. Query and verify ISSU status +# 5. Detach image policies from two of the three switches +# 6. Query and verify ISSU status +# 7. Detach image policy from remaining switch +# 8. Query and verify ISSU status +# 9. Cleanup + +################################################################################ +# REQUIREMENTS +################################################################################ + +# 1. image policies are already configured on the controller: +# - KR5M (Kerry release maintenance 5) +# - NR3F (Niles release maintenance 3) +# The above include both NX-OS and EPLD images. +# +# TODO: Once dcnm_image_policy module is accepted, use that to +# configure the above policies. +# +# Example vars for dcnm_image_upgrade integration tests +# Add to cisco/dcnm/playbooks/dcnm_tests.yaml) +# +# vars: +# # This testcase field can run any test in the tests directory for the role +# testcase: merged +# fabric_name: f1 +# username: admin +# password: "foobar" +# switch_username: admin +# switch_password: "foobar" +# spine1: 172.22.150.114 +# spine2: 172.22.150.115 +# leaf1: 172.22.150.106 +# leaf2: 172.22.150.107 +# leaf3: 172.22.150.108 +# leaf4: 172.22.150.109 +# # for dcnm_image_upgrade role +# test_fabric: "{{ fabric_name }}" +# ansible_switch1: "{{ leaf1 }}" +# ansible_switch2: "{{ leaf2 }}" +# ansible_switch3: "{{ spine1 }}" +# image_policy_1: "KR5M" +# image_policy_2: "NR3F" + +################################################################################ +# SETUP +################################################################################ + +- set_fact: + rest_fabric_create: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/{{ fabric_name }}" + +- name: QUERY - Verify if fabric is deployed. + cisco.dcnm.dcnm_rest: + method: GET + path: "{{ rest_fabric_create }}" + register: result + +- debug: + var: result + +- assert: + that: + - result.response.DATA != None + +- name: QUERY - setup - Clean up any existing devices + cisco.dcnm.dcnm_inventory: + fabric: "{{ fabric_name }}" + state: deleted + +- name: QUERY - Merge switches + cisco.dcnm.dcnm_inventory: + fabric: "{{ fabric_name }}" + state: merged + config: + - seed_ip: "{{ ansible_switch1 }}" + auth_proto: MD5 + user_name: "{{ switch_username }}" + password: "{{ switch_password }}" + max_hops: 0 + role: leaf + preserve_config: False + - seed_ip: "{{ ansible_switch2 }}" + auth_proto: MD5 + user_name: "{{ switch_username }}" + password: "{{ switch_password }}" + max_hops: 0 + role: leaf + preserve_config: False + - seed_ip: "{{ ansible_switch3 }}" + auth_proto: MD5 + user_name: "{{ switch_username }}" + password: "{{ switch_password }}" + max_hops: 0 + role: spine + preserve_config: False + register: result + +- assert: + that: + - result.changed == true + +- assert: + that: + - item["RETURN_CODE"] == 200 + loop: '{{ result.response }}' + +################################################################################ +# QUERY - Upgrade all switches using global_config +################################################################################ + +- name: QUERY - Upgrade all switches using global config + cisco.dcnm.dcnm_image_upgrade: + state: merged + config: + policy: "{{ image_policy_1 }}" + reboot: false + stage: true + validate: true + upgrade: + nxos: true + epld: false + options: + nxos: + mode: disruptive + bios_force: false + epld: + module: ALL + golden: false + reboot: + config_reload: false + write_erase: false + package: + install: false + uninstall: false + switches: + - ip_address: "{{ ansible_switch1 }}" + - ip_address: "{{ ansible_switch2 }}" + - ip_address: "{{ ansible_switch3 }}" + register: result + +- debug: + var: result + +- assert: + that: + - result.changed == true + - result.failed == false + - result.diff.attach_policy[0].policy_name == image_policy_1 + - result.diff.attach_policy[1].policy_name == image_policy_1 + - result.diff.attach_policy[2].policy_name == image_policy_1 + - result.diff.upgrade[0].devices[0].policyName == image_policy_1 + - result.diff.upgrade[1].devices[0].policyName == image_policy_1 + - result.diff.upgrade[2].devices[0].policyName == image_policy_1 + - result.diff.validate[0].policy == image_policy_1 + - result.diff.validate[1].policy == image_policy_1 + - result.diff.validate[2].policy == image_policy_1 + - result.response.attach_policy[0].RETURN_CODE == 200 + - result.response.stage[0].RETURN_CODE == 200 + - result.response.upgrade[0].RETURN_CODE == 200 + - result.response.upgrade[1].RETURN_CODE == 200 + - result.response.upgrade[2].RETURN_CODE == 200 + - result.response.validate[0].RETURN_CODE == 200 + +- name: QUERY - PAUSE 15 minutes for switches to reboot + ansible.builtin.pause: + minutes: 15 + +################################################################################ +# QUERY - Query and verify ISSU status +################################################################################ + +- name: QUERY - Query ISSU Status for three switches + cisco.dcnm.dcnm_image_upgrade: + state: query + config: + switches: + - ip_address: "{{ ansible_switch1 }}" + - ip_address: "{{ ansible_switch2 }}" + - ip_address: "{{ ansible_switch3 }}" + register: result + +- debug: + var: result + +- assert: + that: + - result.changed == false + - result.failed == false + - (result.diff.issu_status | length) == 3 + - (result.diff.detach_policy | length) == 0 + - (result.diff.stage | length) == 0 + - (result.diff.upgrade | length) == 0 + - (result.diff.validate | length) == 0 + - (result.response.issu_status | length) == 1 + - (result.response.attach_policy | length) == 0 + - (result.response.detach_policy | length) == 0 + - (result.response.stage | length) == 0 + - (result.response.upgrade | length) == 0 + - (result.response.validate | length) == 0 + - (result.diff.issu_status[0].ipAddress) == ansible_switch1 + - (result.diff.issu_status[1].ipAddress) == ansible_switch2 + - (result.diff.issu_status[2].ipAddress) == ansible_switch3 + - (result.diff.issu_status[0].policy) == image_policy_1 + - (result.diff.issu_status[1].policy) == image_policy_1 + - (result.diff.issu_status[2].policy) == image_policy_1 + - (result.diff.issu_status[0].statusPercent) == 100 + - (result.diff.issu_status[1].statusPercent) == 100 + - (result.diff.issu_status[2].statusPercent) == 100 + +################################################################################ +# QUERY - Detach policies from two switches and verify +################################################################################ + +- name: QUERY - Detach policies from two switches + cisco.dcnm.dcnm_image_upgrade: + state: deleted + config: + policy: "{{ image_policy_1 }}" + switches: + - ip_address: "{{ ansible_switch1 }}" + - ip_address: "{{ ansible_switch2 }}" + register: result + +- debug: + var: result + +- assert: + that: + - result.changed == true + - result.failed == false + - (result.diff.detach_policy | length) == 2 + - (result.diff.stage | length) == 0 + - (result.diff.upgrade | length) == 0 + - (result.diff.validate | length) == 0 + - (result.response.attach_policy | length) == 0 + - (result.response.detach_policy | length) == 1 + - (result.response.stage | length) == 0 + - (result.response.upgrade | length) == 0 + - (result.response.validate | length) == 0 + + +################################################################################ +# QUERY - Query ISSU status again and verify that policy for two switches +# is set to None +################################################################################ + +- name: QUERY - Query ISSU Status (two switches should have no image policy) + cisco.dcnm.dcnm_image_upgrade: + state: query + config: + switches: + - ip_address: "{{ ansible_switch1 }}" + - ip_address: "{{ ansible_switch2 }}" + - ip_address: "{{ ansible_switch3 }}" + register: result + +- debug: + var: result + +- assert: + that: + - result.changed == false + - result.failed == false + - (result.diff.issu_status | length) == 3 + - (result.diff.detach_policy | length) == 0 + - (result.diff.stage | length) == 0 + - (result.diff.upgrade | length) == 0 + - (result.diff.validate | length) == 0 + - (result.response.issu_status | length) == 1 + - (result.response.attach_policy | length) == 0 + - (result.response.detach_policy | length) == 0 + - (result.response.stage | length) == 0 + - (result.response.upgrade | length) == 0 + - (result.response.validate | length) == 0 + - (result.diff.issu_status[0].ipAddress) == ansible_switch1 + - (result.diff.issu_status[1].ipAddress) == ansible_switch2 + - (result.diff.issu_status[2].ipAddress) == ansible_switch3 + - (result.diff.issu_status[0].policy) == "None" + - (result.diff.issu_status[1].policy) == "None" + - (result.diff.issu_status[2].policy) == image_policy_1 + - (result.diff.issu_status[0].statusPercent) == 0 + - (result.diff.issu_status[1].statusPercent) == 0 + - (result.diff.issu_status[2].statusPercent) == 100 + +################################################################################ +# QUERY - Detach policies from remaining switch and verify +################################################################################ + +- name: QUERY - Detach policy from remaining switch + cisco.dcnm.dcnm_image_upgrade: + state: deleted + config: + policy: "{{ image_policy_1 }}" + switches: + - ip_address: "{{ ansible_switch3 }}" + register: result + +- debug: + var: result + +- assert: + that: + - result.changed == true + - result.failed == false + - (result.diff.attach_policy | length) == 0 + - (result.diff.detach_policy | length) == 1 + - (result.diff.stage | length) == 0 + - (result.diff.upgrade | length) == 0 + - (result.diff.validate | length) == 0 + - (result.response.attach_policy | length) == 0 + - (result.response.detach_policy | length) == 1 + - (result.response.stage | length) == 0 + - (result.response.upgrade | length) == 0 + - (result.response.validate | length) == 0 + +################################################################################ +# QUERY - Query ISSU status again and verify that policy for all switches +# is set to None +################################################################################ + +- name: QUERY - Query ISSU Status (all switches should have no image policy) + cisco.dcnm.dcnm_image_upgrade: + state: query + config: + switches: + - ip_address: "{{ ansible_switch1 }}" + - ip_address: "{{ ansible_switch2 }}" + - ip_address: "{{ ansible_switch3 }}" + register: result + +- debug: + var: result + +- assert: + that: + - result.changed == false + - result.failed == false + - (result.diff.issu_status | length) == 3 + - (result.diff.detach_policy | length) == 0 + - (result.diff.stage | length) == 0 + - (result.diff.upgrade | length) == 0 + - (result.diff.validate | length) == 0 + - (result.response.issu_status | length) == 1 + - (result.response.attach_policy | length) == 0 + - (result.response.detach_policy | length) == 0 + - (result.response.stage | length) == 0 + - (result.response.upgrade | length) == 0 + - (result.response.validate | length) == 0 + - (result.diff.issu_status[0].ipAddress) == ansible_switch1 + - (result.diff.issu_status[1].ipAddress) == ansible_switch2 + - (result.diff.issu_status[2].ipAddress) == ansible_switch3 + - (result.diff.issu_status[0].policy) == "None" + - (result.diff.issu_status[1].policy) == "None" + - (result.diff.issu_status[2].policy) == "None" + - (result.diff.issu_status[0].statusPercent) == 0 + - (result.diff.issu_status[1].statusPercent) == 0 + - (result.diff.issu_status[2].statusPercent) == 0 + +################################################################################ +# CLEAN-UP +################################################################################ + +- name: QUERY - cleanup - Remove devices from fabric + cisco.dcnm.dcnm_inventory: + fabric: "{{ fabric_name }}" + state: deleted \ No newline at end of file