Exemplo n.º 1
0
def execute_test():
    if test_utils.selected_platform != test_utils.Platforms.xi_6:
        return test_utils.print_unsupported_platform(path.basename(__file__), test_utils.selected_platform)

    output_table = []

    # check if platform is supported
    if test_utils.selected_platform == test_utils.Platforms.virtual_machine:
        test_utils.print_unsupported_platform(path.basename(__file__), test_utils.selected_platform)
        return test_utils.count_print_results(output_table)

    for test in tests:
        if test.command == "check":
            success = check_app_status(test.container_id, test.expected_output)
            output = test_utils.create_simple_test_output(test, success)
        else:
            full_command = create_curl_command(test.container_id, test.command)
            result = test_utils.run_command_line(full_command)
            success = test.expected_output in result.stdout
            # success = search(test.expected_output, result.stdout) is not None
            output = test_utils.create_simple_test_output(test, success, log_content=result.stdout+result.stderr)

        output_table.append(output)
        test_utils.print_single_result(output)

    return test_utils.count_print_results(output_table)
Exemplo n.º 2
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)
Exemplo n.º 3
0
def execute_test():

    output_table = []

    with test_utils.dobby_daemon(), test_utils.untar_bundle(container_name) as bundle_path:

        # createRuntime fails with the networking plugin without a container present with
        # permission issues. The networking plugin is not designed to work with standalone
        # DobbyPluginLauncher at the moment, so we can ignore the message. The test will
        # succeed because the networking plugin is set to required=false in the bundle config.

        # Test 0
        test = tests[0]
        command = ["DobbyPluginLauncher",
                   "-v",
                   "-h", hook_name,
                   "-c", bundle_path + "/config.json"]

        # cannot be simple run_command as we need input in this case
        # status = test_utils.run_command_line(command)

        # The state of the container MUST be passed to hooks over stdin so that they may
        # do work appropriate to the current state of the container.
        crun_input = """
        {
        "ociVersion": "1.0.2",
        "id": "%s",
        "status": "running",
        "pid":12345,
        "bundle": "%s",
        "annotations": {
            "myKey": "myValue"
            }
        }
        """ % (container_name, bundle_path)

        status = subprocess.run(command,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE,
                            input=crun_input,
                            universal_newlines=True)

        result = test.expected_output.lower() in status.stderr.lower()
        output = test_utils.create_simple_test_output(test, result, log_content=status.stderr)

        output_table.append(output)
        test_utils.print_single_result(output)

    return test_utils.count_print_results(output_table)
Exemplo n.º 4
0
def execute_test():
    output_table = []

    with test_utils.dobby_daemon():
        for test in tests:
            process = dobby_tool_command(test.command, test.container_id)
            test_utils.print_log("command output = %s" % process.stdout,
                                 test_utils.Severity.debug)
            result = test.expected_output in process.stdout
            if test.negation:
                result = not result
            output = test_utils.create_simple_test_output(test, result)
            output_table.append(output)
            test_utils.print_single_result(output)

    return test_utils.count_print_results(output_table)
Exemplo n.º 5
0
def execute_test():
    if test_utils.selected_platform == test_utils.Platforms.no_selection:
        return test_utils.print_unsupported_platform(
            basename(__file__), test_utils.selected_platform)

    with test_utils.dobby_daemon():
        output_table = []

        for test in tests:
            result = test_container(test.container_id, test.expected_output)
            output = test_utils.create_simple_test_output(
                test, result[0], result[1])

            output_table.append(output)
            test_utils.print_single_result(output)

    return test_utils.count_print_results(output_table)
