Move named volumes matching to config validation phase
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
3da25aa463
commit
3f28472ebc
5 changed files with 83 additions and 74 deletions
|
|
@ -564,6 +564,56 @@ class ConfigTest(unittest.TestCase):
|
|||
]
|
||||
assert service_sort(service_dicts) == service_sort(expected)
|
||||
|
||||
def test_undeclared_volume_v2(self):
|
||||
base_file = config.ConfigFile(
|
||||
'base.yaml',
|
||||
{
|
||||
'version': 2,
|
||||
'services': {
|
||||
'web': {
|
||||
'image': 'busybox:latest',
|
||||
'volumes': ['data0028:/data:ro'],
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
details = config.ConfigDetails('.', [base_file])
|
||||
with self.assertRaises(ConfigurationError):
|
||||
config.load(details)
|
||||
|
||||
base_file = config.ConfigFile(
|
||||
'base.yaml',
|
||||
{
|
||||
'version': 2,
|
||||
'services': {
|
||||
'web': {
|
||||
'image': 'busybox:latest',
|
||||
'volumes': ['./data0028:/data:ro'],
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
details = config.ConfigDetails('.', [base_file])
|
||||
config_data = config.load(details)
|
||||
volume = config_data.services[0].get('volumes')[0]
|
||||
assert not volume.is_named_volume
|
||||
|
||||
def test_undeclared_volume_v1(self):
|
||||
base_file = config.ConfigFile(
|
||||
'base.yaml',
|
||||
{
|
||||
'web': {
|
||||
'image': 'busybox:latest',
|
||||
'volumes': ['data0028:/data:ro'],
|
||||
},
|
||||
}
|
||||
)
|
||||
details = config.ConfigDetails('.', [base_file])
|
||||
config_data = config.load(details)
|
||||
volume = config_data.services[0].get('volumes')[0]
|
||||
assert volume.external == 'data0028'
|
||||
assert volume.is_named_volume
|
||||
|
||||
def test_config_valid_service_names(self):
|
||||
for valid_name in ['_', '-', '.__.', '_what-up.', 'what_.up----', 'whatup']:
|
||||
services = config.load(
|
||||
|
|
|
|||
|
|
@ -7,10 +7,8 @@ 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
|
||||
|
|
@ -478,44 +476,3 @@ 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