Beispiel #1
0
def get_or_add_service(cluster: Cluster, service_name: str):
    """
    Add service if it wasn't added before and return it
    """
    try:
        return cluster.service(name=service_name)
    except ObjectNotFound:
        return cluster.service_add(name=service_name)
Beispiel #2
0
def cluster_with_two_hosts(cluster: Cluster, host_provider: Provider) -> Tuple[Cluster, List[Host]]:
    """Add service, component and host to cluster twice"""
    hosts = []
    for i in range(2):
        host = host_provider.host_create(f"host_{i}")
        hosts.append(host)
        cluster.host_add(host)
    return cluster, hosts
Beispiel #3
0
def test_service_should_be_unlocked_when_ansible_task_killed(complete_cluster: Cluster):
    """Test that service is unlocked if ansible task is killed"""
    service = complete_cluster.service(name="first_service")
    with allure.step("Run action: lock-terminate for cluster"):
        task = complete_cluster.action(name="lock-terminate").run()
    is_locked(service)
    task.wait()
    is_free(service)
 def test_host_belong_to_cluster_should_not_deleted(self, cluster: Cluster, provider: Provider):
     """Test that we should be unable to delete host bounded to cluster"""
     host = provider.host_create(utils.random_string())
     cluster.host_add(host)
     with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
         host.delete()
     with allure.step("Check error host belong to cluster"):
         err.HOST_CONFLICT.equal(e, "Host", "belong to cluster")
Beispiel #5
0
def test_ansible_set_on_action(
    cluster_obj_venv_default_action_9: Cluster,
    cluster_obj_no_venv_action_9: Cluster,
    provider_obj_venv_default_action_9: Provider,
    provider_no_venv_action_9: Provider,
):
    """
    Check that we able to change ansible on action.
    """
    run_cluster_action_and_assert_result(cluster_obj_venv_default_action_9,
                                         "obj_venv_default_action_9",
                                         config=ANSIBLE_9)
    run_service_action_and_assert_result(
        cluster_obj_venv_default_action_9.service(
            name="obj_venv_default_action_9"),
        "obj_venv_default_action_9",
        config=ANSIBLE_9,
    )
    run_component_action_and_assert_result(
        cluster_obj_venv_default_action_9.service(
            name="obj_venv_default_action_9").component(
                name="obj_venv_default_action_9"),
        "obj_venv_default_action_9",
        config=ANSIBLE_9,
    )

    run_cluster_action_and_assert_result(cluster_obj_no_venv_action_9,
                                         "obj_no_venv_action_9",
                                         config=ANSIBLE_9)
    run_service_action_and_assert_result(
        cluster_obj_no_venv_action_9.service(name="obj_no_venv_action_9"),
        "obj_no_venv_action_9",
        config=ANSIBLE_9)
    run_component_action_and_assert_result(
        cluster_obj_no_venv_action_9.service(
            name="obj_no_venv_action_9").component(
                name="obj_no_venv_action_9"),
        "obj_no_venv_action_9",
        config=ANSIBLE_9,
    )

    run_provider_action_and_assert_result(provider_no_venv_action_9,
                                          "no_venv_action_9",
                                          config=ANSIBLE_9)
    run_host_action_and_assert_result(
        provider_no_venv_action_9.host(fqdn="no_venv_action_9"),
        "no_venv_action_9",
        config=ANSIBLE_9)

    run_provider_action_and_assert_result(provider_obj_venv_default_action_9,
                                          "obj_venv_default_action_9",
                                          config=ANSIBLE_9)
    run_host_action_and_assert_result(
        provider_obj_venv_default_action_9.host(
            fqdn="obj_venv_default_action_9"),
        "obj_venv_default_action_9",
        config=ANSIBLE_9,
    )
 def test_cluster_service_create(self, cluster: Cluster):
     """Test create service"""
     expected = cluster.service_add(name="ZOOKEEPER")
     service_list = cluster.service_list()
     assert len(service_list) == 1
     actual = service_list[0]
     with allure.step("Check expected and actual value"):
         assert actual.id == expected.id
         assert actual.name == expected.name
