コード例 #1
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}'
コード例 #2
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"]}')
コード例 #3
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"]}'
コード例 #4
0
def wait_for_task_and_assert_result(task: Task,
                                    status: str,
                                    action_name: str = None,
                                    timeout=None):
    """
    Wait for a task to be completed and assert status to be equal to 'status' argument
    If task is expected to succeed bur have failed then ansible error will be added to
    AssertionError message
    """
    result = task.wait(timeout=timeout)
    ansible_error = ""
    if result != status and status == "success":
        ansible_error = get_error_text_from_task_logs(task)
    assert_action_result(
        name=action_name or task.action().name,
        result=result,
        status=status,
        additional_message=ansible_error,
    )
コード例 #5
0
def test_result_no(sdk_client_fs: ADCMClient):
    """Check config with result no"""
    params = {
        "action": "adcm_check",
        "expected_state": States.success,
    }
    bundle_dir = utils.get_data_dir(__file__, "result_no")
    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 result is False"):
        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 False'
コード例 #6
0
def test_multiple_tasks_action_with_log_files_check(sdk_client_fs: ADCMClient):
    """Check that log_files parameter don't affect action"""
    params = {
        "action": "check_sample",
        "expected_state": States.success,
    }

    bundle_dir = utils.get_data_dir(__file__, "log_files_check")
    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 result is True"):
        logs = job.log_list()
        log = job.log(job_id=job.id, log_id=logs[2].id)
        content = log.content[0]
        assert content[
            "result"], f'Result is {content["result"]}, Expected True'