summaryrefslogtreecommitdiffstats
path: root/roles/openshift_health_checker/test/package_availability_test.py
blob: 9815acb380076c2621b90b961b315e5fde982fb8 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import pytest

from openshift_checks.package_availability import PackageAvailability


@pytest.mark.parametrize('pkg_mgr,is_containerized,is_active', [
    ('yum', False, True),
    ('yum', True, False),
    ('dnf', True, False),
    ('dnf', False, False),
])
def test_is_active(pkg_mgr, is_containerized, is_active):
    task_vars = dict(
        ansible_pkg_mgr=pkg_mgr,
        openshift=dict(common=dict(is_containerized=is_containerized)),
    )
    assert PackageAvailability(None, task_vars).is_active() == is_active


@pytest.mark.parametrize('task_vars,must_have_packages,must_not_have_packages', [
    (
        dict(openshift=dict(common=dict(service_type='openshift'))),
        set(),
        set(['openshift-master', 'openshift-node']),
    ),
    (
        dict(
            openshift=dict(common=dict(service_type='origin')),
            group_names=['oo_masters_to_config'],
        ),
        set(['origin-master']),
        set(['origin-node']),
    ),
    (
        dict(
            openshift=dict(common=dict(service_type='atomic-openshift')),
            group_names=['oo_nodes_to_config'],
        ),
        set(['atomic-openshift-node']),
        set(['atomic-openshift-master']),
    ),
    (
        dict(
            openshift=dict(common=dict(service_type='atomic-openshift')),
            group_names=['oo_masters_to_config', 'oo_nodes_to_config'],
        ),
        set(['atomic-openshift-master', 'atomic-openshift-node']),
        set(),
    ),
])
def test_package_availability(task_vars, must_have_packages, must_not_have_packages):
    return_value = {}

    def execute_module(module_name=None, module_args=None, *_):
        assert module_name == 'check_yum_update'
        assert 'packages' in module_args
        assert set(module_args['packages']).issuperset(must_have_packages)
        assert not set(module_args['packages']).intersection(must_not_have_packages)
        return {'foo': return_value}

    result = PackageAvailability(execute_module, task_vars).run()
    assert result['foo'] is return_value