Allow invoke without checking the return value
Some versions of firmware for at least 13G hardware can return a failure return value and a message indicating success on certain invoke calls. This patch modifies invoke so that it can be used to execute the invoke command and return the result without raising an exception if the return value indicates a failure. This allows the caller to inspect the returned message to determine success or failure. Change-Id: I85a1d234d17ae601ed984109c8aa668aaf86eae2
This commit is contained in:
parent
5e9b27ee97
commit
aca79f0e8c
@ -632,8 +632,14 @@ class WSManClient(wsman.Client):
|
||||
max_elems, auto_pull,
|
||||
filter_query, filter_dialect)
|
||||
|
||||
def invoke(self, resource_uri, method, selectors=None, properties=None,
|
||||
expected_return_value=None, wait_for_idrac=True):
|
||||
def invoke(self,
|
||||
resource_uri,
|
||||
method,
|
||||
selectors=None,
|
||||
properties=None,
|
||||
expected_return_value=None,
|
||||
wait_for_idrac=True,
|
||||
check_return_value=True):
|
||||
"""Invokes a remote WS-Man method
|
||||
|
||||
:param resource_uri: URI of the resource
|
||||
@ -647,6 +653,8 @@ class WSManClient(wsman.Client):
|
||||
:param wait_for_idrac: indicates whether or not to wait for the
|
||||
iDRAC to be ready to accept commands before issuing the
|
||||
command
|
||||
:param check_return_value: indicates if the ReturnValue should be
|
||||
checked and an exception thrown on an unexpected value
|
||||
:returns: an lxml.etree.Element object of the response received
|
||||
:raises: WSManRequestFailure on request failures
|
||||
:raises: WSManInvalidResponse when receiving invalid response
|
||||
@ -666,17 +674,21 @@ class WSManClient(wsman.Client):
|
||||
resp = super(WSManClient, self).invoke(resource_uri, method, selectors,
|
||||
properties)
|
||||
|
||||
return_value = utils.find_xml(resp, 'ReturnValue', resource_uri).text
|
||||
if return_value == utils.RET_ERROR:
|
||||
message_elems = utils.find_xml(resp, 'Message', resource_uri, True)
|
||||
messages = [message_elem.text for message_elem in message_elems]
|
||||
raise exceptions.DRACOperationFailed(drac_messages=messages)
|
||||
if check_return_value:
|
||||
return_value = utils.find_xml(resp, 'ReturnValue',
|
||||
resource_uri).text
|
||||
if return_value == utils.RET_ERROR:
|
||||
message_elems = utils.find_xml(resp, 'Message',
|
||||
resource_uri, True)
|
||||
messages = [message_elem.text for message_elem in
|
||||
message_elems]
|
||||
raise exceptions.DRACOperationFailed(drac_messages=messages)
|
||||
|
||||
if (expected_return_value is not None and
|
||||
return_value != expected_return_value):
|
||||
raise exceptions.DRACUnexpectedReturnValue(
|
||||
expected_return_value=expected_return_value,
|
||||
actual_return_value=return_value)
|
||||
if (expected_return_value is not None and
|
||||
return_value != expected_return_value):
|
||||
raise exceptions.DRACUnexpectedReturnValue(
|
||||
expected_return_value=expected_return_value,
|
||||
actual_return_value=return_value)
|
||||
|
||||
return resp
|
||||
|
||||
|
@ -112,6 +112,20 @@ class WSManClientTestCase(base.BaseTest):
|
||||
self.assertRaises(exceptions.DRACOperationFailed, client.invoke,
|
||||
'http://resource', 'Foo', wait_for_idrac=False)
|
||||
|
||||
def test_invoke_with_unchecked_return_value(self, mock_requests):
|
||||
xml = """
|
||||
<response xmlns:n1="http://resource">
|
||||
<n1:ReturnValue>2</n1:ReturnValue>
|
||||
<result>yay!</result>
|
||||
</response>
|
||||
""" # noqa
|
||||
mock_requests.post('https://1.2.3.4:443/wsman', text=xml)
|
||||
|
||||
client = dracclient.client.WSManClient(**test_utils.FAKE_ENDPOINT)
|
||||
resp = client.invoke('http://resource', 'Foo',
|
||||
wait_for_idrac=False, check_return_value=False)
|
||||
self.assertEqual('yay!', resp.find('result').text)
|
||||
|
||||
def test_invoke_with_unexpected_return_value(self, mock_requests):
|
||||
xml = """
|
||||
<response xmlns:n1="http://resource">
|
||||
|
Loading…
Reference in New Issue
Block a user