Ejemplo n.º 1
0
def test_from_host_actions(two_clusters: Tuple[Cluster, Cluster],
                           two_providers: Tuple[Provider, Provider],
                           sdk_client_fs: ADCMClient):
    """Test that host actions actually change config"""
    name = "first"
    affected_objects = set()
    check_config_changed_local = build_objects_checker(
        extractor=get_config,
        changed={
            **INITIAL_CONFIG, 'int': CHANGED_CONFIG['int']
        },
        field_name='Config')
    with allure.step('Bind component to host'):
        component = (service :=
                     (cluster :=
                      two_clusters[0]).service(name=name)).component(name=name)
        host = two_providers[0].host_list()[0]
        cluster.host_add(host)
        cluster.hostcomponent_set((host, component))
    for obj in (cluster, service, component):
        affected_objects.add(obj)
        classname = obj.__class__.__name__.lower()
        with check_config_changed_local(
                sdk_client_fs, affected_objects), allure.step(
                    f'Check change {compose_name(obj)} config from host action'
                ):
            run_host_action_and_assert_result(host, f'change_{classname}_host')
Ejemplo n.º 2
0
def test_double_call_to_multi_state_set(two_clusters: Tuple[Cluster, Cluster],
                                        sdk_client_fs: ADCMClient):
    """Test that double call to plugin from two files doesn't fail"""
    check_multi_state_after_set = build_objects_checker(
        sorted(['much', 'better', 'actually']),
        extractor=_multi_state_extractor,
        field_name=FIELD_NAME)
    check_multi_state_after_unset = build_objects_checker(
        ['actually'], extractor=_multi_state_extractor, field_name=FIELD_NAME)
    cluster = two_clusters[0]
    with allure.step(SET_STEP_TITLE):
        with check_multi_state_after_set(sdk_client_fs, {cluster}):
            run_cluster_action_and_assert_result(cluster,
                                                 'double_call_two_playbooks')
    with allure.step(UNSET_STEP_TITLE):
        with check_multi_state_after_unset(sdk_client_fs, {cluster}):
            run_cluster_action_and_assert_result(cluster, 'double_unset')
Ejemplo n.º 3
0
def cluster_and_multi_states_checker(sdk_client_fs: ADCMClient,
                                     request) -> Tuple[Cluster, Callable]:
    """Create cluster and multi states checker"""
    bundle = sdk_client_fs.upload_from_fs(request.param)
    cluster = bundle.cluster_create(name=bundle.name)
    bundle.cluster_create(name=f"{bundle.name}_second")
    check_objects_state_changed = build_objects_checker(
        field_name='Multi state',
        changed=[cluster.name],
        extractor=lambda obj: sorted(obj.multi_state),
    )
    return cluster, check_objects_state_changed
Ejemplo n.º 4
0
def provider_and_states_checker(sdk_client_fs: ADCMClient,
                                request) -> Tuple[Provider, Callable]:
    """Create provider and states checker"""
    bundle = sdk_client_fs.upload_from_fs(request.param)
    provider = bundle.provider_create(name=bundle.name)
    bundle.provider_create(name=f"{bundle.name}_second")
    provider.host_create(fqdn=bundle.name)
    provider.host_create(fqdn=f"{bundle.name}_second")
    check_objects_state_changed = build_objects_checker(
        field_name='State',
        changed=bundle.name,
        extractor=lambda obj: obj.state,
    )
    return provider, check_objects_state_changed
Ejemplo n.º 5
0
def provider_and_multi_states_plus_states_checker(
        sdk_client_fs: ADCMClient, request) -> Tuple[Provider, Callable]:
    """Create provider and multi state plus state checker"""
    bundle = sdk_client_fs.upload_from_fs(request.param)
    provider = bundle.provider_create(name=bundle.name)
    bundle.provider_create(name=f"{bundle.name}_second")
    provider.host_create(fqdn=bundle.name)
    provider.host_create(fqdn=f"{bundle.name}_second")
    check_objects_state_changed = build_objects_checker(
        field_name='Multi states and states',
        changed=dict(state=bundle.name, multi_states=[bundle.name]),
        extractor=lambda obj: dict(state=obj.state,
                                   multi_states=sorted(obj.multi_state)),
    )
    return provider, check_objects_state_changed
