mirror of https://github.com/docker/docker-py.git
Merge pull request #291 from yograterol/master
Volumes parameter on create_container should be validated as string
This commit is contained in:
commit
dba1c45454
|
@ -158,6 +158,9 @@ class Client(requests.Session):
|
||||||
exposed_ports['{0}/{1}'.format(port, proto)] = {}
|
exposed_ports['{0}/{1}'.format(port, proto)] = {}
|
||||||
ports = exposed_ports
|
ports = exposed_ports
|
||||||
|
|
||||||
|
if isinstance(volumes, six.string_types):
|
||||||
|
volumes = [volumes, ]
|
||||||
|
|
||||||
if isinstance(volumes, list):
|
if isinstance(volumes, list):
|
||||||
volumes_dict = {}
|
volumes_dict = {}
|
||||||
for vol in volumes:
|
for vol in volumes:
|
||||||
|
@ -500,6 +503,9 @@ class Client(requests.Session):
|
||||||
cpu_shares=None, working_dir=None, domainname=None,
|
cpu_shares=None, working_dir=None, domainname=None,
|
||||||
memswap_limit=0):
|
memswap_limit=0):
|
||||||
|
|
||||||
|
if isinstance(volumes, six.string_types):
|
||||||
|
volumes = [volumes, ]
|
||||||
|
|
||||||
config = self._container_config(
|
config = self._container_config(
|
||||||
image, command, hostname, user, detach, stdin_open, tty, mem_limit,
|
image, command, hostname, user, detach, stdin_open, tty, mem_limit,
|
||||||
ports, environment, dns, volumes, volumes_from, network_disabled,
|
ports, environment, dns, volumes, volumes_from, network_disabled,
|
||||||
|
|
|
@ -248,6 +248,31 @@ class DockerClientTest(Cleanup, unittest.TestCase):
|
||||||
self.assertEqual(args[1]['headers'],
|
self.assertEqual(args[1]['headers'],
|
||||||
{'Content-Type': 'application/json'})
|
{'Content-Type': 'application/json'})
|
||||||
|
|
||||||
|
def test_create_container_with_volume_string(self):
|
||||||
|
mount_dest = '/mnt'
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.client.create_container('busybox', ['ls', mount_dest],
|
||||||
|
volumes=mount_dest)
|
||||||
|
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/create')
|
||||||
|
self.assertEqual(json.loads(args[1]['data']),
|
||||||
|
json.loads('''
|
||||||
|
{"Tty": false, "Image": "busybox",
|
||||||
|
"Cmd": ["ls", "/mnt"], "AttachStdin": false,
|
||||||
|
"Volumes": {"/mnt": {}}, "Memory": 0,
|
||||||
|
"AttachStderr": true,
|
||||||
|
"AttachStdout": true, "OpenStdin": false,
|
||||||
|
"StdinOnce": false,
|
||||||
|
"NetworkDisabled": false,
|
||||||
|
"MemorySwap": 0}'''))
|
||||||
|
self.assertEqual(args[1]['headers'],
|
||||||
|
{'Content-Type': 'application/json'})
|
||||||
|
|
||||||
def test_create_container_with_ports(self):
|
def test_create_container_with_ports(self):
|
||||||
try:
|
try:
|
||||||
self.client.create_container('busybox', 'ls',
|
self.client.create_container('busybox', 'ls',
|
||||||
|
|
Loading…
Reference in New Issue