Esempio n. 1
0
    def test_two_clusters(self, action_name, cluster_with_components: Cluster,
                          provider: Provider):
        """
        Test that component actions on host works fine on two clusters
        """
        second_cluster = cluster_with_components.bundle().cluster_prototype(
        ).cluster_create(name="Second cluster")
        service_on_first_cluster = cluster_with_components.service_add(
            name=FIRST_SERVICE)
        component_on_first_cluster = service_on_first_cluster.component(
            name=FIRST_COMPONENT)
        service_on_second_cluster = second_cluster.service_add(
            name=FIRST_SERVICE)
        component_on_second_cluster = service_on_second_cluster.component(
            name=FIRST_COMPONENT)
        first_host = provider.host_create("host_in_first_cluster")
        second_host = provider.host_create("host_in_second_cluster")
        cluster_with_components.host_add(first_host)
        second_cluster.host_add(second_host)
        cluster_with_components.hostcomponent_set(
            (first_host, component_on_first_cluster))
        second_cluster.hostcomponent_set(
            (second_host, component_on_second_cluster))

        action_in_object_is_present(action_name, first_host)
        action_in_object_is_present(action_name, second_host)
        run_host_action_and_assert_result(first_host,
                                          action_name,
                                          status="success")
        run_host_action_and_assert_result(second_host,
                                          action_name,
                                          status="success")
Esempio n. 2
0
    def test_availability_at_state(self, cluster_with_components: Cluster,
                                   provider: Provider):
        """
        Test that component host action is available on specify service state
        """
        service = cluster_with_components.service_add(name=FIRST_SERVICE)
        component = service.component(name=FIRST_COMPONENT)
        adjacent_component = service.component(name=SECOND_COMPONENT)
        host = provider.host_create("host_in_cluster")
        cluster_with_components.host_add(host)
        cluster_with_components.hostcomponent_set((host, component))

        action_in_object_is_absent(ACTION_ON_HOST_STATE_REQUIRED, host)
        run_cluster_action_and_assert_result(cluster_with_components,
                                             SWITCH_CLUSTER_STATE)
        action_in_object_is_absent(ACTION_ON_HOST_STATE_REQUIRED, host)
        run_service_action_and_assert_result(service, SWITCH_SERVICE_STATE)
        action_in_object_is_absent(ACTION_ON_HOST_STATE_REQUIRED, host)
        run_host_action_and_assert_result(host, SWITCH_HOST_STATE)
        action_in_object_is_absent(ACTION_ON_HOST_STATE_REQUIRED, host)
        run_component_action_and_assert_result(adjacent_component,
                                               SWITCH_COMPONENT_STATE)
        action_in_object_is_absent(ACTION_ON_HOST_STATE_REQUIRED, host)
        run_component_action_and_assert_result(component,
                                               SWITCH_COMPONENT_STATE)
        action_in_object_is_present(ACTION_ON_HOST_STATE_REQUIRED, host)
        run_host_action_and_assert_result(host, ACTION_ON_HOST_STATE_REQUIRED)
Esempio n. 3
0
 def test_invoker_object_url(self, cluster: Cluster, provider: Provider,
                             page: JobListPage):
     """Check link to object that invoked action is correct"""
     host_fqdn = 'run-on-me'
     host_job_link = f'{provider.name}/{host_fqdn}'
     component_link = f'{CLUSTER_NAME}/{SERVICE_NAME}/{COMPONENT_NAME}'
     host_component_link = f'{component_link}/{host_fqdn}'
     with allure.step('Run action on component and check job link to it'):
         service: Service = cluster.service(name=SERVICE_NAME)
         component: Component = service.component(name=COMPONENT_NAME)
         component_action = component.action(
             display_name=COMPONENT_ACTION_DISPLAY_NAME)
         _check_link_to_invoker_object(component_link, page,
                                       component_action)
     with allure.step(
             'Create host, run action on host and check job link to it'):
         host = provider.host_create(host_fqdn)
         host_action = host.action(display_name=FAIL_ACTION_DISPLAY_NAME)
         _check_link_to_invoker_object(host_job_link, page, host_action)
     with allure.step('Add host to the cluster, assign component on it'):
         cluster.host_add(host)
         cluster.hostcomponent_set((host, component))
     with allure.step(
             'Run component host action on host and check job link to it'):
         host_action = _wait_and_get_action_on_host(
             host, ON_HOST_ACTION_DISPLAY_NAME)
         _check_link_to_invoker_object(host_component_link, page,
                                       host_action)
Esempio n. 4
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
Esempio n. 5
0
 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")
Esempio n. 6
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)
Esempio n. 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)
Esempio n. 8
0
 def test_delete_host_from_cluster(self, cluster: Cluster, provider: Provider):
     """Test delete host from cluster"""
     host = provider.host_create(utils.random_string())
     expected = cluster.host_list()
     with allure.step("Create mapping between cluster and host"):
         cluster.host_add(host)
     with allure.step("Deleting host from cluster"):
         cluster.host_delete(host)
     actual = cluster.host_list()
     with allure.step("Check host removed from cluster"):
         assert actual == expected
