Improved tasks and tests layout (#25)

This commit is contained in:
Andrea Tosatto 2018-08-20 20:25:15 +02:00 committed by GitHub
parent 29c8c21e2d
commit 00fdf97379
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 301 additions and 276 deletions

View File

@ -12,9 +12,9 @@ services:
env:
matrix:
- ANSIBLE=2.3
- ANSIBLE=2.4
- ANSIBLE=2.5
- ANSIBLE=2.6
# Install tox
install:

View File

@ -1,14 +1,21 @@
extends: default
ignore: |
.travis/
.travis.yml
meta/
rules:
# Disable line-length and truthy values reporting
line-length: disable
truthy: disable
# Max 1 space to separate the elements in brakets
braces:
max-spaces-inside: 1
level: error
# Max 1 space in empty brackets
brackets:
max-spaces-inside: 1
level: error
line-length: disable
min-spaces-inside-empty: 0
max-spaces-inside-empty: 1

View File

@ -1,8 +1,13 @@
---
scenario:
name: alternative
driver:
name: docker
lint:
name: yamllint
dependency:
name: galaxy
platforms:
- name: minio-centos-7
@ -35,16 +40,22 @@ provisioner:
name: ansible
lint:
name: ansible-lint
options:
diff: True
v: True
playbooks:
create: ../default/create.yml
prepare: ../default/prepare.yml
converge: playbook.yml
destroy: ../default/destroy.yml
create: ../resources/create.yml
prepare: ../resources/prepare.yml
destroy: ../resources/destroy.yml
lint:
name: yamllint
scenario:
name: alternative
verifier:
name: testinfra
options:
vvv: True
additional_files_or_dirs:
- ../resources/tests/
lint:
name: flake8
enabled: true

View File

@ -1,49 +0,0 @@
import yaml
import pytest
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
'.molecule/ansible_inventory').get_hosts('all')
@pytest.fixture()
def AnsibleDefaults(Ansible):
with open("./defaults/main.yml", 'r') as stream:
return yaml.load(stream)
@pytest.mark.parametrize("dirs", [
"/minio-test"
])
def test_directories(host, dirs):
d = host.file(dirs)
assert d.is_directory
assert d.exists
assert d.user == AnsibleDefaults['minio_user']
assert d.group == AnsibleDefaults['minio_group']
assert oct(d.mode) == '0750'
@pytest.mark.parametrize('minio_bin_var', [
'minio_server_bin',
'minio_client_bin',
])
def test_minio_installed(File, AnsibleDefaults, minio_bin_var):
f = File(AnsibleDefaults[minio_bin_var])
assert f.exists
assert f.user == AnsibleDefaults['minio_user']
assert f.group == AnsibleDefaults['minio_group']
assert oct(f.mode) == '0755'
def test_minio_service(Service):
s = Service('minio')
assert s.is_running
assert s.is_enabled
def test_capabilities(host):
service_file = host.file("/etc/systemd/system/minio.service")
assert service_file.contains("AmbientCapabilities=CAP_NET_BIND_SERVICE")

View File

@ -0,0 +1,45 @@
import os
import yaml
import pytest
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
@pytest.fixture()
def AnsibleDefaults(Ansible):
with open("../../defaults/main.yml", 'r') as stream:
return yaml.load(stream)
def test_minio_server_env_file(host, AnsibleDefaults):
f = host.file('/opt/minio')
assert f.is_file
assert f.exists
assert f.user == 'root'
assert f.group == AnsibleDefaults['minio_group']
assert oct(f.mode) == '0640'
@pytest.mark.parametrize('minio_datadir', [
'/srv/data1',
'/srv/data2',
'/srv/data3',
'/srv/data4'
])
def test_minio_server_data_directories(host, AnsibleDefaults, minio_datadir):
d = host.file(minio_datadir)
assert d.is_directory
assert d.exists
assert d.user == AnsibleDefaults['minio_user']
assert d.group == AnsibleDefaults['minio_group']
assert oct(d.mode) == '0750'
def test_minio_server_webserver(host):
host.socket("tcp://127.0.0.1:80").is_listening

View File

