mirror of https://github.com/docker/docs.git
Merge pull request #1515 from aanand/allow-any-volume-mode
Allow any volume mode to be specified
This commit is contained in:
commit
faa7da6eff
|
@ -809,12 +809,7 @@ def parse_volume_spec(volume_config):
|
||||||
if len(parts) == 2:
|
if len(parts) == 2:
|
||||||
parts.append('rw')
|
parts.append('rw')
|
||||||
|
|
||||||
external, internal, mode = parts
|
return VolumeSpec(*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)
|
|
||||||
|
|
||||||
|
|
||||||
# Ports
|
# Ports
|
||||||
|
|
|
@ -372,14 +372,13 @@ class ServiceVolumesTest(unittest.TestCase):
|
||||||
spec = parse_volume_spec('external:interval:ro')
|
spec = parse_volume_spec('external:interval:ro')
|
||||||
self.assertEqual(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):
|
def test_parse_volume_spec_too_many_parts(self):
|
||||||
with self.assertRaises(ConfigError):
|
with self.assertRaises(ConfigError):
|
||||||
parse_volume_spec('one:two:three:four')
|
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):
|
def test_build_volume_binding(self):
|
||||||
binding = build_volume_binding(parse_volume_spec('/outside:/inside'))
|
binding = build_volume_binding(parse_volume_spec('/outside:/inside'))
|
||||||
self.assertEqual(binding, ('/inside', '/outside:/inside:rw'))
|
self.assertEqual(binding, ('/inside', '/outside:/inside:rw'))
|
||||||
|
@ -508,3 +507,26 @@ class ServiceVolumesTest(unittest.TestCase):
|
||||||
create_options['host_config']['Binds'],
|
create_options['host_config']['Binds'],
|
||||||
['/mnt/sda1/host/path:/data:rw'],
|
['/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)
|
||||||
|
|
Loading…
Reference in New Issue