Exemplo n.º 1
0
def test_hostname():
    util.log("[START_TEST] check that hostname inside container ",
        "is 'container'")
    output = aucont.run_cmd(
        util.test_rootfs_path(), '/bin/hostname'
    ).strip()
    util.debug(output)
    util.check(output == 'container')
Exemplo n.º 2
0
def test_hostname():
    util.log("[START_TEST] check that hostname inside container ",
        "is 'container'")
    output = aucont.run_cmd(
        util.test_rootfs_path(), '/bin/hostname'
    ).strip()
    util.debug(output)
    util.check(output == 'container')
Exemplo n.º 3
0
def clist():
    cont_list_cmd_and_args = [
        util.aucont_tool_path('aucont_list')
    ]
    output = subprocess.check_output(cont_list_cmd_and_args)
    pids = output.decode('UTF-8').split('\n')
    pids = list(filter(lambda pid: pid != '', pids))
    util.debug(pids)
    return pids
Exemplo n.º 4
0
def stop(cont_pid, signal=15):
    signal = str(signal)
    cont_stop_cmd_and_args = [
        util.aucont_tool_path('aucont_stop'),
        cont_pid,
        signal
    ]
    util.debug(*cont_stop_cmd_and_args)
    subprocess.check_call(cont_stop_cmd_and_args)
    util.log('stopped container', cont_pid);
Exemplo n.º 5
0
def exec_interactive(cont_pid, *cmd_and_args):
    cont_exec_cmd_and_args = [
        util.aucont_tool_path('aucont_exec'),
        cont_pid
    ]
    cont_exec_cmd_and_args += cmd_and_args
    util.debug(*cont_exec_cmd_and_args)

    subprocess.check_call(cont_exec_cmd_and_args,
        stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr
    )
Exemplo n.º 6
0
def test_daemonization():
    util.log("""[START_TEST] check that daemonized container doesn't
        use tty""")
    cont_pid = aucont.start_daemonized(util.test_rootfs_path(),
                                       '/test/interactive/bin/test')
    time.sleep(1)
    output = aucont.exec_capture_output(cont_pid, "/bin/cat",
                                        "/test/interactive/bin/result.txt")
    aucont.stop(cont_pid, 9)
    output = output.strip()
    util.debug(output)
    util.check(output != 'Ok')
Exemplo n.º 7
0
def test_daemonization():
    util.log("""[START_TEST] check that daemonized container doesn't
        use tty""")
    cont_pid = aucont.start_daemonized(
        util.test_rootfs_path(), '/test/interactive/bin/test'
    )
    time.sleep(1)
    output = aucont.exec_capture_output(
        cont_pid, "/bin/cat", "/test/interactive/bin/result.txt"
    )
    aucont.stop(cont_pid, 9)
    output = output.strip()
    util.debug(output)
    util.check(output != 'Ok')
Exemplo n.º 8
0
def test_cpu_perc_limit():
    util.log("""[START_TEST] check that cpu limitation
        works ok for container""")
    output = aucont.run_cmd(util.test_rootfs_path(),
                            '/test/busyloop/bin/run.sh').strip()
    unlimited_result = int(output)

    output = aucont.run_cmd(util.test_rootfs_path(),
                            '/test/busyloop/bin/run.sh',
                            cpu_perc=20).strip()
    limited_result_20_perc = int(output)
    util.debug(unlimited_result, limited_result_20_perc)

    cpu_boost = unlimited_result / limited_result_20_perc
    util.check(cpu_boost >= 3 and cpu_boost <= 6)
Exemplo n.º 9
0
def exec_capture_output(cont_pid, *cmd_and_args):
    cont_exec_cmd_and_args = [
        util.aucont_tool_path('aucont_exec'),
        cont_pid
    ]
    cont_exec_cmd_and_args += cmd_and_args
    util.debug(*cont_exec_cmd_and_args)

    try:
        output = subprocess.check_output(cont_exec_cmd_and_args,
            stdin=sys.stdin, stderr=subprocess.STDOUT
        )
    except subprocess.CalledProcessError as err:
        util.log(err.returncode, err.output)
        raise
    return output.decode('UTF-8')
