Exemple #1
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,
    )
Exemple #2
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)
Exemple #3
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)
Exemple #4
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)
Exemple #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)
Exemple #6
0
def test_create_one_host(second_p: Provider):
    """Test scenario:

    1. Create three providers
    2. Create host on one of the providers
    3. Ensure host exists
    """
    hostname = "second_h"
    with allure.step('Run action create host'):
        second_p.action(name="create_host").run(config_diff={'fqdn': hostname}).try_wait()
        second_h = second_p.host(fqdn=hostname)
    with allure.step('Check if host is created'):
        assert second_h.provider().id == second_p.id
        assert second_h.fqdn == hostname
Exemple #7
0
def test_create_multi_host_and_delete_one(first_p: Provider, third_p: Provider):
    """Test scenario:

    1. Create three providers
    2. Create two host from first providers
    3. Create one host from third provider
    4. Remove one of host binded to first provider
    5. Check that host has been removed
    6. Check that other hosts still there.
    """
    with allure.step('Create two host from first providers'):
        first_p.action(name="create_host").run(config_diff={'fqdn': "one_one"}).try_wait()
        first_p.action(name="create_host").run(config_diff={'fqdn': "one_two"}).try_wait()
    with allure.step('Create one host from third provider'):
        third_p.action(name="create_host").run(config_diff={'fqdn': "three_one"}).try_wait()
    with allure.step('Remove one of host binded to first provider'):
        one_two = first_p.host(fqdn="one_two")
        one_two.action(name="remove_host").run().try_wait()
    with allure.step('Check that host has been removed'):
        assert first_p.host(fqdn="one_one").fqdn == "one_one"
    with allure.step('Check that other hosts still there'):
        assert third_p.host(fqdn="three_one").fqdn == "three_one"
        with pytest.raises(adcm_client.base.ObjectNotFound):
            first_p.host(fqdn="one_two")
Exemple #8
0
def _expect_correct_fail_on_config(cluster: Cluster, provider: Provider,
                                   config: dict, error: ADCMError):
    """Check that config_set fails with CONFIG_VALUE_ERROR"""
    component = (service := cluster.service()).component()
    host = provider.host()
    for obj in (cluster, service, component, provider, host):
        with allure.step(
                f'Try to change config of {obj.__class__.__name__} and expect {error}'
        ):
            try:
                obj.config_set(config)
            except ErrorMessage as e:
                error.equal(e)
            else:
                raise AssertionError("Config set should've failed")
Exemple #9
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')
Exemple #10
0
def test_check_host_lock_during_operations(forth_p: Provider):
    """Test scenario:

    1. Create provider
    2. Create host first host on provider
    3. Run job that creates the second host on provider
    4. Wait until second host will be created.
    5. Check that both host is locked
    6. Wait for job to be finished without errors
    7. Check that both hosts is free
    8. Run remove action on one of hosts
    9. Check that host under action is locked, while other host is free
    10. Wait for job to be finished without errors
    11. Check that remaining host is free.
    """
    with allure.step('Create host first host on provider'):
        forth_p.action(name="create_host").run(config_diff={'fqdn': "forth_one"}).try_wait()
    with allure.step('Run job that creates the second host on provider'):
        job = forth_p.action(name="create_host").run(config={'fqdn': "forth_two", 'sleep': 2})
    with allure.step('Wait until second host will be created'):
        wait_until_step_succeeds(_assert_that_object_exists, period=0.5, get_object_func=forth_p.host, fqdn="forth_two")
        forth_two_h = forth_p.host(fqdn="forth_two")
        forth_one_h = forth_p.host(fqdn='forth_one')
    with allure.step('Check that both host has is locked'):
        assert forth_one_h.locked is True
        assert forth_two_h.locked is True
    with allure.step('Wait for job to be finished without errors'):
        job.try_wait()
    with allure.step('Check that both hosts is free'):
        forth_one_h.reread()
        forth_two_h.reread()
        assert forth_one_h.locked is False
        assert forth_two_h.locked is False
    with allure.step('Run remove action on one of hosts'):
        job = forth_one_h.action(name="remove_host").run(config={"sleep": 2})
    with allure.step('Check that host under action is locked, while other host is free'):
        forth_one_h.reread()
        forth_two_h.reread()
        assert forth_one_h.locked is True
        assert forth_two_h.locked is False
    with allure.step('Wait for job to be finished without errors'):
        job.try_wait()
    with allure.step('Check that remaining host is free'):
        forth_two_h.reread()
        assert forth_two_h.locked is False
Exemple #11
0
def test_pass_no_config(cluster: Cluster, provider: Provider,
                        sdk_client_fs: ADCMClient):
    """
    Action has config
    Run action without 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 run action that require config with on {obj.__class__.__name__}'
        ):
            with allure.step(
                    'Run action that require config without config and expect ADCM to response with non 500 status code'
            ):
                try:
                    ACTION_MAP[obj.__class__](obj, 'with_config', 'failed')
                except ErrorMessage as e:
                    CONFIG_VALUE_ERROR.equal(e)
                else:
                    raise AssertionError("Action run should've failed")
            with allure.step("Check that job wasn't launched"):
                _check_job_count_equal_to(job_count, sdk_client_fs)