Skip to content

Commit

Permalink
[Defect Fixed : JIT-320930] [omevv_firmware_repository_profile] (#772)
Browse files Browse the repository at this point in the history
* JIT-320930 fixed

* improved test connection functionality

* waiting for response

* sanity fixed
  • Loading branch information
ShivamSh3 authored Nov 21, 2024
1 parent 5a9fe27 commit 0822d80
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
14 changes: 13 additions & 1 deletion plugins/module_utils/omevv_utils/omevv_firmware_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@


from __future__ import (absolute_import, division, print_function)
import time

__metaclass__ = type

Expand All @@ -36,6 +37,7 @@
NO_CLUSTERS_FOUND_MSG = "No clusters found."
PROFILE_URI = "/RepositoryProfiles"
TEST_CONNECTION_URI = "/RepositoryProfiles/TestConnection"
TEST_CONNECTION_HISTORY = "/TestConnectionJobs/{job_id}/ExecutionHistories"
BASELINE_PROFILE_URI = "/Consoles/{vcenter_uuid}/BaselineProfiles"
TEST_CONNECTION_URI = "/RepositoryProfiles/TestConnection"
CLUSTER_URI = "/Consoles/{vcenter_uuid}/Clusters"
Expand Down Expand Up @@ -182,7 +184,17 @@ def test_connection(self, protocol_type, catalog_path, share_username, share_pas
payload = self.form_conn_payload(
protocol_type, catalog_path, share_username, share_password, share_domain)
resp = self.omevv.invoke_request("POST", TEST_CONNECTION_URI, payload)
return resp
if resp.success:
time.sleep(5) # Waiting here because response comes as empty at first call
job_id = resp.json_data
resp_history = self.omevv.invoke_request("GET", TEST_CONNECTION_HISTORY.format(job_id=job_id))
while resp_history.json_data[0]["statusSummary"] != "SUCCESSFUL" and resp_history.json_data[0]["statusSummary"] != "FAILED":
time.sleep(3)
resp_history = self.omevv.invoke_request("GET", TEST_CONNECTION_HISTORY.format(job_id=job_id))
if resp_history.json_data[0]["statusSummary"] == "SUCCESSFUL":
return True
else:
return False

def get_firmware_repository_profile_by_id(self, profile_id):
"""
Expand Down
14 changes: 7 additions & 7 deletions plugins/modules/omevv_firmware_repository_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def test_connection(self, protocol_type, catalog_path):
share_password=self.module.params.get('share_password'),
share_domain=self.module.params.get('share_domain')
)
if resp.success:
if resp:
return True
else:
self.module.exit_json(msg=FAILED_CONN_MSG, failed=True)
Expand Down Expand Up @@ -252,7 +252,7 @@ def create_firmware_repository_profile(self):
profile_resp = self.omevv_profile_obj.get_firmware_repository_profile_by_id(resp.json_data)
while profile_resp.json_data["status"] != "Success" and profile_resp.json_data["status"] != "Failed":
time.sleep(3)
profile_resp = self.omevv_profile_obj.get_firmware_repository_profile(resp.json_data["profileName"])
profile_resp = self.omevv_profile_obj.get_firmware_repository_profile_by_id(resp.json_data)
if self.module._diff and profile_resp.json_data["status"] == "Success":
self.module.exit_json(msg=SUCCESS_CREATION_MSG, profile_info=profile_resp.json_data, diff=diff, changed=True)
elif profile_resp.json_data["status"] == "Success":
Expand Down Expand Up @@ -393,7 +393,7 @@ def execute(self):
if diff and not self.module.check_mode:
self.modify_firmware_repository_profile(api_response, module_response)
else:
self.module.exit_json(msg=CHANGES_NOT_FOUND_MSG, changed=False)
self.module.exit_json(msg=CHANGES_NOT_FOUND_MSG, diff={"before": {}, "after": {}}, changed=False)


class DeleteFirmwareRepositoryProfile(FirmwareRepositoryProfile):
Expand Down Expand Up @@ -424,8 +424,8 @@ def delete_firmware_repository_profile(self, api_response):
resp = self.omevv_profile_obj.delete_firmware_repository_profile(api_response["id"])
if resp.success:
if self.module._diff:
self.module.exit_json(msg=SUCCESS_DELETION_MSG, profile_info={}, diff=diff, changed=True)
self.module.exit_json(msg=SUCCESS_DELETION_MSG, profile_info={}, changed=True)
self.module.exit_json(msg=SUCCESS_DELETION_MSG, diff=diff, changed=True)
self.module.exit_json(msg=SUCCESS_DELETION_MSG, changed=True)
else:
self.module.exit_json(msg=FAILED_DELETION_MSG, failed=True)

Expand All @@ -440,9 +440,9 @@ def execute(self):
if not profile_exists and self.module.check_mode:
self.module.exit_json(msg=CHANGES_NOT_FOUND_MSG, changed=False)
if not profile_exists and not self.module.check_mode and self.module._diff:
self.module.exit_json(msg=PROFILE_NOT_FOUND_MSG.format(profile_name=profile), diff={"before": {}, "after": {}}, profile_info={}, failed=True)
self.module.exit_json(msg=PROFILE_NOT_FOUND_MSG.format(profile_name=profile), diff={"before": {}, "after": {}}, failed=True)
if not profile_exists and not self.module.check_mode:
self.module.exit_json(msg=PROFILE_NOT_FOUND_MSG.format(profile_name=profile), profile_info={}, failed=True)
self.module.exit_json(msg=PROFILE_NOT_FOUND_MSG.format(profile_name=profile), failed=True)
if profile_exists and not self.module.check_mode:
self.delete_firmware_repository_profile(api_response)
if profile_exists and self.module.check_mode:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_connection(self, omevv_connection_firmware_repository_profile, omevv_de
obj = self.module.FirmwareRepositoryProfile(
omevv_connection_firmware_repository_profile, f_module)
result = obj.test_connection(None, None)
assert result is None
assert result is True

def test_trim_api_response(self, omevv_connection_firmware_repository_profile, omevv_default_args):
# Scenario 1: Complete api_response
Expand Down Expand Up @@ -265,11 +265,9 @@ def test_create_firmware_repository_profile(self, omevv_connection_firmware_repo
mocker.patch(MODULE_UTILS_PATH +
PERFORM_CREATE_PROFILE, return_value=(obj, ""))
mocker.patch(MODULE_UTILS_PATH +
GET_PROFILE_BY_ID, return_value=obj3)
GET_PROFILE_BY_ID, side_effect=[obj3, obj2])
mocker.patch(MODULE_PATH +
'time.sleep', return_value=None)
mocker.patch(MODULE_UTILS_PATH +
GET_PROFILE_INFO_KEY, return_value=obj2)
f_module = self.get_module_mock(params=omevv_default_args)
obj = self.module.CreateFirmwareRepositoryProfile(
omevv_connection_firmware_repository_profile, f_module)
Expand Down Expand Up @@ -372,6 +370,8 @@ def test_execute(self, omevv_connection_firmware_repository_profile, omevv_defau
SEARCH_PROFILE_NAME, return_value=obj)
mocker.patch(
MODULE_PATH + 'FirmwareRepositoryProfile.trim_api_response', return_value=(obj, ""))
mocker.patch(
MODULE_PATH + 'FirmwareRepositoryProfile.test_connection', return_value=True)
mocker.patch(
MODULE_PATH + CREATE_DIFF_MODE_CHECK, return_value={})
mocker.patch(MODULE_PATH + 'recursive_diff', return_value=(obj, ""))
Expand Down Expand Up @@ -404,6 +404,8 @@ def test_execute(self, omevv_connection_firmware_repository_profile, omevv_defau
SEARCH_PROFILE_NAME, return_value={})
mocker.patch(
MODULE_PATH + 'FirmwareRepositoryProfile.trim_api_response', return_value=(obj, ""))
mocker.patch(
MODULE_PATH + 'FirmwareRepositoryProfile.test_connection', return_value=True)
mocker.patch(
MODULE_PATH + CREATE_DIFF_MODE_CHECK, return_value={})
mocker.patch(MODULE_PATH + 'recursive_diff', return_value=(obj, ""))
Expand Down

0 comments on commit 0822d80

Please sign in to comment.