コンテンツにスキップ

Testinfra

https://testinfra.readthedocs.io/en/latest/

軽く動かしてみたけど、python版のServerSpecで外形監視向きじゃなかった。終わり。

Install

pip install testinfra

Example: $ cat tests/apache2.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_apache2_is_installed(host):
    apache2 = host.package("apache2")
    assert apache2.is_installed
    assert apache2.version.startswith("2.4.18")


def test_apache2_running_and_enabled(host):
    apache2 = host.service("apache2")
    assert apache2.is_running
    assert apache2.is_enabled

Run

$ py.test -v --hosts='ssh://192.168.122.43' tests/apache2.py
============================================ test session starts ============================================
platform linux -- Python 3.5.2, pytest-3.6.1, py-1.5.3, pluggy-0.6.0 -- /home/yuki/dev/ansible/bin/python3
cachedir: .pytest_cache
rootdir: /home/yuki/dev/ainoniwa-playbooks, inifile:
plugins: testinfra-1.14.0
collected 3 items                                                                                           

tests/apache2.py::test_passwd_file[ssh://192.168.122.43] PASSED                                       [ 33%]
tests/apache2.py::test_apache2_is_installed[ssh://192.168.122.43] PASSED                              [ 66%]
tests/apache2.py::test_apache2_running_and_enabled[ssh://192.168.122.43] PASSED                       [100%]

========================================= 3 passed in 2.57 seconds ==========================================

最終更新日: 2021-06-06 09:29:57