Exemplo n.º 10
0
def test_cpu_perc_limit():
    util.log("""[START_TEST] check that cpu limitation
        works ok for container""")
    output = aucont.run_cmd(
        util.test_rootfs_path(), '/test/busyloop/bin/run.sh'
    ).strip()
    unlimited_result = int(output)

    output = aucont.run_cmd(
        util.test_rootfs_path(), '/test/busyloop/bin/run.sh',
        cpu_perc=20
    ).strip()
    limited_result_20_perc = int(output)
    util.debug(unlimited_result, limited_result_20_perc)

    cpu_boost = unlimited_result / limited_result_20_perc
    util.check(cpu_boost >= 3 and cpu_boost <= 5)
Exemplo n.º 11
0
def test_webserver():
    util.log("""[START TEST] start container with enabled networking,
        run web server on priveledged port inside.
        Warning: stop network manager before running all
        network tests""")
    cont_ip = '192.168.1.1'
    cont_pid = aucont.start_daemonized(util.test_rootfs_path(),
                                       '/test/web/server.sh',
                                       '80',
                                       cont_ip=cont_ip)
    time.sleep(2)
    url = 'http://' + cont_ip + ':80/file.txt'
    http_resp = urlopen(url)
    aucont.stop(cont_pid, 9)
    util.check(http_resp.status == 200)
    http_resp_str = http_resp.read().decode('utf-8')
    util.debug(http_resp_str)
    util.check(http_resp_str.index('OK!') == 0)
Exemplo n.º 12
0
def _make_cont_start_cmd(is_interactive, image_path, cmd_and_args,
    cpu_perc=None, cont_ip=None):
    cont_start_opts_list = []
    if not is_interactive: cont_start_opts_list.append('-d')
    if cpu_perc:
        cont_start_opts_list.extend(['--cpu', str(cpu_perc)])
    if cont_ip: cont_start_opts_list.extend(['--net', cont_ip])

    cont_start_cmd_and_arg_lists = [
        [util.aucont_tool_path('aucont_start')],
        cont_start_opts_list,
        [image_path],
        cmd_and_args
    ]
    cont_start_cmd_and_args = list(
        itertools.chain.from_iterable(cont_start_cmd_and_arg_lists)
    )
    util.debug(*cont_start_cmd_and_args)
    return cont_start_cmd_and_args
Exemplo n.º 13
0
def test_cpu_perc_limit():
    util.log("""[START_TEST] check that cpu limitation
        works ok for container""")
    output = aucont.run_cmd(util.test_rootfs_path(),
                            '/test/busyloop/bin/run.sh').strip()
    unlimited_result = int(output)

    output = aucont.run_cmd(
        util.test_rootfs_path(),
        '/test/busyloop/bin/run.sh',
        cpu_perc=
        25  # changed from 20 because condition checks that boost is near 4 times
    ).strip()
    limited_result_20_perc = int(output)
    util.debug(unlimited_result, limited_result_20_perc)

    cpu_boost = unlimited_result / limited_result_20_perc
    print("cpu_boost is ", cpu_boost)
    util.check(cpu_boost >= 3 and cpu_boost <= 5)
Exemplo n.º 14
0
def test_webserver():
    util.log(
        """[START TEST] start container with enabled networking,
        run web server on priveledged port inside.
        Warning: stop network manager before running all
        network tests"""
    )
    cont_ip = '192.168.1.1'
    cont_pid = aucont.start_daemonized(
        util.test_rootfs_path(), '/test/web/server.sh',
        '80', cont_ip=cont_ip
    )
    time.sleep(2)
    url = 'http://' + cont_ip + ':80/file.txt'
    http_resp = urlopen(url)
    aucont.stop(cont_pid, 9)
    util.check(http_resp.status == 200)
    http_resp_str = http_resp.read().decode('utf-8')
    util.debug(http_resp_str)
    util.check(http_resp_str.index('OK!') == 0)