Exemplo n.º 1
0
def _test_related_hc(client: ADCMClient, case_path: str):
    with allure.step("Upload custom provider bundle and create it in ADCM"):
        provider_bundle = client.upload_from_fs(
            get_data_dir(__file__) + "/provider")
        provider = provider_bundle.provider_prototype().provider_create(
            random_string())
    with allure.step("Upload custom cluster bundle and create it in ADCM"):
        bundle_path = case_path.split(CASES_PATH)[0]
        cluster_bundle = client.upload_from_fs(bundle_path)
        created_cluster = cluster_bundle.cluster_prototype().cluster_create(
            random_string())
    with allure.step(
            "Parse case description from YAML file and set host-component map"
    ):
        with open(case_path, encoding='utf_8') as file:
            case_template = yaml.safe_load(file)
        allure.dynamic.description(case_template["description"])
        hostcomponent_list = []
        for host in case_template["hc_map"].keys():
            added_host = created_cluster.host_add(
                provider.host_create(fqdn=f"fqdn_{random_string()}"))
            for service_with_component in case_template["hc_map"][host]:
                service_name, component_name = service_with_component.split(
                    ".")
                service = _get_or_add_service(created_cluster, service_name)
                hostcomponent_list.append(
                    (added_host, service.component(name=component_name)))
        expectation = _does_not_raise(
        ) if case_template["positive"] else pytest.raises(ErrorMessage)
        with expectation:
            created_cluster.hostcomponent_set(*hostcomponent_list)
Exemplo n.º 2
0
 def test_when_delete_host_all_children_cannot_be_deleted(self, client):
     # Should be faild if random service has not components
     cluster = steps.create_cluster(client)
     with allure.step('Create provider'):
         provider = client.provider.create(
             prototype_id=client.stack.provider.list()[0]['id'],
             name=utils.random_string())
     with allure.step('Create host'):
         host = client.host.create(
             prototype_id=client.stack.host.list()[0]['id'],
             provider_id=provider['id'],
             fqdn=utils.random_string())
     steps.add_host_to_cluster(client, host, cluster)
     with allure.step('Create random service'):
         service = steps.create_random_service(client, cluster['id'])
     with allure.step('Create random service component'):
         component = get_random_cluster_service_component(
             client, cluster, service)
     with allure.step('Create hostcomponent'):
         steps.create_hostcomponent_in_cluster(client, cluster, host,
                                               service, component)
     with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
         client.cluster.host.delete(host_id=host['id'],
                                    cluster_id=cluster['id'])
     with allure.step('Check host conflict'):
         err.HOST_CONFLICT.equal(e)
def test_should_create_provider_w_description(sdk_client_fs: ADCMClient):
    """Test create provider with description"""
    bundle = sdk_client_fs.upload_from_fs(BUNDLES + "hostprovider_bundle")
    description = utils.random_string(140)
    provider = bundle.provider_create(name=utils.random_string(),
                                      description=description)
    with allure.step("Check provider with description"):
        assert provider.description == description
Exemplo n.º 4
0
 def test_create_host_with_max_length_plus_1(self, sdk_client_fs: ADCMClient):
     """We cannot create host with name more then max length
     """
     bundle = sdk_client_fs.upload_from_fs(get_data_dir(__file__, 'hostprovider_simple'))
     hp = bundle.provider_create(utils.random_string())
     with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
         hp.host_create(utils.random_string(257))
     with allure.step('Check LONG_NAME error'):
         err.LONG_NAME.equal(e, 'Host name is too long. Max length is 256')
Exemplo n.º 5
0
 def test_shouldnt_create_host_wo_prototype(self, client):
     with allure.step('Create provider'):
         provider = client.provider.create(prototype_id=client.stack.provider.list()[0]['id'],
                                           name=utils.random_string())
     with allure.step('Try to create host without prototype'):
         with pytest.raises(coreapi.exceptions.ParameterError) as e:
             client.host.create(provider_id=provider['id'], fqdn=utils.random_string())
     with allure.step('Check prototype_id error'):
         assert str(e.value) == "{'prototype_id': 'This parameter is required.'}"
