Beispiel #1
0
def test_multi_state_set_unset_from_different_objects(
        two_clusters: Tuple[Cluster, Cluster], sdk_client_fs: ADCMClient):
    """
    Check that one object change multi-state of another object
        and another object can unset this multi-state
    """
    cluster = two_clusters[0]
    cluster_name = compose_name(cluster)
    service = cluster.service()
    service_name = compose_name(service)
    with check_objects_multi_state_changed(sdk_client_fs, {
            service
    }), allure.step(f'Set multi_state of {service_name} from {cluster_name}'):
        run_cluster_action_and_assert_result(cluster,
                                             f'set_{service.name}_service')

    with check_multi_state_was_unset(
            sdk_client_fs,
        {service
         }), allure.step(f'Unset multi_state of {service_name} from itself'):
        run_service_action_and_assert_result(service, 'unset_service')

    with check_objects_multi_state_changed(
            sdk_client_fs,
        {cluster
         }), allure.step(f'Set multi_state of {cluster_name} from itself'):
        run_cluster_action_and_assert_result(cluster, 'set_cluster')

    with check_multi_state_was_unset(sdk_client_fs, {cluster}), allure.step(
            f'Unset multi_state of {cluster_name} from {service_name}'):
        run_service_action_and_assert_result(service, 'unset_cluster')
Beispiel #2
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')
Beispiel #3
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)
Beispiel #4
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})
Beispiel #5
0
def test_ansible_set_on_prototype(cluster_obj_venv_9: Cluster,
                                  provider_obj_venv_9: Provider):
    """
    Check that we able to change ansible on prototype level, by tweaking venv
    property for object.
    """
    run_cluster_action_and_assert_result(cluster_obj_venv_9,
                                         "obj_venv_9",
                                         config=ANSIBLE_9)
    run_service_action_and_assert_result(
        cluster_obj_venv_9.service(name="obj_venv_9"),
        "obj_venv_9",
        config=ANSIBLE_9)
    run_component_action_and_assert_result(cluster_obj_venv_9.service(
        name="obj_venv_9").component(name="obj_venv_9"),
                                           "obj_venv_9",
                                           config=ANSIBLE_9)

    run_provider_action_and_assert_result(provider_obj_venv_9,
                                          "obj_venv_9",
                                          config=ANSIBLE_9)
    run_host_action_and_assert_result(
        provider_obj_venv_9.host(fqdn="obj_venv_9"),
        "obj_venv_9",
        config=ANSIBLE_9)
Beispiel #6
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,
    )
Beispiel #7
0
def test_missing_ok_multi_state_unset(two_providers: Tuple[Provider, Provider],
                                      two_clusters: Tuple[Cluster, Cluster],
                                      sdk_client_fs: ADCMClient):
    """
    Checking behaviour of flag "missing_ok":
        - Job fails when flag is "false" and state is not in multi_state
        - Job succeed when flag is "true" and state is not in multi_state
    """
    host = (provider := two_providers[0]).host()
    component = (service := (cluster := two_clusters[0]).service()).component()
    with allure.step(
            'Check job fails with "missing_ok: false" and state not in multi_state'
    ):
        for forbidden_action in ('unset_provider', 'unset_host'):
            with check_objects_multi_state_changed(sdk_client_fs):
                run_host_action_and_assert_result(host, forbidden_action,
                                                  'failed')
        with check_objects_multi_state_changed(sdk_client_fs):
            run_provider_action_and_assert_result(provider,
                                                  'unset_host_from_provider',
                                                  status='failed',
                                                  config={'host_id': host.id})
        with check_objects_multi_state_changed(sdk_client_fs):
            run_cluster_action_and_assert_result(cluster,
                                                 'unset_cluster',
                                                 status='failed')
        with check_objects_multi_state_changed(sdk_client_fs):
            run_service_action_and_assert_result(service,
                                                 'unset_service',
                                                 status='failed')
        with check_objects_multi_state_changed(sdk_client_fs):
            run_component_action_and_assert_result(component,
                                                   'unset_component',
                                                   status='failed')

    with allure.step(
            'Check job succeed with "missing_ok: true" without changing multi_state of any object'
    ):
        for allowed_action in ('unset_provider_missing', 'unset_host_missing'):
            with check_objects_multi_state_changed(sdk_client_fs):
                run_host_action_and_assert_result(host, allowed_action)
        with check_objects_multi_state_changed(sdk_client_fs):
            run_provider_action_and_assert_result(
                provider,
                'unset_host_from_provider_missing',
                config={'host_id': host.id})
        with check_objects_multi_state_changed(sdk_client_fs):
            run_cluster_action_and_assert_result(cluster,
                                                 'unset_cluster_missing')
        with check_objects_multi_state_changed(sdk_client_fs):
            run_service_action_and_assert_result(service,
                                                 'unset_service_missing')
        with check_objects_multi_state_changed(sdk_client_fs):
            run_component_action_and_assert_result(component,
                                                   'unset_component_missing')
Beispiel #8
0
 def run_actions_after_upgrade(
     self, cluster_all_services: Cluster, cluster_config_history: Cluster, simple_provider: Provider
 ) -> None:
     """
     Run successful actions on: cluster, service, component.
     Run failed action on provider.
     """
     sauce_service = cluster_config_history.service(name=self.SAUCE_SERVICE)
     run_cluster_action_and_assert_result(cluster_all_services, 'eat_sandwich')
     run_service_action_and_assert_result(sauce_service, 'put_on_bread')
     run_component_action_and_assert_result(sauce_service.component(name=self.SPICE_COMPONENT), 'add_more')
     run_provider_action_and_assert_result(simple_provider, 'validate', status='failed')
