summaryrefslogtreecommitdiffstats
path: root/ansible/roles/certificates/molecule/default/tests/test_infrastructure.py
blob: 6a0aec030c8359f8c838cf271fb09f84159c856b (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
import os
import pytest

import testinfra.utils.ansible_runner

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


@pytest.fixture
def group_vars(host):
    all_file = "file=group_vars/all.yml name=all"
    return host.ansible("include_vars", all_file)["ansible_facts"]["all"]


@pytest.mark.parametrize('cert_file', [
    'nexus_server.crt',
    'nexus_server.csr',
    'nexus_server.key',
    'rootCA.crt',
    'rootCA.csr',
    'rootCA.key'
])
def test_generated_cert_files_copied_to_infra(host, cert_file, group_vars):
    f = host.file(group_vars["app_data_path"] + '/certs/' + cert_file)
    assert f.exists
    assert f.user == 'root'
    assert f.group == 'root'

    os = host.system_info.distribution
    if (os == "centos"):
        node_directory = "certs/"
    elif (os == "ubuntu"):
        node_directory = "../default/certs/"

    # Verify cert files content locally is as in node
    with open(node_directory + cert_file) as local_cert_file:
        local_content = local_cert_file.read().strip()
    assert local_content == f.content_string