Exemplo n.º 6
0
 def test_shouldnt_create_cluster_when_proto_is_string(self, client):
     with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
         client.cluster.create(prototype_id=utils.random_string(),
                               name=utils.random_string())
     with allure.step('Check error about valid integer'):
         assert e.value.error.title == '400 Bad Request'
         assert e.value.error['prototype_id'][
             0] == 'A valid integer is required.'
     steps.delete_all_data(client)
Exemplo n.º 7
0
 def test_shouldnt_create_host_config_when_config_not_json_string(self, client):
     """Should not create host configuration when config string is not json
     """
     host = steps.create_host_w_default_provider(client, utils.random_string())
     config = utils.random_string()
     with allure.step('Try to create the host config from non-json string'):
         with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
             client.host.config.history.create(host_id=host['id'], config=config)
     with allure.step('Check error config should not be just one string'):
         err.JSON_ERROR.equal(e, 'config should not be just one string')
Exemplo n.º 8
0
 def test_shouldnt_create_host_with_wrong_name(self, sdk_client_fs: ADCMClient):
     """Check  that host name cannot contain special characters
     """
     bundle = sdk_client_fs.upload_from_fs(get_data_dir(__file__, 'hostprovider_simple'))
     hp = bundle.provider_create(utils.random_string())
     with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
         hp.host_create(utils.random_string() + utils.random_special_chars())
     with allure.step('Check WRONG_NAME error'):
         err.WRONG_NAME.equal(e, 'Host name is incorrect. '
                                 'Only latin characters, digits, dots (.)')
def test_should_create_provider_w_description(client):
    steps.upload_bundle(client, BUNDLES + 'hostprovider_bundle')
    with allure.step('Create provider'):
        description = utils.random_string()
        provider = client.provider.create(
            prototype_id=client.stack.provider.list()[0]['id'],
            name=utils.random_string(),
            description=description)
    with allure.step('Check provider with description'):
        assert provider['description'] == description
Exemplo n.º 10
0
def test_action_should_not_be_run_while_host_has_an_issue(
        sdk_client_fs: ADCMClient):
    """Test action should not be run while host has an issue"""
    bundle_path = utils.get_data_dir(__file__, "host")
    bundle = sdk_client_fs.upload_from_fs(bundle_path)
    provider = bundle.provider_create(name=utils.random_string())
    host = provider.host_create(fqdn=utils.random_string())
    with allure.step(f"Run action with error for host {host.fqdn}"):
        with pytest.raises(ActionHasIssues):
            host.action(name="install").run()
Exemplo n.º 11
0
 def test_should_return_correct_error_when_read_deleted(self, sdk_client_fs: ADCMClient):
     """Check that we have 409 error if host not found"""
     bundle = sdk_client_fs.upload_from_fs(get_data_dir(__file__, 'hostprovider_simple'))
     hp = bundle.provider_create(utils.random_string())
     host = hp.host_create(utils.random_string())
     with allure.step('delete host'):
         host.delete()
     with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
         host.reread()
     with allure.step('Check HOST_NOT_FOUND'):
         err.HOST_NOT_FOUND.equal(e)
Exemplo n.º 12
0
 def test_shouldnt_create_host_with_unknown_prototype(self, client):
     with allure.step('Create provider'):
         provider_id = client.provider.create(prototype_id=client.stack.provider.list()[0]['id'],
                                              name=utils.random_string())['id']
     with allure.step('Create host'):
         with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
             client.host.create(prototype_id=random.randint(100, 500),
                                provider_id=provider_id,
                                fqdn=utils.random_string())
     with allure.step('Check PROTOTYPE_NOT_FOUND error'):
         err.PROTOTYPE_NOT_FOUND.equal(e, 'prototype doesn\'t exist')
Exemplo n.º 13
0
 def test_should_create_host_config_when_parameter_is_integer_and_not_float(
         self, sdk_client_fs: ADCMClient):
     """Create host config for float parameter with integer
     """
     bundle = sdk_client_fs.upload_from_fs(get_data_dir(__file__, 'hostprovider_bundle'))
     hp = bundle.provider_create(utils.random_string())
     host = hp.host_create(utils.random_string())
     config = {"str-key": "{1bbb}", "required": 158, "fkey": 18, "option": "my.host",
               "sub": {"sub1": 3},
               "credentials": {"sample_string": "txt", "read_only_initiated": {}}}
     host.config_set(config)