Esempio n. 9
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)
Esempio n. 10
0
 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
Esempio n. 11
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")
Esempio n. 12
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"
Esempio n. 13
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
Esempio n. 14
0
    def test_availability_at_host_state(self, cluster_with_service: Cluster,
                                        provider: Provider):
        """
        Test that service host action isn't available on specify host state
        """
        service = cluster_with_service.service_add(name=FIRST_SERVICE)
        host = provider.host_create("host_in_cluster")
        cluster_with_service.host_add(host)
        cluster_with_service.hostcomponent_set(
            (host, service.component(name=FIRST_COMPONENT)))

        action_in_object_is_absent(ACTION_ON_HOST_STATE_REQUIRED, host)
        run_host_action_and_assert_result(host, SWITCH_HOST_STATE)
        action_in_object_is_absent(ACTION_ON_HOST_STATE_REQUIRED, host)
        run_service_action_and_assert_result(service, SWITCH_SERVICE_STATE)
        action_in_object_is_present(ACTION_ON_HOST_STATE_REQUIRED, host)
        run_host_action_and_assert_result(host, ACTION_ON_HOST_STATE_REQUIRED)
Esempio n. 15
0
    def test_availability(self, cluster_with_service: Cluster,
                          provider: Provider, action_name):
        """
        Test that service host action is available on a service host and is absent on cluster
        """
        service = cluster_with_service.service_add(name=FIRST_SERVICE)
        second_service = cluster_with_service.service_add(name=SECOND_SERVICE)
        host_with_two_components = provider.host_create(
            "host_with_two_components")
        host_with_one_component = provider.host_create(
            "host_with_one_component")
        host_without_component = provider.host_create("host_without_component")
        host_with_different_services = provider.host_create(
            "host_with_different_services")
        host_outside_cluster = provider.host_create("host_outside_cluster")
        for host in [
                host_with_two_components,
                host_with_one_component,
                host_without_component,
                host_with_different_services,
        ]:
            cluster_with_service.host_add(host)
        cluster_with_service.hostcomponent_set(
            (host_with_two_components,
             service.component(name=FIRST_COMPONENT)),
            (host_with_two_components,
             service.component(name=SECOND_COMPONENT)),
            (host_with_one_component, service.component(name=FIRST_COMPONENT)),
            (host_with_different_services,
             service.component(name=SECOND_COMPONENT)),
            (host_with_different_services,
             second_service.component(name=FIRST_COMPONENT)),
        )

        action_in_object_is_present(action_name, host_with_one_component)
        action_in_object_is_present(action_name, host_with_two_components)
        action_in_object_is_present(action_name, host_with_different_services)
        action_in_object_is_absent(action_name, host_without_component)
        action_in_object_is_absent(action_name, host_outside_cluster)
        action_in_object_is_absent(action_name, cluster_with_service)
        action_in_object_is_absent(action_name, service)
        run_host_action_and_assert_result(host_with_one_component, action_name)
        run_host_action_and_assert_result(host_with_two_components,
                                          action_name)
        run_host_action_and_assert_result(host_with_different_services,
                                          action_name)
Esempio n. 16
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')
Esempio n. 17
0
 def test_get_cluster_host_info(self, cluster: Cluster, provider: Provider):
     """Test get cluster host info"""
     host = provider.host_create(utils.random_string())
     with allure.step("Create mapping between cluster and host"):
         expected = cluster.host_add(host)
     with allure.step("Get cluster host info"):
         host.reread()
     with allure.step("Check test results"):
         _check_hosts(host, expected)
Esempio n. 18
0
 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)
Esempio n. 19
0
 def test_two_clusters(self, action_name, cluster: Cluster,
                       provider: Provider):
     """
     Test that cluster actions on host works fine on two clusters
     """
     second_cluster = cluster.bundle().cluster_prototype().cluster_create(
         name="Second cluster")
     first_host = provider.host_create("host_in_first_cluster")
     second_host = provider.host_create("host_in_second_cluster")
     cluster.host_add(first_host)
     second_cluster.host_add(second_host)
     action_in_object_is_present(action_name, first_host)
     action_in_object_is_present(action_name, second_host)
     run_host_action_and_assert_result(first_host,
                                       action_name,
                                       status="success")
     run_host_action_and_assert_result(second_host,
                                       action_name,
                                       status="success")
