Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved tasks and tests layout #25

Merged
merged 4 commits into from
Aug 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ services:

env:
matrix:
- ANSIBLE=2.3
- ANSIBLE=2.4
- ANSIBLE=2.5
- ANSIBLE=2.6

# Install tox
install:
Expand Down
15 changes: 11 additions & 4 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -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
29 changes: 20 additions & 9 deletions molecule/alternative/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
---

scenario:
name: alternative

driver:
name: docker
lint:
name: yamllint

dependency:
name: galaxy

platforms:
- name: minio-centos-7
Expand Down Expand Up @@ -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
49 changes: 0 additions & 49 deletions molecule/alternative/tests/test_minio.py

This file was deleted.

45 changes: 45 additions & 0 deletions molecule/alternative/tests/test_minio_alternative.py
Original file line number Diff line number Diff line change
@@ -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
30 changes: 20 additions & 10 deletions molecule/cluster/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
---

scenario:
name: cluster

driver:
name: docker
lint:
name: yamllint

dependency:
name: galaxy

platforms:
- name: minio-centos-7
Expand Down Expand Up @@ -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
32 changes: 12 additions & 20 deletions molecule/cluster/tests/test_minio_cluster.py
Original file line number Diff line number Diff line change
@@ -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
30 changes: 20 additions & 10 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
---

scenario:
name: default

driver:
name: docker
lint:
name: yamllint

dependency:
name: galaxy

platforms:
- name: minio-centos-7
Expand Down Expand Up @@ -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
2 changes: 0 additions & 2 deletions molecule/default/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@
any_errors_fatal: true
roles:
- ansible-minio
vars:
minio_server_datadirs: [ "/minio-test" ]
5 changes: 0 additions & 5 deletions molecule/default/prepare.yml

This file was deleted.

44 changes: 0 additions & 44 deletions molecule/default/tests/test_minio.py

This file was deleted.

Loading