Skip to content

Commit

Permalink
Fix pylint issues, more...
Browse files Browse the repository at this point in the history
ImagePolicyCreateCommon(): set self.response_current and self.result_current directly from dcnm_send() and _handle_response() respectively.
  • Loading branch information
allenrobel committed Feb 13, 2024
1 parent ad992ed commit 873cab2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
31 changes: 19 additions & 12 deletions plugins/module_utils/image_policy/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,20 @@ def _send_payloads(self):
self.result_nok = []
self.diff_nok = []
for payload in self._payloads_to_commit:
response = dcnm_send(
self.response_current = dcnm_send(
self.ansible_module, self.verb, self.path, data=json.dumps(payload)
)
result = self._handle_response(response, self.verb)
self.result_current = self._handle_response(
self.response_current, self.verb
)

if result["success"]:
self.response_ok.append(response)
self.result_ok.append(result)
if self.result_current["success"]:
self.response_ok.append(self.response_current)
self.result_ok.append(self.result_current)
self.diff_ok.append(payload)
else:
self.response_nok.append(response)
self.result_nok.append(result)
self.response_nok.append(self.response_current)
self.result_nok.append(self.result_current)
self.diff_nok.append(payload)

msg = f"self.response_ok: {json.dumps(self.response_ok, indent=4, sort_keys=True)}"
Expand All @@ -157,7 +159,9 @@ def _send_payloads(self):
self.log.debug(msg)
msg = f"self.result_nok: {json.dumps(self.result_nok, indent=4, sort_keys=True)}"
self.log.debug(msg)
msg = f"self.diff_nok: {json.dumps(self.diff_nok, indent=4, sort_keys=True)}"
msg = (
f"self.diff_nok: {json.dumps(self.diff_nok, indent=4, sort_keys=True)}"
)
self.log.debug(msg)

def _process_responses(self):
Expand All @@ -179,6 +183,7 @@ def _process_responses(self):
self.response_current = copy.deepcopy(response)
return

self.failed = True
self.changed = False
# at least one request succeeded, so set changed to True
if len(self.result_nok) != len(self._payloads_to_commit):
Expand All @@ -195,7 +200,6 @@ def _process_responses(self):
for response in self.response_ok:
self.response = copy.deepcopy(response)
self.response_current = copy.deepcopy(response)
self.failed = True

result = {}
result["failed"] = self.failed
Expand Down Expand Up @@ -235,7 +239,7 @@ def payloads(self, value):

class ImagePolicyCreateBulk(ImagePolicyCreateCommon):
"""
Given a property-constructed list of payloads, bulk-create the
Given a properly-constructed list of payloads, bulk-create the
image policies therein. The payload format is given below.
Payload format:
Expand Down Expand Up @@ -307,6 +311,8 @@ def commit(self):

class ImagePolicyCreate(ImagePolicyCreateCommon):
"""
NOTE: This class is not being used currently.
Given a properly-constructed image policy payload (python dict),
send an image policy create request to the controller. The payload
format is given below.
Expand Down Expand Up @@ -364,6 +370,7 @@ def payload(self):
@payload.setter
def payload(self, value):
self._verify_payload(value)
self.properties["payloads"] = [value]
self.properties["payload"] = value

def commit(self):
Expand All @@ -377,8 +384,8 @@ def commit(self):
msg += "payload must be set prior to calling commit."
self.ansible_module.fail_json(msg, **self.failed_result)

# ImagePolicyCreateCommon expects a list of payloads
self.payloads = [self.payload]
# # ImagePolicyCreateCommon expects a list of payloads
# self.payloads = [self.payload]
self._build_payloads_to_commit()

if not self._payloads_to_commit:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
# See the following regarding *_fixture imports
# https://pylint.pycqa.org/en/latest/user_guide/messages/warning/redefined-outer-name.html
# Due to the above, we also need to disable unused-import
# Also, fixtures need to use *args to match the signature of the function they are mocking
# pylint: disable=unused-import
# Some fixtures need to use *args to match the signature of the function they are mocking
# pylint: disable=redefined-outer-name
# pylint: disable=protected-access
# pylint: disable=unused-argument
# pylint: disable=invalid-name

from __future__ import absolute_import, division, print_function

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# pylint: disable=protected-access
# pylint: disable=unused-argument
# pylint: disable=invalid-name

from __future__ import absolute_import, division, print_function

__metaclass__ = type
Expand Down Expand Up @@ -385,8 +386,8 @@ def mock_dcnm_send(*args, **kwargs):
assert instance.result_ok == []
assert instance.diff_ok == []
assert instance.response_nok[0]["RETURN_CODE"] == 500
assert instance.result_nok[0]["changed"] == False
assert instance.result_nok[0]["success"] == False
assert instance.result_nok[0]["changed"] is False
assert instance.result_nok[0]["success"] is False
assert instance.diff_nok[0]["agnostic"] is False
assert instance.diff_nok[0]["policyName"] == "FOO"

Expand Down

0 comments on commit 873cab2

Please sign in to comment.