diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 36f15ba00cbeb54d5c86424c85da0d21c6167ae0..07963bed9165ef7601cddffb308a11477236ad2b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -22,7 +22,7 @@ bootstrap: script: - apk update - apk add ansible musl-dev linux-headers gcc py3-psutil openssh-client - - pip3 install requests tabulate + - pip3 install requests tabulate testinfra # Ensure test/ is not world-writable otherwise ansible-playbook refuses to run, see # https://docs.ansible.com/ansible/devel/reference_appendices/config.html#cfg-in-world-writable-dir - chmod 755 test/ @@ -31,6 +31,7 @@ bootstrap: - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null # - mkdir -p --mode 700 ~/.ssh - ANSIBLE_HOST_KEY_CHECKING=False python3 -u ./ci-bootstrap.py --create_droplet + - py.test -v --ansible-inventory=./inventory.yml --hosts='ansible://*' - python3 -c "import cosmos; cosmos.terminate_droplets_by_name(\"^ci-${CI_JOB_ID}\$\")" artifacts: paths: diff --git a/test/pytest/README.md b/test/pytest/README.md new file mode 100644 index 0000000000000000000000000000000000000000..a7dbbc11b6de376f4359b4703a6f6bce0de6e65b --- /dev/null +++ b/test/pytest/README.md @@ -0,0 +1,16 @@ +# Run testinfra tests + +Test host configured in `test/inventory.yml` + + py.test -v --ansible-inventory=../inventory.yml --hosts='ansible://*' + +Specify host manually: + + py.test -v --hosts='ssh://root@varac-oas.openappstack.net' + +# Issues + +- Default ssh backend is `paramiko`, which doesn't work oout of the + box. It fails to connect to the host because the `ed25519` hostkey + was not verified. Therefore we need to force plain ssh:// with either + `connection=ssh` or `--hosts=ssh://…` diff --git a/test/pytest/test_docker.py b/test/pytest/test_docker.py new file mode 100644 index 0000000000000000000000000000000000000000..ebac75c5b72fe700a7a2cd0ae192f5d011eb0cf1 --- /dev/null +++ b/test/pytest/test_docker.py @@ -0,0 +1,10 @@ +def test_docker_is_installed(host): + docker = host.package("docker-ce") + assert docker.is_installed + assert docker.version.startswith("5:18.09.2") + + +def test_docker_running_and_enabled(host): + docker = host.service("docker") + assert docker.is_running + assert docker.is_enabled diff --git a/test/pytest/test_system.py b/test/pytest/test_system.py new file mode 100644 index 0000000000000000000000000000000000000000..933a18e309a780676ccac795c8928375f06d8552 --- /dev/null +++ b/test/pytest/test_system.py @@ -0,0 +1,3 @@ +def test_release_is_bionic(host): + system_info = host.system_info + assert system_info.release == '18.04'