From 89f6caf871f5e7591f91ce1bc39d79c4ab8c90bd Mon Sep 17 00:00:00 2001 From: Aanand Prasad Date: Fri, 5 Jun 2015 09:57:00 +0100 Subject: [PATCH] Allow any volume mode to be specified Signed-off-by: Aanand Prasad --- compose/service.py | 7 +------ tests/unit/service_test.py | 30 ++++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/compose/service.py b/compose/service.py index a488b2c68c..006696c2dc 100644 --- a/compose/service.py +++ b/compose/service.py @@ -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 diff --git a/tests/unit/service_test.py b/tests/unit/service_test.py index 2b370ebea3..104a90d535 100644 --- a/tests/unit/service_test.py +++ b/tests/unit/service_test.py @@ -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)