2017-07-25 106 views
0

使用testinfra(Pytest插件)進行測試。我想用私鑰來測試Jenkins的遠程主機。用私鑰testinfra ssh執行

[[email protected] tests]# testinfra --ssh-config=/path/to/private/key --sudo [email protected] test.py

其中

cat /path/to/private/key 
-----BEGIN RSA PRIVATE KEY----- 
(...) 
-----END RSA PRIVATE KEY----- 

cat test.py 
def test_redis_is_installed(host): 
    redis = host.package("redis") 
    assert redis.is_installed 

我得到的是

E    Exception: Unparsable line -----BEGIN RSA PRIVATE KEY----- 

/usr/lib/python2.7/site-packages/paramiko/config.py:68: Exception 
================================================================================= warnings summary ================================================================================== 
None 
    Module already imported so can not be re-written: testinfra 

-- Docs: http://doc.pytest.org/en/latest/warnings.html 
======================================================================= 1 failed, 1 warnings in 0.23 seconds ======================================================================== 

好像的paramiko不喜歡這種格式,但試了其它b- ackends,它不工作。我怎樣才能通過私鑰?

回答

0

--ssh-config必須是ssh的路徑config。您在該配置中爲主機配置密鑰對。

喜歡的東西在〜/ .ssh /配置:

Host remotehost 
    User user 
    IdentityFile remotehost-key