Skip to content

Commit

Permalink
WDC Redfish firmware update support for update image creds (#5056)
Browse files Browse the repository at this point in the history
Allows user to specify Basic Auth credentials for firmware update image.

(cherry picked from commit 4eb3540)
  • Loading branch information
mikemoerk authored and patchback[bot] committed Aug 2, 2022
1 parent e56dafd commit d05e15f
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions plugins/module_utils/wdc_redfish_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def _set_root_uri(self, root_uris):
response = self.get_request(uri)
if response['ret']:
self.root_uri = root_uri
break

def _find_updateservice_resource(self):
"""Find the update service resource as well as additional WDC-specific resources."""
Expand Down Expand Up @@ -157,8 +158,7 @@ def firmware_activate(self, update_opts):
'msg': "FWActivate requested"}

def _get_bundle_version(self,
bundle_uri,
update_creds):
bundle_uri):
"""Get the firmware version from a bundle file, and whether or not it is multi-tenant.
Only supports HTTP at this time. Assumes URI exists and is a tarfile.
Expand All @@ -169,20 +169,12 @@ def _get_bundle_version(self,
and checks the appropriate byte in the file.
:param str bundle_uri: HTTP URI of the firmware bundle.
:param dict or None update_creds: Dict containing username and password to access the bundle.
:return: Firmware version number contained in the bundle, and whether or not the bundle is multi-tenant.
Either value will be None if unable to deterine.
:rtype: str or None, bool or None
"""
parsed_url = urlparse(bundle_uri)
if update_creds:
original_netloc = parsed_url.netloc
parsed_url._replace(netloc="{0}:{1}{2}".format(update_creds.get("username"),
update_creds.get("password"),
original_netloc))

bundle_temp_filename = fetch_file(module=self.module,
url=urlunparse(parsed_url))
url=bundle_uri)
if not tarfile.is_tarfile(bundle_temp_filename):
return None, None
tf = tarfile.open(bundle_temp_filename)
Expand Down Expand Up @@ -223,8 +215,21 @@ def update_and_activate(self, update_opts):
Performs retries, handles timeouts as needed.
"""
# Convert credentials to standard HTTP format
if update_opts.get("update_creds") is not None and "username" in update_opts["update_creds"] and "password" in update_opts["update_creds"]:
update_creds = update_opts["update_creds"]
parsed_url = urlparse(update_opts["update_image_uri"])
if update_creds:
original_netloc = parsed_url.netloc
parsed_url = parsed_url._replace(netloc="{0}:{1}@{2}".format(update_creds.get("username"),
update_creds.get("password"),
original_netloc))
update_opts["update_image_uri"] = urlunparse(parsed_url)
del update_opts["update_creds"]

# Make sure bundle URI is HTTP(s)
bundle_uri = update_opts["update_image_uri"]

if not self.uri_is_http(bundle_uri):
return {
'ret': False,
Expand All @@ -250,9 +255,7 @@ def update_and_activate(self, update_opts):
# Check the FW version in the bundle file, and compare it to what is already on the IOMs

# Bundle version number
update_creds = update_opts.get("update_creds")
bundle_firmware_version, is_bundle_multi_tenant = self._get_bundle_version(bundle_uri,
update_creds)
bundle_firmware_version, is_bundle_multi_tenant = self._get_bundle_version(bundle_uri)
if bundle_firmware_version is None or is_bundle_multi_tenant is None:
return {
'ret': False,
Expand Down Expand Up @@ -313,6 +316,7 @@ def update_and_activate(self, update_opts):
if retry_number != 0:
time.sleep(retry_interval_seconds)
retry_number += 1

result = self.simple_update(update_opts)
if result['ret'] is not True:
# Sometimes a timeout error is returned even though the update actually was requested.
Expand Down

0 comments on commit d05e15f

Please sign in to comment.