Exemplo n.º 14
0
def test_provider_shouldnt_be_deleted_when_it_has_host(
        sdk_client_fs: ADCMClient):
    """Test delete provider with host should fail"""
    bundle = sdk_client_fs.upload_from_fs(BUNDLES + "hostprovider_bundle")
    provider = bundle.provider_create(name=utils.random_string())
    provider.host_create(fqdn=utils.random_string())
    with allure.step("Delete provider"):
        with pytest.raises(exceptions.ErrorMessage) as e:
            provider.delete()
    with allure.step("Check error"):
        errorcodes.PROVIDER_CONFLICT.equal(e, "There is host ",
                                           " of host provider ")
Exemplo n.º 15
0
def test_check_host_state_after_run_action_when_empty(
        host_bundle, state, sdk_client_fs: ADCMClient):
    """Test host state after action"""
    bundle_path = utils.get_data_dir(__file__, "empty_states", host_bundle)
    bundle = sdk_client_fs.upload_from_fs(bundle_path)
    provider = bundle.provider_prototype().provider_create(
        name=utils.random_string())
    host = provider.host_create(fqdn=utils.random_string())
    host.action(name="init").run().wait()
    with allure.step(f"Check if host is in state {state}"):
        host.reread()
        assert host.state == state
Exemplo n.º 16
0
def test_when_host_config_must_contains_some_subkeys(sdk_client_fs: ADCMClient):
    stack_dir = utils.get_data_dir(__file__, 'host_config_with_empty_subkeys')
    bundle = sdk_client_fs.upload_from_fs(stack_dir)
    with allure.step('Create provider'):
        bad_config = {"str-key": "bluh", "subkeys": {}}
        provider = bundle.provider_create(utils.random_string())
    with allure.step('Create host'):
        host = provider.host_create(utils.random_string())
    with allure.step('Set bad config: "str-key": "bluh", "subkeys": {}'):
        with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
            host.config_set(bad_config)
    with allure.step('Check error: should contains some subkeys'):
        errorcodes.CONFIG_KEY_ERROR.equal(e, 'should contains some subkeys')
Exemplo n.º 17
0
 def test_adding_host_to_cluster(self, sdk_client_fs: ADCMClient):
     bundle = sdk_client_fs.upload_from_fs(
         get_data_dir(__file__, 'cluster_simple'))
     bundle_hp = sdk_client_fs.upload_from_fs(
         get_data_dir(__file__, 'hostprovider_bundle'))
     cluster = bundle.cluster_create(utils.random_string())
     hp = bundle_hp.provider_create(utils.random_string())
     host = hp.host_create(utils.random_string())
     actual = cluster.host_add(host)
     with allure.step('Get cluster host info'):
         expected = cluster.host_list()[0]
     with allure.step('Check mapping'):
         assert actual.fqdn == expected.fqdn
         assert actual.id == expected.id
Exemplo n.º 18
0
 def test_partial_update_cluster_name_and_desc(self, client):
     name = utils.random_string()
     desc = utils.random_string()
     with allure.step('Create cluster'):
         cluster = steps.create_cluster(client)
     with allure.step('Trying to update cluster name and description'):
         expected = steps.partial_update_cluster(client, cluster, name,
                                                 desc)
     with allure.step('Take actual data about cluster'):
         actual = steps.read_cluster(client, cluster['id'])
     with allure.step('Check actual and expected result'):
         assert expected['name'] == name
         assert expected == actual
     steps.delete_all_data(client)
Exemplo n.º 19
0
 def test_should_return_correct_error_when_delete_nonexist_host(
         self, sdk_client_fs: ADCMClient):
     """If we try to delete deleted host we've got 409 error.
     """
     bundle = sdk_client_fs.upload_from_fs(get_data_dir(__file__, 'hostprovider_simple'))
     hp = bundle.provider_create(utils.random_string())
     host = hp.host_create(utils.random_string())
     with allure.step('delete host'):
         host.delete()
     with allure.step('delete host second time'):
         with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
             host.delete()
     with allure.step('Check HOST_NOT_FOUND'):
         err.HOST_NOT_FOUND.equal(e, 'host doesn\'t exist')