@ -1,8 +1,13 @@
---
scenario:
name: cluster
driver:
name: docker
lint:
name: yamllint
dependency:
name: galaxy
platforms:
- name: minio-centos-7
@ -31,21 +36,26 @@ platforms:
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
provisioner:
name: ansible
lint:
name: ansible-lint
options:
diff: True
v: True
playbooks:
create: ../default/create.yml
prepare: ../default/prepare.yml
converge: playbook.yml
destroy: ../default/destroy.yml
create: ../resources/create.yml
prepare: ../resources/prepare.yml
destroy: ../resources/destroy.yml
lint:
name: yamllint
scenario:
name: cluster
verifier:
name: testinfra
options:
vvv: True
additional_files_or_dirs:
- ../resources/tests/
lint:
name: flake8
enabled: true

View File

@ -1,38 +1,30 @@
import os
import yaml
import pytest
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
'.molecule/ansible_inventory').get_hosts('all')
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
@pytest.fixture()
def AnsibleDefaults(Ansible):
with open("./defaults/main.yml", 'r') as stream:
with open("../../defaults/main.yml", 'r') as stream:
return yaml.load(stream)
@pytest.mark.parametrize("dirs", [
"/minio-test"
@pytest.mark.parametrize('minio_datadir', [
'/test1',
'/test2',
'/test3',
'/test4'
])
def test_directories(host, dirs):
d = host.file(dirs)
def test_directories(host, AnsibleDefaults, minio_datadir):
d = host.file(minio_datadir)
assert d.is_directory
assert d.exists
assert d.user == AnsibleDefaults['minio_user']
assert d.group == AnsibleDefaults['minio_group']
assert oct(d.mode) == '0750'
def test_env_file(host):
env_file = host.file("/etc/default/minio")
a = host.ansible.get_variables()
host = a['ansible_hostname']
volume_string = "MINIO_VOLUMES=\"http://%s:9091/test1 " % (host)
assert env_file.contains(volume_string)
def test_minio_service(Service):
s = Service('minio')
assert s.is_running
assert s.is_enabled

View File

@ -1,8 +1,13 @@
---
scenario:
name: default
driver:
name: docker
lint:
name: yamllint
dependency:
name: galaxy
platforms:
- name: minio-centos-7
@ -31,21 +36,26 @@ platforms:
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
provisioner:
name: ansible
lint:
name: ansible-lint
options:
diff: True
v: True
playbooks:
create: create.yml
prepare: prepare.yml
converge: playbook.yml
destroy: destroy.yml
create: ../resources/create.yml
destroy: ../resources/destroy.yml
prepare: ../resources/prepare.yml
lint:
name: yamllint
scenario:
name: default
verifier:
name: testinfra
options:
vvv: True
additional_files_or_dirs:
- ../resources/tests/
lint:
name: flake8
enabled: true

View File

@ -4,5 +4,3 @@
any_errors_fatal: true
roles:
- ansible-minio
vars:
minio_server_datadirs: [ "/minio-test" ]

View File

@ -1,5 +0,0 @@
---
- name: Prepare
hosts: all
gather_facts: false
tasks: []

View File

@ -1,44 +0,0 @@
import yaml
import pytest
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
'.molecule/ansible_inventory').get_hosts('all')
@pytest.fixture()
def AnsibleDefaults(Ansible):
with open("./defaults/main.yml", 'r') as stream:
return yaml.load(stream)
@pytest.mark.parametrize("dirs", [
"/minio-test"
])
def test_directories(host, dirs):
d = host.file(dirs)
assert d.is_directory
assert d.exists
assert d.user == AnsibleDefaults['minio_user']
assert d.group == AnsibleDefaults['minio_group']
assert oct(d.mode) == '0750'
@pytest.mark.parametrize('minio_bin_var', [
'minio_server_bin',
'minio_client_bin',
])
def test_minio_installed(File, AnsibleDefaults, minio_bin_var):
f = File(AnsibleDefaults[minio_bin_var])
assert f.exists
assert f.user == AnsibleDefaults['minio_user']
assert f.group == AnsibleDefaults['minio_group']
assert oct(f.mode) == '0755'
def test_minio_service(Service):
s = Service('minio')
assert s.is_running
assert s.is_enabled

View File

@ -0,0 +1,43 @@
import os
import yaml
import pytest
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
@pytest.fixture()
def AnsibleDefaults(Ansible):
with open("../../defaults/main.yml", 'r') as stream:
return yaml.load(stream)
@pytest.mark.parametrize('minio_bin_var', [
'minio_server_bin',
'minio_client_bin',
])
def test_minio_installed(host, AnsibleDefaults, minio_bin_var):
f = host.file(AnsibleDefaults[minio_bin_var])
assert f.exists
assert f.user == 'root'
assert f.group == 'root'
assert oct(f.mode) == '0755'
def test_minio_server_data_directories(host, AnsibleDefaults):
for datadir in AnsibleDefaults['minio_server_datadirs']:
d = host.file(datadir)
assert d.is_directory
assert d.exists
assert d.user == AnsibleDefaults['minio_user']
assert d.group == AnsibleDefaults['minio_group']
assert oct(d.mode) == '0750'
def test_minio_server_webserver(host):
host.socket("tcp://127.0.0.1:9091").is_listening

View File

@ -0,0 +1,12 @@
---
- name: Prepare
hosts: all
gather_facts: true
tasks:
- name: Install ansible support packages
package:
name: "{{ item }}"
state: present
with_items:
- ca-certificates
when: ansible_os_family == 'Debian'

View File

@ -0,0 +1,13 @@
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def test_minio_service(host):
s = host.service('minio')
assert s.is_running
assert s.is_enabled

View File

@ -1,13 +0,0 @@
---
- name: download minio client
get_url:
url: "{{ minio_client_download_url }}"
dest: "{{ minio_client_bin }}"
owner: "root"
group: "root"
mode: 0755
checksum: "sha256:{{ minio_client_checksum }}"
register: _download_client
until: _download_client is succeeded
retries: 5
delay: 2

22
tasks/install-client.yml Normal file
View File

@ -0,0 +1,22 @@
---
- name: Compose the Minio client download url
set_fact:
_minio_client_download_url: "https://dl.minio.io/client/mc/release/linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}/mc"
- name: "Get the Minio client checksum for {{ go_arch_map[ansible_architecture] | default(ansible_architecture) }} architecture"
set_fact:
_minio_client_checksum: "{{ lookup('url', _minio_client_download_url + '.sha256sum').split(' ')[0] }}"
- name: Download the Minio client
get_url:
url: "{{ _minio_client_download_url }}"
dest: "{{ minio_client_bin }}"
owner: "root"
group: "root"
mode: 0755
checksum: "sha256:{{ _minio_client_checksum }}"
register: _download_client
until: _download_client is succeeded
retries: 5
delay: 2

75
tasks/install-server.yml Normal file
View File

@ -0,0 +1,75 @@
---
- name: Compose the Minio server download url
set_fact:
_minio_server_download_url: "https://dl.minio.io/server/minio/release/linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}/minio"
- name: "Get the Minio server checksum for {{ go_arch_map[ansible_architecture] | default(ansible_architecture) }} architecture"
set_fact:
_minio_server_checksum: "{{ lookup('url', _minio_server_download_url + '.sha256sum').split(' ')[0] }}"
- name: Create Minio group
group:
name: "{{ minio_group }}"
state: present
- name: Create Minio user
user:
name: "{{ minio_user }}"
group: "{{ minio_group }}"
shell: /bin/bash
- name: Create the Minio data storage directories
file:
path: "{{ item }}"
state: directory
owner: "{{ minio_user }}"
group: "{{ minio_group }}"
mode: 0750
when: minio_server_make_datadirs
with_items: "{{ minio_server_datadirs }}"
- name: Download the Minio server
get_url:
url: "{{ _minio_server_download_url }}"
dest: "{{ minio_server_bin }}"
owner: "root"
group: "root"
mode: 0755
checksum: "sha256:{{ _minio_server_checksum }}"
register: _download_server
until: _download_server is succeeded
retries: 5
delay: 2
- name: Generate the Minio server envfile
template:
src: minio.env.j2
dest: "{{ minio_server_envfile }}"
owner: "root"
group: "{{ minio_group }}"
mode: 0640
notify: restart minio
- name: Create the Minio server systemd config
template:
src: minio.service.j2
dest: "/etc/systemd/system/minio.service"
owner: "root"
group: "root"
when: ansible_service_mgr == "systemd"
- name: Create the Minio server init.d config
template:
src: minio.init.j2
dest: "/etc/init.d/minio"
owner: "root"
group: "root"
mode: 0750
when: ansible_service_mgr != "systemd"
- name: Enable and start the Minio service
service:
name: minio
state: started
enabled: true

View File

@ -1,38 +1,14 @@
---
- include: preflight.yml
- name: add the python sni support to legacy python installations
- name: Add sni support to legacy python installations
include: python_sni.yml
when:
- ansible_os_family == 'Debian'
- ansible_python_version is version_compare('2.6.0', '>=')
- ansible_python_version is version_compare('2.7.9', '<')
- name: install ansible support packages
package:
name: "{{ item }}"
state: present
with_items:
- ca-certificates
register: _install_packages
until: _install_packages is succeeded
retries: 5
delay: 2
when: ansible_os_family == 'Debian'
- name: create minio group
group:
name: "{{ minio_group }}"
state: present
- name: create minio user
user:
name: "{{ minio_user }}"
group: "{{ minio_group }}"
shell: /bin/bash
- include: server.yml
- include: install-server.yml
when: minio_install_server
- include: client.yml
- include: install-client.yml
when: minio_install_client

View File

@ -1,22 +0,0 @@
---
- block:
- name: Compose Minio download url
set_fact:
minio_server_download_url: "https://dl.minio.io/server/minio/release/linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}/minio"
- name: "Minio server checksum for {{ go_arch_map[ansible_architecture] | default(ansible_architecture) }} architecture"
set_fact:
minio_server_checksum: "{{ lookup('url', minio_server_download_url + '.sha256sum').split(' ')[0] }}"
when:
- minio_install_server
- block:
- name: Compose MC download url
set_fact:
minio_client_download_url: "https://dl.minio.io/client/mc/release/linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}/mc"
- name: "Minio client checksum for {{ go_arch_map[ansible_architecture] | default(ansible_architecture) }} architecture"
set_fact:
minio_client_checksum: "{{ lookup('url', minio_client_download_url + '.sha256sum').split(' ')[0] }}"
when:
- minio_install_client

View File

@ -1,4 +1,5 @@
---
- name: install python-pip and SNI support packages
package:
name: "{{ item }}"

View File

@ -1,59 +0,0 @@
---
- name: create minio group
group:
name: "{{ minio_group }}"
state: present
- name: create minio user
user:
name: "{{ minio_user }}"
group: "{{ minio_group }}"
shell: /bin/bash
- name: create data storage directories
file:
path: "{{ item }}"
state: directory
owner: "{{ minio_user }}"
group: "{{ minio_group }}"
mode: 0750
when: minio_server_make_datadirs
with_items: "{{ minio_server_datadirs }}"
- name: download minio server
get_url:
url: "{{ minio_server_download_url }}"
dest: "{{ minio_server_bin }}"
owner: "root"
group: "root"
mode: 0755
checksum: "sha256:{{ minio_server_checksum }}"
register: _download_server
until: _download_server is succeeded
retries: 5
delay: 2
- name: generate the minio server envfile
template:
src: minio.env.j2
dest: "{{ minio_server_envfile }}"
notify: restart minio
- name: create the minio server systemd config
template:
src: minio.service.j2
dest: "/etc/systemd/system/minio.service"
when: ansible_service_mgr == "systemd"
- name: create the minio server init.d config
template:
src: minio.init.j2
dest: "/etc/init.d/minio"
mode: 0750
when: ansible_service_mgr != "systemd"
- name: enable and start the minio service
service:
name: minio
state: started
enabled: true

View File

@ -1,6 +1,6 @@
[tox]
minversion = 1.8
envlist = py{27}-ansible{23,24,25}
envlist = py{27}-ansible{23,24,25,26}
skipsdist = true
[travis:env]
@ -8,6 +8,7 @@ ANSIBLE=
2.3: ansible23
2.4: ansible24
2.5: ansible25
2.6: ansible26
[testenv]
passenv = *
@ -16,5 +17,6 @@ deps =
ansible23: ansible<2.4
ansible24: ansible<2.5
ansible25: ansible<2.6
ansible26: ansible<2.7
commands =
{posargs:molecule test --all --destroy always}