Skip to content

Commit

Permalink
Merge pull request #198 from fcoelho/fix-volumes-from
Browse files Browse the repository at this point in the history
Sanitize create_container input for volumes_from
  • Loading branch information
shin- committed Apr 23, 2014
2 parents 6fd343d + 3fa6f23 commit 6c1f7f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions docker/client.py
Expand Up @@ -121,8 +121,12 @@ def _container_config(self, image, command, hostname=None, user=None,
volumes_dict[vol] = {}
volumes = volumes_dict

if volumes_from and not isinstance(volumes_from, six.string_types):
volumes_from = ','.join(volumes_from)
if volumes_from:
if not isinstance(volumes_from, six.string_types):
volumes_from = ','.join(volumes_from)
else:
# Force None, an empty list or dict causes client.start to fail
volumes_from = None

attach_stdin = False
attach_stdout = False
Expand Down
10 changes: 10 additions & 0 deletions tests/test.py
Expand Up @@ -342,6 +342,16 @@ def test_create_container_with_volumes_from(self):
self.assertEqual(args[1]['headers'],
{'Content-Type': 'application/json'})

def test_create_container_empty_volumes_from(self):
try:
self.client.create_container('busybox', 'true', volumes_from=[])
except Exception as e:
self.fail('Command should not raise exception: {0}'.format(e))

args = fake_request.call_args
data = json.loads(args[1]['data'])
self.assertTrue('VolumesFrom' not in data)

def test_create_named_container(self):
try:
self.client.create_container('busybox', 'true',
Expand Down

0 comments on commit 6c1f7f3

Please sign in to comment.