Beispiel #7
0
 def test_lock_unlock(self, cluster: Cluster, host: Host, lock_action):
     """
     Test that cluster locked when action running and unlocked when action ends
     """
     cluster.host_add(host)
     is_free(cluster)
     task = _lock_obj(cluster, lock_action)
     is_locked(cluster)
     task.wait()
     is_free(cluster)
 def test_adding_host_to_cluster(self, cluster: Cluster, provider: Provider):
     """Test add host to cluster"""
     host = provider.host_create(utils.random_string())
     expected = cluster.host_add(host)
     with allure.step("Get cluster host info"):
         host_list = cluster.host_list()
         assert len(host_list) == 1
         actual = host_list[0]
     with allure.step("Check mapping"):
         _check_hosts(actual, expected)
Beispiel #9
0
 def test_availability_at_state(self, cluster: Cluster, provider: Provider):
     """
     Test that cluster host action is available on specify cluster state
     """
     host = provider.host_create("host_in_cluster")
     cluster.host_add(host)
     action_in_object_is_absent(ACTION_ON_HOST_STATE_REQUIRED, host)
     run_cluster_action_and_assert_result(cluster, SWITCH_CLUSTER_STATE)
     action_in_object_is_present(ACTION_ON_HOST_STATE_REQUIRED, host)
     run_host_action_and_assert_result(host, ACTION_ON_HOST_STATE_REQUIRED)
 def test_get_nonexistent_cluster_config(self, cluster: Cluster):
     """Test get nonexistent cluster config"""
     # we try to get a nonexistant cluster config, test should raise exception
     with allure.step(f"Removing cluster id={cluster.id}"):
         cluster.delete()
     with allure.step("Get cluster config from non existent cluster"):
         with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
             cluster.config()
     with allure.step("Check that cluster doesn't exist"):
         err.CLUSTER_NOT_FOUND.equal(e, "Cluster", "does not exist")
 def test_get_cluster_service_list(self, sdk_client_fs: ADCMClient, cluster: Cluster):
     """Test cluster service list"""
     expected = []
     with allure.step("Create a list of services in the cluster"):
         for prototype in sdk_client_fs.service_prototype_list(bundle_id=cluster.bundle_id):
             service = cluster.service_add(prototype_id=prototype.id)
             expected.append(service._data)
     with allure.step("Get a service list in cluster"):
         actual = [x._data for x in cluster.service_list()]
     with allure.step("Check expected and actual value"):
         assert actual == expected
Beispiel #12
0
 def test_lock_unlock(self, cluster: Cluster, host: Host, lock_action):
     """
     Test that service locked when action running and unlocked when action ends
     """
     cluster.host_add(host)
     service = cluster.service_add(name="first_service")
     is_free(service)
     task = _lock_obj(service, lock_action)
     is_locked(service)
     task.wait()
     is_free(service)
 def test_get_cluster_hosts_list(self, cluster: Cluster, provider: Provider):
     """Test get cluster hosts list"""
     actual, expected = [], []
     with allure.step("Create host list in cluster"):
         for fqdn in utils.random_string_list():
             host = provider.host_create(fqdn)
             cluster.host_add(host)
             expected.append(host.id)
     for host in cluster.host_list():
         actual.append(host.id)
     with allure.step("Check test data"):
         assert actual == expected
Beispiel #14
0
 def test_availability(self, cluster: Cluster, provider: Provider,
                       action_name):
     """
     Test that cluster host action is available on cluster host and is absent on cluster
     """
     host1 = provider.host_create("host_in_cluster")
     host2 = provider.host_create("host_not_in_cluster")
     cluster.host_add(host1)
     action_in_object_is_present(action_name, host1)
     action_in_object_is_absent(action_name, host2)
     action_in_object_is_absent(action_name, cluster)
     run_host_action_and_assert_result(host1, action_name, status="success")
Beispiel #15
0
def test_target_group_in_inventory(cluster_with_target_group_action: Cluster,
                                   provider: Provider, sdk_client_fs):
    """
    Test that target group action has inventory_hostname info
    """
    hostname = "host_in_cluster"
    host = provider.host_create(hostname)
    cluster_with_target_group_action.host_add(host)
    action_in_object_is_present(ACTION_ON_HOST, host)
    run_host_action_and_assert_result(host, ACTION_ON_HOST)
    with allure.step("Assert that hostname in job log is present"):
        assert (f"We are on host: {hostname}" in sdk_client_fs.job().log(
            type="stdout").content), "No hostname info in the job log"
 def test_check_that_file_field_put_correct_data_in_file_inside_docker(
         self, cluster: Cluster):
     """Another mysterious type checking test"""
     test_data = "lorem ipsum"
     with allure.step("Create config data"):
         config_data = utils.ordered_dict_to_dict(cluster.config())
         config_data["input_file"] = test_data
         config_data["required"] = 42
     with allure.step("Create config history"):
         cluster.config_set(config_data)
     with allure.step("Check file type"):
         run_cluster_action_and_assert_result(cluster=cluster,
                                              action="check-file-type")
