diff options
author | Michal Ptacek <m.ptacek@partner.samsung.com> | 2019-04-16 10:46:49 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-04-16 10:46:49 +0000 |
commit | 50487218e4cddd1261d4d41c27ae4eba54d1ffab (patch) | |
tree | 94258118dac4e037ff87eb249bfa11060660e9d3 /ansible | |
parent | 765c16bf21409add3b3810a5b3f025345215039f (diff) | |
parent | fef434d08941acc5394eac6bc24c0dae75cbeca8 (diff) |
Merge "Molecule role tests for setup role"
Diffstat (limited to 'ansible')
-rw-r--r-- | ansible/roles/setup/.yamllint | 13 | ||||
-rw-r--r-- | ansible/roles/setup/defaults/main.yml | 2 | ||||
-rw-r--r-- | ansible/roles/setup/molecule/default/Dockerfile.j2 | 14 | ||||
-rw-r--r-- | ansible/roles/setup/molecule/default/molecule.yml | 20 | ||||
-rw-r--r-- | ansible/roles/setup/molecule/default/playbook.yml | 5 | ||||
-rw-r--r-- | ansible/roles/setup/molecule/default/tests/test_default.py | 30 | ||||
-rw-r--r-- | ansible/roles/setup/tasks/main.yml | 1 |
7 files changed, 83 insertions, 2 deletions
diff --git a/ansible/roles/setup/.yamllint b/ansible/roles/setup/.yamllint new file mode 100644 index 00000000..3a2255e4 --- /dev/null +++ b/ansible/roles/setup/.yamllint @@ -0,0 +1,13 @@ +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable + # NOTE(retr0h): Templates no longer fail this lint rule. + # Uncomment if running old Molecule templates. + # truthy: disable diff --git a/ansible/roles/setup/defaults/main.yml b/ansible/roles/setup/defaults/main.yml index e7e89721..050589e7 100644 --- a/ansible/roles/setup/defaults/main.yml +++ b/ansible/roles/setup/defaults/main.yml @@ -1,3 +1,3 @@ --- ssh_dir: ~/.ssh -offline_ssh_key_file_name: offline_ssh_key
\ No newline at end of file +offline_ssh_key_file_name: offline_ssh_key diff --git a/ansible/roles/setup/molecule/default/Dockerfile.j2 b/ansible/roles/setup/molecule/default/Dockerfile.j2 new file mode 100644 index 00000000..0a605536 --- /dev/null +++ b/ansible/roles/setup/molecule/default/Dockerfile.j2 @@ -0,0 +1,14 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi diff --git a/ansible/roles/setup/molecule/default/molecule.yml b/ansible/roles/setup/molecule/default/molecule.yml new file mode 100644 index 00000000..1e9a4c19 --- /dev/null +++ b/ansible/roles/setup/molecule/default/molecule.yml @@ -0,0 +1,20 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: instance + image: ${PLATFORM_DISTRO:-centos}:${DISTRO_VERSION:-7} +provisioner: + name: ansible + lint: + name: ansible-lint +scenario: + name: default +verifier: + name: testinfra + lint: + name: flake8 diff --git a/ansible/roles/setup/molecule/default/playbook.yml b/ansible/roles/setup/molecule/default/playbook.yml new file mode 100644 index 00000000..19a90501 --- /dev/null +++ b/ansible/roles/setup/molecule/default/playbook.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: all + roles: + - role: setup diff --git a/ansible/roles/setup/molecule/default/tests/test_default.py b/ansible/roles/setup/molecule/default/tests/test_default.py new file mode 100644 index 00000000..6bf6b6ba --- /dev/null +++ b/ansible/roles/setup/molecule/default/tests/test_default.py @@ -0,0 +1,30 @@ +import os +import pytest +from os.path import expanduser + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +@pytest.fixture +def get_vars(host): + defaults_files = "file=../../defaults/main.yml name=role_defaults" + ansible_vars = host.ansible( + "include_vars", + defaults_files)["ansible_facts"]["role_defaults"] + return ansible_vars + + +def test_authorized_keys(host, get_vars): + public_key_file = get_vars['offline_ssh_key_file_name'] + '.pub' + with open(expanduser("~") + '/.ssh/' + public_key_file, 'r') as pkf: + public_key_content = pkf.read().strip() + + f = host.file('/root/.ssh/authorized_keys') + assert f.exists + assert f.user == 'root' + assert f.group == 'root' + assert oct(f.mode) == '0o600' + assert f.content_string == public_key_content diff --git a/ansible/roles/setup/tasks/main.yml b/ansible/roles/setup/tasks/main.yml index 5ffcbab9..1003370b 100644 --- a/ansible/roles/setup/tasks/main.yml +++ b/ansible/roles/setup/tasks/main.yml @@ -25,6 +25,5 @@ user: root state: present key: "{{ lookup('file', public_key) }}" - become: true vars: public_key: "{{ ssh_dir }}/{{ offline_ssh_key_file_name }}.pub" |