Beispiel #1
0
def execute_test():

    # this testcase is using tarball bundle so it gets all empty folders. They would get skipped by git. So in that
    # case it is better to untar and cleanup to have easy "diff" than to hack "diff -ignore" files.

    output_table = []

    with test_utils.untar_bundle(container_name) as bundle_path:
        # Test 0
        test = tests[0]
        status = test_utils.run_command_line([
            "DobbyBundleGenerator", "-i",
            test_utils.get_container_spec_path(test.container_id), "-o",
            test_utils.get_bundle_path(test.container_id)
        ])

        message = ""
        result = True
        if test.expected_output.lower() not in status.stdout.lower():
            message = "Failed to run Dobby Bundle Generator Tool"
            result = False
        if "failed to create bundle" in status.stderr.lower():
            message = "Failed to create bundle"
            result = False

        output = test_utils.create_simple_test_output(test, result, message,
                                                      status.stderr)
        output_table.append(output)
        test_utils.print_single_result(output)

        # Test 1
        test = tests[1]
        status = test_utils.run_command_line([
            "diff", "-r",
            test_utils.get_bundle_path(test.container_id), bundle_path
        ])

        output = test_utils.create_simple_test_output(test,
                                                      status.stdout is "", "",
                                                      status.stdout)
        output_table.append(output)
        test_utils.print_single_result(output)

        # Test 2
        test = tests[2]
        status = test_utils.run_command_line(
            ["rm", "-rf",
             test_utils.get_bundle_path(test.container_id)])

        output = test_utils.create_simple_test_output(test,
                                                      status.stderr is "", "",
                                                      status.stderr)
        output_table.append(output)
        test_utils.print_single_result(output)

    return test_utils.count_print_results(output_table)
def dobby_tool_command(command, container_id):
    """Runs DobbyTool command

    Parameters:
    command (string): command that should be run
    container_id (string): name of container to run

    Returns:
    process (process): process that runs selected command

    """

    full_command = ["DobbyTool", command, container_id]
    if command == "start":
        container_path = test_utils.get_container_spec_path(container_id)
        full_command.append(container_path)

    process = test_utils.run_command_line(full_command)

    return process
Beispiel #3
0
def create_curl_command(test, bundle_path):
    """Creates curl command for selected testcase

    Parameters:
    test (Test): test case for which to create curl

    Returns:
    curl_command (list(string)): command in format required by subprocess.run

    """

    params = ""
    if test.command != "listContainers":
        params += '"containerId": "%s"' % test.container_id
    if test.command == "startContainer":
        params += ', "bundlePath": "%s"' % bundle_path
    if test.command == "startContainerFromDobbySpec":
        with open(test_utils.get_container_spec_path("sleepy"), 'r') as file:
            data = file.read().replace('\n', '').replace(' ', '')
        params += ', "dobbySpec": %s' % data

    if params:
        params = ', "params":{%s}' % params

    plugin_name = "org.rdk.OCIContainer.1"

    if test_utils.selected_platform == test_utils.Platforms.xi_6:
        plugin_name = "org.rdk." + plugin_name

    curl_command = ["curl",
                    "--silent",
                    "-X",
                    "POST",
                    "http://127.0.0.1:9998/jsonrpc/",
                    "--header",
                    "Content-Type: application/json",
                    "-d",
                    '{ "jsonrpc": "2.0", "id": 3, "method": "%s.%s"%s}' % (plugin_name, test.command, params)]
    return curl_command
def test_container(container_id, expected_output):
    """Runs container and check if output contains expected output

    Parameters:
    container_id (string): name of container to run
    expected_output (string): output that should be provided by containter

    Returns:
    (pass (bool), message (string)): Returns if expected output found and message

    """

    test_utils.print_log("Running %s container test" % container_id, test_utils.Severity.debug)

    spec = test_utils.get_container_spec_path(container_id)

    launch_result = test_utils.launch_container(container_id, spec)

    if launch_result:
        return validate_output_file(container_id, expected_output)

    return False, "Container did not launch successfully"