diff options
author | Radoslav Gerganov <rgerganov@vmware.com> | 2017-06-21 11:28:17 +0300 |
---|---|---|
committer | Radoslav Gerganov <rgerganov@vmware.com> | 2017-06-21 11:33:03 +0300 |
commit | 49c5999903d48ec21de77bef9f9f630ee2087515 (patch) | |
tree | 14b233f34a5c185e376b8dbe16753ed0cd919d55 | |
parent | e9578e13d07abffa7dd9c61d670005f35994d698 (diff) | |
download | oslo-vmware-49c5999903d48ec21de77bef9f9f630ee2087515.tar.gz |
Do not prune some special XML elements which are empty2.21.0
There are some special elements like VirtualMachineEmptyProfileSpec
which are allowed to be empty and should not be pruned.
Change-Id: Icf09849083c5a83cf69ec3cb6216697870527096
-rw-r--r-- | oslo_vmware/service.py | 14 | ||||
-rw-r--r-- | oslo_vmware/tests/test_service.py | 3 |
2 files changed, 15 insertions, 2 deletions
diff --git a/oslo_vmware/service.py b/oslo_vmware/service.py index 8a75bda..0f262ab 100644 --- a/oslo_vmware/service.py +++ b/oslo_vmware/service.py @@ -50,6 +50,9 @@ LOG = logging.getLogger(__name__) class ServiceMessagePlugin(plugin.MessagePlugin): """Suds plug-in handling some special cases while calling VI SDK.""" + # list of XML elements which are allowed to be empty + EMPTY_ELEMENTS = ["VirtualMachineEmptyProfileSpec"] + def add_attribute_for_value(self, node): """Helper to handle AnyType. @@ -68,6 +71,15 @@ class ServiceMessagePlugin(plugin.MessagePlugin): except (ValueError, TypeError): node.set('xsi:type', 'xsd:string') + def prune(self, el): + pruned = [] + for c in el.children: + self.prune(c) + if c.isempty(False) and c.name not in self.EMPTY_ELEMENTS: + pruned.append(c) + for p in pruned: + el.children.remove(p) + def marshalled(self, context): """Modifies the envelope document before it is sent. @@ -80,7 +92,7 @@ class ServiceMessagePlugin(plugin.MessagePlugin): # VI SDK throws server errors if optional SOAP nodes are sent # without values; e.g., <test/> as opposed to <test>test</test>. - context.envelope.prune() + self.prune(context.envelope) context.envelope.walk(self.add_attribute_for_value) diff --git a/oslo_vmware/tests/test_service.py b/oslo_vmware/tests/test_service.py index dc28cd2..336ef0d 100644 --- a/oslo_vmware/tests/test_service.py +++ b/oslo_vmware/tests/test_service.py @@ -47,8 +47,9 @@ class ServiceMessagePluginTest(base.TestCase): def test_marshalled(self): context = mock.Mock() + self.plugin.prune = mock.Mock() self.plugin.marshalled(context) - context.envelope.prune.assert_called_once_with() + self.plugin.prune.assert_called_once_with(context.envelope) context.envelope.walk.assert_called_once_with( self.plugin.add_attribute_for_value) |