From 97f0ff4c4488270cca2d17b2bf5f890d3a47873a Mon Sep 17 00:00:00 2001 From: Paul Belanger Date: Tue, 27 Mar 2018 17:11:37 -0400 Subject: [PATCH] WIP: Add ansible-role-functional-centos-7 job Add an example ansible functional jobs using tests from the test folder. This leverages tox to allow a user to run these locally if needed. Signed-off-by: Paul Belanger --- .zuul.yaml | 28 ++++++++++++++++--- test-requirements.txt | 1 + tests/ansible.cfg | 2 ++ .../ansible-role-functional/pre.yaml | 11 ++++++++ tests/playbooks/tox-with-sudo/run.yaml | 3 ++ tests/test.yml | 5 ++-- tox.ini | 10 +++++++ 7 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 tests/ansible.cfg create mode 100644 tests/playbooks/ansible-role-functional/pre.yaml create mode 100644 tests/playbooks/tox-with-sudo/run.yaml diff --git a/.zuul.yaml b/.zuul.yaml index 7a78699..2a6f548 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -1,7 +1,27 @@ +- nodeset: + name: centos-7 + nodes: + - name: centos-7 + label: dib-centos-7 + +- job: + name: ansible-role-functional-base + abstract: true + parent: tox + description: | + Run functional functional tests for ansible-role projects. + + Uses tox with the ``functional`` environment. + pre-run: tests/playbooks/ansible-role-functional/pre.yaml + run: tests/playbooks/tox-with-sudo/run.yaml + vars: + tox_envlist: functional + +- job: + name: ansible-role-functional-centos-7 + parent: ansible-role-functional-base + - project: check: jobs: - - tox-linters - gate: - jobs: - - tox-linters + - ansible-role-functional-centos-7 diff --git a/test-requirements.txt b/test-requirements.txt index 3930480..e078257 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1 +1,2 @@ flake8 +ansible diff --git a/tests/ansible.cfg b/tests/ansible.cfg new file mode 100644 index 0000000..6c8a344 --- /dev/null +++ b/tests/ansible.cfg @@ -0,0 +1,2 @@ +[defaults] +roles_path = ../.. diff --git a/tests/playbooks/ansible-role-functional/pre.yaml b/tests/playbooks/ansible-role-functional/pre.yaml new file mode 100644 index 0000000..da110c0 --- /dev/null +++ b/tests/playbooks/ansible-role-functional/pre.yaml @@ -0,0 +1,11 @@ +- hosts: all + name: Set up SSH login + tasks: + - name: Allow ssh login into localhost + shell: + cmd: | + # Allow user to ssh into localhost + ssh-keygen -f ~/.ssh/id_rsa -N "" + cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys + ssh-keyscan localhost >> ~/.ssh/known_hosts + ssh-keyscan 127.0.0.1 >> ~/.ssh/known_hosts diff --git a/tests/playbooks/tox-with-sudo/run.yaml b/tests/playbooks/tox-with-sudo/run.yaml new file mode 100644 index 0000000..22f8209 --- /dev/null +++ b/tests/playbooks/tox-with-sudo/run.yaml @@ -0,0 +1,3 @@ +- hosts: all + roles: + - tox diff --git a/tests/test.yml b/tests/test.yml index 92ad039..c5d0a31 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -1,5 +1,6 @@ --- - hosts: localhost - remote_user: root + vars: + rolename: "{{ lookup('pipe', 'pwd') | dirname | basename }}" roles: - - network-engine \ No newline at end of file + - "{{ rolename }}" diff --git a/tox.ini b/tox.ini index 896598a..f854851 100644 --- a/tox.ini +++ b/tox.ini @@ -6,6 +6,16 @@ skipsdist = True [testenv] deps = -r{toxinidir}/test-requirements.txt +[testenv:functional] +commands = + ansible-playbook -i tests/inventory tests/test.yaml +passenv = + HOME + USER +setenv = + ANSIBLE_CONFIG = {toxinidir}/tests/ansible.cfg + PYTHONUNBUFFERED = 1 + [testenv:venv] commands = {posargs}