Add support for lists in wsman properties

Change-Id: I697538153cbac1e0ddf40a85b0149bfea46bbf6a
changes/44/232044/3 0.0.1
Imre Farkas 7 years ago
parent 0004c088fc
commit 79cace86b6
  1. 38
      dracclient/tests/test_wsman.py
  2. 16
      dracclient/wsman.py

@ -276,3 +276,41 @@ class PayloadTestCase(base.BaseTest):
self.assertEqual(lxml.etree.tostring(expected_payload_obj),
lxml.etree.tostring(payload_obj))
@mock.patch.object(uuid, 'uuid4', autospec=True)
def test_build_invoke_with_list_in_properties(self, mock_uuid):
expected_payload = """<?xml version="1.0" ?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsman="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd">
<s:Header>
<wsa:To s:mustUnderstand="true">http://host:443/wsman</wsa:To>
<wsman:ResourceURI s:mustUnderstand="true">http://resource_uri</wsman:ResourceURI>
<wsa:MessageID s:mustUnderstand="true">uuid:1234-12</wsa:MessageID>
<wsa:ReplyTo>
<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>
</wsa:ReplyTo>
<wsa:Action s:mustUnderstand="true">http://resource_uri/method</wsa:Action>
<wsman:SelectorSet>
<wsman:Selector Name="selector">foo</wsman:Selector>
</wsman:SelectorSet>
</s:Header>
<s:Body>
<ns0:method_INPUT xmlns:ns0="http://resource_uri">
<ns0:property>foo</ns0:property>
<ns0:property>bar</ns0:property>
<ns0:property>baz</ns0:property>
</ns0:method_INPUT>
</s:Body>
</s:Envelope>
""" # noqa
expected_payload_obj = lxml.objectify.fromstring(expected_payload)
mock_uuid.return_value = '1234-12'
payload = dracclient.wsman._InvokePayload(
'http://host:443/wsman', 'http://resource_uri', 'method',
{'selector': 'foo'}, {'property': ['foo', 'bar', 'baz']}).build()
payload_obj = lxml.objectify.fromstring(payload)
self.assertEqual(lxml.etree.tostring(expected_payload_obj),
lxml.etree.tostring(payload_obj))

@ -366,9 +366,13 @@ class _InvokePayload(_Payload):
'method': self.method}))
for (name, value) in self.properties.items():
property_elem = ElementTree.SubElement(
method_elem,
('{%(resource_uri)s}%(name)s' %
{'resource_uri': self.resource_uri,
'name': name}))
property_elem.text = value
if not isinstance(value, list):
value = [value]
for item in value:
property_elem = ElementTree.SubElement(
method_elem,
('{%(resource_uri)s}%(name)s' %
{'resource_uri': self.resource_uri,
'name': name}))
property_elem.text = item

Loading…
Cancel
Save