From 2c34d1d7a33e34c9984ac78460fd8e7c815024c5 Mon Sep 17 00:00:00 2001 From: Jan Benedikt Date: Mon, 10 Feb 2020 16:29:43 +0100 Subject: Adding Ubuntu support in Ansible - package-repository role Extending ansible playbooks of ubuntu support. Creating new test with Ubuntu image for Molecule in package-repository role. Issue-ID: OOM-1671 Signed-off-by: Jan Benedikt Change-Id: I85d4e6857536fa06c7eb4f4042c1ed64fcbf903e --- .../molecule/default/Dockerfile.j2 | 5 ++- .../molecule/default/molecule.yml | 2 - .../default/tests/test_infrastructure-server.py | 13 ++++-- .../default/tests/test_kubernetes-node-1.py | 13 ++++-- .../molecule/ubuntu/molecule.yml | 51 ++++++++++++++++++++++ 5 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 ansible/roles/package-repository/molecule/ubuntu/molecule.yml (limited to 'ansible/roles/package-repository/molecule') diff --git a/ansible/roles/package-repository/molecule/default/Dockerfile.j2 b/ansible/roles/package-repository/molecule/default/Dockerfile.j2 index 0a605536..b76a6dd7 100644 --- a/ansible/roles/package-repository/molecule/default/Dockerfile.j2 +++ b/ansible/roles/package-repository/molecule/default/Dockerfile.j2 @@ -6,9 +6,12 @@ FROM {{ item.registry.url }}/{{ item.image }} 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; \ +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y sudo bash ca-certificates python3-apt && 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 + +# Create symlink python3 -> python +RUN if [ $(command -v apt-get) ]; then ln -s /usr/bin/python3 /usr/bin/python; fi diff --git a/ansible/roles/package-repository/molecule/default/molecule.yml b/ansible/roles/package-repository/molecule/default/molecule.yml index df2024d7..7abb08d4 100644 --- a/ansible/roles/package-repository/molecule/default/molecule.yml +++ b/ansible/roles/package-repository/molecule/default/molecule.yml @@ -36,8 +36,6 @@ provisioner: all: app_name: moleculetestapp app_data_path: "/opt/{{ app_name }}" -scenario: - name: default verifier: name: testinfra options: 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 index 9fb1a4f9..5b3fce4d 100644 --- a/ansible/roles/package-repository/molecule/default/tests/test_infrastructure-server.py +++ b/ansible/roles/package-repository/molecule/default/tests/test_infrastructure-server.py @@ -7,10 +7,17 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( def test_onap_repo(host): - fc = host.file('/etc/yum.repos.d/moleculetestapp.repo').content_string - expected_content = """[moleculetestapp] + os = host.system_info.distribution + if os == "centos": + fc = host.file('/etc/yum.repos.d/moleculetestapp.repo').content_string + expected_content = """[moleculetestapp] baseurl = file:///opt/moleculetestapp/pkg/rpm enabled = 1 gpgcheck = 0 name = MOLECULETESTAPP offline repository""" - assert fc == expected_content + assert fc == expected_content + elif os == "ubuntu": + fc = host.file('/etc/apt/sources.list.d/moleculetestapp.list') + fc = fc.content_string + ec = "deb [trusted=yes] file:///opt/moleculetestapp/pkg/deb ./" + assert fc == ec 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 index fda85e8d..c1831f70 100644 --- 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 @@ -7,10 +7,17 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( def test_onap_repo(host): - fc = host.file('/etc/yum.repos.d/moleculetestapp.repo').content_string - expected_content = """[moleculetestapp] + os = host.system_info.distribution + if os == "centos": + fc = host.file('/etc/yum.repos.d/moleculetestapp.repo').content_string + expected_content = """[moleculetestapp] baseurl = http://repo.infra-server/rpm enabled = 1 gpgcheck = 0 name = MOLECULETESTAPP offline repository""" - assert fc == expected_content + assert fc == expected_content + elif os == "ubuntu": + fc = host.file('/etc/apt/sources.list.d/moleculetestapp.list') + fc = fc.content_string + ec = "deb [trusted=yes] http://repo.infra-server/deb ./" + assert fc == ec diff --git a/ansible/roles/package-repository/molecule/ubuntu/molecule.yml b/ansible/roles/package-repository/molecule/ubuntu/molecule.yml new file mode 100644 index 00000000..07c2d888 --- /dev/null +++ b/ansible/roles/package-repository/molecule/ubuntu/molecule.yml @@ -0,0 +1,51 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: infrastructure-server + image: ${PLATFORM_DISTRO:-ubuntu}:${ISTRO_VERSION:-18.04} + dockerfile: ../default/Dockerfile.j2 + 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:-ubuntu}:${ISTRO_VERSION:-18.04} + dockerfile: ../default/Dockerfile.j2 + 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 + playbooks: + converge: ../default/playbook.yml + 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: ubuntu +verifier: + name: testinfra + options: + verbose: true + lint: + name: flake8 + directory: ../default/tests -- cgit 1.2.3-korg