Example #1
0
def test_many_cont_networks():
    util.log(
        """[START TEST] start 2 containers run simple networking
        tests in each one.
        Warning: stop network manager before running all
        network tests"""
    )
    cont1_ip = '192.168.1.1'
    host1_ip = '192.168.1.2'
    cont1_pid = aucont.start_daemonized(
        util.test_rootfs_path(), '/bin/sleep', '10000',
        cont_ip=cont1_ip
    )
    
    cont2_ip = '10.0.0.1'
    host2_ip = '10.0.0.2'
    cont2_pid = aucont.start_daemonized(
        util.test_rootfs_path(), '/bin/sleep', '10000',
        cont_ip=cont2_ip
    )

    time.sleep(2)

    aucont.exec_capture_output(cont1_pid, '/test/net/test.sh',
        cont1_ip, host1_ip
    )
    aucont.exec_capture_output(cont1_pid, '/test/net/test.sh',
        cont1_ip, host1_ip
    )

    cleanup()
Example #2
0
def test_many_cont_networks():
    util.log("""[START TEST] start 2 containers run simple networking
        tests in each one.
        Warning: stop network manager before running all
        network tests""")
    cont1_ip = '192.168.1.1'
    host1_ip = '192.168.1.2'
    cont1_pid = aucont.start_daemonized(util.test_rootfs_path(),
                                        '/bin/sleep',
                                        '10000',
                                        cont_ip=cont1_ip)

    cont2_ip = '10.0.0.1'
    host2_ip = '10.0.0.2'
    cont2_pid = aucont.start_daemonized(util.test_rootfs_path(),
                                        '/bin/sleep',
                                        '10000',
                                        cont_ip=cont2_ip)

    time.sleep(2)

    aucont.exec_capture_output(cont1_pid, '/test/net/test.sh', cont1_ip,
                               host1_ip)
    aucont.exec_capture_output(cont1_pid, '/test/net/test.sh', cont1_ip,
                               host1_ip)

    cleanup()
Example #3
0
def test_many_conts_start_stop():
    util.log("""[START_TEST] start 3 containers.
        Wait exiting of some of them.
        Stop all the containers manually.""")
    cont1_pid = aucont.start_daemonized(util.test_rootfs_path(), '/bin/sleep',
                                        '1')
    cont2_pid = aucont.start_daemonized(util.test_rootfs_path(), '/bin/sleep',
                                        '5')
    cont3_pid = aucont.start_daemonized(util.test_rootfs_path(), '/bin/sleep',
                                        '10')
    time.sleep(4)
    aucont.stop(cont3_pid, 9)
    aucont.stop(cont1_pid, 9)
    aucont.stop(cont2_pid, 9)
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)
Example #5
0
def test_many_cont_list():
    util.log("""[START_TEST] start 3 containers.
        Check that aucont_list tool returns right
        values.""")
    cont1_pid = aucont.start_daemonized(util.test_rootfs_path(), '/bin/sleep',
                                        '1')
    cont2_pid = aucont.start_daemonized(util.test_rootfs_path(), '/bin/sleep',
                                        '5')
    cont3_pid = aucont.start_daemonized(util.test_rootfs_path(), '/bin/sleep',
                                        '10')
    cont_list = aucont.clist()
    util.check(len(cont_list) == 3)
    cont_list.index(cont1_pid)
    cont_list.index(cont2_pid)
    cont_list.index(cont3_pid)
    cleanup()
Example #6
0
def test_simple_start_stop():
    util.log('[START TEST] start daemonized container and kill it')
    cont_pid = aucont.start_daemonized(util.test_rootfs_path(), '/bin/sleep',
                                       '5')
    util.check(aucont.clist()[0] == cont_pid)
    aucont.stop(cont_pid, 9)
    util.check(len(aucont.clist()) == 0)
Example #7
0
def test_cont_user_root_is_fake():
    util.log("""[START_TEST] check that root inside container
        is not initial user namespace root""")
    aucont.run_cmd(
        util.test_rootfs_path(), '/test/kmodule/bin/test',
        '/test/kmodule/module.ko'
    )
Example #8
0
def test_cont_user_is_root():
    util.log("""[START_TEST] check that user name inside container
        is root""")
    output = aucont.run_cmd(
        util.test_rootfs_path(), '/bin/sh', '-c', 'whoami'
    ).strip()
    util.check(output == 'root')
Example #9
0
def test_fs_contents():
    util.log("[START_TEST] check file system contents inside container")
    output = aucont.run_cmd(
        util.test_rootfs_path(), '/test/fs/test.sh'
    ).strip()
    util.log("\n==== CHECK THIS OUTPUT MANUALLY ====\n",
        output, "\n")
