Handle volume driver change error in config.
Assume version=1 if file is empty in get_config_version Empty files are invalid anyway, so this simplifies the algorithm somewhat. https://github.com/docker/compose/pull/2421#discussion_r47223144 Don't leak version considerations in interpolation/service validation Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
f3a9533dc0
commit
a7689f3da8
6 changed files with 94 additions and 21 deletions
|
|
@ -579,11 +579,11 @@ class ProjectTest(DockerClientTestCase):
|
|||
vol_name = '{0:x}'.format(random.getrandbits(32))
|
||||
|
||||
config_data = config.Config(
|
||||
2, [{
|
||||
version=2, services=[{
|
||||
'name': 'web',
|
||||
'image': 'busybox:latest',
|
||||
'command': 'top'
|
||||
}], {vol_name: {'driver': 'foobar'}}
|
||||
}], volumes={vol_name: {'driver': 'foobar'}}
|
||||
)
|
||||
|
||||
project = Project.from_config(
|
||||
|
|
@ -592,3 +592,37 @@ class ProjectTest(DockerClientTestCase):
|
|||
)
|
||||
with self.assertRaises(config.ConfigurationError):
|
||||
project.initialize_volumes()
|
||||
|
||||
def test_project_up_updated_driver(self):
|
||||
vol_name = '{0:x}'.format(random.getrandbits(32))
|
||||
full_vol_name = 'composetest_{0}'.format(vol_name)
|
||||
|
||||
config_data = config.Config(
|
||||
version=2, services=[{
|
||||
'name': 'web',
|
||||
'image': 'busybox:latest',
|
||||
'command': 'top'
|
||||
}], volumes={vol_name: {'driver': 'local'}}
|
||||
)
|
||||
project = Project.from_config(
|
||||
name='composetest',
|
||||
config_data=config_data, client=self.client
|
||||
)
|
||||
project.initialize_volumes()
|
||||
|
||||
volume_data = self.client.inspect_volume(full_vol_name)
|
||||
self.assertEqual(volume_data['Name'], full_vol_name)
|
||||
self.assertEqual(volume_data['Driver'], 'local')
|
||||
|
||||
config_data = config_data._replace(
|
||||
volumes={vol_name: {'driver': 'smb'}}
|
||||
)
|
||||
project = Project.from_config(
|
||||
name='composetest',
|
||||
config_data=config_data, client=self.client
|
||||
)
|
||||
with self.assertRaises(config.ConfigurationError) as e:
|
||||
project.initialize_volumes()
|
||||
assert 'Configuration for volume {0} specifies driver smb'.format(
|
||||
vol_name
|
||||
) in str(e.exception)
|
||||
|
|
|
|||
|
|
@ -286,6 +286,18 @@ class ConfigTest(unittest.TestCase):
|
|||
error_msg = "Top level object in 'override.yml' needs to be an object"
|
||||
assert error_msg in exc.exconly()
|
||||
|
||||
def test_load_with_multiple_files_and_empty_override_v2(self):
|
||||
base_file = config.ConfigFile(
|
||||
'base.yml',
|
||||
{'version': 2, 'services': {'web': {'image': 'example/web'}}})
|
||||
override_file = config.ConfigFile('override.yml', None)
|
||||
details = config.ConfigDetails('.', [base_file, override_file])
|
||||
|
||||
with pytest.raises(ConfigurationError) as exc:
|
||||
config.load(details)
|
||||
error_msg = "Top level object in 'override.yml' needs to be an object"
|
||||
assert error_msg in exc.exconly()
|
||||
|
||||
def test_load_with_multiple_files_and_empty_base(self):
|
||||
base_file = config.ConfigFile('base.yml', None)
|
||||
override_file = config.ConfigFile(
|
||||
|
|
@ -297,6 +309,17 @@ class ConfigTest(unittest.TestCase):
|
|||
config.load(details)
|
||||
assert "Top level object in 'base.yml' needs to be an object" in exc.exconly()
|
||||
|
||||
def test_load_with_multiple_files_and_empty_base_v2(self):
|
||||
base_file = config.ConfigFile('base.yml', None)
|
||||
override_file = config.ConfigFile(
|
||||
'override.tml',
|
||||
{'version': 2, 'services': {'web': {'image': 'example/web'}}}
|
||||
)
|
||||
details = config.ConfigDetails('.', [base_file, override_file])
|
||||
with pytest.raises(ConfigurationError) as exc:
|
||||
config.load(details)
|
||||
assert "Top level object in 'base.yml' needs to be an object" in exc.exconly()
|
||||
|
||||
def test_load_with_multiple_files_and_extends_in_override_file(self):
|
||||
base_file = config.ConfigFile(
|
||||
'base.yaml',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue