Skip to content

Commit

Permalink
dcnm_image_policy: fix for issue #347 (#348)
Browse files Browse the repository at this point in the history
* Fix for issue 347

Manually tested this to verify.

Still need to update integration and unit tests.

* dcnm_image_policy: Update integration test

Update integration test for overridden state.

1. playbooks/roles/dcnm_image_policy/dcnm_tests.yaml

- Add vars
    - install_package_1
    - uninstall_package_1

2. test/integration/targets/dcnm_image_policy/tests/dcnm_image_policy_overridden.yaml

- Add packages.install and packages.uninstall configuration
- Verify that merged state adds these packages to the controller config
- Verify that overridden state removes packages.install and packages.uninstall
- Verify that overridden state metadata.action is "replace" instead of "update"
  • Loading branch information
allenrobel committed Dec 3, 2024
1 parent 0b17715 commit 6e32f42
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
2 changes: 2 additions & 0 deletions playbooks/roles/dcnm_image_policy/dcnm_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
leaf2: 192.168.1.5
leaf3: 192.168.1.6
leaf4: 192.168.1.7
install_package_1: cfg_cmp-0.3.1.0-1.x86_64.rpm
uninstall_package_1: mtx-grpctunnel-2.1.0.0-10.4.1.lib32_64_n9000
image_policy_1: "KR5M"
image_policy_2: "NR3F"
epld_image_1: n9000-epld.10.2.5.M.img
Expand Down
8 changes: 4 additions & 4 deletions plugins/modules/dcnm_image_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ def __init__(self, params):
raise ValueError(msg) from error

self.delete = ImagePolicyDelete()
self.merged = Merged(params)
self.replaced = Replaced(params)

msg = f"ENTERED {self.class_name}().{method_name}: "
msg += f"state: {self.state}, "
Expand Down Expand Up @@ -627,10 +627,10 @@ def commit(self) -> None:

self._delete_policies_not_in_want()
# pylint: disable=attribute-defined-outside-init
self.merged.rest_send = self.rest_send
self.replaced.rest_send = self.rest_send
# pylint: enable=attribute-defined-outside-init
self.merged.results = self.results
self.merged.commit()
self.replaced.results = self.results
self.replaced.commit()

def _delete_policies_not_in_want(self) -> None:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
#
# SETUP
# 1. The following images must already be uploaded to the controller
# See vars: section in cisco/dcnm/playbooks/dcnm_tests.yaml
# See vars: section in cisco/dcnm/playbooks/dcnm_image_policy/dcnm_tests.yaml
# - nxos_image_1
# - nxos_image_2
# - epld_image_1
# - epld_image_2
# - install_package_1
# - uninstall_package_1
# 2. No need for fabric or switches
# 3. Delete image policies under test, if they exist
# - image_policy_1
Expand All @@ -43,6 +45,8 @@
# - nxos_image_2
# - epld_image_1
# - epld_image_2
# - install_package_1
# - uninstall_package_1
# 2. No need for fabric or switches
#
# Example vars for dcnm_image_policy integration tests
Expand Down Expand Up @@ -71,6 +75,8 @@
# nxos_image_2: n9000-dk9.10.3.1.F.bin
# nxos_release_1: 10.2.5_nxos64-cs_64bit
# nxos_release_2: 10.3.1_nxos64-cs_64bit
# install_package_1: cfg_cmp-0.3.1.0-1.x86_64.rpm
# uninstall_package_1: mtx-grpctunnel-2.1.0.0-10.4.1.lib32_64_n9000
#
################################################################################
# SETUP
Expand Down Expand Up @@ -99,10 +105,12 @@
# "agnostic": false,
# "epldImgName": "n9000-epld.10.2.5.M.img",
# "nxosVersion": "10.2.5_nxos64-cs_64bit",
# "packageName": "cfg_cmp-0.3.1.0-1.x86_64.rpm",
# "platform": "N9K",
# "policyDescr": "KR5M",
# "policyName": "KR5M",
# "policyType": "PLATFORM",
# "rpmimages": "mtx-grpctunnel-2.1.0.0-10.4.1.lib32_64_n9000",
# "sequence_number": 1
# },
# {
Expand Down Expand Up @@ -162,7 +170,8 @@
# }
# ]
# }
# }################################################################################
# }
################################################################################

