Skip to content

Commit

Permalink
ImagePolicies: Add unit tests, update docstrings, remove inherited pr…
Browse files Browse the repository at this point in the history
…operties

Removed the following properties which are inherited from ImageUpgradeCommon:

- response_data
- response
- result

Add unit tests for:

- ImagePolicies._get (two tests)
- ImagePolicies.all_policies (two tests)

Improve docstrings for existing tests.
  • Loading branch information
allenrobel committed Feb 26, 2024
1 parent 9bb1b50 commit db36e9f
Show file tree
Hide file tree
Showing 3 changed files with 303 additions and 46 deletions.
27 changes: 2 additions & 25 deletions plugins/module_utils/image_upgrade/image_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class ImagePolicies(ImageUpgradeCommon):
Usage (where module is an instance of AnsibleModule):
instance = ImagePolicies(module).refresh()
instance = ImagePolicies(module)
instance.refresh()
instance.policy_name = "NR3F"
if instance.name is None:
print("policy NR3F does not exist on the controller")
Expand All @@ -48,8 +49,6 @@ class ImagePolicies(ImageUpgradeCommon):
epd_image_name = instance.epld_image_name
etc...
Policies can be refreshed by calling instance.refresh().
Endpoint:
/appcenter/cisco/ndfc/api/v1/imagemanagement/rest/policymgnt/policies
"""
Expand Down Expand Up @@ -187,28 +186,6 @@ def name(self):
"""
return self._get("policyName")

@property
def response_data(self):
"""
Return the parsed data from the response as a dictionary,
keyed on policy_name.
"""
return self.properties["response_data"]

@property
def response(self):
"""
Return the raw response from the controller.
"""
return self.properties["response"]

@property
def result(self):
"""
Return the raw result.
"""
return self.properties["result"]

@property
def policy_name(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,5 +270,97 @@
],
"message": ""
}
},
"test_image_upgrade_image_policies_00041a": {
"RETURN_CODE": 200,
"METHOD": "GET",
"REQUEST_PATH": "https://172.22.150.244:443/appcenter/cisco/ndfc/api/v1/imagemanagement/rest/policymgnt/policies",
"MESSAGE": "OK",
"DATA": {
"status": "SUCCESS",
"lastOperDataObject": [
{
"policyName": "KR5M",
"policyType": "PLATFORM",
"nxosVersion": "10.2.5_nxos64-cs_64bit",
"packageName": "",
"platform": "N9K/N3K",
"policyDescr": "10.2.(5) with EPLD",
"platformPolicies": "",
"epldImgName": "n9000-epld.10.2.5.M.img",
"rpmimages": "",
"imageName": "nxos64-cs.10.2.5.M.bin",
"agnostic": "false",
"ref_count": 10
}
],
"message": ""
}
},
"test_image_upgrade_image_policies_00042a": {
"RETURN_CODE": 200,
"METHOD": "GET",
"REQUEST_PATH": "https://172.22.150.244:443/appcenter/cisco/ndfc/api/v1/imagemanagement/rest/policymgnt/policies",
"MESSAGE": "OK",
"DATA": {
"status": "SUCCESS",
"lastOperDataObject": [
{
"policyName": "KR5M",
"policyType": "PLATFORM",
"nxosVersion": "10.2.5_nxos64-cs_64bit",
"packageName": "",
"platform": "N9K/N3K",
"policyDescr": "10.2.(5) with EPLD",
"platformPolicies": "",
"epldImgName": "n9000-epld.10.2.5.M.img",
"rpmimages": "",
"imageName": "nxos64-cs.10.2.5.M.bin",
"agnostic": "false",
"ref_count": 10
}
],
"message": ""
}
},
"test_image_upgrade_image_policies_00051a": {
"RETURN_CODE": 200,
"METHOD": "GET",
"REQUEST_PATH": "https://172.22.150.244:443/appcenter/cisco/ndfc/api/v1/imagemanagement/rest/policymgnt/policies",
"MESSAGE": "OK",
"DATA": {
"status": "SUCCESS",
"lastOperDataObject": [
{
"policyName": "KR5M",
"policyType": "PLATFORM",
"nxosVersion": "10.2.5_nxos64-cs_64bit",
"packageName": "",
"platform": "N9K/N3K",
"policyDescr": "10.2.(5) with EPLD",
"platformPolicies": "",
"epldImgName": "n9000-epld.10.2.5.M.img",
"rpmimages": "",
"imageName": "nxos64-cs.10.2.5.M.bin",
"agnostic": "false",
"ref_count": 10
},
{
"policyName": "OR1F",
"policyType": "PLATFORM",
"nxosVersion": "10.4.1_nxos64-cs_64bit",
"packageName": "",
"platform": "N9K/N3K",
"policyDescr": "OR1F EPLD",
"platformPolicies": "",
"epldImgName": "n9000-epld.10.4.1.F.img",
"rpmimages": "",
"imageName": "nxos64-cs.10.4.1.F.bin",
"agnostic": "false",
"ref_count": 0
}
],
"message": ""
}
}
}
Loading

0 comments on commit db36e9f

Please sign in to comment.