将vcrpy与Pyvmomi一起使用来模拟肥皂响应时,如何解决此错误?

时间:2019-03-28 15:39:05

标签: python pyvmomi

我正在使用vcrpy模拟pyvmomi响应,因此在测试过程中我不会进行真正的呼叫。

奇怪的PyVmomi捕获到错误:

pyVmomi.VmomiSupport.vim.fault.HostConnectFault: (vim.fault.HostConnectFault) {
   dynamicType = <unset>,
   dynamicProperty = (vmodl.DynamicProperty) [],
   msg = "'_HTTPSConnection' object has no attribute '_baseclass'",
   faultCause = <unset>,
   faultMessage = (vmodl.LocalizableMessage) []
}

当我回到调用堆栈中时:

# Note: Only works if the ssl params are passing in as kwargs
class _HTTPSConnection(http_client.HTTPSConnection):
   def __init__(self, *args, **kwargs):
      # Extract ssl.wrap_socket param unknown to httplib.HTTPSConnection,
      # and push back the params in connect()
      self._sslArgs = {}
      tmpKwargs = kwargs.copy()
      for key in ["server_side", "cert_reqs", "ssl_version", "ca_certs",
                  "do_handshake_on_connect", "suppress_ragged_eofs",
                  "ciphers"]:
         if key in tmpKwargs:
            self._sslArgs[key] = tmpKwargs.pop(key)
      http_client.HTTPSConnection.__init__(self, *args, **tmpKwargs)

此呼叫http_client.HTTPSConnection.__init__(self, *args, **tmpKwargs)正在呼叫:vcr/stubs/__init__.py

然后,当它引用self._baseclass时,它没有该属性...

def __init__(self, *args, **kwargs):
    if six.PY3:
        kwargs.pop('strict', None)  # apparently this is gone in py3

    # need to temporarily reset here because the real connection
    # inherits from the thing that we are mocking out.  Take out
    # the reset if you want to see what I mean :)
    from vcr.patch import force_reset
    with force_reset():
        self.real_connection = self._baseclass(*args, **kwargs)

    self._sock = None

我知道这是一个非常棘手的问题,但是如果您对我如何进行进一步调试有任何想法,请告诉我。

我所看到的是它在调用栈中变得更早了,连接和我认为vcrpy可能在第一次调用中就已经建立了连接,而SoapAdapter在第二次调用中就成为了连接。

>
   ## Get a HTTP connection from the pool
   def GetConnection(self):
      self.lock.acquire()
      self._CloseIdleConnections()
      if self.pool:
         result, _ = self.pool.pop(0)
         self.lock.release()
      else:
         self.lock.release()
         result = self.scheme(self.host, **self.schemeArgs)

0 个答案:

没有答案