feat: add basic tests to verify packages are installed and ssh is listening

This commit is contained in:
Aravinth Manivannan 2022-10-24 17:02:20 +05:30
parent 9901351198
commit 371a88c8de
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
3 changed files with 75 additions and 0 deletions

View File

@ -2,3 +2,12 @@ default:
echo yes | terraform destroy
terraform plan --out=plan
terraform apply plan
configure:
./ansible/init.sh
test:
. ./tests/venv/bin/activate && \
py.test --hosts='ansible://all' \
--ansible-inventory=./ansible

View File

@ -0,0 +1,9 @@
attrs==22.1.0
iniconfig==1.1.1
packaging==21.3
pluggy==1.0.0
py==1.11.0
pyparsing==3.0.9
pytest==7.1.3
pytest-testinfra==6.8.0
tomli==2.0.1

View File

@ -0,0 +1,57 @@
import os
def test_packages_are_installed(host):
packages = [
"git",
"zip",
"wget",
"curl",
"nginx",
]
for p in packages:
print(f"[*] Checking if {p} is installed")
pkg = host.package(p)
assert pkg.is_installed
#def test_nginx_service_running_and_enabled(host):
# service = host.service("nginx")
# assert service.is_running
# assert service.is_enabled
def test_ssh_is_listening(host):
socket = host.socket(f"tcp://0.0.0.0:22")
assert socket.is_listening
#
#def test_ufw_is_installed(host):
# pkg = host.package("ufw")
# assert pkg.is_installed
#def test_ufw_service_running_and_enabled(host):
# service = host.service("ufw")
# assert service.is_running
# assert service.is_enabled
#
#
#def test_fail2ban_is_installed(host):
# pkg = host.package("fail2ban")
# assert pkg.is_installed
#
#
#def test_fail2ban_is_enabled_and_running(host):
# service = host.service("fail2ban")
# assert service.is_running
# assert service.is_enabled
#
#
#def test_ssh_is_installed(host):
# pkg = host.package("openssh-server")
# assert pkg.is_installed
#
#
#def test_ssh_is_enabled_and_running(host):
# service = host.service("sshd")
# assert service.is_running
# assert service.is_enabled