Skip to content

Commit

Permalink
Initial integration test for "merged" state
Browse files Browse the repository at this point in the history
  • Loading branch information
allenrobel committed Jan 19, 2024
1 parent 5cc8f68 commit 46de1a0
Show file tree
Hide file tree
Showing 5 changed files with 318 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
testcase: "*"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dependencies: []
20 changes: 20 additions & 0 deletions tests/integration/targets/dcnm_image_upgrade/tasks/dcnm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- name: collect dcnm test cases
find:
paths: "{{ role_path }}/tests"
patterns: "{{ testcase }}.yaml"
connection: local
register: dcnm_cases

- set_fact:
test_cases:
files: "{{ dcnm_cases.files }}"

- name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"

- name: run test cases (connection=httpapi)
include: "{{ test_case_to_run }}"
with_items: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run
2 changes: 2 additions & 0 deletions tests/integration/targets/dcnm_image_upgrade/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
- { include: dcnm.yaml, tags: ['dcnm'] }
293 changes: 293 additions & 0 deletions tests/integration/targets/dcnm_image_upgrade/tests/merged.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,293 @@
################################################################################
# RUNTIME
################################################################################

# About 1.5 hours

################################################################################
# STEPS
################################################################################

# 1. Create a fabric
# 2. Merge switches into fabric
# 3. Upgrade switches using global config
# 4. Upgrade switches using switch config, overriding policy in global config

################################################################################
# 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: MERGED - 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: MERGED - setup - Clean up any existing devices
cisco.dcnm.dcnm_inventory:
fabric: "{{ fabric_name }}"
state: deleted

- name: MERGED - 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 }}'

################################################################################
# MERGED global_config
################################################################################

- name: MERGED - Upgrade all switches using global config.
cisco.dcnm.dcnm_image_upgrade: &global_config
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: "{{ leaf1 }}"
- ip_address: "{{ leaf2 }}"
- ip_address: "{{ spine1 }}"
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'

################################################################################
# MERGED IDEMPOTENCE global_config
################################################################################

- name: MERGED - global_config - Idempotence PAUSE 15 minutes
ansible.builtin.pause:
minutes: 15

- name: MERGED - global_config - Idempotence
cisco.dcnm.dcnm_image_upgrade: *global_config
register: result

- debug:
var: result

- assert:
that:
- 'result.changed == false'
- 'result.failed == false'
- '(result.diff.attach_policy | length) == 0'
- '(result.diff.stage | length) == 0'
- '(result.diff.upgrade | length) == 0'
- '(result.diff.validate | length) == 0'
- '(result.response.attach_policy | length) == 0'
- '(result.response.stage | length) == 0'
- '(result.response.upgrade | length) == 0'
- '(result.response.validate | length) == 0'


################################################################################
# MERGED switch_config
################################################################################

- name: MERGED - Upgrade all switches using global config. Override policy in switch configs.
cisco.dcnm.dcnm_image_upgrade: &switch_config
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: "{{ leaf1 }}"
policy: "{{ image_policy_2 }}"
- ip_address: "{{ leaf2 }}"
policy: "{{ image_policy_2 }}"
- ip_address: "{{ spine1 }}"
policy: "{{ image_policy_2 }}"
register: result

- debug:
var: result

- assert:
that:
- 'result.changed == true'
- 'result.failed == false'
- 'result.diff.attach_policy[0].policy_name == "{{ image_policy_2 }}"'
- 'result.diff.attach_policy[1].policy_name == "{{ image_policy_2 }}"'
- 'result.diff.attach_policy[2].policy_name == "{{ image_policy_2 }}"'
- 'result.diff.upgrade[0].devices[0].policyName == "{{ image_policy_2 }}"'
- 'result.diff.upgrade[1].devices[0].policyName == "{{ image_policy_2 }}"'
- 'result.diff.upgrade[2].devices[0].policyName == "{{ image_policy_2 }}"'
- 'result.diff.validate[0].policy == "{{ image_policy_2 }}"'
- 'result.diff.validate[1].policy == "{{ image_policy_2 }}"'
- 'result.diff.validate[2].policy == "{{ image_policy_2 }}"'
- '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'

################################################################################
# MERGED IDEMPOTENCE switch_config
################################################################################

- name: MERGED - switch_config - Idempotence PAUSE 15 minutes
ansible.builtin.pause:
minutes: 15

- name: MERGED - switch_config - Idempotence
cisco.dcnm.dcnm_image_upgrade: *switch_config
register: result

- assert:
that:
- 'result.changed == false'
- 'result.failed == false'
- '(result.diff.attach_policy | length) == 0'
- '(result.diff.stage | length) == 0'
- '(result.diff.upgrade | length) == 0'
- '(result.diff.validate | length) == 0'
- '(result.response.attach_policy | length) == 0'
- '(result.response.stage | length) == 0'
- '(result.response.upgrade | length) == 0'
- '(result.response.validate | length) == 0'

################################################################################
# CLEAN-UP
################################################################################

- name: MERGED - cleanup - Clean up any existing devices
cisco.dcnm.dcnm_inventory:
fabric: "{{ fabric_name }}"
state: deleted

0 comments on commit 46de1a0

Please sign in to comment.