Beispiel #9
0
def test_actions(sdk_client_fs: ADCMClient):
    """
    Tests that action works on latest adcm client and old adcm versions
    """
    cluster_bundle = sdk_client_fs.upload_from_fs(get_data_dir(__file__, "cluster"))
    provider_bundle = sdk_client_fs.upload_from_fs(get_data_dir(__file__, 'provider'))
    cluster = cluster_bundle.cluster_prototype().cluster_create(name="Some cluster")
    service = cluster.service_add(name="dummy")
    provider = provider_bundle.provider_create("provider_with_actions")
    host = provider.host_create(fqdn="localhost")
    run_cluster_action_and_assert_result(cluster, "dummy")
    run_service_action_and_assert_result(service, "dummy")
    run_host_action_and_assert_result(host, "dummy")
    assert provider.action(name="dummy").run().wait() == "success"
Beispiel #10
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 #11
0
 def run_immediate_change_test(self, provider_host: Tuple[Provider, Host],
                               cluster_service_component: Tuple[Cluster,
                                                                Service,
                                                                Component]):
     """
     Run the same action (self._action) for cluster, service, component, provider, host
         and expect them to succeed
     """
     cluster, service, component = cluster_service_component
     provider, host = provider_host
     run_cluster_action_and_assert_result(cluster, self._action)
     run_service_action_and_assert_result(service, self._action)
     run_component_action_and_assert_result(component, self._action)
     run_provider_action_and_assert_result(provider, self._action)
     run_host_action_and_assert_result(host, self._action)
Beispiel #12
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 #13
0
 def test_service_state_after_action(self, sdk_client_fs: ADCMClient,
                                     cluster_and_states_checker):
     """Test service state after action"""
     cluster_obj, check_objects_state_changed = cluster_and_states_checker
     object_to_be_changed = cluster_obj.service_add(name='first_srv')
     cluster_obj.service_add(name='second_srv')
     with check_objects_state_changed(
             sdk_client_fs,
         {object_to_be_changed
          }), allure.step(f'Run service action: {ACTION_NAME}'):
         run_service_action_and_assert_result(
             object_to_be_changed,
             action=ACTION_NAME,
             status="success"
             if "fail" not in cluster_obj.name else "failed",
         )
Beispiel #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)
Beispiel #15
0
def test_component_action_availability_at_state(
        cluster_with_components: Cluster):
    """
    Test that component action is available on specific component state
    """
    service = cluster_with_components.service_add(name=FIRST_SERVICE)
    component_1 = service.component(name=FIRST_COMPONENT)
    component_2 = service.component(name=SECOND_COMPONENT)

    _assert_actions_state_created(component_1)
    run_cluster_action_and_assert_result(cluster_with_components,
                                         SWITCH_CLUSTER_STATE)
    _assert_actions_state_created(component_1)
    run_service_action_and_assert_result(service, SWITCH_SERVICE_STATE)
    _assert_actions_state_created(component_1)
    run_component_action_and_assert_result(component_1, SWITCH_COMPONENT_STATE)
    _assert_actions_state_installed(component_1)
    _assert_actions_state_created(component_2)
    run_component_action_and_assert_result(component_1, ACTION_STATE_INSTALLED)
Beispiel #16
0
 def test_service_multi_state_after_action(
         self, sdk_client_fs: ADCMClient, cluster_and_multi_states_checker):
     """
     Test service and multi states after action
     Before action add multi state that should be unset via action
     """
     cluster_obj, check_objects_multi_state_changed = cluster_and_multi_states_checker
     object_to_be_changed = cluster_obj.service_add(name='first_srv')
     cluster_obj.service_add(name='second_srv')
     run_service_action_and_assert_result(object_to_be_changed,
                                          ACTION_SET_MULTISTATE_NAME)
     with check_objects_multi_state_changed(
             sdk_client_fs,
         {object_to_be_changed
          }), allure.step(f'Run service action: {ACTION_NAME}'):
         run_service_action_and_assert_result(
             object_to_be_changed,
             action=ACTION_NAME,
             status="success"
             if "fail" not in cluster_obj.name else "failed",
         )
Beispiel #17
0
def test_forbidden_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"
    first_first_fqdn = "first-first"
    first_second_fqdn = "first-second"
    with allure.step(f'Check forbidden from cluster "{name}" context actions'):
        cluster = sdk_client_fs.cluster(name=name)
        for forbidden_action in ('set_service', 'set_component'):
            with check_objects_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)
        with check_objects_state_changed(sdk_client_fs):
            run_service_action_and_assert_result(service,
                                                 'set_component',
                                                 status='failed')
    with allure.step(
            f'Check forbidden from provider "{name}" context actions'):
        provider = sdk_client_fs.provider(name=name)
        with check_objects_state_changed(sdk_client_fs):
            run_provider_action_and_assert_result(provider,
                                                  'set_host',
                                                  status='failed')
    with allure.step(
            f'Check forbidden from host "{first_first_fqdn}" context actions'):
        host_first = sdk_client_fs.host(fqdn=first_first_fqdn)
        host_second = sdk_client_fs.host(fqdn=first_second_fqdn)
        with check_objects_state_changed(sdk_client_fs):
            run_host_action_and_assert_result(
                host_first,
                'set_host_from_provider',
                config={'host_id': host_second.id},
                status='failed')