Skip to content

Commit

Permalink
fix: wait until scp is applied (#504)
Browse files Browse the repository at this point in the history
fix: add idrac_redfish_job_tracking for http share
  • Loading branch information
satoshi-tokyo authored Jun 26, 2023
1 parent 6996548 commit 288936b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
3 changes: 0 additions & 3 deletions plugins/module_utils/idrac_redfish.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,6 @@ def import_scp_share(self, shutdown_type=None, host_powerstate=None, job_wait=Tr
if share.get("proxy_password") is not None:
payload["ShareParameters"]["ProxyPassword"] = share["proxy_password"]
response = self.invoke_request(IMPORT_URI, "POST", data=payload)
if response.status_code == 202 and job_wait:
task_uri = response.headers["Location"]
response = self.wait_for_job_complete(task_uri, job_wait=job_wait)
return response

def import_preview(self, import_buffer=None, target=None, share=None, job_wait=False):
Expand Down
19 changes: 17 additions & 2 deletions plugins/modules/idrac_server_config_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@
from os.path import exists
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.dellemc.openmanage.plugins.module_utils.idrac_redfish import iDRACRedfishAPI, idrac_auth_params
from ansible_collections.dellemc.openmanage.plugins.module_utils.utils import strip_substr_dict
from ansible_collections.dellemc.openmanage.plugins.module_utils.utils import idrac_redfish_job_tracking, \
strip_substr_dict
from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError
from ansible.module_utils.urls import ConnectionError, SSLValidationError
from ansible.module_utils.six.moves.urllib.parse import urlparse
Expand All @@ -535,6 +536,9 @@
SCP_ALL_ERR_MSG = "The option ALL cannot be used with options IDRAC, BIOS, NIC, or RAID."
MUTUALLY_EXCLUSIVE = "import_buffer is mutually exclusive with {0}."
PROXY_ERR_MSG = "proxy_support is enabled but all of the following are missing: proxy_server"
iDRAC_JOB_URI = "/redfish/v1/Managers/iDRAC.Embedded.1/Jobs/{job_id}"
SUCCESS_COMPLETE = "Successfully applied the iDRAC attributes update."
SCHEDULED_SUCCESS = "Successfully scheduled the job for the iDRAC attributes update."


def get_scp_file_format(module):
Expand All @@ -555,7 +559,8 @@ def get_scp_file_format(module):
def response_format_change(response, params, file_name):
resp = {}
if params["job_wait"]:
response = response.json_data
if hasattr(response, "json_data"):
response = response.json_data
response.pop("Description", None)
response.pop("Name", None)
response.pop("EndTime", None)
Expand Down Expand Up @@ -646,6 +651,11 @@ def run_export_import_scp_http(idrac, module):
host_powerstate=module.params["end_host_power_state"],
job_wait=module.params["job_wait"],
target=scp_target, share=share, )
job_id = scp_response.headers["Location"].split("/")[-1]
if module.params["job_wait"]:
job_failed, msg, job_dict, wait_time = idrac_redfish_job_tracking(
idrac, iDRAC_JOB_URI.format(job_id=job_id))
scp_response = job_dict
elif command == "export":
scp_file_name_format = get_scp_file_format(module)
share["file_name"] = scp_file_name_format
Expand Down Expand Up @@ -807,6 +817,11 @@ def import_scp_redfish(module, idrac, http_share):
job_wait=module.params["job_wait"],
target=scp_targets,
import_buffer=buffer_text, share=share_dict, )
job_id = scp_response.headers["Location"].split("/")[-1]
if module.params["job_wait"]:
job_failed, msg, job_dict, wait_time = idrac_redfish_job_tracking(
idrac, iDRAC_JOB_URI.format(job_id=job_id))
scp_response = job_dict
else:
scp_response = idrac.import_scp(import_buffer=import_buffer, target=scp_targets, job_wait=module.params["job_wait"])
scp_response = response_format_change(scp_response, module.params, share.get("file_name"))
Expand Down

0 comments on commit 288936b

Please sign in to comment.