def test_get_docker_run_cmd_interactive_false(): memory = 555 random_port = 666 container_name = 'Docker' * 6 + 'Doc' volumes = ['7_Brides_for_7_Brothers', '7-Up', '7-11'] env = {} interactive = False docker_hash = '8' * 40 command = ['IE9.exe', '/VERBOSE', '/ON_ERROR_RESUME_NEXT'] hostname = 'fake_hostname' net = 'bridge' docker_params = [] actual = get_docker_run_cmd(memory, random_port, container_name, volumes, env, interactive, docker_hash, command, hostname, net, docker_params) assert any(['--env=MARATHON_PORT=%s' % random_port in arg for arg in actual]) assert '--memory=%dm' % memory in actual assert any(['--publish=%s' % random_port in arg for arg in actual]) assert '--name=%s' % container_name in actual assert all(['--volume=%s' % volume in actual for volume in volumes]) assert '--detach=true' in actual assert '--interactive=true' not in actual assert '--tty=true' not in actual assert docker_hash in actual assert ' '.join(pipes.quote(part) for part in command) in actual
def test_get_docker_run_cmd_interactive_false(): memory = 555 random_port = 666 container_name = 'Docker' * 6 + 'Doc' volumes = ['7_Brides_for_7_Brothers', '7-Up', '7-11'] env = {} interactive = False docker_hash = '8' * 40 command = ['IE9.exe', '/VERBOSE', '/ON_ERROR_RESUME_NEXT'] hostname = 'fake_hostname' net = 'bridge' actual = get_docker_run_cmd(memory, random_port, container_name, volumes, env, interactive, docker_hash, command, hostname, net) assert any( ['--env=MARATHON_PORT=%s' % random_port in arg for arg in actual]) assert '--memory=%dm' % memory in actual assert any(['--publish=%s' % random_port in arg for arg in actual]) assert '--name=%s' % container_name in actual assert all(['--volume=%s' % volume in actual for volume in volumes]) assert '--detach=true' in actual assert '--interactive=true' not in actual assert '--tty=true' not in actual assert docker_hash in actual assert ' '.join(pipes.quote(part) for part in command) in actual
def test_get_docker_run_cmd_interactive_true(): memory = 555 random_port = 666 container_name = 'Docker' * 6 + 'Doc' volumes = ['7_Brides_for_7_Brothers', '7-Up', '7-11'] env = {} interactive = True docker_hash = '8' * 40 command = ['IE9.exe', '/VERBOSE', '/ON_ERROR_RESUME_NEXT'] actual = get_docker_run_cmd(memory, random_port, container_name, volumes, env, interactive, docker_hash, command) assert '--interactive=true' in actual assert '--tty=true' in actual
def test_get_docker_run_cmd_with_env_vars(): memory = 555 random_port = 666 container_name = 'Docker' * 6 + 'Doc' volumes = ['7_Brides_for_7_Brothers', '7-Up', '7-11'] env = {'foo': 'bar', 'baz': 'qux', 'x': ' with spaces'} interactive = False docker_hash = '8' * 40 command = None actual = get_docker_run_cmd(memory, random_port, container_name, volumes, env, interactive, docker_hash, command) assert '--env="foo=bar"' in actual assert '--env="baz=qux"' in actual assert '--env="x= with spaces"' in actual
def test_get_docker_run_cmd_without_additional_args(): memory = 555 random_port = 666 container_name = 'Docker' * 6 + 'Doc' volumes = ['7_Brides_for_7_Brothers', '7-Up', '7-11'] env = {} interactive = False docker_hash = '8' * 40 command = None actual = get_docker_run_cmd(memory, random_port, container_name, volumes, env, interactive, docker_hash, command) # Since we can't assert that the command isn't present in the output, we do # the next best thing and check that the docker hash is the last thing in # the docker run command (the command would have to be after it if it existed) assert actual[-1] == docker_hash
def test_get_docker_run_cmd_memory_swap(): memory = 555 random_port = 666 container_name = 'Docker' * 6 + 'Doc' volumes = ['7_Brides_for_7_Brothers', '7-Up', '7-11'] env = {} interactive = False docker_hash = '8' * 40 command = ['IE9.exe', '/VERBOSE', '/ON_ERROR_RESUME_NEXT'] hostname = 'fake_hostname' net = 'bridge' actual = get_docker_run_cmd(memory, random_port, container_name, volumes, env, interactive, docker_hash, command, hostname, net) assert '--memory-swap=555m' in actual
def test_get_docker_run_cmd_host_networking(): memory = 555 random_port = 666 container_name = 'Docker' * 6 + 'Doc' volumes = ['7_Brides_for_7_Brothers', '7-Up', '7-11'] env = {} interactive = True docker_hash = '8' * 40 command = ['IE9.exe', '/VERBOSE', '/ON_ERROR_RESUME_NEXT'] hostname = 'fake_hostname' net = 'host' docker_params = [] actual = get_docker_run_cmd(memory, random_port, container_name, volumes, env, interactive, docker_hash, command, hostname, net, docker_params) assert '--net=host' in actual
def test_get_docker_run_docker_params(): memory = 555 random_port = 666 container_name = 'Docker' * 6 + 'Doc' volumes = ['7_Brides_for_7_Brothers', '7-Up', '7-11'] env = {} interactive = False docker_hash = '8' * 40 command = ['IE9.exe', '/VERBOSE', '/ON_ERROR_RESUME_NEXT'] hostname = 'fake_hostname' net = 'bridge' docker_params = [{'key': 'memory-swap', 'value': '%sm' % memory}, {'key': 'cpu-period', 'value': '200000'}, {'key': 'cpu-quota', 'value': '150000'}] actual = get_docker_run_cmd(memory, random_port, container_name, volumes, env, interactive, docker_hash, command, hostname, net, docker_params) assert '--memory-swap=555m' in actual assert '--cpu-period=200000' in actual assert '--cpu-quota=150000' in actual
def test_get_docker_run_cmd_interactive_false(): memory = 555 random_port = 666 container_name = 'Docker' * 6 + 'Doc' volumes = ['7_Brides_for_7_Brothers', '7-Up', '7-11'] env = {} interactive = False docker_hash = '8' * 40 command = ['IE9.exe', '/VERBOSE', '/ON_ERROR_RESUME_NEXT'] actual = get_docker_run_cmd(memory, random_port, container_name, volumes, env, interactive, docker_hash, command) assert any(['--env=PORT=' in arg for arg in actual]) assert '--memory=%dm' % memory in actual assert any(['--publish=%s' % random_port in arg for arg in actual]) assert '--name=%s' % container_name in actual assert all(['--volume=%s' % volume in actual for volume in volumes]) assert '--detach=true' in actual assert '--interactive=true' not in actual assert '--tty=true' not in actual assert docker_hash in actual assert all([arg in actual for arg in command])