Skip to content

Commit

Permalink
redfish: clean etag of quotes before patch (#3296)
Browse files Browse the repository at this point in the history
* Some vendors surround header etag with quotes, which need to be cleaned before sending a patch

* Minor change fragment

* Add etag strip quote option

* Rebase

* Cleanup fragment

* Apply suggestions from code review

Co-authored-by: Felix Fontein <[email protected]>

* Update plugins/modules/remote_management/redfish/redfish_command.py

Co-authored-by: Felix Fontein <[email protected]>

* Description update

* Update plugins/modules/remote_management/redfish/redfish_config.py

Co-authored-by: Felix Fontein <[email protected]>

Co-authored-by: Kyle Williams <[email protected]>
Co-authored-by: Felix Fontein <[email protected]>
  • Loading branch information
3 people authored Sep 1, 2021
1 parent 7c493eb commit 3502f3b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/3296-clean-etag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- "redfish_command and redfish_config and redfish_utils module utils - add parameter to strip etag of quotes before patch, since some vendors do not properly ``If-Match`` etag with quotes (https:/ansible-collections/community.general/pull/3296)."
5 changes: 4 additions & 1 deletion plugins/module_utils/redfish_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
class RedfishUtils(object):

def __init__(self, creds, root_uri, timeout, module, resource_id=None,
data_modification=False):
data_modification=False, strip_etag_quotes=False):
self.root_uri = root_uri
self.creds = creds
self.timeout = timeout
self.module = module
self.service_root = '/redfish/v1/'
self.resource_id = resource_id
self.data_modification = data_modification
self.strip_etag_quotes = strip_etag_quotes
self._init_session()

def _auth_params(self, headers):
Expand Down Expand Up @@ -121,6 +122,8 @@ def patch_request(self, uri, pyld):
if not etag:
etag = r['data'].get('@odata.etag')
if etag:
if self.strip_etag_quotes:
etag = etag.strip('"')
req_headers['If-Match'] = etag
username, password, basic_auth = self._auth_params(req_headers)
try:
Expand Down
17 changes: 15 additions & 2 deletions plugins/modules/remote_management/redfish/redfish_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@
description:
- The transfer method to use with the image
type: str
strip_etag_quotes:
description:
- Removes surrounding quotes of etag used in C(If-Match) header
of C(PATCH) requests.
- Only use this option to resolve bad vendor implementation where
C(If-Match) only matches the unquoted etag string.
type: bool
default: false
version_added: 3.7.0
author: "Jose Delarosa (@jose-delarosa)"
'''
Expand Down Expand Up @@ -631,7 +640,8 @@ def main():
transfer_protocol_type=dict(),
transfer_method=dict(),
)
)
),
strip_etag_quotes=dict(type='bool', default=False),
),
required_together=[
('username', 'password'),
Expand Down Expand Up @@ -686,10 +696,13 @@ def main():
# VirtualMedia options
virtual_media = module.params['virtual_media']

# Etag options
strip_etag_quotes = module.params['strip_etag_quotes']

# Build root URI
root_uri = "https://" + module.params['baseuri']
rf_utils = RedfishUtils(creds, root_uri, timeout, module,
resource_id=resource_id, data_modification=True)
resource_id=resource_id, data_modification=True, strip_etag_quotes=strip_etag_quotes)

# Check that Category is valid
if category not in CATEGORY_COMMANDS_ALL:
Expand Down
17 changes: 15 additions & 2 deletions plugins/modules/remote_management/redfish/redfish_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@
- setting dict of EthernetInterface on OOB controller
type: dict
version_added: '0.2.0'
strip_etag_quotes:
description:
- Removes surrounding quotes of etag used in C(If-Match) header
of C(PATCH) requests.
- Only use this option to resolve bad vendor implementation where
C(If-Match) only matches the unquoted etag string.
type: bool
default: false
version_added: 3.7.0
author: "Jose Delarosa (@jose-delarosa)"
'''
Expand Down Expand Up @@ -237,7 +246,8 @@ def main():
nic_config=dict(
type='dict',
default={}
)
),
strip_etag_quotes=dict(type='bool', default=False),
),
required_together=[
('username', 'password'),
Expand Down Expand Up @@ -275,10 +285,13 @@ def main():
nic_addr = module.params['nic_addr']
nic_config = module.params['nic_config']

# Etag options
strip_etag_quotes = module.params['strip_etag_quotes']

# Build root URI
root_uri = "https://" + module.params['baseuri']
rf_utils = RedfishUtils(creds, root_uri, timeout, module,
resource_id=resource_id, data_modification=True)
resource_id=resource_id, data_modification=True, strip_etag_quotes=strip_etag_quotes)

# Check that Category is valid
if category not in CATEGORY_COMMANDS_ALL:
Expand Down

0 comments on commit 3502f3b

Please sign in to comment.