- name: OVERRIDDEN - TEST - Create two image policies using merged state
cisco.dcnm.dcnm_image_policy:
Expand All @@ -172,6 +181,11 @@
agnostic: false
description: "{{ image_policy_1 }}"
epld_image: "{{ epld_image_1 }}"
packages:
install:
- "{{ install_package_1 }}"
uninstall:
- "{{ uninstall_package_1 }}"
platform: N9K
release: "{{ nxos_release_1 }}"
type: PLATFORM
Expand All @@ -190,6 +204,8 @@
- result.changed == true
- result.failed == false
- (result.diff | length) == 2
- result.diff[0].packageName == install_package_1
- result.diff[0].rpmimages == uninstall_package_1
- result.diff[0].policyName == image_policy_1
- result.diff[1].policyName == image_policy_2
- result.diff[0].policyDescr == image_policy_1
Expand Down Expand Up @@ -249,18 +265,14 @@
# {
# "agnostic": false,
# "epldImgName": "n9000-epld.10.2.5.M.img",
# "fabricPolicyName": null,
# "imagePresent": "Present",
# "nxosVersion": "10.2.5_nxos64-cs_64bit",
# "packageName": "",
# "platform": "N9K",
# "policyDescr": "KR5M overridden",
# "policyName": "KR5M",
# "policyType": "PLATFORM",
# "role": null,
# "rpmimages": null,
# "sequence_number": 2,
# "unInstall": false
# "rpmimages": "",
# "sequence_number": 2
# }
# ],
# "failed": false,
Expand All @@ -272,7 +284,7 @@
# "state": "overridden"
# },
# {
# "action": "update",
# "action": "replace",
# "check_mode": false,
# "sequence_number": 2,
# "state": "overridden"
Expand Down Expand Up @@ -334,6 +346,8 @@
- image_policy_2 in result.diff[0].policyNames
- result.diff[0].sequence_number == 1
- result.diff[1].agnostic == false
- result.diff[1].packageName == ""
- result.diff[1].rpmimages == ""
- result.diff[1].policyName == image_policy_1
- result.diff[1].policyDescr == image_policy_1 + " overridden"
- result.diff[1].epldImgName == epld_image_1
Expand All @@ -343,7 +357,7 @@
- result.diff[1].sequence_number == 2
- (result.metadata | length) == 2
- result.metadata[0].action == "delete"
- result.metadata[1].action == "update"
- result.metadata[1].action == "replace"
- result.metadata[0].state == "overridden"
- result.metadata[1].state == "overridden"
- result.metadata[0].check_mode == False
Expand Down Expand Up @@ -371,7 +385,7 @@
# OVERRIDDEN - TEST - query image policies and verify results
################################################################################
# Expected result
# ok: [172.22.150.244] => {
# ok: [dcnm] => {
# "result": {
# "changed": false,
# "diff": [
Expand All @@ -390,7 +404,7 @@
# "policyType": "PLATFORM",
# "ref_count": 0,
# "role": null,
# "rpmimages": null,
# "rpmimages": "",
# "sequence_number": 1,
# "unInstall": false
# }
Expand Down Expand Up @@ -423,7 +437,7 @@
# "policyType": "PLATFORM",
# "ref_count": 0,
# "role": null,
# "rpmimages": null,
# "rpmimages": "",
# "unInstall": false
# }
# ],
Expand Down Expand Up @@ -465,6 +479,8 @@
- result.failed == false
- (result.diff | length) == 1
- result.diff[0].agnostic == false
- result.diff[0].packageName == ""
- result.diff[0].rpmimages == ""
- result.diff[0].policyName == image_policy_1
- result.diff[0].policyDescr == image_policy_1 + " overridden"
- result.diff[0].epldImgName == epld_image_1
Expand Down

0 comments on commit 6e32f42

Please sign in to comment.