pytest-dev / pytest-testinfra

Testinfra test your infrastructures
https://testinfra.readthedocs.io
Apache License 2.0
2.37k stars 355 forks source link

Tests failed with encondig set #113

Closed freeseacher closed 7 years ago

freeseacher commented 8 years ago

Hi! default tests from molecule failed

def test_hosts_file(File):
    hosts = File('/etc/hosts')

    assert hosts.user == 'root'
    assert hosts.group == 'root'

on server with locale LANG=ru_RU.UTF-8 tests filed with

_______________________________________________________________ ERROR at setup of test_hosts_file[ansible://tower-01] _______________________________________________________________
[gw0] linux2 -- Python 2.7.11 /usr/bin/python
TestinfraBackend = <testinfra.backend.ansible.AnsibleBackend object at 0x7fb567387b90>

    @pytest.fixture()
    def f(TestinfraBackend):
>       return TestinfraBackend.get_module(cls.__name__)

/usr/local/lib/python2.7/dist-packages/testinfra/modules/base.py:75: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/local/lib/python2.7/dist-packages/testinfra/backend/base.py:225: in get_module
    module = getattr(testinfra.modules, name).get_module(self)
/usr/local/lib/python2.7/dist-packages/testinfra/modules/base.py:62: in get_module
    klass = cls.get_module_class(_backend)
/usr/local/lib/python2.7/dist-packages/testinfra/modules/file.py:178: in get_module_class
    if SystemInfo.type == "linux":
/usr/local/lib/python2.7/dist-packages/testinfra/modules/systeminfo.py:103: in type
    return self.sysinfo["type"]
/usr/local/lib/python2.7/dist-packages/testinfra/modules/systeminfo.py:31: in sysinfo
    self._sysinfo = self.get_system_info()
/usr/local/lib/python2.7/dist-packages/testinfra/modules/systeminfo.py:88: in get_system_info
    sysinfo.update(**self._get_linux_sysinfo())
/usr/local/lib/python2.7/dist-packages/testinfra/modules/systeminfo.py:38: in _get_linux_sysinfo
    lsb = self.run("lsb_release -a")
/usr/local/lib/python2.7/dist-packages/testinfra/modules/base.py:23: in run
    return self._backend.run(command, *args, **kwargs)
/usr/local/lib/python2.7/dist-packages/testinfra/backend/ansible.py:43: in run
    stderr_bytes = b"".join((chr(ord(c)) for c in out['stderr']))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

.0 = <iterator object at 0x7fb564e78f90>

>   stderr_bytes = b"".join((chr(ord(c)) for c in out['stderr']))
E   ValueError: chr() arg not in range(256)

i am using molecule 1.5.1 and ansible 2.1.0.0 and

% testinfra --version
This is pytest version 2.9.2, imported from /usr/local/lib/python2.7/dist-packages/pytest.pyc
setuptools registered plugins:
  testinfra-1.3.1 at /usr/local/lib/python2.7/dist-packages/testinfra/plugin.pyc
  pytest-xdist-1.14 at /usr/local/lib/python2.7/dist-packages/xdist/boxed.pyc
  pytest-xdist-1.14 at /usr/local/lib/python2.7/dist-packages/xdist/looponfail.pyc
  pytest-xdist-1.14 at /usr/local/lib/python2.7/dist-packages/xdist/plugin.pyc

that can be workarounded with explicit set export LANG=C

philpep commented 8 years ago

Hi, thanks for the report.

Can you send me the output of the command lsb_release -a ? I think maybe the decoding of "command not found" is causing the error.

freeseacher commented 8 years ago

yep. here the full output

Executing testinfra tests found in tests/.
============================= test session starts ==============================
platform linux2 -- Python 2.7.11+, pytest-2.9.2, py-1.4.31, pluggy-0.3.1
rootdir: /home/shirokih/vagrant/molecule/tower, inifile: 
plugins: testinfra-1.3.1, xdist-1.14
gw0 [4] / gw1 [4] / gw2 [4]
scheduling tests via LoadScheduling
EEEE
==================================== ERRORS ====================================
____________ ERROR at setup of test_hosts_file[ansible://tower-01] _____________
[gw1] linux2 -- Python 2.7.11 /usr/bin/python
TestinfraBackend = <testinfra.backend.ansible.AnsibleBackend object at 0x7fd3adc84cd0>

    @pytest.fixture()
    def f(TestinfraBackend):
>       return TestinfraBackend.get_module(cls.__name__)

/usr/local/lib/python2.7/dist-packages/testinfra/modules/base.py:75: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/local/lib/python2.7/dist-packages/testinfra/backend/base.py:225: in get_module
    module = getattr(testinfra.modules, name).get_module(self)
/usr/local/lib/python2.7/dist-packages/testinfra/modules/base.py:62: in get_module
    klass = cls.get_module_class(_backend)
/usr/local/lib/python2.7/dist-packages/testinfra/modules/file.py:178: in get_module_class
    if SystemInfo.type == "linux":
/usr/local/lib/python2.7/dist-packages/testinfra/modules/systeminfo.py:103: in type
    return self.sysinfo["type"]
/usr/local/lib/python2.7/dist-packages/testinfra/modules/systeminfo.py:31: in sysinfo
    self._sysinfo = self.get_system_info()
/usr/local/lib/python2.7/dist-packages/testinfra/modules/systeminfo.py:88: in get_system_info
    sysinfo.update(**self._get_linux_sysinfo())
/usr/local/lib/python2.7/dist-packages/testinfra/modules/systeminfo.py:38: in _get_linux_sysinfo
    lsb = self.run("lsb_release -a")
/usr/local/lib/python2.7/dist-packages/testinfra/modules/base.py:23: in run
    return self._backend.run(command, *args, **kwargs)
/usr/local/lib/python2.7/dist-packages/testinfra/backend/ansible.py:43: in run
    stderr_bytes = b"".join((chr(ord(c)) for c in out['stderr']))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

.0 = <iterator object at 0x7fd3a76141d0>

>   stderr_bytes = b"".join((chr(ord(c)) for c in out['stderr']))
E   ValueError: chr() arg not in range(256)

/usr/local/lib/python2.7/dist-packages/testinfra/backend/ansible.py:43: ValueError
___ ERROR at setup of test_noc_tower_running_and_enabled[ansible://tower-01] ___
[gw0] linux2 -- Python 2.7.11 /usr/bin/python
TestinfraBackend = <testinfra.backend.ansible.AnsibleBackend object at 0x7f6c81a71cd0>

    @pytest.fixture()
    def f(TestinfraBackend):
>       return TestinfraBackend.get_module(cls.__name__)

/usr/local/lib/python2.7/dist-packages/testinfra/modules/base.py:75: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/local/lib/python2.7/dist-packages/testinfra/backend/base.py:225: in get_module
    module = getattr(testinfra.modules, name).get_module(self)
/usr/local/lib/python2.7/dist-packages/testinfra/modules/base.py:62: in get_module
    klass = cls.get_module_class(_backend)
/usr/local/lib/python2.7/dist-packages/testinfra/modules/service.py:50: in get_module_class
    File = _backend.get_module("File")
/usr/local/lib/python2.7/dist-packages/testinfra/backend/base.py:225: in get_module
    module = getattr(testinfra.modules, name).get_module(self)
/usr/local/lib/python2.7/dist-packages/testinfra/modules/base.py:62: in get_module
    klass = cls.get_module_class(_backend)
/usr/local/lib/python2.7/dist-packages/testinfra/modules/file.py:178: in get_module_class
    if SystemInfo.type == "linux":
/usr/local/lib/python2.7/dist-packages/testinfra/modules/systeminfo.py:103: in type
    return self.sysinfo["type"]
/usr/local/lib/python2.7/dist-packages/testinfra/modules/systeminfo.py:31: in sysinfo
    self._sysinfo = self.get_system_info()
/usr/local/lib/python2.7/dist-packages/testinfra/modules/systeminfo.py:88: in get_system_info
    sysinfo.update(**self._get_linux_sysinfo())
/usr/local/lib/python2.7/dist-packages/testinfra/modules/systeminfo.py:38: in _get_linux_sysinfo
    lsb = self.run("lsb_release -a")
/usr/local/lib/python2.7/dist-packages/testinfra/modules/base.py:23: in run
    return self._backend.run(command, *args, **kwargs)
/usr/local/lib/python2.7/dist-packages/testinfra/backend/ansible.py:43: in run
    stderr_bytes = b"".join((chr(ord(c)) for c in out['stderr']))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

.0 = <iterator object at 0x7f6c82f3dbd0>

>   stderr_bytes = b"".join((chr(ord(c)) for c in out['stderr']))
E   ValueError: chr() arg not in range(256)

/usr/local/lib/python2.7/dist-packages/testinfra/backend/ansible.py:43: ValueError
_________ ERROR at setup of test_deploy_keys_setup[ansible://tower-01] _________
[gw2] linux2 -- Python 2.7.11 /usr/bin/python
TestinfraBackend = <testinfra.backend.ansible.AnsibleBackend object at 0x7fefc00a9cd0>

    @pytest.fixture()
    def f(TestinfraBackend):
>       return TestinfraBackend.get_module(cls.__name__)

/usr/local/lib/python2.7/dist-packages/testinfra/modules/base.py:75: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/local/lib/python2.7/dist-packages/testinfra/backend/base.py:225: in get_module
    module = getattr(testinfra.modules, name).get_module(self)
/usr/local/lib/python2.7/dist-packages/testinfra/modules/base.py:62: in get_module
    klass = cls.get_module_class(_backend)
/usr/local/lib/python2.7/dist-packages/testinfra/modules/file.py:178: in get_module_class
    if SystemInfo.type == "linux":
/usr/local/lib/python2.7/dist-packages/testinfra/modules/systeminfo.py:103: in type
    return self.sysinfo["type"]
/usr/local/lib/python2.7/dist-packages/testinfra/modules/systeminfo.py:31: in sysinfo
    self._sysinfo = self.get_system_info()
/usr/local/lib/python2.7/dist-packages/testinfra/modules/systeminfo.py:88: in get_system_info
    sysinfo.update(**self._get_linux_sysinfo())
/usr/local/lib/python2.7/dist-packages/testinfra/modules/systeminfo.py:38: in _get_linux_sysinfo
    lsb = self.run("lsb_release -a")
/usr/local/lib/python2.7/dist-packages/testinfra/modules/base.py:23: in run
    return self._backend.run(command, *args, **kwargs)
/usr/local/lib/python2.7/dist-packages/testinfra/backend/ansible.py:43: in run
    stderr_bytes = b"".join((chr(ord(c)) for c in out['stderr']))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

.0 = <iterator object at 0x7fefb98471d0>

>   stderr_bytes = b"".join((chr(ord(c)) for c in out['stderr']))
E   ValueError: chr() arg not in range(256)

/usr/local/lib/python2.7/dist-packages/testinfra/backend/ansible.py:43: ValueError
___________ ERROR at setup of test_db_file_setup[ansible://tower-01] ___________
[gw1] linux2 -- Python 2.7.11 /usr/bin/python
TestinfraBackend = <testinfra.backend.ansible.AnsibleBackend object at 0x7fd3adc84cd0>

    @pytest.fixture()
    def f(TestinfraBackend):
>       return TestinfraBackend.get_module(cls.__name__)

/usr/local/lib/python2.7/dist-packages/testinfra/modules/base.py:75: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/local/lib/python2.7/dist-packages/testinfra/backend/base.py:225: in get_module
    module = getattr(testinfra.modules, name).get_module(self)
/usr/local/lib/python2.7/dist-packages/testinfra/modules/base.py:62: in get_module
    klass = cls.get_module_class(_backend)
/usr/local/lib/python2.7/dist-packages/testinfra/modules/file.py:178: in get_module_class
    if SystemInfo.type == "linux":
/usr/local/lib/python2.7/dist-packages/testinfra/modules/systeminfo.py:103: in type
    return self.sysinfo["type"]
/usr/local/lib/python2.7/dist-packages/testinfra/modules/systeminfo.py:31: in sysinfo
    self._sysinfo = self.get_system_info()
/usr/local/lib/python2.7/dist-packages/testinfra/modules/systeminfo.py:88: in get_system_info
    sysinfo.update(**self._get_linux_sysinfo())
/usr/local/lib/python2.7/dist-packages/testinfra/modules/systeminfo.py:38: in _get_linux_sysinfo
    lsb = self.run("lsb_release -a")
/usr/local/lib/python2.7/dist-packages/testinfra/modules/base.py:23: in run
    return self._backend.run(command, *args, **kwargs)
/usr/local/lib/python2.7/dist-packages/testinfra/backend/ansible.py:43: in run
    stderr_bytes = b"".join((chr(ord(c)) for c in out['stderr']))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

.0 = <iterator object at 0x7fd3a75fef90>

>   stderr_bytes = b"".join((chr(ord(c)) for c in out['stderr']))
E   ValueError: chr() arg not in range(256)

/usr/local/lib/python2.7/dist-packages/testinfra/backend/ansible.py:43: ValueError
=========================== 4 error in 2.79 seconds ============================
ERROR: 

  RAN: '/usr/local/bin/testinfra tests/test_default.py tests/test_env.py -n 3 --connection=ansible --ansible-inventory=.molecule/ansible_inventory'

  STDOUT:

  STDERR:

[shirokih-hom] 15:25:27 /home/shirokih/vagrant/molecule/tower % lsb_release -a
No LSB modules are available.
Distributor ID: LinuxMint
Description:    Linux Mint 18 Sarah
Release:    18
Codename:   sarah
[shirokih-hom] 15:26:27 /home/shirokih/vagrant/molecule/tower % locale
LANG=ru_RU.UTF-8
LANGUAGE=
LC_CTYPE="ru_RU.UTF-8"
LC_NUMERIC=en_US.UTF-8
LC_TIME=ru_RU.UTF-8
LC_COLLATE="ru_RU.UTF-8"
LC_MONETARY=en_US.UTF-8
LC_MESSAGES="ru_RU.UTF-8"
LC_PAPER=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
LC_ALL=
[shirokih-hom] 15:26:41 /home/shirokih/vagrant/molecule/tower % molecule login
Warning: Permanently added '[127.0.0.1]:2222' (ECDSA) to the list of known hosts.
Last login: Wed Jun 29 08:25:23 2016 from 10.0.2.2
[vagrant@localhost ~]$ lsb_release -a
-bash: lsb_release: command not found
[vagrant@localhost ~]$ sudo -s
[root@localhost vagrant]# lsb_release -a
bash: lsb_release: command not found
[root@localhost vagrant]# exit
[vagrant@localhost ~]$ logout
Connection to 127.0.0.1 closed.
[shirokih-hom] 15:27:16 /home/shirokih/vagrant/molecule/tower % export LANG=en
[shirokih-hom] 15:28:38 /home/shirokih/vagrant/molecule/tower % molecule verify

Executing testinfra tests found in tests/.
============================= test session starts ==============================
platform linux2 -- Python 2.7.11+, pytest-2.9.2, py-1.4.31, pluggy-0.3.1
rootdir: /home/shirokih/vagrant/molecule/tower, inifile: 
plugins: testinfra-1.3.1, xdist-1.14
gw0 [4] / gw1 [4] / gw2 [4]
scheduling tests via LoadScheduling
....
=========================== 4 passed in 4.52 seconds ===========================

No serverspec tests found in spec/.
philpep commented 7 years ago

Related to #140