summaryrefslogtreecommitdiffstats
path: root/ansible/roles/docker/molecule/default/tests/test_default.py
blob: fc87a6c854beb69347384bf8cd8e051c82a6947e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import pytest
import json

import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')


@pytest.mark.parametrize('os_family, packages', [
    ('debian', ['python3-docker', 'python3-json-pointer', 'iproute2',
                'docker-ce']),
    ('centos', ['python-docker-py', 'python-jsonpointer', 'docker-ce'])
])
def test_packages_installed(host, os_family, packages):
    if host.system_info.distribution == os_family:
        for package in packages:
            assert host.package(package).is_installed


@pytest.mark.parametrize('svc', [
    'docker'
])
def test_service(host, svc):
    service = host.service(svc)

    assert service.is_running
    assert service.is_enabled


def test_docker_daemon_file(host):
    f = host.file('/etc/docker/daemon.json')

    assert f.exists
    assert f.user == 'root'
    assert f.group == 'root'
    print(f.content_string)
    json_data = json.loads(f.content_string)
    assert json_data["log-driver"] == "json-file"
    assert json_data["log-opts"]["max-size"] == "100m"
    assert json_data["log-opts"]["max-file"] == "3"
    assert json_data["dns"][0] == "1.2.3.4"