Merge pull request #1515 from aanand/allow-any-volume-mode

Allow any volume mode to be specified
This commit is contained in:
Aanand Prasad 2015-07-17 17:10:59 +01:00
commit faa7da6eff
2 changed files with 27 additions and 10 deletions

View File

@ -809,12 +809,7 @@ def parse_volume_spec(volume_config):
if len(parts) == 2:
parts.append('rw')
external, internal, mode = parts
if mode not in ('rw', 'ro'):
raise ConfigError("Volume %s has invalid mode (%s), should be "
"one of: rw, ro." % (volume_config, mode))
return VolumeSpec(external, internal, mode)
return VolumeSpec(*parts)
# Ports

View File

@ -372,14 +372,13 @@ class ServiceVolumesTest(unittest.TestCase):
spec = parse_volume_spec('external:interval:ro')
self.assertEqual(spec, ('external', 'interval', 'ro'))
spec = parse_volume_spec('external:interval:z')
self.assertEqual(spec, ('external', 'interval', 'z'))
def test_parse_volume_spec_too_many_parts(self):
with self.assertRaises(ConfigError):
parse_volume_spec('one:two:three:four')
def test_parse_volume_bad_mode(self):
with self.assertRaises(ConfigError):
parse_volume_spec('one:two:notrw')
def test_build_volume_binding(self):
binding = build_volume_binding(parse_volume_spec('/outside:/inside'))
self.assertEqual(binding, ('/inside', '/outside:/inside:rw'))
@ -508,3 +507,26 @@ class ServiceVolumesTest(unittest.TestCase):
create_options['host_config']['Binds'],
['/mnt/sda1/host/path:/data:rw'],
)
def test_create_with_special_volume_mode(self):
self.mock_client.inspect_image.return_value = {'Id': 'imageid'}
create_calls = []
def create_container(*args, **kwargs):
create_calls.append((args, kwargs))
return {'Id': 'containerid'}
self.mock_client.create_container = create_container
volumes = ['/tmp:/foo:z']
Service(
'web',
client=self.mock_client,
image='busybox',
volumes=volumes,
).create_container()
self.assertEqual(len(create_calls), 1)
self.assertEqual(create_calls[0][1]['host_config']['Binds'], volumes)