diff options
author | Michal Ptacek <m.ptacek@partner.samsung.com> | 2019-04-16 10:45:35 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-04-16 10:45:35 +0000 |
commit | 765c16bf21409add3b3810a5b3f025345215039f (patch) | |
tree | 6f2cabcbed788e1670eb69b4185307ab87291c62 | |
parent | 0c4706b81b274d2cf5c0172b48672b8f9e4a2d4d (diff) | |
parent | b3acc41fd78367e5bed759dc914e6f0f93d37efe (diff) |
Merge "Molecule tests for package-repository role"
8 files changed, 122 insertions, 4 deletions
diff --git a/ansible/roles/package-repository/.yamllint b/ansible/roles/package-repository/.yamllint new file mode 100644 index 00000000..3a2255e4 --- /dev/null +++ b/ansible/roles/package-repository/.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/package-repository/molecule/default/Dockerfile.j2 b/ansible/roles/package-repository/molecule/default/Dockerfile.j2 new file mode 100644 index 00000000..0a605536 --- /dev/null +++ b/ansible/roles/package-repository/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/package-repository/molecule/default/molecule.yml b/ansible/roles/package-repository/molecule/default/molecule.yml new file mode 100644 index 00000000..df2024d7 --- /dev/null +++ b/ansible/roles/package-repository/molecule/default/molecule.yml @@ -0,0 +1,46 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: infrastructure-server + image: ${PLATFORM_DISTRO:-centos}:${DISTRO_VERSION:-7} + groups: + - infrastructure + # By design certain file like /etc/resolv.conf cannot be edited in docker + # container. To enable role to "edit" /etc/resolv.conf define value already to same. + dns_servers: + - 6.5.4.3 + + - name: kubernetes-node-1 + image: ${PLATFORM_DISTRO:-centos}:${DISTRO_VERSION:-7} + groups: + - kubernetes + # By design certain file like /etc/resolv.conf cannot be edited in docker + # container. To enable role to "edit" /etc/resolv.conf define value already to same. + dns_servers: + - 6.5.4.3 + +provisioner: + name: ansible + lint: + name: ansible-lint + inventory: + host_vars: + infrastructure-server: + cluster_ip: 6.5.4.3 + group_vars: + all: + app_name: moleculetestapp + app_data_path: "/opt/{{ app_name }}" +scenario: + name: default +verifier: + name: testinfra + options: + verbose: true + lint: + name: flake8 diff --git a/ansible/roles/package-repository/molecule/default/playbook.yml b/ansible/roles/package-repository/molecule/default/playbook.yml new file mode 100644 index 00000000..0b9c72f0 --- /dev/null +++ b/ansible/roles/package-repository/molecule/default/playbook.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: all + roles: + - package-repository diff --git a/ansible/roles/package-repository/molecule/default/tests/test_default.py b/ansible/roles/package-repository/molecule/default/tests/test_default.py new file mode 100644 index 00000000..34884cfe --- /dev/null +++ b/ansible/roles/package-repository/molecule/default/tests/test_default.py @@ -0,0 +1,11 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_etc_resolv_conf_file(host): + f = host.file('/etc/resolv.conf') + assert f.contains("nameserver 6.5.4.3") diff --git a/ansible/roles/package-repository/molecule/default/tests/test_infrastructure-server.py b/ansible/roles/package-repository/molecule/default/tests/test_infrastructure-server.py new file mode 100644 index 00000000..63588e26 --- /dev/null +++ b/ansible/roles/package-repository/molecule/default/tests/test_infrastructure-server.py @@ -0,0 +1,16 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('infrastructure-server') + + +def test_onap_repo(host): + fc = host.file('/etc/yum.repos.d/moleculetestapp.repo').content_string + expected_content = """[moleculetestapp] +baseurl = file:///opt/moleculetestapp/pkg/rhel +enabled = 1 +gpgcheck = 0 +name = MOLECULETESTAPP offline repository""" + assert fc == expected_content diff --git a/ansible/roles/package-repository/molecule/default/tests/test_kubernetes-node-1.py b/ansible/roles/package-repository/molecule/default/tests/test_kubernetes-node-1.py new file mode 100644 index 00000000..eab7d065 --- /dev/null +++ b/ansible/roles/package-repository/molecule/default/tests/test_kubernetes-node-1.py @@ -0,0 +1,16 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('kubernetes-node-1') + + +def test_onap_repo(host): + fc = host.file('/etc/yum.repos.d/moleculetestapp.repo').content_string + expected_content = """[moleculetestapp] +baseurl = http://repo.infra-server/rhel +enabled = 1 +gpgcheck = 0 +name = MOLECULETESTAPP offline repository""" + assert fc == expected_content diff --git a/ansible/roles/package-repository/tasks/main.yml b/ansible/roles/package-repository/tasks/main.yml index 4949345a..599e1052 100644 --- a/ansible/roles/package-repository/tasks/main.yml +++ b/ansible/roles/package-repository/tasks/main.yml @@ -5,7 +5,6 @@ path: /etc/resolv.conf state: present insertbefore: BOF - become: true - name: Disable all OS default repositories block: @@ -20,7 +19,7 @@ - name: Backup repo files copy: - remote_src: yes + remote_src: true src: "{{ item.path }}" dest: "{{ item.path }}.disabled" loop: "{{ repo_files.files }}" @@ -32,7 +31,6 @@ state: absent loop: "{{ repo_files.files }}" when: "(item.path | basename | splitext)[0] not in package_repositories_names" - become: yes - name: Add application offline package repository yum_repository: @@ -44,4 +42,3 @@ enabled: "{{ item.enabled | default(false) }}" state: "{{ item.state | default('present') }}" loop: "{{ package_repositories }}" - become: true |