pytest-testinfra
pytest-testinfra copied to clipboard
Unreachable host - better error message?
testinfra 1.14.1
ansible 2.6.3 (really any version)
It seems that if a host is unreachable with the ansible backend, you might get a traceback like:
=================================== FAILURES===================================
test_apt_transport_https_is_installed[ansible://molecule-test-bionic]
host = <testinfra.host.Host object at 0x7efccc5f8390>
def test_apt_transport_https_is_installed(host):
> assert host.package("apt-transport-https").is_installed
tests/roles/common/test_default.py:3:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../venv/local/lib/python2.7/site-packages/testinfra/host.py:91: in __getattr__
obj = module_class.get_module(self)
../../venv/local/lib/python2.7/site-packages/testinfra/modules/base.py:33: in get_module
klass = cls.get_module_class(_host)
../../venv/local/lib/python2.7/site-packages/testinfra/modules/package.py:68: in get_module_class
if host.system_info.type == "freebsd":
../../venv/local/lib/python2.7/site-packages/testinfra/modules/systeminfo.py:124: in type
return self.sysinfo["type"]
../../venv/local/lib/python2.7/site-packages/testinfra/utils/__init__.py:42: in __get__
value = obj.__dict__[self.func.__name__] = self.func(obj)
../../venv/local/lib/python2.7/site-packages/testinfra/modules/systeminfo.py:33: in sysinfo
sysinfo["type"] = self.check_output("uname -s").lower()
../../venv/local/lib/python2.7/site-packages/testinfra/host.py:55: in run
return self.backend.run(command, *args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <testinfra.backend.ansible.AnsibleBackend object at 0x7efccc5f8110>
command = 'uname -s', args = (), kwargs = {}, out = {}
def run(self, command, *args, **kwargs):
command = self.get_command(command, *args)
out = self.run_ansible("shell", module_args=command)
return self.result(
> out['rc'],
command,
stdout_bytes=None,
stderr_bytes=None,
stdout=out["stdout"], stderr=out["stderr"],
)
E KeyError: u'rc'
../../venv/local/lib/python2.7/site-packages/testinfra/backend/ansible.py:44: KeyError
----------------------------- Captured stderr call -----------------------------
[WARNING]: Failure using method (v2_runner_on_unreachable) in callback plugin
(<testinfra.utils.ansible_runner.Callback object at 0x7efccb1c7350>): Host
molecule-test-bionic is unreachable: {'changed': False, 'msg':
u'container not found: molecule-test-bionic', 'unreachable': True}
The traceback itself is not very helpful (KeyError?), and only the captured stderr points to the problem. This may not be captured if you run with -s. Maybe it could check earlier for whether the host is reachable and fail there with an appropriate message?
Yes, I think we could catch the {'unreachable': True} in the ansible result and display appropriate message.