示例#1
0
def assert_provider_host_states(bundle: Bundle, statemap: dict):
    for pname, pv in statemap.items():
        pstate = bundle.provider(name=pname).state
        pstate_expected = pv['state']
        expect(
            pstate == pstate_expected,
            f"Provider \"{pname}\" is \"{pstate}\" while expected \"{pstate_expected}\""
        )
        for hname, hstate_expected in pv['hosts'].items():
            hstate = bundle.provider(name=pname).host(fqdn=hname).state
            expect(hstate == hstate_expected,
                   f'Host state is {hstate} while expected {hstate_expected}')
    assert_expectations()
示例#2
0
def test_change_provider_state(host_bundle: Bundle):
    expected_state = copy.deepcopy(INITIAL_HOST_STATE)
    assert_provider_host_states(host_bundle, expected_state)
    with allure.step('Run second host action: set state'):
        second = host_bundle.provider(name='second')
        second.action(name='set_state').run().try_wait()
    expected_state['second']['state'] = 'pstatex'
    assert_provider_host_states(host_bundle, expected_state)
示例#3
0
def assert_provider_config(bundle: Bundle, statemap: dict):
    for pname, plv in statemap.items():
        actual_cnf = bundle.provider(name=pname).config()
        expected_cnf = plv['config']
        for k, v in expected_cnf.items():
            expect(
                v == actual_cnf[k],
                'Provider {} config "{}" is "{}" while expected "{}"'.format(
                    pname, k, str(actual_cnf[k]), str(v)))
        for hname, host_expected_cnf in plv['hosts'].items():
            host_actual_cnf = bundle.provider(name=pname).host(
                fqdn=hname).config()
            for k, v in host_expected_cnf.items():
                expect(
                    v == host_actual_cnf[k],
                    'Provider {} host {} config {} is {} while expected {}'.
                    format(pname, hname, k, str(host_actual_cnf[k]), str(v)))
    assert_expectations()
示例#4
0
def test_change_host_from_provider_state(host_bundle: Bundle):
    expected_state = copy.deepcopy(INITIAL_HOST_STATE)
    assert_provider_host_states(host_bundle, expected_state)
    with allure.step('Run second host action: set host state'):
        second = host_bundle.provider(name='second')
        second.action(name='set_host_state').run(config={
            "fqdn": "second_host2"
        }).try_wait()
    expected_state['second']['hosts']['second_host2'] = 'stateq'
    assert_provider_host_states(host_bundle, expected_state)
示例#5
0
def test_change_host_state(host_bundle: Bundle):
    expected_state = copy.deepcopy(INITIAL_HOST_STATE)
    assert_provider_host_states(host_bundle, expected_state)
    first = host_bundle.provider(name='first')
    second = host_bundle.provider(name='second')
    with allure.step('Run first host action: set host'):
        first.host(fqdn='first_host1').action(name='set_host').run().try_wait()
    expected_state['first']['hosts']['first_host1'] = 'statez'
    assert_provider_host_states(host_bundle, expected_state)
    with allure.step('Run second host action: set host'):
        second.host(fqdn='second_host1').action(
            name='set_host').run().try_wait()
    expected_state['second']['hosts']['second_host1'] = 'statez'
    assert_provider_host_states(host_bundle, expected_state)
    with allure.step('Change second host'):
        second.host(fqdn='second_host3').action(
            name='set_host').run().try_wait()
    expected_state['second']['hosts']['second_host3'] = 'statez'
    assert_provider_host_states(host_bundle, expected_state)
示例#6
0
def test_provider_config(provider_bundle: Bundle):
    expected_state = copy.deepcopy(INITIAL_PROVIDERS_CONFIG)
    assert_provider_config(provider_bundle, expected_state)
    with allure.step('Check provider config'):
        for key, pname in sparse_matrix(KEYS, PROVIDERS):
            provider = provider_bundle.provider(name=pname)
            provider.action(name='provider_' + key).run().try_wait()
            expected_state[pname]["config"][key] = NEW_VALUES[key]

    assert_provider_config(provider_bundle, expected_state)
示例#7
0
def test_host_config(provider_bundle: Bundle):
    expected_state = copy.deepcopy(INITIAL_PROVIDERS_CONFIG)
    assert_provider_config(provider_bundle, expected_state)
    with allure.step('Check host config'):
        for key, pname, host_idx in sparse_matrix(KEYS, PROVIDERS, [0, 1]):
            provider = provider_bundle.provider(name=pname)
            fqdn = list(
                INITIAL_PROVIDERS_CONFIG[pname]['hosts'].keys())[host_idx]
            host = provider.host(fqdn=fqdn)
            host.action(name='host_' + key).run().try_wait()
            expected_state[pname]["hosts"][fqdn][key] = NEW_VALUES[key]
            assert_provider_config(provider_bundle, expected_state)
示例#8
0
def forth_p(bundle: Bundle):
    """Forth provider"""
    return bundle.provider(name="forth_p")
示例#9
0
def third_p(bundle: Bundle):
    """Third provider"""
    return bundle.provider(name="third_p")
示例#10
0
def second_p(bundle: Bundle):
    """Second provider"""
    return bundle.provider(name="second_p")
示例#11
0
def first_p(bundle: Bundle):
    """First provider"""
    return bundle.provider(name="first_p")