Example #1
0
 def _run_actions_on_components(self, cluster: Cluster, service: Service, components: dict, hosts: tuple):
     """Utility function to run actions on components (host actions too)"""
     cluster.action(name='make_sauce').run(
         hc=tuple(
             (
                 {'host_id': host_id, 'service_id': service.id, 'component_id': component_id}
                 for host_id, component_id in (
                     (hosts[1].id, components[self.SPICE_COMPONENT].id),
                     (hosts[1].id, components[self.LEMON_COMPONENT].id),
                     (hosts[2].id, components[self.TOMATO_COMPONENT].id),
                 )
             )
         )
     ).wait()
     cluster.hostcomponent_set(
         (hosts[0], components[self.MILK_COMPONENT]),
         *[
             (cluster.host(id=hc['host_id']), service.component(id=hc['component_id']))
             for hc in cluster.hostcomponent()
         ],
     )
     _wait_for_tasks(
         (
             components[self.TOMATO_COMPONENT].action(name='add_more').run(),
             components[self.SPICE_COMPONENT].action(name='add_more').run(),
         )
     )
Example #2
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)
Example #3
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")
Example #4
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)
Example #5
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
Example #6
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')
Example #7
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)
Example #8
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)
Example #9
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)
Example #10
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')
Example #11
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)
Example #12
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
Example #13
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