diff options
author | Imre Farkas <ifarkas@redhat.com> | 2015-01-14 16:19:32 +0100 |
---|---|---|
committer | Imre Farkas <ifarkas@redhat.com> | 2015-01-21 15:15:26 +0100 |
commit | 63ccb2072261550e731e9bf607a35659dfc5ffd1 (patch) | |
tree | 94e3fe633515a1803ae9dc49df7cfdb82a6e1c0d /ironic/drivers/modules/drac/client.py | |
parent | 5ef7e3a991625cb7c4c408825d5724996418e376 (diff) | |
download | ironic-63ccb2072261550e731e9bf607a35659dfc5ffd1.tar.gz |
DracClient to handle ReturnValue validation
The ReturnValue in the response xml document was checked separately each
time DracClient#invoke was called. This patch moves the ReturnValue
checking logic to the invoke functions, which helps keeping the code
DRY.
Change-Id: Ifa0433da6bd4260754217f56c2f7f200b1d710d7
Diffstat (limited to 'ironic/drivers/modules/drac/client.py')
-rw-r--r-- | ironic/drivers/modules/drac/client.py | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/ironic/drivers/modules/drac/client.py b/ironic/drivers/modules/drac/client.py index 166b2cfb2..168d65a48 100644 --- a/ironic/drivers/modules/drac/client.py +++ b/ironic/drivers/modules/drac/client.py @@ -20,6 +20,7 @@ from xml.etree import ElementTree from oslo.utils import importutils from ironic.common import exception +from ironic.drivers.modules.drac import common as drac_common pywsman = importutils.try_import('pywsman') @@ -30,6 +31,27 @@ _SOAP_ENVELOPE_URI = 'http://www.w3.org/2003/05/soap-envelope' _FILTER_DIALECT_MAP = {'cql': 'http://schemas.dmtf.org/wbem/cql/1/dsp0202.pdf', 'wql': 'http://schemas.microsoft.com/wbem/wsman/1/WQL'} +# ReturnValue constants +RET_SUCCESS = '0' +RET_ERROR = '2' +RET_CREATED = '4096' + + +def get_wsman_client(node): + """Return a DRAC client object. + + Given an ironic node object, this method gives back a + Client object which is a wrapper for pywsman.Client. + + :param node: an ironic node object. + :returns: a Client object. + :raises: InvalidParameterValue if some mandatory information + is missing on the node or on invalid inputs. + """ + driver_info = drac_common.parse_driver_info(node) + client = Client(**driver_info) + return client + class Client(object): @@ -90,14 +112,17 @@ class Client(object): return final_xml def wsman_invoke(self, resource_uri, method, selectors=None, - properties=None): + properties=None, expected_return_value=RET_SUCCESS): """Invokes a remote WS-Man method. :param resource_uri: URI of the resource. :param method: name of the method to invoke. :param selectors: dictionary of selectors. :param properties: dictionary of properties. + :param expected_return_value: expected return value. :raises: DracClientError on an error from pywsman library. + :raises: DracOperationFailed on error reported back by DRAC. + :raises: DracUnexpectedReturnValue on return value mismatch. :returns: an ElementTree object of the response received. """ if selectors is None: @@ -135,7 +160,21 @@ class Client(object): options.add_property(name, value) doc = self.client.invoke(options, resource_uri, method, xml_doc) - return self._get_root(doc) + root = self._get_root(doc) + + return_value = drac_common.find_xml(root, 'ReturnValue', + resource_uri).text + if return_value != expected_return_value: + if return_value == RET_ERROR: + message = drac_common.find_xml(root, 'Message', + resource_uri).text + raise exception.DracOperationFailed(message=message) + else: + raise exception.DracUnexpectedReturnValue( + expected_return_value=expected_return_value, + actual_return_value=return_value) + + return root def _get_root(self, doc): if doc is None or doc.root() is None: |