Match named volumes in service definitions with declared volumes
Raise ConfigurationError for undeclared named volumes Test new behavior Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
e35bf47a7f
commit
9e67eae311
4 changed files with 118 additions and 12 deletions
|
|
@ -813,3 +813,39 @@ class ProjectTest(DockerClientTestCase):
|
|||
assert 'Volume {0} declared as external'.format(
|
||||
vol_name
|
||||
) in str(e.exception)
|
||||
|
||||
@v2_only()
|
||||
def test_project_up_named_volumes_in_binds(self):
|
||||
vol_name = '{0:x}'.format(random.getrandbits(32))
|
||||
full_vol_name = 'composetest_{0}'.format(vol_name)
|
||||
|
||||
base_file = config.ConfigFile(
|
||||
'base.yml',
|
||||
{
|
||||
'version': 2,
|
||||
'services': {
|
||||
'simple': {
|
||||
'image': 'busybox:latest',
|
||||
'command': 'top',
|
||||
'volumes': ['{0}:/data'.format(vol_name)]
|
||||
},
|
||||
},
|
||||
'volumes': {
|
||||
vol_name: {'driver': 'local'}
|
||||
}
|
||||
|
||||
})
|
||||
config_details = config.ConfigDetails('.', [base_file])
|
||||
config_data = config.load(config_details)
|
||||
project = Project.from_config(
|
||||
name='composetest', config_data=config_data, client=self.client
|
||||
)
|
||||
service = project.services[0]
|
||||
self.assertEqual(service.name, 'simple')
|
||||
volumes = service.options.get('volumes')
|
||||
self.assertEqual(len(volumes), 1)
|
||||
self.assertEqual(volumes[0].external, full_vol_name)
|
||||
project.up()
|
||||
engine_volumes = self.client.volumes()
|
||||
self.assertIsNone(next(v for v in engine_volumes if v['Name'] == vol_name))
|
||||
self.assertIsNotNone(next(v for v in engine_volumes if v['Name'] == full_vol_name))
|
||||
|
|
|
|||
|
|
@ -7,8 +7,10 @@ import docker
|
|||
|
||||
from .. import mock
|
||||
from .. import unittest
|
||||
from compose.config import ConfigurationError
|
||||
from compose.config.config import Config
|
||||
from compose.config.types import VolumeFromSpec
|
||||
from compose.config.types import VolumeSpec
|
||||
from compose.const import LABEL_SERVICE
|
||||
from compose.container import Container
|
||||
from compose.project import Project
|
||||
|
|
@ -476,3 +478,44 @@ class ProjectTest(unittest.TestCase):
|
|||
),
|
||||
)
|
||||
self.assertEqual([c.id for c in project.containers()], ['1'])
|
||||
|
||||
def test_undeclared_volume_v2(self):
|
||||
config = Config(
|
||||
version=2,
|
||||
services=[
|
||||
{
|
||||
'name': 'web',
|
||||
'image': 'busybox:latest',
|
||||
'volumes': [VolumeSpec.parse('data0028:/data:ro')],
|
||||
},
|
||||
],
|
||||
networks=None,
|
||||
volumes=None,
|
||||
)
|
||||
with self.assertRaises(ConfigurationError):
|
||||
Project.from_config('composetest', config, None)
|
||||
|
||||
config = Config(
|
||||
version=2,
|
||||
services=[
|
||||
{
|
||||
'name': 'web',
|
||||
'image': 'busybox:latest',
|
||||
'volumes': [VolumeSpec.parse('./data0028:/data:ro')],
|
||||
},
|
||||
], networks=None, volumes=None,
|
||||
)
|
||||
Project.from_config('composetest', config, None)
|
||||
|
||||
def test_undeclared_volume_v1(self):
|
||||
config = Config(
|
||||
version=1,
|
||||
services=[
|
||||
{
|
||||
'name': 'web',
|
||||
'image': 'busybox:latest',
|
||||
'volumes': [VolumeSpec.parse('data0028:/data:ro')],
|
||||
},
|
||||
], networks=None, volumes=None,
|
||||
)
|
||||
Project.from_config('composetest', config, None)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue