From a5f60ce8f10280278e4088d2a86557ddf8e7ad40 Mon Sep 17 00:00:00 2001 From: Emerson Rocha Luiz Date: Thu, 26 Dec 2019 23:44:02 -0300 Subject: [PATCH] testinfra (#44): improved tests and draft of documentation --- molecule/default/tests/test_default.py | 54 +++++++++++++------------- tests/README.md | 18 +++++++++ tests/test_alb-standard-node.py | 46 ++++++++++++---------- 3 files changed, 69 insertions(+), 49 deletions(-) diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py index 007eed2..7045e9b 100644 --- a/molecule/default/tests/test_default.py +++ b/molecule/default/tests/test_default.py @@ -12,42 +12,40 @@ def test_hosts_file(host): assert f.exists assert f.user == 'root' - assert f.group == 'root' + assert f.group == 'root' or f.group == 'wheel' -def test_haproxy_is_installed_and_running(host): - haproxy = host.package("haproxy") +def test_haproxy_is_installed(host): + assert host.package("haproxy").is_installed - assert haproxy.is_installed - # assert haproxy.is_running - # Error: E AttributeError: 'DebianPackage' object has no attribute - # 'is_running' +def test_haproxy_is_enabled(host): + assert host.service("haproxy").is_enabled -def test_openresty_is_installed_and_running(host): - openresty = host.package("openresty") - assert openresty.is_installed - # assert openresty.is_running - # Error: E AttributeError: 'DebianPackage' object has no attribute - # 'is_running' +def test_haproxy_is_running(host): + assert host.service("haproxy").is_running -# From https://testinfra.readthedocs.io/en/latest/#quick-start -# 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_openresty_is_installed(host): + assert host.package("openresty").is_installed + + +def test_openresty_is_enabled(host): + assert host.service("openresty").is_enabled + + +def test_openresty_is_running(host): + assert host.service("openresty").is_running + + +#def test_ufw_is_installed(host): +# assert host.package("ufw").is_installed # # -# def test_nginx_is_installed(host): -# nginx = host.package("nginx") -# assert nginx.is_installed -# assert nginx.version.startswith("1.2") +#def test_ufw_is_enabled(host): +# assert host.service("ufw").is_enabled # # -# def test_nginx_running_and_enabled(host): -# nginx = host.service("nginx") -# assert nginx.is_running -# assert nginx.is_enabled +#def test_ufw_is_running(host): +# assert host.service("ufw").is_running diff --git a/tests/README.md b/tests/README.md index 04a7582..be4bbbe 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1 +1,19 @@ # AP-ALB tests + +The files on directory `ap-application-load-balancer/tests` by default will be +be sincronized and be avalible on each host ALB node `/opt/alb/bin/tests/`. + +Note, the tests will NOT be installed if a node is not installed as `alb-standard` +e.g. is installed as `alb-minimal` since `alb-minimal` do not create `/opt/alb/` +folder structure. + +```bash +py.test ad-hoc-alb-tests/test_alb-standard-node.py --hosts='ansible://all' +py.test tests/test_alb-standard-node.py --ssh-identity-file="~/.ssh/id_rsa-rocha" --hosts="root@aguia-pescadora-foxtrot.etica.ai" +``` + + +## How to run + +### Extra backends +- diff --git a/tests/test_alb-standard-node.py b/tests/test_alb-standard-node.py index c919492..7e1a229 100644 --- a/tests/test_alb-standard-node.py +++ b/tests/test_alb-standard-node.py @@ -1,32 +1,36 @@ # FILE: /opt/alb/bin/tests/test_alb-standard-node.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_haproxy_is_installed(host): + assert host.package("haproxy").is_installed + + +def test_haproxy_is_enabled(host): + assert host.service("haproxy").is_enabled + + +def test_haproxy_is_running(host): + assert host.service("haproxy").is_running def test_openresty_is_installed(host): - nginx = host.package("openresty") - assert nginx.is_installed - # assert nginx.version.startswith("1.2") + assert host.package("openresty").is_installed -def test_openresty_running_and_enabled(host): - nginx = host.service("openresty") - assert nginx.is_running - assert nginx.is_enabled +def test_openresty_is_enabled(host): + assert host.service("openresty").is_enabled -def test_haproxy_is_installed(host): - nginx = host.package("haproxy") - assert nginx.is_installed - # assert nginx.version.startswith("1.2") +def test_openresty_is_running(host): + assert host.service("openresty").is_running + + +def test_ufw_is_installed(host): + assert host.package("ufw").is_installed + + +def test_ufw_is_enabled(host): + assert host.service("ufw").is_enabled -def test_haproxy_running_and_enabled(host): - nginx = host.service("haproxy") - assert nginx.is_running - assert nginx.is_enabled \ No newline at end of file +def test_ufw_is_running(host): + assert host.service("ufw").is_running \ No newline at end of file