Beispiel #17
0
def test_default_ansible(
    cluster_no_venv: Cluster,
    cluster_obj_venv_default: Cluster,
    provider_no_venv: Provider,
    provider_obj_venv_default: Provider,
):
    """
    Check that by default (if developer write nothing) we have Ansible 2.8.
    """
    run_cluster_action_and_assert_result(cluster_no_venv,
                                         "no_venv",
                                         config=DEFAULT_ANSIBLE_VER)
    run_service_action_and_assert_result(
        cluster_no_venv.service(name="no_venv"),
        "no_venv",
        config=DEFAULT_ANSIBLE_VER)
    run_component_action_and_assert_result(
        cluster_no_venv.service(name="no_venv").component(name="no_venv"),
        "no_venv",
        config=DEFAULT_ANSIBLE_VER)

    run_cluster_action_and_assert_result(cluster_obj_venv_default,
                                         "obj_venv_default",
                                         config=DEFAULT_ANSIBLE_VER)
    run_service_action_and_assert_result(
        cluster_obj_venv_default.service(name="obj_venv_default"),
        "obj_venv_default",
        config=DEFAULT_ANSIBLE_VER)
    run_component_action_and_assert_result(
        cluster_obj_venv_default.service(name="obj_venv_default").component(
            name="obj_venv_default"),
        "obj_venv_default",
        config=DEFAULT_ANSIBLE_VER,
    )

    run_provider_action_and_assert_result(provider_no_venv,
                                          "no_venv",
                                          config=DEFAULT_ANSIBLE_VER)
    run_host_action_and_assert_result(provider_no_venv.host(fqdn="no_venv"),
                                      "no_venv",
                                      config=DEFAULT_ANSIBLE_VER)

    run_provider_action_and_assert_result(provider_obj_venv_default,
                                          "obj_venv_default",
                                          config=DEFAULT_ANSIBLE_VER)
    run_host_action_and_assert_result(
        provider_obj_venv_default.host(fqdn="obj_venv_default"),
        "obj_venv_default",
        config=DEFAULT_ANSIBLE_VER)
Beispiel #18
0
def _cluster_with_components(cluster: Cluster, hosts: List[Host]):
    host1, host2 = hosts
    try:
        first_service = cluster.service(name="first_service")
    except ObjectNotFound:
        first_service = cluster.service_add(name="first_service")
    second_service = cluster.service_add(name="second_service")
    first_service_component = first_service.component(name="first_service_component_1")
    second_service_component = second_service.component(name="second_service_component_1")
    cluster.hostcomponent_set(
        (host1, first_service_component),
        (host1, second_service_component),
        (host2, first_service_component),
    )
    return first_service_component, second_service_component
 def test_should_not_set_invalid_cluster_config(
     self,
     cluster: Cluster,
     cluster_config: Any,
     expected_error: Tuple[err.ADCMError, str],
 ):
     """Invalid cluster config should not be set"""
     adcm_error, expected_msg = expected_error
     with allure.step("Try to set invalid config"):
         allure.attach(json.dumps(cluster_config), "config.json",
                       allure.attachment_type.JSON)
         with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
             cluster.config_set(cluster_config)
     with allure.step("Check error"):
         adcm_error.equal(e, expected_msg)
Beispiel #20
0
def test_service_action_availability_at_state(cluster_with_service: Cluster):
    """
    Test that service action is available on specific service state
    """
    service_1 = cluster_with_service.service_add(name=FIRST_SERVICE)
    service_2 = cluster_with_service.service_add(name=SECOND_SERVICE)

    _assert_actions_state_created(service_1)
    run_cluster_action_and_assert_result(cluster_with_service,
                                         SWITCH_CLUSTER_STATE)
    _assert_actions_state_created(service_1)
    run_service_action_and_assert_result(service_1, SWITCH_SERVICE_STATE)
    _assert_actions_state_installed(service_1)
    _assert_actions_state_created(service_2)
    run_service_action_and_assert_result(service_1, ACTION_STATE_INSTALLED)
