summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul CI <zuul@softwarefactory-project.io>2019-01-29 19:10:06 +0000
committerGerrit Code Review <gerrit@softwarefactory-project.io>2019-01-29 19:10:06 +0000
commit3f048cf55c9e11b08a7b4d69beb1e56c14323c33 (patch)
tree0577501b1046bbcebd2daffca458b71b5c4ea66e
parentd53e27b06e4b5c953a21e600ec44a987e14ab983 (diff)
parent811bec0e2be8c1a246b2be9403cfc2421d836cf1 (diff)
Merge "Add molecule configuration"
-rw-r--r--.yamllint10
-rw-r--r--meta/main.yml1
-rw-r--r--molecule/default/Dockerfile.j212
-rw-r--r--molecule/default/molecule.yml25
-rw-r--r--molecule/default/playbook.yml19
-rw-r--r--molecule/default/tests/test_docker.py57
-rw-r--r--molecule/default/tests/test_docker_distribution.py49
-rw-r--r--tox.ini13
8 files changed, 186 insertions, 0 deletions
diff --git a/.yamllint b/.yamllint
new file mode 100644
index 0000000..a4d53d6
--- /dev/null
+++ b/.yamllint
@@ -0,0 +1,10 @@
+extends: default
+
+rules:
+ braces:
+ max-spaces-inside: 1
+ level: error
+ brackets:
+ max-spaces-inside: 1
+ level: error
+ line-length: disable
diff --git a/meta/main.yml b/meta/main.yml
index cf5d205..658eda0 100644
--- a/meta/main.yml
+++ b/meta/main.yml
@@ -1,3 +1,4 @@
+---
galaxy_info:
author: Distributed-CI Team
description: An Ansible role that sync DCI registry
diff --git a/molecule/default/Dockerfile.j2 b/molecule/default/Dockerfile.j2
new file mode 100644
index 0000000..c8e170a
--- /dev/null
+++ b/molecule/default/Dockerfile.j2
@@ -0,0 +1,12 @@
+{% if item.registry is defined %}
+FROM {{ item.registry.url }}/{{ item.image }}
+{% else %}
+FROM {{ item.image }}
+{% endif %}
+
+RUN yum install -y sudo iproute && \
+ yum clean all
+
+RUN adduser centos && \
+ echo 'centos ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/90-centos && \
+ chmod 440 /etc/sudoers.d/90-centos
diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml
new file mode 100644
index 0000000..c2e7743
--- /dev/null
+++ b/molecule/default/molecule.yml
@@ -0,0 +1,25 @@
+---
+dependency:
+ name: galaxy
+ enabled: false
+driver:
+ name: docker
+lint:
+ name: yamllint
+platforms:
+ - name: el7
+ image: centos/systemd:latest
+ privileged: true
+ command: /sbin/init
+provisioner:
+ name: ansible
+ connection_options:
+ ansible_user: centos
+ lint:
+ name: ansible-lint
+scenario:
+ name: default
+verifier:
+ name: testinfra
+ lint:
+ name: flake8
diff --git a/molecule/default/playbook.yml b/molecule/default/playbook.yml
new file mode 100644
index 0000000..fc3cf52
--- /dev/null
+++ b/molecule/default/playbook.yml
@@ -0,0 +1,19 @@
+---
+- name: Converge
+ hosts: all
+ tasks:
+ - name: Create images_list.yaml file
+ copy:
+ dest: /var/tmp/images_list.yaml
+ content: |
+ ---
+ - docker.io/amd64/busybox:latest
+ - docker.io/amd64/registry:latest
+ - docker.io/amd64/haproxy:latest
+
+ - include_role:
+ name: ansible-role-dci-sync-registry
+ vars:
+ dci_sync_registry_images_list: /var/tmp/images_list.yaml
+ dci_sync_registry_local_ip: 127.0.0.1
+ dci_sync_registry_storage: vfs
diff --git a/molecule/default/tests/test_docker.py b/molecule/default/tests/test_docker.py
new file mode 100644
index 0000000..de4665c
--- /dev/null
+++ b/molecule/default/tests/test_docker.py
@@ -0,0 +1,57 @@
+import os
+
+import testinfra.utils.ansible_runner
+
+testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
+ os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
+
+
+def test_docker_daemon_config(host):
+ f = host.file('/etc/docker/daemon.json')
+ assert f.exists
+ assert f.is_file
+ assert f.user == 'root'
+ assert f.group == 'root'
+ assert f.contains('insecure-registries')
+ assert f.contains('127.0.0.1:5000')
+
+
+def test_docker_proxy_config(host):
+ f = host.file('/etc/systemd/system/docker.service.d/http-proxy.conf')
+ assert f.exists
+ assert f.is_file
+ assert f.user == 'root'
+ assert f.group == 'root'
+ assert f.contains('[Service]')
+
+
+def test_docker_storage_config(host):
+ f = host.file('/etc/sysconfig/docker-storage-setup')
+ assert f.exists
+ assert f.is_file
+ assert f.user == 'root'
+ assert f.group == 'root'
+ assert f.contains('STORAGE_DRIVER=vfs')
+
+
+def test_docker_package(host):
+ package = host.package('docker')
+ assert package.is_installed
+
+
+def test_docker_service(host):
+ service = host.service('docker')
+ assert service.is_running
+ assert service.is_enabled
+
+
+def test_docker_socket(host):
+ socket = host.socket('unix:///var/run/docker.sock')
+ assert socket.is_listening
+
+
+def test_docker_info(host):
+ cmd = host.run('sudo docker info')
+ assert cmd.rc == 0
+ assert 'Storage Driver: vfs' in cmd.stdout
+ assert ' 127.0.0.1:5000' in cmd.stdout
diff --git a/molecule/default/tests/test_docker_distribution.py b/molecule/default/tests/test_docker_distribution.py
new file mode 100644
index 0000000..a652dec
--- /dev/null
+++ b/molecule/default/tests/test_docker_distribution.py
@@ -0,0 +1,49 @@
+import os
+import json
+
+import testinfra.utils.ansible_runner
+
+testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
+ os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
+
+
+def test_docker_distribution_config(host):
+ f = host.file('/etc/docker-distribution/registry/config.yml')
+ assert f.exists
+ assert f.is_file
+ assert f.user == 'root'
+ assert f.group == 'root'
+ assert f.contains('addr: 127.0.0.1:5000')
+
+
+def test_docker_distribution_package(host):
+ package = host.package('docker-distribution')
+ assert package.is_installed
+
+
+def test_docker_distribution_service(host):
+ service = host.service('docker-distribution')
+ assert service.is_running
+ assert service.is_enabled
+
+
+def test_docker_distribution_socket(host):
+ socket = host.socket('tcp://127.0.0.1:5000')
+ assert socket.is_listening
+
+
+def test_docker_distribution_pull_image(host):
+ cmd = host.run('sudo docker pull 127.0.0.1:5000/amd64/busybox:latest')
+ assert cmd.rc == 0
+ assert 'Pull complete' in cmd.stdout
+ assert '127.0.0.1:5000/amd64/busybox:latest' in cmd.stdout
+
+
+def test_docker_distribution_catalog(host):
+ cmd = host.run('curl -s http://127.0.0.1:5000/v2/_catalog')
+ repositories = json.loads(cmd.stdout)['repositories']
+ assert cmd.rc == 0
+ assert len(repositories) == 3
+ assert repositories[0] == 'amd64/busybox'
+ assert repositories[1] == 'amd64/haproxy'
+ assert repositories[2] == 'amd64/registry'
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..1119322
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,13 @@
+[tox]
+minversion = 1.8
+envlist = py{27,36}
+skipsdist = true
+
+[testenv]
+passenv = *
+deps =
+ ansible>=2.7,<2.8
+ docker
+ molecule
+commands =
+ molecule test