pytest-testinfra icon indicating copy to clipboard operation
pytest-testinfra copied to clipboard

With paramiko I get ImportError: Unable to import a GSS-API / SSPI module!

Open arthurlutz opened this issue 4 years ago • 0 comments

While trying to use the kitchen example https://testinfra.readthedocs.io/en/latest/examples.html#integration-with-kitchenci

I get a weird gss-api traceback

kitchen verify
-----> Starting Kitchen (v2.3.3)
-----> Verifying <default-debian-buster64>...
       [Shell] Verify on instance default-debian-buster64 with state={:hostname=>"127.0.0.1", :port=>"2222", :username=>"vagrant", :ssh_key=>"/home/arthur/local/install_script/.kitchen/kitchen-vagrant/default-debian-buster64/.vagrant/machines/default/virtualbox/private_key", :last_action=>"setup", :last_error=>"Kitchen::ActionFailed"}
============================= test session starts ==============================
platform linux -- Python 3.6.8, pytest-5.3.0, py-1.8.0, pluggy-0.13.1
rootdir: /home/arthur/local/install_script
plugins: testinfra-3.2.1
collected 1 item

tests/test_nginx.py F                                                    [100%]

=================================== FAILURES ===================================
_____________ test_nginx_running_and_enabled[paramiko://127.0.0.1] _____________

host = <testinfra.host.Host object at 0x7fa0e10eea20>

    def test_nginx_running_and_enabled(host):
>       nginx = host.service("nginx")

tests/test_nginx.py:3: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../.virtualenvs/testinfra/lib/python3.6/site-packages/testinfra/host.py:111: in __getattr__
    obj = module_class.get_module(self)
../../.virtualenvs/testinfra/lib/python3.6/site-packages/testinfra/modules/base.py:22: in get_module
    klass = cls.get_module_class(_host)
../../.virtualenvs/testinfra/lib/python3.6/site-packages/testinfra/modules/service.py:51: in get_module_class
    if host.system_info.type == "linux":
../../.virtualenvs/testinfra/lib/python3.6/site-packages/testinfra/modules/systeminfo.py:143: in type
    return self.sysinfo["type"]
../../.virtualenvs/testinfra/lib/python3.6/site-packages/testinfra/utils/__init__.py:44: in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
../../.virtualenvs/testinfra/lib/python3.6/site-packages/testinfra/modules/systeminfo.py:33: in sysinfo
    uname = self.run_expect([0, 1], 'uname -s')
../../.virtualenvs/testinfra/lib/python3.6/site-packages/testinfra/host.py:75: in run
    return self.backend.run(command, *args, **kwargs)
../../.virtualenvs/testinfra/lib/python3.6/site-packages/testinfra/backend/paramiko.py:119: in run
    rc, stdout, stderr = self._exec_command(command)
../../.virtualenvs/testinfra/lib/python3.6/site-packages/testinfra/backend/paramiko.py:106: in _exec_command
    chan = self.client.get_transport().open_session()
../../.virtualenvs/testinfra/lib/python3.6/site-packages/testinfra/utils/__init__.py:44: in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
../../.virtualenvs/testinfra/lib/python3.6/site-packages/testinfra/backend/paramiko.py:102: in client
    client.connect(**cfg)
../../.virtualenvs/testinfra/lib/python3.6/site-packages/paramiko/client.py:374: in connect
    disabled_algorithms=disabled_algorithms,
../../.virtualenvs/testinfra/lib/python3.6/site-packages/paramiko/transport.py:445: in __init__
    self.kexgss_ctxt = GSSAuth("gssapi-keyex", gss_deleg_creds)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

auth_method = 'gssapi-keyex', gss_deleg_creds = True

    def GSSAuth(auth_method, gss_deleg_creds=True):
        """
        Provide SSH2 GSS-API / SSPI authentication.
    
        :param str auth_method: The name of the SSH authentication mechanism
                                (gssapi-with-mic or gss-keyex)
        :param bool gss_deleg_creds: Delegate client credentials or not.
                                     We delegate credentials by default.
        :return: Either an `._SSH_GSSAPI_OLD` or `._SSH_GSSAPI_NEW` (Unix)
                 object or an `_SSH_SSPI` (Windows) object
        :rtype: object
    
        :raises: ``ImportError`` -- If no GSS-API / SSPI module could be imported.
    
        :see: `RFC 4462 <http://www.ietf.org/rfc/rfc4462.txt>`_
        :note: Check for the available API and return either an `._SSH_GSSAPI_OLD`
               (MIT GSSAPI using python-gssapi package) object, an
               `._SSH_GSSAPI_NEW` (MIT GSSAPI using gssapi package) object
               or an `._SSH_SSPI` (MS SSPI) object.
               If there is no supported API available,
               ``None`` will be returned.
        """
        if _API == "MIT":
            return _SSH_GSSAPI_OLD(auth_method, gss_deleg_creds)
        elif _API == "PYTHON-GSSAPI-NEW":
            return _SSH_GSSAPI_NEW(auth_method, gss_deleg_creds)
        elif _API == "SSPI" and os.name == "nt":
            return _SSH_SSPI(auth_method, gss_deleg_creds)
        else:
>           raise ImportError("Unable to import a GSS-API / SSPI module!")
E           ImportError: Unable to import a GSS-API / SSPI module!

../../.virtualenvs/testinfra/lib/python3.6/site-packages/paramiko/ssh_gss.py:107: ImportError
=============================== warnings summary ===============================
/home/arthur/.virtualenvs/testinfra/lib/python3.6/site-packages/_pytest/junitxml.py:436
  /home/arthur/.virtualenvs/testinfra/lib/python3.6/site-packages/_pytest/junitxml.py:436: PytestDeprecationWarning: The 'junit_family' default value will change to 'xunit2' in pytest 6.0.
  Add 'junit_family=legacy' to your pytest.ini file to silence this warning and make your suite compatible.
    _issue_warning_captured(deprecated.JUNIT_XML_DEFAULT_FAMILY, config.hook, 2)

-- Docs: https://docs.pytest.org/en/latest/warnings.html
- generated xml file: /home/arthur/local/install_script/junit-default-debian-buster64.xml -
========================= 1 failed, 1 warning in 0.16s =========================
sys:1: ResourceWarning: unclosed <socket.socket fd=11, family=AddressFamily.AF_INET, type=2049, proto=0, laddr=('127.0.0.1', 58588), raddr=('127.0.0.1', 2222)>
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>>     Verify failed on instance <default-debian-buster64>.  Please see .kitchen/logs/default-debian-buster64.log for more details
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration

Am wondering if the problem lies in the following code https://github.com/philpep/testinfra/blob/master/testinfra/backend/paramiko.py#L65-L68 ... abrupty commenting it out get it to work...

arthurlutz avatar Nov 24 '19 21:11 arthurlutz