From 82fb23c5e00b80e53cd796aa4a0b2eca3fb44400 Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Tue, 22 Nov 2016 18:06:05 +0200 Subject: [PATCH] - Run Molecule tests with Docker in Travis CI. --- .travis.yml | 2 ++ README.rst | 11 +++-------- molecule.yml | 6 ++++++ tests/requirements.txt | 1 + tests/test_example.py | 7 ++++++- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9ed5a61..adf6897 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ python: "2.7" dist: trusty sudo: false group: beta +services: [docker] install: - pip install -r tests/requirements.txt @@ -12,6 +13,7 @@ install: script: - pre-commit run --all-files + - molecule test --driver docker notifications: webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/README.rst b/README.rst index 5dedbe3..a2e5cc1 100644 --- a/README.rst +++ b/README.rst @@ -29,8 +29,9 @@ See :code:`tests/playbook.yml`. Testing ------- -Testing requires Virtualbox, Vagrant and Python 2.7. Install the Python -dependencies, dependent roles and roles required for testing: +Testing requires Python 2.7 and either Docker or Vagrant and Virtualbox. +Install the Python dependencies, dependent roles and roles required for +testing: .. code:: shell @@ -58,9 +59,3 @@ Nimrod Adar, `contact me <nimrod@shore.co.il>`_ or visit my `website <https://www.shore.co.il/>`_. Patches are welcome via `git send-email <http://git-scm.com/book/en/v2/Git-Commands-Email>`_. The repository is located at: https://www.shore.co.il/git/. - -TODO ----- - -- Perform pre-commit tests in TravisCI. -- Perform Molecule tests using Docker (just Linux) in TravisCI. diff --git a/molecule.yml b/molecule.yml index 8772054..ae3190e 100644 --- a/molecule.yml +++ b/molecule.yml @@ -27,3 +27,9 @@ vagrant: - 'vbguest.auto_update = false' - 'landrush.enabled = false' - 'landrush_ip.override = false' + +docker: + containers: + - name: ansible-role-example-ubuntu + image: ubuntu + image_version: xenial diff --git a/tests/requirements.txt b/tests/requirements.txt index b7cbb3f..db304aa 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -5,3 +5,4 @@ ansible-lint==3.4.4 pre-commit==0.9.3 piprot==0.9.7 python-vagrant==0.5.14 +docker-py==1.10.6 diff --git a/tests/test_example.py b/tests/test_example.py index 12d4c7a..aaea500 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -1,7 +1,12 @@ +from testinfra.utils.ansible_runner import AnsibleRunner + +testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all') + + def test_example(Command): assert Command('uname').rc == 0 def test_root(Command, Sudo): with Sudo(): - assert Command('whoami').stdout == 'root' + assert Command('whoami').stdout.strip() == 'root' -- GitLab