Example #10
0
def test_fs_contents():
    util.log("[START_TEST] check file system contents inside container")
    output = aucont.run_cmd(
        util.test_rootfs_path(), '/test/fs/test.sh'
    ).strip()
    util.log("\n==== CHECK THIS OUTPUT MANUALLY ====\n",
        output, "\n")
Example #11
0
def test_user_is_root():
    util.log("""[START_TEST] check that user name inside container
        is root""")
    output = aucont.run_cmd(
        util.test_rootfs_path(), '/bin/sh', '-c', 'whoami'
    ).strip()
    util.check(output == 'root')
Example #12
0
def test_user_root_is_fake():
    util.log("""[START_TEST] check that root inside container
        is not initial user namespace root""")
    aucont.run_cmd(
        util.test_rootfs_path(), '/test/kmodule/bin/test',
        '/test/kmodule/module.ko'
    )
Example #13
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')
Example #14
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')
Example #15
0
def test_many_conts_start_stop():
    util.log("""[START_TEST] start 3 containers.
        Wait exiting of some of them.
        Stop all the containers manually.""")
    cont1_pid = aucont.start_daemonized(
        util.test_rootfs_path(), '/bin/sleep', '1'
    )
    cont2_pid = aucont.start_daemonized(
        util.test_rootfs_path(), '/bin/sleep', '5'
    )
    cont3_pid = aucont.start_daemonized(
        util.test_rootfs_path(), '/bin/sleep', '10'
    )
    time.sleep(4)
    aucont.stop(cont3_pid, 9)
    aucont.stop(cont1_pid, 9)
    aucont.stop(cont2_pid, 9)
Example #16
0
def test_simple_start_stop():
    util.log('[START TEST] start daemonized container and kill it')
    cont_pid = aucont.start_daemonized(
        util.test_rootfs_path(), '/bin/sleep', '5'
    )
    util.check(aucont.clist()[0] == cont_pid)
    aucont.stop(cont_pid, 9)
    util.check(len(aucont.clist()) == 0)
Example #17
0
def test_host_user_uid_preserved():
    util.log(
        '[START TEST] check that host uid and gid of container isn\'t changed')
    cont_pid = aucont.start_daemonized(util.test_rootfs_path(), '/bin/sleep',
                                       '5')
    cont_euid, cont_egid = util.get_pid_eids(cont_pid)
    aucont.stop(cont_pid, 9)
    util.check(os.geteuid() == cont_euid and os.getegid() == cont_egid)
Example #18
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)
Example #19
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)
Example #20
0
def test_many_cont_list():
    util.log("""[START_TEST] start 3 containers.
        Check that aucont_list tool returns right
        values.""")
    cont1_pid = aucont.start_daemonized(
        util.test_rootfs_path(), '/bin/sleep', '1'
    )
    cont2_pid = aucont.start_daemonized(
        util.test_rootfs_path(), '/bin/sleep', '5'
    )
    cont3_pid = aucont.start_daemonized(
        util.test_rootfs_path(), '/bin/sleep', '10'
    )
    cont_list = aucont.clist()
    util.check(len(cont_list) == 3)
    cont_list.index(cont1_pid)
    cont_list.index(cont2_pid)
    cont_list.index(cont3_pid)
    cleanup()
Example #21
0
def test_basic_networking():
    util.log("""[START TEST] start container with enabled networking and
        ping back and forth. Warning: stop network manager before
        running all network tests""")
    cont_ip = '10.0.0.1'
    host_ip = '10.0.0.2'
    aucont.run_cmd(util.test_rootfs_path(),
                   '/test/net/test.sh',
                   cont_ip,
                   host_ip,
                   cont_ip=cont_ip)
Example #22
0
def test_basic_networking():
    util.log(
        """[START TEST] start container with enabled networking and
        ping back and forth. Warning: stop network manager before
        running all network tests"""
    )
    cont_ip = '10.0.0.1'
    host_ip = '10.0.0.2'
    aucont.run_cmd(
        util.test_rootfs_path(), '/test/net/test.sh',
        cont_ip, host_ip, cont_ip=cont_ip
    )
Example #23
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')
Example #24
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')
Example #25
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)
Example #26
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)
Example #27
0
def test_start_with_interactive_shell():
    util.log('[START TEST] start container with interactive shell')
    aucont.start_interactive(util.test_rootfs_path(), '/bin/sh')
    util.check(len(aucont.clist()) == 0)
Example #28
0
def test_start_with_interactive_shell():
    util.log('[START TEST] start container with interactive shell')
    aucont.start_interactive(
        util.test_rootfs_path(), '/bin/sh'
    )
    util.check(len(aucont.clist()) == 0)