From 08e82da1a4c7954de248da3ebc12317e82dc238b Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Sun, 24 Jun 2018 14:53:32 +0200 Subject: [PATCH] Update molecule to 2.x * Adds yamllint. * Use working docker images. --- .travis.yml | 2 +- .yamllint | 14 ++++++ molecule.yml | 48 ------------------- molecule/default/create.yml | 37 ++++++++++++++ molecule/default/destroy.yml | 32 +++++++++++++ molecule/default/molecule.yml | 35 ++++++++++++++ molecule/default/playbook.yml | 8 ++++ molecule/default/prepare.yml | 5 ++ .../default/tests}/test_minio.py | 0 playbook.yml | 6 --- test-requirements.txt | 5 +- 11 files changed, 135 insertions(+), 57 deletions(-) create mode 100644 .yamllint delete mode 100644 molecule.yml create mode 100644 molecule/default/create.yml create mode 100644 molecule/default/destroy.yml create mode 100644 molecule/default/molecule.yml create mode 100644 molecule/default/playbook.yml create mode 100644 molecule/default/prepare.yml rename {tests => molecule/default/tests}/test_minio.py (100%) delete mode 100644 playbook.yml diff --git a/.travis.yml b/.travis.yml index 8163938..affbbd0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ install: # Execute the tests using the molecule docker driver script: - - molecule test --driver docker + - molecule test --all notifications: webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..06fd860 --- /dev/null +++ b/.yamllint @@ -0,0 +1,14 @@ +extends: default +ignore: | + .travis/ + .travis.yml + meta/ + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable diff --git a/molecule.yml b/molecule.yml deleted file mode 100644 index 7c636d8..0000000 --- a/molecule.yml +++ /dev/null @@ -1,48 +0,0 @@ ---- - -# docker driver configuration (CI) -docker: - containers: - - name: minio-centos-7 - image: atosatto/centos - image_version: 7-systemd - privileged: True - - name: minio-ubuntu-16.04 - image: atosatto/ubuntu - image_version: 16.04 - privileged: True - # TODO: Find a workaround to - # https://github.com/ansible/ansible/issues/18894 - # and add ubuntu-14.04 to CI. - # - name: minio-ubuntu-14.04 - # image: ubuntu - # image_version: 14.04 - # privileged: True - - -# vagrant driver configuration (development) -vagrant: - platforms: - - name: centos-7 - box: centos/7 - - name: ubuntu-16.04 - box: bento/ubuntu-16.04 - - name: ubuntu-14.04 - box: bento/ubuntu-14.04 - providers: - - name: virtualbox - type: virtualbox - options: - memory: 2048 - cpus: 2 - instances: - - name: ansible-minio-01 - interfaces: - - network_name: private_network - type: dhcp - auto_config: true - options: - append_platform_to_hostname: yes - -verifier: - name: testinfra diff --git a/molecule/default/create.yml b/molecule/default/create.yml new file mode 100644 index 0000000..022fe2a --- /dev/null +++ b/molecule/default/create.yml @@ -0,0 +1,37 @@ +--- +- name: Create + hosts: localhost + connection: local + gather_facts: false + no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}" + tasks: + - name: Create molecule instance(s) + docker_container: + name: "{{ item.name }}" + docker_host: "{{ item.docker_host | default('unix://var/run/docker.sock') }}" + hostname: "{{ item.name }}" + image: "{{ item.image }}" + state: started + recreate: false + log_driver: json-file + command: "{{ item.command | default(omit) }}" + privileged: "{{ item.privileged | default(omit) }}" + volumes: "{{ item.volumes | default(omit) }}" + capabilities: "{{ item.capabilities | default(omit) }}" + exposed_ports: "{{ item.exposed_ports | default(omit) }}" + published_ports: "{{ item.published_ports | default(omit) }}" + ulimits: "{{ item.ulimits | default(omit) }}" + networks: "{{ item.networks | default(omit) }}" + dns_servers: "{{ item.dns_servers | default(omit) }}" + register: server + with_items: "{{ molecule_yml.platforms }}" + async: 7200 + poll: 0 + + - name: Wait for instance(s) creation to complete + async_status: + jid: "{{ item.ansible_job_id }}" + register: docker_jobs + until: docker_jobs.finished + retries: 300 + with_items: "{{ server.results }}" diff --git a/molecule/default/destroy.yml b/molecule/default/destroy.yml new file mode 100644 index 0000000..2c2bf11 --- /dev/null +++ b/molecule/default/destroy.yml @@ -0,0 +1,32 @@ +--- +- name: Destroy + hosts: localhost + connection: local + gather_facts: false + no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}" + tasks: + - name: Destroy molecule instance(s) + docker_container: + name: "{{ item.name }}" + docker_host: "{{ item.docker_host | default('unix://var/run/docker.sock') }}" + state: absent + force_kill: "{{ item.force_kill | default(true) }}" + register: server + with_items: "{{ molecule_yml.platforms }}" + async: 7200 + poll: 0 + + - name: Wait for instance(s) deletion to complete + async_status: + jid: "{{ item.ansible_job_id }}" + register: docker_jobs + until: docker_jobs.finished + retries: 300 + with_items: "{{ server.results }}" + + - name: Delete docker network(s) + docker_network: + name: "{{ item }}" + docker_host: "{{ item.docker_host | default('unix://var/run/docker.sock') }}" + state: absent + with_items: "{{ molecule_yml.platforms | molecule_get_docker_networks }}" diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..56fe2ba --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,35 @@ +--- +driver: + name: docker +lint: + name: yamllint + +platforms: + - name: minio-centos-7 + image: paulfantom/centos-molecule:7 + privileged: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + - name: minio-ubuntu-16.04 + image: paulfantom/ubuntu-molecule:16.04 + privileged: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + +provisioner: + name: ansible + lint: + name: ansible-lint + playbooks: + create: create.yml + prepare: prepare.yml + converge: playbook.yml + destroy: destroy.yml + +scenario: + name: default +verifier: + name: testinfra + lint: + name: flake8 + enabled: true diff --git a/molecule/default/playbook.yml b/molecule/default/playbook.yml new file mode 100644 index 0000000..dc269bd --- /dev/null +++ b/molecule/default/playbook.yml @@ -0,0 +1,8 @@ +--- + +- hosts: all + any_errors_fatal: true + roles: + - ansible-minio + vars: + minio_server_datadirs: [ "/minio-test" ] diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml new file mode 100644 index 0000000..5358b3b --- /dev/null +++ b/molecule/default/prepare.yml @@ -0,0 +1,5 @@ +--- +- name: Prepare + hosts: all + gather_facts: false + tasks: [] diff --git a/tests/test_minio.py b/molecule/default/tests/test_minio.py similarity index 100% rename from tests/test_minio.py rename to molecule/default/tests/test_minio.py diff --git a/playbook.yml b/playbook.yml deleted file mode 100644 index e432c4b..0000000 --- a/playbook.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- - -- hosts: all - roles: - - { role: ansible-minio, - minio_server_datadirs: [ "/minio-test" ] } diff --git a/test-requirements.txt b/test-requirements.txt index bc4cea1..25117e9 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,3 +1,4 @@ -molecule==1.17.3 -docker-py==1.10.6 +molecule>=2.15.0 +docker-py>=1.10.0 PyYAML==3.12 +ansible-lint>=3.4.0