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)
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')
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')
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')
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)
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')
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)
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')
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')
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)
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()
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)
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)
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()
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)
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)
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)
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)