Ejemplo n.º 6
0
 def test_upgrade_dirty_adcm(
     self,
     adcm_fs: ADCM,
     sdk_client_fs: ADCMClient,
     adcm_api_credentials: dict,
     upgrade_target: Tuple[str, str],
     dirty_adcm: dict,
 ):
     """
     Create previous version ADCM with a lot of different objects.
     Upgrade ADCM.
     Run actions on ADCM.
     """
     objects_are_not_changed = build_objects_checker(changed=None, extractor=_get_object_fields)
     with allure.step('Upgrade ADCM and expect all objects to be same'), objects_are_not_changed(
         sdk_client_fs
     ), self.check_job_related_objects_are_not_changed(sdk_client_fs):
         upgrade_adcm_version(adcm_fs, sdk_client_fs, adcm_api_credentials, upgrade_target)
     self.run_actions_after_upgrade(
         dirty_adcm['complex']['clusters']['all_services'],
         dirty_adcm['complex']['clusters']['config_history'],
         dirty_adcm['simple']['providers'][0],
     )
Ejemplo n.º 7
0
from tests.functional.plugin_utils import (
    build_objects_checker,
    generate_cluster_success_params,
    get_cluster_related_object,
    compose_name,
    generate_provider_success_params,
    get_provider_related_object,
    create_two_providers,
    create_two_clusters,
    run_successful_task,
    TestImmediateChange,
)

check_objects_state_changed = build_objects_checker(
    field_name='State',
    changed='ifeelgood!',
    extractor=lambda obj: obj.state,
)

# !===== Fixtures =====!


@pytest.fixture()
def two_providers(sdk_client_fs: ADCMClient) -> Tuple[Provider, Provider]:
    """Get two providers with two hosts"""
    return create_two_providers(sdk_client_fs, __file__, "hostprovider")


@pytest.fixture()
def two_clusters(request,
                 sdk_client_fs: ADCMClient) -> Tuple[Cluster, Cluster]:
Ejemplo n.º 8
0
        "x": "new"
    }, {
        "y": "z"
    }],
    'dummy': 'donthurtme',
    "map": {
        "one": "two",
        "two": "new"
    },
    "list": ["one", "new", "three"],
}
CONFIG_KEYS = set(CHANGED_CONFIG.keys())

check_config_changed = build_objects_checker(
    field_name='Config',
    changed=CHANGED_CONFIG,
    extractor=get_config,
)


@pytest.fixture()
def two_clusters(request,
                 sdk_client_fs: ADCMClient) -> Tuple[Cluster, Cluster]:
    """Get two clusters with both services"""
    bundle_dir = "cluster" if not hasattr(request, 'param') else request.param
    return create_two_clusters(sdk_client_fs, __file__, bundle_dir)


@pytest.fixture()
def two_providers(sdk_client_fs: ADCMClient) -> Tuple[Provider, Provider]:
    """Get two providers with two hosts"""
Ejemplo n.º 9
0
    create_two_clusters,
    create_two_providers,
    run_successful_task,
    TestImmediateChange,
)

# pylint: disable=redefined-outer-name, duplicate-code

FIELD_NAME = 'Multi state'
SET_STEP_TITLE = 'Set multi state'
UNSET_STEP_TITLE = 'Unset multi state'

# Prepare common functions for working with ADCM objects state

check_objects_multi_state_changed = build_objects_checker(
    field_name=FIELD_NAME,
    changed=['ifeelgood!'],
    extractor=(_multi_state_extractor := lambda obj: sorted(obj.multi_state)),
)
check_multi_state_was_unset = build_objects_checker(
    field_name=FIELD_NAME, changed=[], extractor=_multi_state_extractor)

# !===== Fixtures =====!


@pytest.fixture()
def two_clusters(request,
                 sdk_client_fs: ADCMClient) -> Tuple[Cluster, Cluster]:
    """Get two clusters with both services"""
    return create_two_clusters(
        sdk_client_fs,
        caller_file=__file__,