Beispiel #21
0
 def test_run_multijob(self, cluster: Cluster, page: JobListPage):
     """Run action with many jobs"""
     with allure.step('Run action with multiple job'):
         action = cluster.action(display_name=MULTIJOB_ACTION_DISPLAY_NAME)
         task = run_cluster_action_and_assert_result(cluster, action.name)
     page.expand_task_in_row(0)
     with allure.step('Check jobs info'):
         expected_jobs = [{
             'name': job['name'],
             'status': JobStatus.SUCCESS
         } for job in action.subs]
         jobs_info = page.get_all_jobs_info()
         assert (expected_amount := len(expected_jobs)) == (
             actual_amount := len(jobs_info)
         ), ('Amount of jobs is not correct: '
             f'should be {expected_amount}, but {actual_amount} was found')
         for i in range(actual_amount):
             assert (actual_info := asdict(jobs_info[i])) == (
                 expected_info := expected_jobs[i]
             ), f'Job at position #{i} should be {expected_info}, not {actual_info}'
     with allure.step("Open first job's page"):
         page.click_on_job()
         detail_page = JobPageStdout(page.driver, page.base_url,
                                     task.jobs[0]['id'])
         detail_page.wait_page_is_opened()
Beispiel #22
0
 def test_no_horizontal_lock(self, cluster: Cluster, lock_action):
     """
     Test that no horizontal lock when cluster locked
     """
     second_cluster = cluster.prototype().cluster_create(name=random_string())
     _lock_obj(cluster, lock_action)
     is_free(second_cluster)
Beispiel #23
0
 def test_no_horizontal_lock(self, complete_cluster: Cluster, lock_action):
     """
     Test that no horizontal lock when component locked
     """
     service = complete_cluster.service(name="first_service")
     _lock_obj(service.component(name="first_service_component_1"), lock_action)
     is_free(service.component(name="first_service_component_2"))
Beispiel #24
0
def check_cluster_actions_roles_are_created_correctly(
    client: ADCMClient,
    cluster: Cluster,
    hidden_role_names: set,
    hidden_role_prefix: str,
):
    """
    Check that all cluster action roles have corresponding hidden roles,
    that roles are bonded to correct business role,
    and the business role is assigned to correct default RBAC roles.
    """
    cluster_proto = cluster.prototype()
    actions = cluster_proto.actions
    full_hidden_prefix = f'{hidden_role_prefix}{get_prototype_prefix_for_action_role(cluster_proto)}'
    with allure.step(
            'Check that "hidden" roles are created for each action in cluster'
    ):
        cluster_actions_role_names = get_actions_role_names(
            full_hidden_prefix, actions)
        is_superset_of(hidden_role_names, cluster_actions_role_names,
                       'Not all expected "hidden" roles were found')
    _, business = check_business_roles_children(client, cluster_proto, actions,
                                                cluster_actions_role_names)

    with allure.step(
            'Check that business roles are applied correctly to RBAC default roles'
    ):
        business_roles_ids = get_roles_ids_from_info(business)
        check_roles_are_added_to_rbac_roles(
            client,
            rbac_roles=(RbacRoles.ClusterAdministrator, ),
            children_roles_ids=business_roles_ids,
        )

    check_all_roles_have_category(cluster_proto.display_name, business)
Beispiel #25
0
def test_incorrect_config(cluster: Cluster, provider: Provider,
                          sdk_client_fs: ADCMClient):
    """
    Action's configuration not presented
    Run action with "incorrect" config
    """
    job_count = len(sdk_client_fs.job_list())
    component = (service := cluster.service()).component()
    host = provider.host()
    for obj in (cluster, service, component, provider, host):
        with allure.step(
                f'Check "incorrect" config with action on {obj.__class__.__name__}'
        ):
            with allure.step(
                    'Run action with "incorrect" config and expect ADCM response with non 500 status code'
            ):
                try:
                    ACTION_MAP[obj.__class__](obj,
                                              'with_config',
                                              'failed',
                                              config={
                                                  'no_such_param': "1"
                                              })
                except ErrorMessage as e:
                    CONFIG_KEY_ERROR.equal(e)
                else:
                    raise AssertionError("Action should've failed")
            with allure.step("Check that job wasn't launched"):
                _check_job_count_equal_to(job_count, sdk_client_fs)
Beispiel #26
0
def test_config_not_presented(cluster: Cluster, provider: Provider,
                              sdk_client_fs: ADCMClient):
    """
    Action's configuration not presented
    Run action with config
    """
    job_count = len(sdk_client_fs.job_list())
    component = (service := cluster.service()).component()
    host = provider.host()
    for obj in (cluster, service, component, provider, host):
        with allure.step(
                f'Check no config with action on {obj.__class__.__name__}'):
            with allure.step(
                    'Run action without config and expect it to fail with ansible error'
            ):
                try:
                    ACTION_MAP[obj.__class__](obj,
                                              'no_config',
                                              'failed',
                                              config={
                                                  'some_param': "1"
                                              })
                except ErrorMessage as e:
                    CONFIG_VALUE_ERROR.equal(e)
                else:
                    raise AssertionError("Action run request should've failed")
            with allure.step("Check that job wasn't launched"):
                _check_job_count_equal_to(job_count, sdk_client_fs)
Beispiel #27
0
 def test_get_hostcomponent_list(self, cluster: Cluster, provider: Provider):
     """
     Check that hostcomponent map retrieved successfully
     """
     service = cluster.service_add(name="ZOOKEEPER")
     components = service.component_list()
     hc_map_temp = []
     for fqdn in utils.random_string_list():
         host = provider.host_create(fqdn=fqdn)
         cluster.host_add(host)
         component = random.choice(components)
         hc_map_temp.append((host, component))
     hc_map_expected = cluster.hostcomponent_set(*hc_map_temp)
     with allure.step("Check created data with data from API"):
         hc_map_actual = cluster.hostcomponent()
         assert hc_map_actual == hc_map_expected
Beispiel #28
0
def test_cluster_should_be_unlocked_when_ansible_task_killed(cluster: Cluster):
    """Test that cluster is unlocked if ansible task is killed"""
    with allure.step("Run cluster action: lock-terminate for cluster"):
        task = cluster.action(name="lock-terminate").run()
    is_locked(cluster)
    task.wait()
    assert_state(cluster, "terminate_failed")
Beispiel #29
0
    def test_secret_text_field(self, cluster: Cluster, provider: Provider):
        """Test "secrettext" config field type"""
        value_to_set = "verysimple\nI'am"
        default_value = "very\nsecret\ntext"
        fields = (
            'secret_required_default',
            'secret_not_required_default',
            'secret_not_required_no_default',
            'secret_required_no_default',
        )
        required_default, not_required_default, not_required_no_default, required_no_default = fields
        required_diff = {required_no_default: value_to_set}
        changed_diff = {
            field: value_to_set
            for field in fields if field != required_no_default
        }
        default_diff = {
            not_required_no_default: None,
            required_default: default_value,
            not_required_default: default_value,
        }

        service = cluster.service()
        component = service.component()
        host = provider.host()
        cluster.host_add(host)
        cluster.hostcomponent_set((host, component))
        objects_to_change = (cluster, service, component, provider, host)

        # to make actions available
        with allure.step(
                f'Set required fields that has no default to {value_to_set}'):
            for adcm_object in objects_to_change:
                adcm_object.config_set_diff(required_diff)
        with allure.step(
                f'Set other fields to {value_to_set} and check that config changed correctly'
        ):
            self._change_config_and_check_changed_by_action(
                objects_to_change, changed_diff, 'check_default',
                'check_changed')
        with allure.step(
                'Set default values for fields and check that config changed correctly'
        ):
            self._change_config_and_check_changed_by_action(
                objects_to_change, default_diff, 'check_changed',
                'check_default')
Beispiel #30
0
def test_host_should_be_unlocked_when_ansible_task_killed(complete_cluster: Cluster, host: Host):
    """Test that host is unlocked if ansible task is killed"""
    with allure.step("Run action: lock-terminate for cluster"):
        task = complete_cluster.action(name="lock-terminate").run()

    is_locked(host)
    task.wait()
    is_free(host)