mirror of https://github.com/docker/docker-py.git
Re-added start with hostconfig tests
This commit is contained in:
parent
f07524f2db
commit
12aad176b9
242
tests/test.py
242
tests/test.py
|
@ -707,7 +707,7 @@ class DockerClientTest(Cleanup, unittest.TestCase):
|
|||
docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||
)
|
||||
|
||||
def test_start_container_with_port_binds(self):
|
||||
def test_create_container_with_port_binds(self):
|
||||
self.maxDiff = None
|
||||
try:
|
||||
self.client.create_container(
|
||||
|
@ -861,6 +861,246 @@ class DockerClientTest(Cleanup, unittest.TestCase):
|
|||
docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||
)
|
||||
|
||||
def test_start_container_with_lxc_conf(self):
|
||||
try:
|
||||
self.client.start(
|
||||
fake_api.FAKE_CONTAINER_ID,
|
||||
lxc_conf={'lxc.conf.k': 'lxc.conf.value'}
|
||||
)
|
||||
except Exception as e:
|
||||
self.fail('Command should not raise exception: {0}'.format(e))
|
||||
args = fake_request.call_args
|
||||
self.assertEqual(
|
||||
args[0][0],
|
||||
url_prefix + 'containers/3cc2351ab11b/start'
|
||||
)
|
||||
self.assertEqual(
|
||||
json.loads(args[1]['data']),
|
||||
{"LxcConf": [{"Value": "lxc.conf.value", "Key": "lxc.conf.k"}]}
|
||||
)
|
||||
self.assertEqual(
|
||||
args[1]['headers'],
|
||||
{'Content-Type': 'application/json'}
|
||||
)
|
||||
self.assertEqual(
|
||||
args[1]['timeout'],
|
||||
docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||
)
|
||||
|
||||
def test_start_container_with_lxc_conf_compat(self):
|
||||
try:
|
||||
self.client.start(
|
||||
fake_api.FAKE_CONTAINER_ID,
|
||||
lxc_conf=[{'Key': 'lxc.conf.k', 'Value': 'lxc.conf.value'}]
|
||||
)
|
||||
except Exception as e:
|
||||
self.fail('Command should not raise exception: {0}'.format(e))
|
||||
|
||||
args = fake_request.call_args
|
||||
self.assertEqual(args[0][0], url_prefix +
|
||||
'containers/3cc2351ab11b/start')
|
||||
self.assertEqual(
|
||||
json.loads(args[1]['data']),
|
||||
{"LxcConf": [{"Key": "lxc.conf.k", "Value": "lxc.conf.value"}]}
|
||||
)
|
||||
self.assertEqual(args[1]['headers'],
|
||||
{'Content-Type': 'application/json'})
|
||||
self.assertEqual(
|
||||
args[1]['timeout'],
|
||||
docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||
)
|
||||
|
||||
def test_start_container_with_binds_ro(self):
|
||||
try:
|
||||
mount_dest = '/mnt'
|
||||
mount_origin = '/tmp'
|
||||
self.client.start(fake_api.FAKE_CONTAINER_ID,
|
||||
binds={mount_origin: {
|
||||
"bind": mount_dest,
|
||||
"ro": True
|
||||
}})
|
||||
except Exception as e:
|
||||
self.fail('Command should not raise exception: {0}'.format(e))
|
||||
|
||||
args = fake_request.call_args
|
||||
self.assertEqual(args[0][0], url_prefix +
|
||||
'containers/3cc2351ab11b/start')
|
||||
self.assertEqual(
|
||||
json.loads(args[1]['data']), {"Binds": ["/tmp:/mnt:ro"]}
|
||||
)
|
||||
self.assertEqual(args[1]['headers'],
|
||||
{'Content-Type': 'application/json'})
|
||||
self.assertEqual(
|
||||
args[1]['timeout'],
|
||||
docker.client.DEFAULT_TIMEOUT_SECONDS)
|
||||
|
||||
def test_start_container_with_binds_rw(self):
|
||||
try:
|
||||
mount_dest = '/mnt'
|
||||
mount_origin = '/tmp'
|
||||
self.client.start(fake_api.FAKE_CONTAINER_ID,
|
||||
binds={mount_origin: {
|
||||
"bind": mount_dest, "ro": False}})
|
||||
except Exception as e:
|
||||
self.fail('Command should not raise exception: {0}'.format(e))
|
||||
|
||||
args = fake_request.call_args
|
||||
self.assertEqual(args[0][0], url_prefix +
|
||||
'containers/3cc2351ab11b/start')
|
||||
self.assertEqual(
|
||||
json.loads(args[1]['data']), {"Binds": ["/tmp:/mnt:rw"]}
|
||||
)
|
||||
self.assertEqual(args[1]['headers'],
|
||||
{'Content-Type': 'application/json'})
|
||||
self.assertEqual(
|
||||
args[1]['timeout'],
|
||||
docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||
)
|
||||
|
||||
def test_start_container_with_port_binds(self):
|
||||
self.maxDiff = None
|
||||
try:
|
||||
self.client.start(fake_api.FAKE_CONTAINER_ID, port_bindings={
|
||||
1111: None,
|
||||
2222: 2222,
|
||||
'3333/udp': (3333,),
|
||||
4444: ('127.0.0.1',),
|
||||
5555: ('127.0.0.1', 5555),
|
||||
6666: [('127.0.0.1',), ('192.168.0.1',)]
|
||||
})
|
||||
except Exception as e:
|
||||
self.fail('Command should not raise exception: {0}'.format(e))
|
||||
|
||||
args = fake_request.call_args
|
||||
self.assertEqual(args[0][0], url_prefix +
|
||||
'containers/3cc2351ab11b/start')
|
||||
data = json.loads(args[1]['data'])
|
||||
self.assertTrue('1111/tcp' in data['PortBindings'])
|
||||
self.assertTrue('2222/tcp' in data['PortBindings'])
|
||||
self.assertTrue('3333/udp' in data['PortBindings'])
|
||||
self.assertTrue('4444/tcp' in data['PortBindings'])
|
||||
self.assertTrue('5555/tcp' in data['PortBindings'])
|
||||
self.assertTrue('6666/tcp' in data['PortBindings'])
|
||||
self.assertEqual(
|
||||
[{"HostPort": "", "HostIp": ""}],
|
||||
data['PortBindings']['1111/tcp']
|
||||
)
|
||||
self.assertEqual(
|
||||
[{"HostPort": "2222", "HostIp": ""}],
|
||||
data['PortBindings']['2222/tcp']
|
||||
)
|
||||
self.assertEqual(
|
||||
[{"HostPort": "3333", "HostIp": ""}],
|
||||
data['PortBindings']['3333/udp']
|
||||
)
|
||||
self.assertEqual(
|
||||
[{"HostPort": "", "HostIp": "127.0.0.1"}],
|
||||
data['PortBindings']['4444/tcp']
|
||||
)
|
||||
self.assertEqual(
|
||||
[{"HostPort": "5555", "HostIp": "127.0.0.1"}],
|
||||
data['PortBindings']['5555/tcp']
|
||||
)
|
||||
self.assertEqual(len(data['PortBindings']['6666/tcp']), 2)
|
||||
self.assertEqual(args[1]['headers'],
|
||||
{'Content-Type': 'application/json'})
|
||||
self.assertEqual(
|
||||
args[1]['timeout'],
|
||||
docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||
)
|
||||
|
||||
def test_start_container_with_links(self):
|
||||
# one link
|
||||
try:
|
||||
link_path = 'path'
|
||||
alias = 'alias'
|
||||
self.client.start(fake_api.FAKE_CONTAINER_ID,
|
||||
links={link_path: alias})
|
||||
except Exception as e:
|
||||
self.fail('Command should not raise exception: {0}'.format(e))
|
||||
|
||||
args = fake_request.call_args
|
||||
self.assertEqual(
|
||||
args[0][0],
|
||||
url_prefix + 'containers/3cc2351ab11b/start'
|
||||
)
|
||||
self.assertEqual(
|
||||
json.loads(args[1]['data']), {"Links": ["path:alias"]}
|
||||
)
|
||||
self.assertEqual(
|
||||
args[1]['headers'],
|
||||
{'Content-Type': 'application/json'}
|
||||
)
|
||||
|
||||
def test_start_container_with_multiple_links(self):
|
||||
try:
|
||||
link_path = 'path'
|
||||
alias = 'alias'
|
||||
self.client.start(
|
||||
fake_api.FAKE_CONTAINER_ID,
|
||||
links={
|
||||
link_path + '1': alias + '1',
|
||||
link_path + '2': alias + '2'
|
||||
}
|
||||
)
|
||||
except Exception as e:
|
||||
self.fail('Command should not raise exception: {0}'.format(e))
|
||||
|
||||
args = fake_request.call_args
|
||||
self.assertEqual(
|
||||
args[0][0],
|
||||
url_prefix + 'containers/3cc2351ab11b/start'
|
||||
)
|
||||
self.assertEqual(
|
||||
json.loads(args[1]['data']),
|
||||
{"Links": ["path1:alias1", "path2:alias2"]}
|
||||
)
|
||||
self.assertEqual(
|
||||
args[1]['headers'],
|
||||
{'Content-Type': 'application/json'}
|
||||
)
|
||||
|
||||
def test_start_container_with_links_as_list_of_tuples(self):
|
||||
# one link
|
||||
try:
|
||||
link_path = 'path'
|
||||
alias = 'alias'
|
||||
self.client.start(fake_api.FAKE_CONTAINER_ID,
|
||||
links=[(link_path, alias)])
|
||||
except Exception as e:
|
||||
self.fail('Command should not raise exception: {0}'.format(e))
|
||||
|
||||
args = fake_request.call_args
|
||||
self.assertEqual(
|
||||
args[0][0],
|
||||
url_prefix + 'containers/3cc2351ab11b/start'
|
||||
)
|
||||
self.assertEqual(
|
||||
json.loads(args[1]['data']), {"Links": ["path:alias"]}
|
||||
)
|
||||
self.assertEqual(
|
||||
args[1]['headers'], {'Content-Type': 'application/json'}
|
||||
)
|
||||
|
||||
def test_start_container_privileged(self):
|
||||
try:
|
||||
self.client.start(fake_api.FAKE_CONTAINER_ID, privileged=True)
|
||||
except Exception as e:
|
||||
self.fail('Command should not raise exception: {0}'.format(e))
|
||||
|
||||
args = fake_request.call_args
|
||||
self.assertEqual(
|
||||
args[0][0],
|
||||
url_prefix + 'containers/3cc2351ab11b/start'
|
||||
)
|
||||
self.assertEqual(json.loads(args[1]['data']), {"Privileged": True})
|
||||
self.assertEqual(args[1]['headers'],
|
||||
{'Content-Type': 'application/json'})
|
||||
self.assertEqual(
|
||||
args[1]['timeout'],
|
||||
docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||
)
|
||||
|
||||
def test_start_container_with_dict_instead_of_id(self):
|
||||
try:
|
||||
self.client.start({'Id': fake_api.FAKE_CONTAINER_ID})
|
||||
|
|
Loading…
Reference in New Issue