Ejemplo n.º 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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
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 container

    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)

    with test_utils.untar_bundle(container_id) as bundle_path:
        launch_result = test_utils.launch_container(container_id, bundle_path)

    if launch_result:
        return validate_output_file(container_id, expected_output)

    return False, "Container did not launch successfully"
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)