Handle weak Etags
Refine the handling if resources provide weak Etags. In order to be compatible with vendor implementations, sushy will provide the original Etags in addition to Etags with stripped qualifiers. Story: #2009680 Task: #43967 Change-Id: I47ce9fcd2fcd961c752545774ed4c95e496f7ea9
This commit is contained in:
parent
e0d5bded4c
commit
041c8ee6fb
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
fixes:
|
||||
- |
|
||||
Makes the unstripped version of an Etag available in addition to
|
||||
the stripped one in order to support vendor implementations which
|
||||
require one or the other.
|
|
@ -576,11 +576,21 @@ class ResourceBase(object, metaclass=abc.ABCMeta):
|
|||
|
||||
:returns ETag or None
|
||||
"""
|
||||
pattern = re.compile(r'^(W\/)?("\w*")$')
|
||||
match = pattern.match(self._get_headers().get('ETag', ''))
|
||||
etag = self._get_headers().get('ETag')
|
||||
if not etag:
|
||||
return None
|
||||
|
||||
# Note (arne_wiebalck): in case there is a weak Etag,
|
||||
# return it with and without the qualifier to handle
|
||||
# vendor implementations which may require one or the
|
||||
# other (but should actually not use weak tags in the
|
||||
# first place).
|
||||
pattern = re.compile(r'^(W\/)("\w*")$')
|
||||
match = pattern.match(etag)
|
||||
if match:
|
||||
return match.group(2)
|
||||
return None
|
||||
return etag + ',' + match.group(2)
|
||||
|
||||
return etag
|
||||
|
||||
def _get_headers(self):
|
||||
"""Returns the HTTP headers of the request for the resource.
|
||||
|
|
|
@ -140,7 +140,7 @@ class VirtualMediaTestCase(base.TestCase):
|
|||
("/redfish/v1/Managers/BMC/VirtualMedia/Floppy1"),
|
||||
data={"Image": "https://www.dmtf.org/freeImages/Sardine.img",
|
||||
"Inserted": True, "WriteProtected": False},
|
||||
headers={"If-Match": '"3d7b8a7360bf2941d"'})
|
||||
headers={"If-Match": 'W/"3d7b8a7360bf2941d","3d7b8a7360bf2941d"'})
|
||||
self.assertTrue(self.sys_virtual_media._is_stale)
|
||||
|
||||
@mock.patch.object(requests, 'post', autospec=True)
|
||||
|
@ -204,7 +204,7 @@ class VirtualMediaTestCase(base.TestCase):
|
|||
self.sys_virtual_media._conn.patch.assert_called_once_with(
|
||||
("/redfish/v1/Managers/BMC/VirtualMedia/Floppy1"),
|
||||
data={"Image": None, "Inserted": False},
|
||||
headers={"If-Match": '"3d7b8a7360bf2941d"'})
|
||||
headers={"If-Match": 'W/"3d7b8a7360bf2941d","3d7b8a7360bf2941d"'})
|
||||
self.assertTrue(self.sys_virtual_media._is_stale)
|
||||
|
||||
def test_eject_media_pass_empty_dict_415(self):
|
||||
|
|
Loading…
Reference in New Issue