summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Benedikt <j.benedikt@partner.samsung.com>2020-05-05 08:46:19 +0200
committerJan Benedikt <j.benedikt@partner.samsung.com>2020-05-14 09:28:34 +0200
commite56bd4f45f5d9f68aeb406510cf4aa5741405d80 (patch)
tree9436bb14f10ba9e9f480dc73e8921895aa4093ca
parent56af1f9d2c3e2d0b6529d71014d619619cf25933 (diff)
Fix lint errors in package-repository-check role
In package-repository-check was changed command module to service module due to lint failing. Failing was caused by errors: [301] Commands should not change things if nothing needs doing [303] service used in place of service module Added molecule test. Issue-ID: OOM-2395 Signed-off-by: Jan Benedikt <j.benedikt@partner.samsung.com> Change-Id: I6cfdfe920eabfb9a0c43cc9ba4ffcd81df1d6852
-rwxr-xr-xansible/roles/package-repository-check/.yamllint11
-rwxr-xr-xansible/roles/package-repository-check/molecule/default/molecule.yml58
-rwxr-xr-xansible/roles/package-repository-check/molecule/default/playbook.yml5
-rwxr-xr-xansible/roles/package-repository-check/molecule/ubuntu/Dockerfile.j214
-rwxr-xr-xansible/roles/package-repository-check/molecule/ubuntu/molecule.yml54
-rwxr-xr-xansible/roles/package-repository-check/molecule/ubuntu/tests/test_default.py17
-rwxr-xr-x[-rw-r--r--]ansible/roles/package-repository-check/tasks/Debian.yml6
-rwxr-xr-x[-rw-r--r--]ansible/roles/package-repository-check/tasks/RedHat.yml2
-rwxr-xr-x[-rw-r--r--]ansible/roles/package-repository-check/tasks/main.yml2
9 files changed, 165 insertions, 4 deletions
diff --git a/ansible/roles/package-repository-check/.yamllint b/ansible/roles/package-repository-check/.yamllint
new file mode 100755
index 00000000..ad0be760
--- /dev/null
+++ b/ansible/roles/package-repository-check/.yamllint
@@ -0,0 +1,11 @@
+extends: default
+
+rules:
+ braces:
+ max-spaces-inside: 1
+ level: error
+ brackets:
+ max-spaces-inside: 1
+ level: error
+ line-length: disable
+ truthy: disable
diff --git a/ansible/roles/package-repository-check/molecule/default/molecule.yml b/ansible/roles/package-repository-check/molecule/default/molecule.yml
new file mode 100755
index 00000000..27003dcb
--- /dev/null
+++ b/ansible/roles/package-repository-check/molecule/default/molecule.yml
@@ -0,0 +1,58 @@
+---
+dependency:
+ name: galaxy
+driver:
+ name: docker
+lint:
+ name: yamllint
+platforms:
+ - name: infra_host
+ image: molecule-${PREBUILD_PLATFORM_DISTRO:-centos}:${PREBUILD_DISTRO_VERSION:-centos7.6}
+ pre_build_image: True
+ privileged: true
+ volume_mounts:
+ - "/sys/fs/cgroup:/sys/fs/cgroup:ro"
+ override_command: False
+ groups:
+ - infrastructure
+ - name: node0
+ image: molecule-${PREBUILD_PLATFORM_DISTRO:-centos}:${PREBUILD_DISTRO_VERSION:-centos7.6}
+ pre_build_image: True
+ privileged: true
+ volume_mounts:
+ - "/sys/fs/cgroup:/sys/fs/cgroup:ro"
+ override_command: False
+ groups:
+ - kubernetes
+provisioner:
+ name: ansible
+ lint:
+ name: ansible-lint
+ env:
+ ANSIBLE_ROLES_PATH: ../../../../test/roles
+scenario:
+ name: default
+ test_sequence:
+ - lint
+ - cleanup
+ - destroy
+ - dependency
+ - syntax
+ - create
+ - prepare
+ - converge
+ # - idempotence
+ # --> Action: 'idempotence'
+ # ERROR: Idempotence test failed because of the following tasks:
+ # * [infra_host] => package-repository-check : Clean yum cache
+ # * [node0] => package-repository-check : Clean yum cache
+ - side_effect
+ - verify
+ - cleanup
+ - destroy
+verifier:
+ name: testinfra
+ lint:
+ name: flake8
+ options:
+ v: 1
diff --git a/ansible/roles/package-repository-check/molecule/default/playbook.yml b/ansible/roles/package-repository-check/molecule/default/playbook.yml
new file mode 100755
index 00000000..7dd80c77
--- /dev/null
+++ b/ansible/roles/package-repository-check/molecule/default/playbook.yml
@@ -0,0 +1,5 @@
+---
+- name: Activate repository on node host
+ hosts: all
+ roles:
+ - package-repository-check
diff --git a/ansible/roles/package-repository-check/molecule/ubuntu/Dockerfile.j2 b/ansible/roles/package-repository-check/molecule/ubuntu/Dockerfile.j2
new file mode 100755
index 00000000..5e856c0a
--- /dev/null
+++ b/ansible/roles/package-repository-check/molecule/ubuntu/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 apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean
+
+# /etc/resolv.conf cannot be edited in docker container
+# due to cannot be installed resolvconf
+# https://github.com/moby/moby/issues/1297
+RUN echo "resolvconf resolvconf/linkify-resolvconf boolean false" | debconf-set-selections
diff --git a/ansible/roles/package-repository-check/molecule/ubuntu/molecule.yml b/ansible/roles/package-repository-check/molecule/ubuntu/molecule.yml
new file mode 100755
index 00000000..ba08e86b
--- /dev/null
+++ b/ansible/roles/package-repository-check/molecule/ubuntu/molecule.yml
@@ -0,0 +1,54 @@
+---
+dependency:
+ name: galaxy
+driver:
+ name: docker
+lint:
+ name: yamllint
+platforms:
+ - name: infrastructure-server
+ image: ${PLATFORM_DISTRO:-ubuntu}:${DISTRO_VERSION:-18.04}
+ groups:
+ - infrastructure
+
+ - name: kubernetes-node-1
+ image: ${PLATFORM_DISTRO:-ubuntu}:${DISTRO_VERSION:-18.04}
+ groups:
+ - kubernetes
+
+provisioner:
+ name: ansible
+ lint:
+ name: ansible-lint
+ playbooks:
+ converge: ../default/playbook.yml
+ inventory:
+ host_vars:
+ infrastructure-server:
+ cluster_ip: 6.5.4.3
+scenario:
+ name: ubuntu
+ test_sequence:
+ - lint
+ - cleanup
+ - destroy
+ - dependency
+ - syntax
+ - create
+ - prepare
+ - converge
+ # - idempotence
+ # --> Action: 'idempotence'
+ # ERROR: Idempotence test failed because of the following tasks:
+ # * [infra_host] => package-repository-check : Clean yum cache
+ # * [node0] => package-repository-check : Clean yum cache
+ - side_effect
+ - verify
+ - cleanup
+ - destroy
+verifier:
+ name: testinfra
+ lint:
+ name: flake8
+ options:
+ v: 1
diff --git a/ansible/roles/package-repository-check/molecule/ubuntu/tests/test_default.py b/ansible/roles/package-repository-check/molecule/ubuntu/tests/test_default.py
new file mode 100755
index 00000000..3e7f3864
--- /dev/null
+++ b/ansible/roles/package-repository-check/molecule/ubuntu/tests/test_default.py
@@ -0,0 +1,17 @@
+import os
+import pytest
+
+import testinfra.utils.ansible_runner
+
+testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
+ os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
+
+
+@pytest.mark.parametrize('distro,pkg', [
+ ('ubuntu', 'resolvconf')
+])
+def test_pkg(host, distro, pkg):
+ os = host.system_info.distribution
+ if distro == os:
+ package = host.package(pkg)
+ assert package.is_installed
diff --git a/ansible/roles/package-repository-check/tasks/Debian.yml b/ansible/roles/package-repository-check/tasks/Debian.yml
index 8fb37848..45a2b1cf 100644..100755
--- a/ansible/roles/package-repository-check/tasks/Debian.yml
+++ b/ansible/roles/package-repository-check/tasks/Debian.yml
@@ -12,7 +12,7 @@
update_cache: yes
state: latest
tags:
- - skip_ansible_lint # Prevent '[403] Package installs should not use latest' ansible lint task rule
+ - skip_ansible_lint # Prevent '[403] Package installs should not use latest' ansible lint task rule
rescue:
- name: Fail if apt cache updating failed
fail:
@@ -31,4 +31,6 @@
create: yes
- name: Make DNS settings permanent
- command: service resolvconf restart
+ service:
+ name: resolvconf
+ state: restarted
diff --git a/ansible/roles/package-repository-check/tasks/RedHat.yml b/ansible/roles/package-repository-check/tasks/RedHat.yml
index ed496f99..e841f172 100644..100755
--- a/ansible/roles/package-repository-check/tasks/RedHat.yml
+++ b/ansible/roles/package-repository-check/tasks/RedHat.yml
@@ -12,7 +12,7 @@
update_cache: yes
state: latest
tags:
- - skip_ansible_lint # Prevent '[403] Package installs should not use latest' ansible lint task rule
+ - skip_ansible_lint # Prevent '[403] Package installs should not use latest' ansible lint task rule
rescue:
- name: Fail if yum cache updating failed
fail:
diff --git a/ansible/roles/package-repository-check/tasks/main.yml b/ansible/roles/package-repository-check/tasks/main.yml
index 11fb3296..ca43715e 100644..100755
--- a/ansible/roles/package-repository-check/tasks/main.yml
+++ b/ansible/roles/package-repository-check/tasks/main.yml
@@ -7,5 +7,5 @@
# Successfull prior invocation of 'package-repository' and 'nginx' role on infrastructure hosts
# is prerequisite for playing this one on 'kubernetes' group.
-#Set of tasks designated to failing fast if configured repos are not functioning properly
+# Set of tasks designated to failing fast if configured repos are not functioning properly
- include_tasks: "{{ ansible_os_family }}.yml"