pytest-dev / pytest-testinfra

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

Support linux remote cmd execution from Windows #271

Closed igilbert closed 6 years ago

igilbert commented 6 years ago

I tried the ssh pure backend and paramiko backend, neither of them can be launched from the Windows PC. So does testinfra support this approach? I think the support would be very nice for someone using a Windows PC to develop scripts for linux servers . So I wish it happen.

Error details: The error message is as follows:

"py.test --ssh-config=ssh-config test_myinfra.py
============================= test session starts =============================
platform win32 -- Python 2.7.13, pytest-3.2.5, py-1.5.2, pluggy-0.4.0
rootdir: D:\Users\gilbert.guo\IdeaProjects\moana\spectest, inifile:
plugins: testinfra-1.9.0
collected 1 item                                                                

test_myinfra.py F

================================== FAILURES ===================================
___________________________ test_passwd_file[local] ___________________________

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

    def test_passwd_file(host):
>       passwd = host.file("/etc/passwd")

test_myinfra.py:2:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
d:\python27\lib\site-packages\testinfra\host.py:91: in __getattr__
    obj = module_class.get_module(self)
d:\python27\lib\site-packages\testinfra\modules\base.py:33: in get_module
    klass = cls.get_module_class(_host)
d:\python27\lib\site-packages\testinfra\modules\file.py:176: in get_module_class
    if host.system_info.type == "linux":
d:\python27\lib\site-packages\testinfra\modules\systeminfo.py:114: in type
    return self.sysinfo["type"]
d:\python27\lib\site-packages\testinfra\utils\__init__.py:42: in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <testinfra.modules.base.SystemInfo object at 0x0000000004411080>

    @cached_property
    def sysinfo(self):
        sysinfo = {
            "type": None,
            "distribution": None,
            "codename": None,
            "release": None,
        }
>       sysinfo["type"] = self.check_output("uname -s").lower()
E       AssertionError: Unexpected exit code 1 for CommandResult(command='uname -s', exit_status=1, stdout=None, stderr="'uname' \xb2\xbb\xca\
xc7\xc4\xda\xb2\xbf\xbb\xf2\xcd\xe2\xb2\xbf\xc3\xfc\xc1\xee\xa3\xac\xd2\xb2\xb2\xbb\xca\xc7\xbf\xc9\xd4\xcb\xd0\xd0\xb5\xc4\xb3\xcc\xd0\xf2\r\
n\xbb\xf2\xc5\xfa\xb4\xa6\xc0\xed\xce\xc4\xbc\xfe\xa1\xa3\r\n")
E       assert 1 == 0
E        +  where 1 = CommandResult(command='uname -s', exit_status=1, stdout=None, stderr="'uname' ...3\xcc\xd0\xf2\r\n\xbb\xf2\xc5\xfa\xb4\x
a6\xc0\xed\xce\xc4\xbc\xfe\xa1\xa3\r\n").rc

d:\python27\lib\site-packages\testinfra\modules\systeminfo.py:33: AssertionError
========================== 1 failed in 0.31 seconds =  "
igilbert commented 6 years ago

Succeeded in executing remote command from PC with paramiko. Need to config the host fixfure in the code and then do the test.