Github: https://github.com/philpep/testinfra
インフラストラクチャをテストする
最新のドキュメント: https : //testinfra.readthedocs.io/en/latest
約
TestinfraではPythonで単体テストを書いて、 Salt 、 Ansible 、 Puppet 、 Chefなどの管理ツールで設定されたサーバの実際の状態をテストできます。
TestinfraはPythonでServerspecに相当することを目指しており、強力なPytestテストエンジンへのプラグインとして書かれています
クイックスタート
pipinを使用してtestinfraをインストールします。
$ pip install testinfra # or install the devel version $ pip install 'git+https://github.com/philpep/testinfra@master#egg=testinfra'
最初のテストファイルをtest_myinfra.pyに書き込みます:
def test_passwd_file(host):
passwd = host.file("/etc/passwd")
assert passwd.contains("root")
assert passwd.user == "root"
assert passwd.group == "root"
assert passwd.mode == 0o644
def test_nginx_is_installed(host):
nginx = host.package("nginx")
assert nginx.is_installed
assert nginx.version.startswith("1.2")
def test_nginx_running_and_enabled(host):
nginx = host.service("nginx")
assert nginx.is_running
assert nginx.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 ====================