Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Malformed Faults fail in non-informative ways #72

Closed
hartsock opened this issue Jul 2, 2014 · 3 comments · Fixed by #105
Closed

Malformed Faults fail in non-informative ways #72

hartsock opened this issue Jul 2, 2014 · 3 comments · Fixed by #105

Comments

@hartsock
Copy link
Member

hartsock commented Jul 2, 2014

Malformed Faults fail in non-informative ways. Example: LicenseUsageFaults will emit the following SOAP envelope. This envelope will not properly map onto the ServerFaultCode data type inside pyVmomi. The result is that the message will not map onto the appropriate fault type.

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope 
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <soapenv:Fault>
      <faultcode>ServerFaultCode</faultcode>
      <faultstring/>
      <detail>
        <LicenseUsageFaultFault xsi:type="LicenseUsageFault">
           <reason>dataTampered</reason></LicenseUsageFaultFault>
      </detail>
    </soapenv:Fault>
   </soapenv:Body>
</soapenv:Envelope>
@hartsock hartsock added this to the pyVmomi 5.5.0-2014.1 milestone Jul 2, 2014
@hartsock hartsock self-assigned this Jul 2, 2014
@hartsock hartsock removed the blocker label Jul 3, 2014
@hartsock hartsock removed the blocker label Jul 17, 2014
@hartsock
Copy link
Member Author

At present, I have not been able to determine if the library can successfully deserialize and then marshal a fault object. The XML parsers seem capable of handling the payload from initial testing.

@hartsock
Copy link
Member Author

After two days in the debugger I've figured out that the SoapAdapter.py matches the detail tag's first child tag name against the WSDL and then maps that to a data type. In this case the data type vmodl.fault.LicenseUsageFaultFault would make sense (FaultFault? really guys?) but the type is not present in the WSDL. That causes a key error when attempting to perform dynamic type look up. Trace is below...

Traceback (most recent call last):
  File "/Applications/PyCharm.app/helpers/pydev/pydevd.py", line 1539, in
<module>
    debugger.run(setup['file'], None, None)
  File "/Applications/PyCharm.app/helpers/pydev/pydevd.py", line 1150, in run
    pydev_imports.execfile(file, globals, locals) #execute the script
  File "/Users/hartsocks/PycharmProjects/pyvmomi/sample/poweronvm.py", line
153, in <module>
    main()
  File "/Users/hartsocks/PycharmProjects/pyvmomi/sample/poweronvm.py", line
144, in main
    vm.TerminateVM()
  File "/Users/hartsocks/PycharmProjects/pyvmomi/pyVmomi/VmomiSupport.py", line
553, in <lambda>
    self.f(*(self.args + (obj,) + args), **kwargs)
  File "/Users/hartsocks/PycharmProjects/pyvmomi/pyVmomi/VmomiSupport.py", line
362, in _InvokeMethod
    return self._stub.InvokeMethod(self, info, args)
  File "/Users/hartsocks/PycharmProjects/pyvmomi/pyVmomi/SoapAdapter.py", line
1226, in InvokeMethod
    obj = SoapResponseDeserializer(outerStub).Deserialize(fd, info.result)
  File "/Users/hartsocks/PycharmProjects/pyvmomi/pyVmomi/SoapAdapter.py", line
747, in Deserialize
    self.parser.ParseFile(response)
  File "/Users/hartsocks/PycharmProjects/pyvmomi/pyVmomi/SoapAdapter.py", line
569, in StartElementHandler
    objType = self.LookupWsdlType(ns, name[:-5])
  File "/Users/hartsocks/PycharmProjects/pyvmomi/pyVmomi/SoapAdapter.py", line
559, in LookupWsdlType
    return GuessWsdlType(name)
  File "/Users/hartsocks/PycharmProjects/pyvmomi/pyVmomi/VmomiSupport.py", line
1017, in GuessWsdlType
    raise KeyError(name)
KeyError: u'LicenseUsageFault'

To be able to support arbitrary Fault tags we need to put in a trap for Faults that will allow the type resolution logic to escape to a known-good data type if you can't match the data type based on the detail tag's first child.

@hartsock hartsock changed the title LicenseUsageFault is incorrectly de-serialized through pyVmomi Undocumented Faults incorrectly de-serialized through pyVmomi example: LicenseUsageFault Jul 17, 2014
hartsock added a commit to hartsock/pyvmomi that referenced this issue Jul 17, 2014
example: LicenseUsageFault
  <soapenv:Body>
    <soapenv:Fault>
      <faultcode>ServerFaultCode</faultcode>
      <faultstring/>
      <detail>
        <LicenseUsageFaultFault xsi:type="LicenseUsageFault">
           <reason>dataTampered</reason></LicenseUsageFaultFault>
      </detail>
    </soapenv:Fault>

The detail tag's first child represents the data type to unmarshal the Fault message envelope's contents into. If that child tag does not have a matching WSDL definition pyVmomi fails to raise the fault.

This change lets the library dynamically create the new fault data type at runtime.

closes vmware#72
@hartsock hartsock changed the title Undocumented Faults incorrectly de-serialized through pyVmomi example: LicenseUsageFault Malformed Faults fail in non-informative ways Jul 28, 2014
@hartsock hartsock removed their assignment Jul 28, 2014
hartsock added a commit to hartsock/pyvmomi that referenced this issue Jul 29, 2014
This initial patch introduces a test to demonstrate current fault
handling in the VmomiSupport and SoapAdapter components.

partial: vmware#72
hartsock added a commit to hartsock/pyvmomi that referenced this issue Jul 29, 2014
* Malformed Faults: introduces test for fault handler
* fixes KeyError raises statements to use 'format' instead

partial: vmware#72
partial: vmware#55
hartsock added a commit to hartsock/pyvmomi that referenced this issue Jul 30, 2014
* Malformed Faults: introduces test for fault handler
* fixes KeyError raises statements to use 'format' instead

partial: vmware#72
partial: vmware#55
hartsock added a commit to hartsock/pyvmomi that referenced this issue Jul 30, 2014
* Malformed Faults: introduces test for fault handler
* introduces ParserError which includes the malformed XML
* testing demonstrates ParserError includes malformed XML

closes: vmware#72
@hartsock
Copy link
Member Author

The proposed resolution to this problem is to include the malformed XML document inside the Exception. This has the benefit of allowing a developer to see exactly what killed their client and to include this information in incident reports. We can then build fixtures to simulate the failure and resolve this class of problem much more quickly.

This does impact performance and stack trace message size.

@hartsock hartsock self-assigned this Jul 31, 2014
hartsock added a commit to hartsock/pyvmomi that referenced this issue Aug 12, 2014
* Malformed Faults: introduces test for fault handler
* introduces ParserError which includes the malformed XML
* testing demonstrates ParserError includes malformed XML

closes: vmware#72
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment