Exemple #1
0
def test_forbidden_multi_state_set_actions(sdk_client_fs: ADCMClient):
    """
    Check that forbidden caller-context combinations fail as actions
        and don't affect any ADCM objects
    """
    name = "first"
    with allure.step(f'Check forbidden from cluster "{name}" context actions'):
        cluster = sdk_client_fs.cluster(name=name)
        # missing is used because it should fail for misconfiguration reasons, not because state not set
        for forbidden_action in ('set_service', 'set_component',
                                 'unset_service_missing',
                                 'unset_component_missing'):
            with check_objects_multi_state_changed(sdk_client_fs):
                run_cluster_action_and_assert_result(cluster,
                                                     forbidden_action,
                                                     status='failed')
    with allure.step(f'Check forbidden from service "{name}" context actions'):
        service = cluster.service(name=name)
        for forbidden_action in ('set_component', 'unset_component_missing'):
            with check_objects_multi_state_changed(sdk_client_fs):
                run_service_action_and_assert_result(service,
                                                     forbidden_action,
                                                     status='failed')
    with allure.step(
            f'Check forbidden from provider "{name}" context actions'):
        provider = sdk_client_fs.provider(name=name)
        for forbidden_action in ('set_host', 'unset_host_missing'):
            with check_objects_multi_state_changed(sdk_client_fs):
                run_provider_action_and_assert_result(provider,
                                                      forbidden_action,
                                                      status='failed')
Exemple #2
0
def test_upgrade_cluster_with_export(sdk_client_fs: ADCMClient):
    """Scenario:
    1. Create cluster for upgrade with export
    2. Create cluster for upgrade with import
    3. Load upgradable bundle with import
    4. Bind service and cluster
    5. Upgrade cluster with import
    6. Check that cluster was upgraded
    """
    with allure.step('Create cluster for upgrade with exports'):
        bundle = sdk_client_fs.upload_from_fs(
            get_data_dir(__file__, 'cluster_with_export'))
        cluster = bundle.cluster_create("test")
        service = cluster.service_add(name="hadoop")
    with allure.step(
            'Create cluster for upgrade with imports. Load upgradable bundle with import'
    ):
        bundle_import = sdk_client_fs.upload_from_fs(
            get_data_dir(__file__, 'upgrade_cluster_with_import'))
        sdk_client_fs.upload_from_fs(
            get_data_dir(__file__, 'upgradable_cluster_with_import'))
        cluster_import = bundle_import.cluster_create("cluster_import")
    bind_service_and_cluster(cluster_import, service, cluster)
    with allure.step('Upgrade cluster with import to 1.6'):
        upgr = cluster_import.upgrade(name='upgrade to 1.6')
        id_before = cluster_import.prototype_id
        upgr.do()
    with allure.step('Check that cluster was upgraded'):
        cluster_import.reread()
        assert cluster_import.prototype().version == '1.6'
        assert cluster_import.prototype_id != id_before
Exemple #3
0
def create_action_policy(
    client: ADCMClient,
    adcm_object: Union[AnyADCMObject, List[AnyADCMObject]],
    *business_roles: BusinessRole,
    user=None,
    group=None,
) -> Policy:
    """Create policy based on business roles"""
    if not (user or group):
        raise ValueError(
            "Either user or group should be provided to create policy")
    user = user or []
    group = group or []
    child_roles = [{
        'id': client.role(name=role.role_name).id
    } for role in business_roles]
    role_name = f"Test Action Role {random_string(6)}"
    action_parent_role = client.role_create(name=role_name,
                                            display_name=role_name,
                                            child=child_roles)
    return client.policy_create(
        name=f"Test Action Policy {role_name[-6:]}",
        role=action_parent_role,
        objects=adcm_object
        if isinstance(adcm_object, list) else [adcm_object],
        user=user if isinstance(user, list) else [user],
        group=group if isinstance(group, list) else [group],
    )
def test_check_config(sdk_client_fs: ADCMClient):
    """Check default service and cluster config fields after upgrade
    :return:
    """
    with allure.step('Create upgradable cluster'):
        bundle = sdk_client_fs.upload_from_fs(get_data_dir(
            __file__, 'cluster'))
        sdk_client_fs.upload_from_fs(
            get_data_dir(__file__, 'upgradable_cluster'))
        cluster = bundle.cluster_create("test")
        service = cluster.service_add(name="zookeeper")
        cluster_config_before = cluster.config()
        service_config_before = service.config()
    with allure.step('Upgrade cluster to 1.6'):
        upgr = cluster.upgrade(name='upgrade to 1.6')
        upgr.do()
    with allure.step('Check config'):
        cluster.reread()
        service.reread()
        cluster_config_after = cluster.config()
        service_config_after = service.config()
        assert cluster.prototype().version == '1.6'
        assert service.prototype().version == '3.4.11'
        for variable in cluster_config_before:
            assert cluster_config_before[variable] == cluster_config_after[
                variable]
        for variable in service_config_before:
            assert service_config_before[variable] == service_config_after[
                variable]
Exemple #5
0
def test_upgrade_cluster_without_service_config_in_import(
        sdk_client_fs: ADCMClient):
    """Upgrade cluster with service when in new cluster when
    we haven't some service configuration variables
    Scenario:
    1. Create cluster for upgrade with export
    2. Create upgradable cluster with import and without config in import
    3. Bind service from cluster with export to cluster with import
    4. Upgrade cluster with export
    5. Check upgrade error
    """
    with allure.step(
            'Create cluster for upgrade with exports and cluster without config in import'
    ):
        bundle = sdk_client_fs.upload_from_fs(
            get_data_dir(__file__, 'upgrade_cluster_with_export'))
        bundle_import = sdk_client_fs.upload_from_fs(
            get_data_dir(__file__, 'upgradable_cluster_without_service'))
        cluster = bundle.cluster_create("test")
        service = cluster.service_add(name="hadoop")
        cluster_import = bundle_import.cluster_create("cluster_import")
    with allure.step(
            'Bind service from cluster with export to cluster with import'):
        cluster_import.bind(service)
        cluster_import.bind(cluster)
    with allure.step('Upgrade cluster with export'):
        upgr = cluster.upgrade(name='upgrade to 1.6')
        with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
            upgr.do()
    with allure.step('Check upgrade error'):
        err.UPGRADE_ERROR.equal(e)
def test_changed_variable_type(sdk_client_fs: ADCMClient):
    """Change config variable type for upgrade

    :param sdk_client_fs:
    :return:
    """
    with allure.step('Create upgradable cluster with change variable type'):
        bundle = sdk_client_fs.upload_from_fs(get_data_dir(
            __file__, 'cluster'))
        sdk_client_fs.upload_from_fs(
            get_data_dir(__file__, 'upgradable_cluster_change_variable_type'))
        cluster = bundle.cluster_create("test")
        service = cluster.service_add(name="zookeeper")
        cluster_config_before = cluster.config()
        service_config_before = service.config()
    with allure.step('Upgrade cluster with change variable type to 1.6'):
        upgr = cluster.upgrade(name='upgrade to 1.6')
        upgr.do()
    with allure.step('Check changed variable type'):
        cluster.reread()
        service.reread()
        cluster_config_after = cluster.config()
        service_config_after = service.config()
        assert isinstance(cluster_config_after['required'], str)
        assert isinstance(service_config_after['required_service'], str)
        assert int(cluster_config_after['required']
                   ) == cluster_config_before['required']
        assert int(service_config_after['required_service']
                   ) == service_config_before['required_service']
def test_change_config(sdk_client_fs: ADCMClient):
    """Upgrade cluster with other config
    """
    with allure.step('Create upgradable cluster with new change values'):
        bundle = sdk_client_fs.upload_from_fs(get_data_dir(
            __file__, 'cluster'))
        sdk_client_fs.upload_from_fs(
            get_data_dir(__file__, 'upgradable_cluster_new_change_values'))
        cluster = bundle.cluster_create("test")
        service = cluster.service_add(name="zookeeper")
    with allure.step('Set cluster and service config'):
        cluster_config_before = cluster.config()
        service_config_before = service.config()
        cluster_config_before['required'] = 25
        cluster_config_before['int_key'] = 245
        cluster_config_before['str-key'] = "new_value"
        service_config_before['required_service'] = 20
        service_config_before['int_key_service'] = 333
        cluster.config_set(cluster_config_before)
        service.config_set(service_config_before)
    with allure.step('Upgrade cluster with new change values to 1.6'):
        upgr = cluster.upgrade(name='upgrade to 1.6')
        upgr.do()
    with allure.step('Check upgraded cluster and service'):
        cluster.reread()
        service.reread()
        cluster_config_after = cluster.config()
        service_config_after = service.config()
        assert len(cluster_config_before.keys()) == len(
            cluster_config_after.keys())
        for key in cluster_config_before:
            assert cluster_config_before[key] == cluster_config_after[key]
        for key in service_config_before:
            assert service_config_before[key] == service_config_after[key]
Exemple #8
0
def test_check_cluster_bundle_versions_as_a_string(sdk_client_fs: ADCMClient):
    stack_dir = utils.get_data_dir(__file__, 'cluster_service_versions_as_a_string')
    sdk_client_fs.upload_from_fs(stack_dir)
    with allure.step('Check bundle versions'):
        prototype = random.choice(sdk_client_fs.service_prototype_list())
        assert isinstance(prototype.version, str) is True
        assert isinstance(prototype.version, str) is True
Exemple #9
0
def test_load_bundle_with_undefined_config_parameter(sdk_client_fs: ADCMClient):
    stack_dir = utils.get_data_dir(__file__, 'param_not_defined')
    with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
        sdk_client_fs.upload_from_fs(stack_dir)
    with allure.step('Check error: should be a map'):
        errorcodes.INVALID_CONFIG_DEFINITION.equal(e, 'Config definition of cluster',
                                                   'should be a map')
Exemple #10
0
def _test_related_hc(client: ADCMClient, case_path: str):
    with allure.step("Upload custom provider bundle and create it in ADCM"):
        provider_bundle = client.upload_from_fs(
            get_data_dir(__file__) + "/provider")
        provider = provider_bundle.provider_prototype().provider_create(
            random_string())
    with allure.step("Upload custom cluster bundle and create it in ADCM"):
        bundle_path = case_path.split(CASES_PATH)[0]
        cluster_bundle = client.upload_from_fs(bundle_path)
        created_cluster = cluster_bundle.cluster_prototype().cluster_create(
            random_string())
    with allure.step(
            "Parse case description from YAML file and set host-component map"
    ):
        with open(case_path, encoding='utf_8') as file:
            case_template = yaml.safe_load(file)
        allure.dynamic.description(case_template["description"])
        hostcomponent_list = []
        for host in case_template["hc_map"].keys():
            added_host = created_cluster.host_add(
                provider.host_create(fqdn=f"fqdn_{random_string()}"))
            for service_with_component in case_template["hc_map"][host]:
                service_name, component_name = service_with_component.split(
                    ".")
                service = _get_or_add_service(created_cluster, service_name)
                hostcomponent_list.append(
                    (added_host, service.component(name=component_name)))
        expectation = _does_not_raise(
        ) if case_template["positive"] else pytest.raises(ErrorMessage)
        with expectation:
            created_cluster.hostcomponent_set(*hostcomponent_list)
Exemple #11
0
def test_config_has_one_definition_and_two_diff_types(sdk_client_fs: ADCMClient, entity):
    name = 'cluster_has_a_' + entity + '_definition'
    stack_dir = utils.get_data_dir(__file__, name)
    with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
        sdk_client_fs.upload_from_fs(stack_dir)
    with allure.step('Check error: definition in cluster type bundle'):
        errorcodes.BUNDLE_ERROR.equal(e, entity + ' definition in cluster type bundle')
Exemple #12
0
def test_check_prototype(sdk_client_fs: ADCMClient):
    """Check prototype for provider and host after upgrade"""
    with allure.step('Create upgradable hostprovider and get id'):
        bundle = sdk_client_fs.upload_from_fs(
            get_data_dir(__file__, 'hostprovider'))
        sdk_client_fs.upload_from_fs(
            get_data_dir(__file__, 'upgradable_hostprovider'))
        hostprovider = bundle.provider_create("test")
        host = hostprovider.host_create(fqdn="localhost")
        hostprovider_proto_before = hostprovider.prototype()
        hp_id_before = hostprovider.id
        host_proto_before = host.prototype()
        ht_id_before = host.id
    with allure.step('Upgrade hostprovider to 2.0'):
        upgr = hostprovider.upgrade(name='upgrade to 2.0')
        upgr.do()
    with allure.step('Check prototype for provider and host after upgrade'):
        hostprovider.reread()
        host.reread()
        hostprovider_proto_after = hostprovider.prototype()
        host_proto_after = host.prototype()
        assert hp_id_before == hostprovider.id
        assert ht_id_before == host.id
        assert hostprovider_proto_before.id != hostprovider_proto_after.id
        assert host_proto_before.id != host_proto_after.id
Exemple #13
0
def test_change_config(sdk_client_fs: ADCMClient):
    """Upgrade hostprovider with other config"""
    with allure.step('Create upgradable hostprovider with new change values'):
        bundle = sdk_client_fs.upload_from_fs(
            get_data_dir(__file__, 'hostprovider'))
        sdk_client_fs.upload_from_fs(
            get_data_dir(__file__,
                         'upgradable_hostprovider_new_change_values'))
        hostprovider = bundle.provider_create("test")
    host = create_host(hostprovider)
    hostprovider_config_before = hostprovider.config()
    host_config_before = host.config()
    hostprovider_config_before['required'] = 25
    hostprovider_config_before['str-key'] = "new_value"
    host_config_before['str_param'] = "str_param_new"
    with allure.step('Set config'):
        hostprovider.config_set(hostprovider_config_before)
        host.config_set(host_config_before)
    with allure.step('Upgrade hostprovider with other config'):
        upgr = hostprovider.upgrade(name='upgrade to 2.0')
        upgr.do()
    with allure.step('Check hostprovider config'):
        hostprovider.reread()
        host.reread()
        hostprovider_config_after = hostprovider.config()
        host_config_after = host.config()
        assert len(hostprovider_config_before.keys()) == len(
            hostprovider_config_after.keys())
        for key in hostprovider_config_before:
            assert hostprovider_config_before[
                key] == hostprovider_config_after[key]
        for key in host_config_before:
            assert host_config_before[key] == host_config_after[key]
Exemple #14
0
def test_upgrade_contains_strict_and_nonstrict_value(sdk_client_fs: ADCMClient, boundary, expected):
    """Test upgrade contains strict and nonstrict value"""
    bundledir = utils.get_data_dir(__file__, 'strict_and_non_strict_upgrade', boundary)
    with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
        sdk_client_fs.upload_from_fs(bundledir)
    with allure.step(f'Check if error is {expected}'):
        INVALID_VERSION_DEFINITION.equal(e, expected)
def test_with_new_default_variables(sdk_client_fs: ADCMClient):
    """Upgrade cluster with new default fields. Old and new config variables should be presented
    :return:
    """
    with allure.step('Create upgradable cluster new default variables'):
        bundle = sdk_client_fs.upload_from_fs(get_data_dir(
            __file__, 'cluster'))
        upgr_bundle = sdk_client_fs.upload_from_fs(
            get_data_dir(__file__, 'upgradable_cluster_new_default_variables'))
        upgr_cluster_prototype = upgr_bundle.cluster_prototype().config
        upgr_service_prototype = upgr_bundle.service_prototype().config
        cluster = bundle.cluster_create("test")
        service = cluster.service_add(name="zookeeper")
    with allure.step('Upgrade cluster with new default variables to 1.6'):
        upgr = cluster.upgrade(name='upgrade to 1.6')
        upgr.do()
    with allure.step('Check old and new config'):
        cluster.reread()
        service.reread()
        cluster_config_after = cluster.config()
        service_config_after = service.config()
        for variable in upgr_cluster_prototype:
            assert variable['name'] in cluster_config_after.keys()
        for variable in upgr_service_prototype:
            assert variable['name'] in service_config_after.keys()
Exemple #16
0
def test_when_bundle_hasnt_only_host_definition(sdk_client_fs: ADCMClient):
    bundledir = utils.get_data_dir(__file__, 'host_wo_provider')
    with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
        sdk_client_fs.upload_from_fs(bundledir)
    with allure.step('Check error: There isnt any cluster or host provider definition in bundle'):
        errorcodes.BUNDLE_ERROR.equal(e, "There isn't any cluster or "
                                         "host provider definition in bundle")
def test_decrase_config(sdk_client_fs: ADCMClient):
    """Upgrade cluster with config without old values in config. Deleted lines not presented
    """
    with allure.step('Create upgradable cluster with decrase variables'):
        bundle = sdk_client_fs.upload_from_fs(get_data_dir(
            __file__, 'cluster'))
        sdk_client_fs.upload_from_fs(
            get_data_dir(__file__, 'upgradable_cluster_decrase_variables'))
        cluster = bundle.cluster_create("test")
        service = cluster.service_add(name="zookeeper")
        cluster_config_before = cluster.config()
        service_config_before = service.config()
    with allure.step(
            'Upgrade cluster with config without old values in config to 1.6'):
        upgr = cluster.upgrade(name='upgrade to 1.6')
        upgr.do()
    with allure.step('Check that deleted lines not presented'):
        cluster.reread()
        service.reread()
        cluster_config_after = cluster.config()
        service_config_after = service.config()
        assert len(cluster_config_after.keys()) == 1
        assert len(service_config_after.keys()) == 1
        for key in cluster_config_after:
            assert cluster_config_before[key] == cluster_config_after[key]
        for key in service_config_after:
            assert service_config_before[key] == service_config_after[key]
Exemple #18
0
    def create_complex_providers_and_clusters(
        self, adcm_client: ADCMClient, bundles_directory: Path
    ) -> Tuple[Provider, Provider, Cluster, Cluster, Cluster]:
        """
        Upload complex_provider and complex_cluster

        Create two complex providers:
            1.  Provider that supply hosts for complex clusters
                (all hosts created by provider action and taken by clusters)
            2.  Provider that create multiple hosts via action, run actions on some of hosts
                and then delete multiple of them by host delete action

        And three complex clusters:
            1.  Cluster with all services and finished jobs
            2.  Cluster with config history (on cluster, one service and its components)
            3.  Not configured cluster just with hosts and one service added

        :returns: Tuple with provider and cluster objects in order that is declared above
        """
        provider_bundle = adcm_client.upload_from_fs(bundles_directory / "complex_provider")
        provider_bundle.license_accept()
        provider, host_create_task = self.create_complex_provider(provider_bundle)
        provider_with_free_hosts, _ = self.create_complex_provider(provider_bundle, template='doomed-host')
        self._run_actions_on_host_and_delete_with_action(provider)
        cluster_bundle = adcm_client.upload_from_fs(bundles_directory / "complex_cluster")
        cluster_bundle.license_accept()
        cluster_with_history = self._create_cluster_with_config_history(cluster_bundle)
        # we want to wait for tasks on provider to be finished (for hosts to be created)
        host_create_task.wait()
        cluster_with_all_services = self._create_cluster_with_all_services(
            cluster_bundle, tuple(provider.host_list())[:3]
        )
        cluster_with_hosts = self._create_cluster_with_hosts(cluster_bundle, tuple(provider.host_list())[3:])
        return provider, provider_with_free_hosts, cluster_with_all_services, cluster_with_history, cluster_with_hosts
def test_upgrade_with_two_clusters(sdk_client_fs: ADCMClient):
    """Upgrade cluster when we have two created clusters from one bundle
    Scenario:
    1. Create two clusters from one bundle
    2. Upload upgradable bundle
    3. Upgrade first cluster
    4. Check that only first cluster was upgraded
    """
    with allure.step('Create two clusters from one bundle'):
        bundle = sdk_client_fs.upload_from_fs(get_data_dir(
            __file__, 'cluster'))
        sdk_client_fs.upload_from_fs(
            get_data_dir(__file__, 'upgradable_cluster'))
        cluster_first = bundle.cluster_create("test")
        cluster_second = bundle.cluster_create("test2")
        service = cluster_first.service_add(name="zookeeper")
    with allure.step('Upgrade first cluster'):
        upgr_cl = cluster_first.upgrade(name='upgrade to 1.6')
        upgr_cl.do()
    with allure.step('Check that only first cluster was upgraded'):
        cluster_first.reread()
        service.reread()
        cluster_second.reread()
        assert cluster_first.prototype().version == '1.6'
        assert service.prototype().version == '3.4.11'
        assert cluster_second.prototype().version == '1.5'
Exemple #20
0
def _check_basic_actions_are_available(client: ADCMClient):
    """Check if basic actions are available for provided ADCM client"""
    try:
        client.cluster_list()
    except NoSuchEndpointOrAccessIsDenied as e:
        raise AssertionError(
            'Call to get cluster list should be available for any user') from e
def test_check_prototype(sdk_client_fs: ADCMClient):
    """Check prototype for service and cluster after upgrade
    :param sdk_client_fs:
    :return:
    """
    with allure.step('Create test cluster'):
        bundle = sdk_client_fs.upload_from_fs(get_data_dir(
            __file__, 'cluster'))
        sdk_client_fs.upload_from_fs(
            get_data_dir(__file__, 'upgradable_cluster'))
        cluster = bundle.cluster_create("test")
        cl_id_before = cluster.id
        service = cluster.service_add(name="zookeeper")
        serv_id_before = service.id
        cluster_proto_before = cluster.prototype()
        service_proto_before = service.prototype()
    with allure.step('Upgrade test cluster to 1.6'):
        upgr = cluster.upgrade(name='upgrade to 1.6')
        upgr.do()
    with allure.step('Check prototype'):
        cluster.reread()
        service.reread()
        cluster_proto_after = cluster.prototype()
        service_proto_after = service.prototype()
        assert cl_id_before == cluster.id
        assert serv_id_before == service.id
        assert cluster_proto_before.id != cluster_proto_after.id
        assert service_proto_before.id != service_proto_after.id
Exemple #22
0
def _check_client_is_unauthorized(client: ADCMClient):
    """Check that ADCM client can't perform basic actions, because session is out"""
    with pytest.raises(ErrorMessage) as e:
        client.cluster_list()
    assert (
        error_message := e.value.error.title
    ) == HTTP_401_MESSAGE, f'HTTP error should be {HTTP_401_MESSAGE}, not {error_message}'
