Handle TransferMethod in vmedia insertion
This commit adds the TransferMethod to insertmedia calls if necessary. Some HW require that the TransferMethod is set before inserting virtual media. Change-Id: I7fc5d41cdcf79d61cb1906f2755f55f284efe766
This commit is contained in:
parent
2506b87d87
commit
c416bf158e
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- |
|
||||||
|
Add TransferMethod for any general error that mentions it.
|
|
@ -121,6 +121,16 @@ class VirtualMedia(base.ResourceBase):
|
||||||
and "#/TransferProtocolType" in error.related_properties
|
and "#/TransferProtocolType" in error.related_properties
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def is_transfer_method_required(self, error=None):
|
||||||
|
"""Check the response code and body and in case of failure
|
||||||
|
|
||||||
|
Try to determine if it happened due to missing TransferMethod
|
||||||
|
"""
|
||||||
|
if (error.code.endswith('GeneralError')
|
||||||
|
and 'TransferMethod' in error.detail):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def insert_media(self, image, inserted=True, write_protected=True,
|
def insert_media(self, image, inserted=True, write_protected=True,
|
||||||
username=None, password=None, transfer_method=None):
|
username=None, password=None, transfer_method=None):
|
||||||
"""Attach remote media to virtual media
|
"""Attach remote media to virtual media
|
||||||
|
@ -186,7 +196,18 @@ class VirtualMedia(base.ResourceBase):
|
||||||
payload['TransferProtocolType'] = "HTTPS"
|
payload['TransferProtocolType'] = "HTTPS"
|
||||||
elif payload['Image'].startswith('http://'):
|
elif payload['Image'].startswith('http://'):
|
||||||
payload['TransferProtocolType'] = "HTTP"
|
payload['TransferProtocolType'] = "HTTP"
|
||||||
self._conn.post(target_uri, data=payload)
|
|
||||||
|
# NOTE (iurygregory) we try to handle the case where a
|
||||||
|
# a TransferMethod is also required in the payload.
|
||||||
|
try:
|
||||||
|
self._conn.post(target_uri, data=payload)
|
||||||
|
except exceptions.HTTPError as error2:
|
||||||
|
if self.is_transfer_method_required(error2):
|
||||||
|
payload['TransferMethod'] = "Stream"
|
||||||
|
self._conn.post(target_uri, data=payload)
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
self.invalidate()
|
self.invalidate()
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"error": {
|
||||||
|
"code": "Base.1.4.0.GeneralError",
|
||||||
|
"message": "See ExtendedInfo for more information.",
|
||||||
|
"@Message.ExtendedInfo": [
|
||||||
|
{
|
||||||
|
"@odata.type": "Message.v1_0_6.Message",
|
||||||
|
"MessageId": "Base.1.4.0.GeneralError",
|
||||||
|
"Message": "'TransferMethod' property which is mandatory to complete the action is missing in the request body.",
|
||||||
|
"MessageArgs": [],
|
||||||
|
"Severity": "Critical"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -207,6 +207,16 @@ class VirtualMediaTestCase(base.TestCase):
|
||||||
retval = self.sys_virtual_media.is_transfer_protocol_required(error)
|
retval = self.sys_virtual_media.is_transfer_protocol_required(error)
|
||||||
self.assertTrue(retval)
|
self.assertTrue(retval)
|
||||||
|
|
||||||
|
def test_is_transfer_method_required(self):
|
||||||
|
with open('sushy/tests/unit/json_samples/'
|
||||||
|
'transfer_method_required_error.json') as f:
|
||||||
|
response_obj = json.load(f)
|
||||||
|
response = mock.Mock(spec=['json', 'status_code'])
|
||||||
|
response.json.return_value = response_obj
|
||||||
|
error = exceptions.HTTPError('POST', 'VirtualMedia', response)
|
||||||
|
retval = self.sys_virtual_media.is_transfer_method_required(error)
|
||||||
|
self.assertTrue(retval)
|
||||||
|
|
||||||
def test_eject_media_none(self):
|
def test_eject_media_none(self):
|
||||||
self.sys_virtual_media._actions.eject_media = None
|
self.sys_virtual_media._actions.eject_media = None
|
||||||
self.assertRaisesRegex(
|
self.assertRaisesRegex(
|
||||||
|
|
Loading…
Reference in New Issue