From 80bd0fbf0bef89fb2a07cbc50d69fa6b88bf2cef Mon Sep 17 00:00:00 2001 From: Michael Crilly Date: Mon, 27 Feb 2017 19:11:46 +1000 Subject: [PATCH] Adding Molecule tests with Docker supporting systemd --- .gitignore | 5 +++- molecule.yml | 11 +++++++ playbook.yml | 4 +++ tasks/main.yml | 5 ++++ tests/main.yml | 20 ------------- tests/test_default.py | 67 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 91 insertions(+), 21 deletions(-) create mode 100644 molecule.yml create mode 100644 playbook.yml delete mode 100644 tests/main.yml create mode 100644 tests/test_default.py diff --git a/.gitignore b/.gitignore index 28bbe3b..a30094d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,7 @@ .*.sw* *~ .idea/ - +.cache/ +.molecule/ +tests/__pycache__/ +*.pyc diff --git a/molecule.yml b/molecule.yml new file mode 100644 index 0000000..b5890c8 --- /dev/null +++ b/molecule.yml @@ -0,0 +1,11 @@ +--- +driver: + name: docker +docker: + containers: + - name: ansible-nginx + image: solita/ubuntu-systemd + image_version: latest + privileged: True +verifier: + name: testinfra diff --git a/playbook.yml b/playbook.yml new file mode 100644 index 0000000..f8b3bf3 --- /dev/null +++ b/playbook.yml @@ -0,0 +1,4 @@ +--- +- hosts: all + roles: + - role: ansible-nginx diff --git a/tasks/main.yml b/tasks/main.yml index 1ce6f58..b003903 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,5 +1,10 @@ --- +- name: Install system dependencies + apt: + name: 'openssl' + state: 'present' + - name: Install role dependencies apt: name: 'python-passlib' diff --git a/tests/main.yml b/tests/main.yml deleted file mode 100644 index 5c2879a..0000000 --- a/tests/main.yml +++ /dev/null @@ -1,20 +0,0 @@ ---- - -- hosts: all - vars: - nginx_basic_auth: - - { user: 'coolperson', password: 'heylookatmeicanviewtheprivateblog' } - - nginx_sites: - default: - domains: ['localhost'] - listen_http: 8080 - listen_https: 8081 - - pre_tasks: - - name: Update APT cache - apt: - update_cache: True - - roles: - - this_role diff --git a/tests/test_default.py b/tests/test_default.py new file mode 100644 index 0000000..29b4ef6 --- /dev/null +++ b/tests/test_default.py @@ -0,0 +1,67 @@ +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + '.molecule/ansible_inventory').get_hosts('all') + + +def test_service(Service): + present = [ + "nginx" + ] + + if present: + for service in present: + s = Service(service) + assert s.is_running + assert s.is_enabled + + +def test_files(File): + present = [ + "/etc/nginx/nginx.conf", + ] + + if present: + for file in present: + f = File(file) + assert f.exists + assert f.is_file + + +def test_packages(Package): + present = [ + "nginx" + ] + + if present: + for package in present: + p = Package(package) + assert p.is_installed + + +def test_directories(File): + present = [ + "/etc/nginx", + "/etc/nginx/ssl", + "/etc/nginx/conf.d", + "/etc/nginx/sites-enabled", + "/etc/nginx/sites-available", + "/usr/share/nginx/html", + ] + + absent = [ + "/var/www/html", + "/etc/nginx/sites-enabled/default", + "/etc/nginx/sites-available/default", + ] + + if present: + for directory in present: + d = File(directory) + assert d.is_directory + assert d.exists + + if absent: + for directory in absent: + d = File(directory) + assert not d.exists