Exemple #23
0
def test_incorrect_import_version(sdk_client_fs: ADCMClient, path):
    """Upgrade cluster with service incorrect version
    Scenario:
    1. Create cluster for upgrade with exports
    2. Create upgradable cluster with import and incorrect version
    3. Create service
    4. Import service from cluster with export to cluster from step 2 (with import)
    5. Upgrade cluster from step 1
    6. Check that cluster was not upgraded because incorrect version for service
    in cluster with import
    """
    with allure.step(
            'Create cluster for upgrade with exports and cluster with correct import'
    ):
        bundle = sdk_client_fs.upload_from_fs(
            get_data_dir(__file__, 'upgrade_cluster_with_export'))
        sdk_client_fs.upload_from_fs(path)
        bundle_import_correct = sdk_client_fs.upload_from_fs(
            get_data_dir(__file__, 'cluster_with_correct_import'))
        cluster = bundle.cluster_create("test")
        service = cluster.service_add(name="hadoop")
        cluster_import = bundle_import_correct.cluster_create("cluster_import")
    bind_service_and_cluster(cluster_import, service, cluster)
    with allure.step('Upgrade cluster with import to 1.6 with error'):
        upgr = cluster_import.upgrade(name='upgrade to 1.6')
        with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
            upgr.do()
    with allure.step('Check that cluster was not upgraded'):
        err.UPGRADE_ERROR.equal(e)
def policy_creation_should_fail(admin_client: ADCMClient, role: Role, adcm_object: AnyADCMObject, user: User):
    """Try to create policy based on given role and expect creation to fail"""
    with allure.step(f'Create policy based on role "{role.display_name}" and expect it to fail'):
        policy_name = f'Test role {random_string(5)}'
        with pytest.raises(ErrorMessage) as e:
            admin_client.policy_create(name=policy_name, role=role, objects=[adcm_object], user=[user])
        BAD_REQUEST.equal(e, f'Role with type "{role.type}" could not be used in policy')
Exemple #25
0
def test_upgrade_cluster_with_new_configuration_variables(
        sdk_client_fs: ADCMClient):
    """Upgrade to cluster with new configuration variables"""
    with allure.step(
            'Create cluster for upgrade with exports and cluster with import new config vars'
    ):
        bundle = sdk_client_fs.upload_from_fs(
            get_data_dir(__file__, 'upgrade_cluster_with_export'))
        bundle_import = sdk_client_fs.upload_from_fs(
            get_data_dir(__file__,
                         'upgradable_cluster_with_import_new_config_vars'))
        cluster = bundle.cluster_create("test")
        service = cluster.service_add(name="hadoop")
        cluster_config_before = cluster.config()
        service_config_before = service.config()
        cluster_import = bundle_import.cluster_create("cluster_import")
    bind_service_and_cluster(cluster_import, service, cluster)
    with allure.step('Upgrade cluster with export'):
        upgr = cluster.upgrade(name='upgrade to 1.6')
        upgr.do()
    with allure.step('Check upgraded cluster'):
        cluster.reread()
        service.reread()
        cluster_config_after = cluster.config()
        service_config_after = service.config()
        assert cluster.prototype().version == '1.6'
        assert service.prototype().version == '2.2'
        assert len(cluster_config_after) == 4, cluster_config_after
        assert len(service_config_after) == 3, service_config_after
        for variable in cluster_config_before:
            assert cluster_config_before[variable] == cluster_config_after[
                variable]
        for variable in service_config_before:
            assert service_config_before[variable] == service_config_after[
                variable]
Exemple #26
0
def test_check_host_bundle_versions_as_a_string(sdk_client_fs: ADCMClient):
    """Test upload hostprovider bundle with versions"""
    stack_dir = utils.get_data_dir(__file__, "host_version_as_a_string")
    sdk_client_fs.upload_from_fs(stack_dir)
    with allure.step("Check host versions"):
        prototype = sdk_client_fs.host_prototype()
        assert isinstance(prototype.version, str)