Esempio n. 20
0
    def test_availability(self, cluster_with_components: Cluster,
                          provider: Provider, action_name):
        """
        Test that component host action is available on a component host
        """
        service = cluster_with_components.service_add(name=FIRST_SERVICE)
        component_with_action = service.component(name=FIRST_COMPONENT)
        component_without_action = service.component(name=SECOND_COMPONENT)

        host_single_component = provider.host_create(
            "host_with_single_component")
        host_two_components = provider.host_create("host_with_two_components")
        host_component_without_action = provider.host_create(
            "host_component_without_action")
        host_without_components = provider.host_create(
            "host_without_components")
        host_outside_cluster = provider.host_create("host_outside_cluster")
        for host in [
                host_single_component,
                host_two_components,
                host_component_without_action,
                host_without_components,
        ]:
            cluster_with_components.host_add(host)
        cluster_with_components.hostcomponent_set(
            (host_single_component, component_with_action),
            (host_two_components, component_with_action),
            (host_two_components, component_without_action),
            (host_component_without_action, component_without_action),
        )
        action_in_object_is_present(action_name, host_single_component)
        action_in_object_is_present(action_name, host_two_components)
        action_in_object_is_absent(action_name, host_component_without_action)
        action_in_object_is_absent(action_name, host_without_components)
        action_in_object_is_absent(action_name, host_outside_cluster)
        action_in_object_is_absent(action_name, cluster_with_components)
        action_in_object_is_absent(action_name, service)
        action_in_object_is_absent(action_name, component_with_action)
        action_in_object_is_absent(action_name, component_without_action)
        run_host_action_and_assert_result(host_single_component, action_name)
        run_host_action_and_assert_result(host_two_components, action_name)
Esempio n. 21
0
def test_check_inventories_file(cluster: Cluster, provider: Provider,
                                adcm_fs: ADCM, request: SubRequest):
    """Assert inventory file contents for the action"""
    host = provider.host_create(fqdn=HOST_FQDN)
    with allure.step('Configure cluster'):
        service = cluster.service_add(name="zookeeper")
        cluster.host_add(host)
        component = service.component(name=GROUP_COMPONENT_NAME)
        cluster.hostcomponent_set((host, component))
    with allure.step(
            f'Create config group with {GROUP_COMPONENT_NAME} and change it'):
        config_group = create_config_group_and_add_host(
            'group_name', component, host)
        config_group.config_set(CONFIG_TO_CHANGE)
    with allure.step('Run actions on cluster'):
        run_cluster_action_and_assert_result(cluster, "set_multi_states")
        run_cluster_action_and_assert_result(cluster, "install")
    with allure.step('Get inventory file from container'):
        text = get_file_from_container(adcm_fs, '/adcm/data/run/2/',
                                       'inventory.json')
        inventory_content = text.read().decode('utf8')
        inventory = json.loads(inventory_content)
        _attach_inventory_file(request, inventory_content,
                               'Actual content of inventory.json')
    with allure.step('Get expected inventory file'):
        with open(utils.get_data_dir(__file__, 'cluster-inventory.json'),
                  'rb') as template:
            expected_content = template.read().decode('utf8')
            expected = json.loads(expected_content)
        _attach_inventory_file(request, expected_content,
                               'Expected content of inventory.json')
    with allure.step('Compare actual and expected config'):
        assert (
            inventory == expected
        ), "Content of file inventory.json doesn't match expected. See attachments for more info."
    with allure.step(
            'Check that object attributes are available in ansible script'):
        run_cluster_action_and_assert_result(cluster, 'check')
Esempio n. 22
0
def test_host_should_be_unlocked_after_host_action(
    cluster: Cluster,
    host_provider: Provider,
    adcm_object: str,
    host_action_postfix: str,
    run_on_host: str,
):
    """Test that host is unlocked after host action"""
    action_name = f"{adcm_object}_{host_action_postfix}"
    first_service = cluster.service_add(name="first_service")
    second_service = cluster.service_add(name="second_service")

    host_with_two_components = host_provider.host_create("host_with_two_components")
    host_with_one_component = host_provider.host_create("host_with_one_component")
    host_with_different_services = host_provider.host_create("host_with_different_services")

    cluster_hosts = [
        host_with_two_components,
        host_with_one_component,
        host_with_different_services,
    ]
    for host in cluster_hosts:
        cluster.host_add(host)

    cluster.hostcomponent_set(
        (host_with_two_components, second_service.component(name="second_service_component_1")),
        (host_with_two_components, second_service.component(name="second_service_component_2")),
        (host_with_one_component, second_service.component(name="second_service_component_1")),
        (host_with_different_services, first_service.component(name="first_service_component_2")),
        (host_with_different_services, second_service.component(name="second_service_component_1")),
    )
    host = cluster.host(fqdn=run_on_host)
    with allure.step(f"Run action {action_name} on {host}"):
        host.action(name=action_name).run().wait(timeout=30)
    for host in cluster_hosts:
        is_free(host)
Esempio n. 23
0
def complete_cluster(cluster: Cluster, host: Host) -> Cluster:
    """Add service, component and host to cluster"""
    cluster.host_add(host)
    service = cluster.service_add(name="first_service")
    cluster.hostcomponent_set((host, service.component(name="first_service_component_1")))
    return cluster