Exemplo n.º 20
0
 def test_host_along_to_cluster_shouldnt_deleted(self,
                                                 sdk_client_fs: ADCMClient):
     bundle = sdk_client_fs.upload_from_fs(
         get_data_dir(__file__, 'cluster_simple'))
     bundle_hp = sdk_client_fs.upload_from_fs(
         get_data_dir(__file__, 'hostprovider_bundle'))
     cluster = bundle.cluster_create(utils.random_string())
     hp = bundle_hp.provider_create(utils.random_string())
     host = hp.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')
Exemplo n.º 21
0
def test_shouldnt_create_host_with_unknown_prototype(sdk_client_fs):
    """Test create host with unknown prototype should fail"""
    bundle = sdk_client_fs.upload_from_fs(BUNDLES + "hostprovider_bundle")
    provider = bundle.provider_create(name=utils.random_string())
    with allure.step("Delete provider"):
        provider.delete()
    with allure.step("Create host"):
        with pytest.raises(exceptions.ErrorMessage) as e:
            # Using lack of auto refresh of object as workaround.
            # If adcm_client object behaviour will be changed, test may fall.
            provider.host_create(fqdn=utils.random_string())
    with allure.step("Check error provider doesnt exist"):
        errorcodes.PROVIDER_NOT_FOUND.equal(e, "HostProvider",
                                            "does not exist")
Exemplo n.º 22
0
 def test_create_host(self, sdk_client_fs: ADCMClient):
     """Check that host have same fqdn and status after reread config
     """
     bundle = sdk_client_fs.upload_from_fs(get_data_dir(__file__, 'hostprovider_bundle'))
     hp = bundle.provider_create(utils.random_string())
     host = hp.host_create(utils.random_string())
     host_status_before = host.status
     host_fqdn_before = host.fqdn
     with allure.step('Reread host'):
         host.reread()
         host_status_after = host.status
         host_fqdn_after = host.fqdn
     with allure.step('Check states and fqdn'):
         assert host_fqdn_before == host_fqdn_after
         assert host_status_before == host_status_after
Exemplo n.º 23
0
 def get_random_config_map() -> dict:
     return {
         'a_lot_of_text': {'simple_string': random_string(25), 'file_pass': random_string(16)},
         'from_doc': {
             'memory_size': random.randint(2, 64),
             'person': {
                 'name': random_string(13),
                 'age': str(random.randint(14, 80)),
                 'custom_field': random_string(12),
             },
         },
         'country_codes': [
             {'country': random_string(12), 'code': int(random.randint(1, 200))} for _ in range(4)
         ],
     }
Exemplo n.º 24
0
 def test_shouldnt_create_duplicate_host_in_cluster(
         self, sdk_client_fs: ADCMClient):
     bundle = sdk_client_fs.upload_from_fs(
         get_data_dir(__file__, 'cluster_simple'))
     bundle_hp = sdk_client_fs.upload_from_fs(
         get_data_dir(__file__, 'hostprovider_bundle'))
     cluster = bundle.cluster_create(utils.random_string())
     hp = bundle_hp.provider_create(utils.random_string())
     host = hp.host_create(utils.random_string())
     with allure.step('Create mapping between cluster and host'):
         cluster.host_add(host)
         with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
             cluster.host_add(host)
     with allure.step('Check error about duplicate host in cluster'):
         err.HOST_CONFLICT.equal(e, 'duplicate host in cluster')
def prepare_cluster(sdk_client: ADCMClient, path) -> Cluster:
    """Create cluster"""

    bundle = sdk_client.upload_from_fs(path)
    cluster_name = "_".join(path.split("/")[-1:] + [random_string()])
    cluster = bundle.cluster_create(name=cluster_name)
    return cluster
Exemplo n.º 26
0
def prepare_cluster_and_get_config(sdk_client: ADCMClient, path, app):
    bundle = sdk_client.upload_from_fs(path)
    cluster_name = "_".join(path.split("/")[-1:] + [random_string()])
    cluster = bundle.cluster_create(name=cluster_name)
    config = Configuration(
        app.driver, f"{app.adcm.url}/cluster/{cluster.cluster_id}/config")
    return cluster, config