Exemple #27
0
def test_forbidden_actions(sdk_client_fs: ADCMClient):
    """
    Check that forbidden caller-context combinations fail as actions
        and don't affect any ADCM objects
    """
    name = "first"
    with allure.step(f'Check forbidden from cluster "{name}" context actions'):
        cluster = sdk_client_fs.cluster(name=name)
        for forbidden_action in ('change_service', 'change_component'):
            with check_config_changed(sdk_client_fs):
                run_cluster_action_and_assert_result(cluster,
                                                     forbidden_action,
                                                     status='failed')
    with allure.step(f'Check forbidden from service "{name}" context actions'):
        service = cluster.service(name=name)
        with check_config_changed(sdk_client_fs):
            run_service_action_and_assert_result(service,
                                                 'change_component',
                                                 status='failed')
    with allure.step(
            f'Check forbidden from provider "{name}" context actions'):
        provider = sdk_client_fs.provider(name=name)
        with check_config_changed(sdk_client_fs):
            run_provider_action_and_assert_result(provider,
                                                  'change_host',
                                                  status='failed')
        first_host, second_host, *_ = provider.host_list()
        with check_config_changed(sdk_client_fs):
            run_host_action_and_assert_result(
                first_host,
                'change_host_from_provider',
                status='failed',
                config={'host_id': second_host.id})
Exemple #28
0
def test_cluster_bundle_can_be_on_any_level(sdk_client_fs: ADCMClient):
    """Test upload cluster bundle lower that in directory root"""
    stack_dir = utils.get_data_dir(__file__, "cluster_bundle_on_any_level")
    sdk_client_fs.upload_from_fs(stack_dir)
    with allure.step("Check cluster bundle"):
        assert sdk_client_fs.service_prototype_list()
        assert sdk_client_fs.cluster_prototype_list()
def test_load_host_provider(sdk_client_fs: ADCMClient):
    """Test load hostprovider bundle"""
    sdk_client_fs.upload_from_fs(BUNDLES + "hostprovider_bundle")
    with allure.step("Check bundle list"):
        assert "provider_sample" in [
            bundle.name for bundle in sdk_client_fs.bundle_list()
        ]
def test_delete_service_with_host(sdk_client_fs: ADCMClient):
    """Check that it is possible to delete service with host component binded to cluster
    And HC map is automatically updated after service deletion"""
    hostprovider_bundle = sdk_client_fs.upload_from_fs(
        utils.get_data_dir(__file__, 'cluster_service_hostcomponent', 'hostprovider')
    )
    provider = hostprovider_bundle.provider_create("test")
    host_1 = provider.host_create("test_host_1")
    host_2 = provider.host_create("test_host_2")
    bundle = sdk_client_fs.upload_from_fs(utils.get_data_dir(__file__, 'cluster_service_hostcomponent', 'cluster'))
    cluster = bundle.cluster_create("test")
    service_1 = cluster.service_add(name="zookeeper")
    service_2 = cluster.service_add(name="second_service")
    cluster.host_add(host_1)
    cluster.host_add(host_2)
    component_1 = service_1.component(name="ZOOKEEPER_SERVER")
    component_2 = service_2.component(name="some_component")
    cluster.hostcomponent_set((host_1, component_1), (host_2, component_1), (host_2, component_2))
    assert len(cluster.service_list()) == 2, "It should be 2 services"
    assert len(cluster.hostcomponent()) == 3, "HC map should contain 3 mappings"
    task = service_1.action(name='remove_service').run()
    task.wait()
    with allure.step("Check that service has been deleted and HC map was cleaned"):
        assert task.status == 'success', f"Current job status {task.status}. Expected: success"
        assert len(cluster.service_list()) == 1, "It should be 1 service"
        assert cluster.service_list()[0].name == "second_service", "It should be only second service left"
        assert len(cluster.hostcomponent()) == 1, "HC map should contain 1 mapping"
    with allure.step("Check that there is no issues on objects"):
        cluster.reread()
        assert not cluster.concerns(), "It should be no concerns on cluster"
        host_1.reread()
        assert not host_1.concerns(), "It should be no concerns on host"
        host_2.reread()
        assert not host_2.concerns(), "It should be no concerns on host"