Exemplo n.º 6
0
def execute_test():
    if test_utils.selected_platform != test_utils.Platforms.virtual_machine:
        return test_utils.print_unsupported_platform(
            basename(__file__), test_utils.selected_platform)

    output_table = []

    #TODO: Update to use test_utils.dobby_daemon class for consistency

    # Test 0
    test = tests[0]
    subproc = start_dobby_daemon()
    result = read_asynchronous(subproc, test.expected_output, 5)
    output = test_utils.create_simple_test_output(test, result)
    output_table.append(output)
    test_utils.print_single_result(output)

    # Test 1
    test = tests[1]
    result = check_if_process_present(test.expected_output)
    output = test_utils.create_simple_test_output(test, result)
    output_table.append(output)
    test_utils.print_single_result(output)

    # Test 2
    test = tests[2]
    stop_dobby_daemon()
    result = read_asynchronous(subproc, test.expected_output, 5)
    output = test_utils.create_simple_test_output(test, result)
    output_table.append(output)
    test_utils.print_single_result(output)

    # Test 3
    test = tests[3]
    # in this test we CANNOT find running DobbyDaemon
    result = not check_if_process_present(test.expected_output)
    output = test_utils.create_simple_test_output(test, result)
    output_table.append(output)
    test_utils.print_single_result(output)

    return test_utils.count_print_results(output_table)
Exemplo n.º 7
0
def execute_test():
    if test_utils.selected_platform == test_utils.Platforms.no_selection:
        return test_utils.print_unsupported_platform(basename(__file__), test_utils.selected_platform)

    tests = create_tests()

    wpeframework = start_wpeframework()

    output_table = []

    with test_utils.dobby_daemon(), test_utils.untar_bundle(container_name) as bundle_path:
        for test in tests:
            full_command = create_curl_command(test, bundle_path)
            result = test_utils.run_command_line(full_command)
            # success = test.expected_output in result.stdout
            success = search(test.expected_output, result.stdout) is not None
            output = test_utils.create_simple_test_output(test, success, log_content=result.stdout+result.stderr)

            output_table.append(output)
            test_utils.print_single_result(output)

    stop_wpeframework(wpeframework)

    return test_utils.count_print_results(output_table)
Exemplo n.º 8
0
def execute_test():

    output_table = []

    with test_utils.dobby_daemon(), test_utils.untar_bundle(
            container_name) as bundle_path:

        # Test 0
        test = tests[0]
        command = [
            "DobbyPluginLauncher", "-v", "-h", "createRuntime", "-c",
            bundle_path + "/config.json"
        ]

        status = test_utils.run_command_line(command)

        result = test.expected_output.lower() in status.stderr.lower()
        output = test_utils.create_simple_test_output(
            test, result, log_content=status.stderr)

        output_table.append(output)
        test_utils.print_single_result(output)

    return test_utils.count_print_results(output_table)
Exemplo n.º 9
0
def execute_test():

    # We use a preconfigured tarball bundle for this test, the container has the following arg:
    #
    #   echo DOBBY_TEST | netcat 100.64.11.1 7357
    #
    # This will send 'DOBBY_TEST' to the dobby0 bridge device at port 7357. We're expecting
    # this to be received on the listening port 7357 on the localhost because of the added
    # networking configuration in the bundle config:
    #
    #   "portForwarding": {
    #       "containerToHost": [
    #           {
    #               "port": 7357,
    #               "protocol": "udp"
    #           },
    #           {
    #               "port": 7357,
    #               "protocol": "tcp"
    #           }
    #       ]
    #   }
    #

    # netcat is not available on RDK builds, skip test
    if test_utils.selected_platform == test_utils.Platforms.xi_6:
        return test_utils.print_unsupported_platform(
            basename(__file__), test_utils.selected_platform)

    output_table = []

    with test_utils.dobby_daemon(), netcat_listener(
    ) as nc, test_utils.untar_bundle(container_name) as bundle_path:
        # Test 0
        test = tests[0]
        command = ["DobbyTool", "start", container_name, bundle_path]

        status = test_utils.run_command_line(command)

        message = ""
        result = True

        # give container time to start and send message before checking netcat listener
        sleep(2)

        nc_message = nc.get_output().rstrip("\n")

        # check if netcat listener received message
        if test.expected_output.lower() not in nc_message.lower():
            message = "Received '%s' from container, expected '%s'" % (
                nc_message.lower(), test.expected_output.lower())
            result = False
        else:
            message = "Successfully received message '%s' from container" % nc_message

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

    return test_utils.count_print_results(output_table)