Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redfish: Added handling for trailing slashes in URIs when extracting member identifiers #9057

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/9047-redfish-uri-parsing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- redfish_utils module utils - fix issue with URI parsing to gracefully handling trailing slashes when extracting member identifiers (https://github.com/ansible-collections/community.general/issues/9047).
mraineri marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 8 additions & 8 deletions plugins/module_utils/redfish_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ def get_logs(self):
entry[prop] = logEntry.get(prop)
if entry:
list_of_log_entries.append(entry)
log_name = log_svcs_uri.split('/')[-1]
log_name = log_svcs_uri.rstrip('/').split('/')[-1]
logs[log_name] = list_of_log_entries
list_of_logs.append(logs)

Expand Down Expand Up @@ -1052,7 +1052,7 @@ def get_volume_inventory(self, systems_uri):
if 'Drives' in data[u'Links']:
for link in data[u'Links'][u'Drives']:
drive_id_link = link[u'@odata.id']
drive_id = drive_id_link.split("/")[-1]
drive_id = drive_id_link.rstrip('/').split('/')[-1]
drive_id_list.append({'Id': drive_id})
volume_result['Linked_drives'] = drive_id_list
volume_results.append(volume_result)
Expand Down Expand Up @@ -3432,7 +3432,7 @@ def set_hostinterface_attributes(self, hostinterface_config, hostinterface_id=No

# Capture list of URIs that match a specified HostInterface resource Id
if hostinterface_id:
matching_hostinterface_uris = [uri for uri in uris if hostinterface_id in uri.split('/')[-1]]
matching_hostinterface_uris = [uri for uri in uris if hostinterface_id in uri.rstrip('/').split('/')[-1]]
if hostinterface_id and matching_hostinterface_uris:
hostinterface_uri = list.pop(matching_hostinterface_uris)
elif hostinterface_id and not matching_hostinterface_uris:
Expand Down Expand Up @@ -3551,12 +3551,12 @@ def get_service_identification(self, manager):
result = {}
if manager is None:
if len(self.manager_uris) == 1:
manager = self.manager_uris[0].split('/')[-1]
manager = self.manager_uris[0].rstrip('/').split('/')[-1]
elif len(self.manager_uris) > 1:
entries = self.get_multi_manager_inventory()['entries']
managers = [m[0]['manager_uri'] for m in entries if m[1].get('ServiceIdentification')]
if len(managers) == 1:
manager = managers[0].split('/')[-1]
manager = managers[0].rstrip('/').split('/')[-1]
else:
self.module.fail_json(msg=[
"Multiple managers with ServiceIdentification were found: %s" % str(managers),
Expand Down Expand Up @@ -3714,7 +3714,7 @@ def delete_volumes(self, storage_subsystem_id, volume_ids):
# Matching Storage Subsystem ID with user input
self.storage_subsystem_uri = ""
for storage_subsystem_uri in self.storage_subsystems_uris:
if storage_subsystem_uri.split("/")[-2] == storage_subsystem_id:
if storage_subsystem_uri.rstrip('/').split('/')[-1] == storage_subsystem_id:
self.storage_subsystem_uri = storage_subsystem_uri

if not self.storage_subsystem_uri:
Expand Down Expand Up @@ -3742,7 +3742,7 @@ def delete_volumes(self, storage_subsystem_id, volume_ids):

# Delete each volume
for volume in self.volume_uris:
if volume.split("/")[-1] in volume_ids:
if volume.rstrip('/').split('/')[-1] in volume_ids:
response = self.delete_request(self.root_uri + volume)
if response['ret'] is False:
return response
Expand Down Expand Up @@ -3776,7 +3776,7 @@ def create_volume(self, volume_details, storage_subsystem_id, storage_none_volum
# Matching Storage Subsystem ID with user input
self.storage_subsystem_uri = ""
for storage_subsystem_uri in self.storage_subsystems_uris:
if storage_subsystem_uri.split("/")[-2] == storage_subsystem_id:
if storage_subsystem_uri.rstrip('/').split('/')[-1] == storage_subsystem_id:
self.storage_subsystem_uri = storage_subsystem_uri

if not self.storage_subsystem_uri:
Expand Down
Loading