测试基础设施
testinfra的Python项目详细描述
最新文档:https://testinfra.readthedocs.io/en/latest
关于
使用testinfra,您可以用python编写单元测试来测试 由管理工具配置的服务器,如Salt、Ansible、Puppet, Chef等等。
testinfra的目标是成为python中的Serverspec等价物,并编写为 强大的Pytest测试引擎的插件
快速启动
使用pip安装testinfra:
$ pip install testinfra # or install the devel version $ pip install 'git+https://github.com/philpep/testinfra@master#egg=testinfra'
将第一个测试文件写入test myinfra.py
deftest_passwd_file(host):passwd=host.file("/etc/passwd")assertpasswd.contains("root")assertpasswd.user=="root"assertpasswd.group=="root"assertpasswd.mode==0o644deftest_nginx_is_installed(host):nginx=host.package("nginx")assertnginx.is_installedassertnginx.version.startswith("1.2")deftest_nginx_running_and_enabled(host):nginx=host.service("nginx")assertnginx.is_runningassertnginx.is_enabled
运行它:
$ py.test -v test_myinfra.py ====================== test session starts ====================== platform linux -- Python 2.7.3 -- py-1.4.26 -- pytest-2.6.4 plugins: testinfra collected 3 items test_myinfra.py::test_passwd_file[local] PASSED test_myinfra.py::test_nginx_is_installed[local] PASSED test_myinfra.py::test_nginx_running_and_enabled[local] PASSED =================== 3 passed in 0.66 seconds ====================