Exemplo n.º 27
0
def test_all_fields(sdk_client_fs: ADCMClient, name, result):
    """Check that we can run jobs with all fields for
    adcm_check task and check all fields after action
    execution.
    """
    group_msg, task_msg, group_result, task_result = result
    params = {
        "action": "adcm_check",
        "expected_state": States.success,
        "expected_title": "Name of group check.",
        "content_title": "Check",
    }
    cluster = sdk_client_fs.upload_from_fs(utils.get_data_dir(
        __file__, name)).cluster_create(utils.random_string())
    task = run_cluster_action_and_assert_result(
        cluster, action=params["action"], status=params["expected_state"])
    job = task.job()
    with allure.step("Check all fields after action execution"):
        logs = job.log_list()
        content = job.log(job_id=job.id, log_id=logs[2].id).content[0]
        assert content[
            "message"] == group_msg, f'Expected message {group_msg}. Current message {content["message"]}'
        assert content["result"] is group_result
        assert (
            content["title"] == params["expected_title"]
        ), f'Expected title {params["expected_title"]}. Current title {content["title"]}'
        content_title = content["content"][0]["title"]
        assert (
            content_title == params["content_title"]
        ), f'Expected title {params["content_title"]}. Current title {content_title}'
        content_message = content["content"][0]["message"]
        assert content_message == task_msg, f"Expected message {task_msg}. Current message {content_message}"
        assert content["content"][0]["result"] is task_result
Exemplo n.º 28
0
def test_field_validation(sdk_client_fs: ADCMClient, missed_field):
    """Check bad configurations: missed title,
    missed result field, missed message field,
    only success message field, only fail message field.
    Expected result: job failed.
    """
    params = {
        "action": "adcm_check",
        "expected_state": States.failed,
        "logs_amount": 2
    }
    bundle_dir = utils.get_data_dir(__file__, missed_field)
    bundle = sdk_client_fs.upload_from_fs(bundle_dir)
    cluster = bundle.cluster_create(utils.random_string())
    task = cluster.action(name=params["action"]).run()
    task.wait()
    assert_action_result(result=task.status,
                         status=params["expected_state"],
                         name=params["action"])
    with allure.step(f'Check if logs count is equal {params["logs_amount"]}'):
        job = task.job()
        logs = job.log_list()
        current_len = len(logs)
        assert (
            current_len == params["logs_amount"]
        ), f'Logs count not equal {params["logs_amount"]}, current log count {current_len}'
Exemplo n.º 29
0
def test_success_and_fail_msg_on_fail(sdk_client_fs: ADCMClient):
    """Check that we can run adcm_check plugin with success and fail message and
    success and fail message will be in their own fields.
    """
    params = {
        "action": "adcm_check",
        "expected_state": States.success,
        "expected_message": MessageStates.fail_msg,
    }
    bundle_dir = utils.get_data_dir(__file__, "success_and_fail_msg_on_fail")
    bundle = sdk_client_fs.upload_from_fs(bundle_dir)
    cluster = bundle.cluster_create(utils.random_string())
    task = cluster.action(name=params["action"]).run()
    task.wait()
    job = task.job()
    assert_action_result(result=job.status,
                         status=params["expected_state"],
                         name=params["action"])
    with allure.step(
            "Check if success and fail message are in their own fields"):
        logs = job.log_list()
        log = job.log(job_id=job.id, log_id=logs[2].id)
        content = log.content[0]
        assert not content[
            "result"], f'Result is {content["result"]} expected True'
        assert content["message"] == params["expected_message"], (
            f'Expected message: {params["expected_message"]}. '
            f'Current message {content["message"]}')
Exemplo n.º 30
0
def test_message_with_other_field(sdk_client_fs: ADCMClient, name):
    """Check that we can create action with
    specific (success or fail) message and message.
    Expected that missed message will be written in
    msg attribute and specific message
    will be in success or fail attribute depends on config.
    """
    params = {
        "action": "adcm_check",
        "expected_state": States.success,
    }
    bundle_dir = utils.get_data_dir(__file__, name)
    bundle = sdk_client_fs.upload_from_fs(bundle_dir)
    cluster = bundle.cluster_create(utils.random_string())
    task = cluster.action(name=params["action"]).run()
    task.wait()
    job = task.job()
    assert_action_result(result=job.status,
                         status=params["expected_state"],
                         name=params["action"])
    with allure.step(f"Check if content message is {name}"):
        logs = job.log_list()
        log = job.log(log_id=logs[2].id)
        content = log.content[0]
        assert content[
            "message"] == name, f'Expected content message {name}. Current {content["message"]}'