Merge pull request #2665 from dnephin/check_extends_use_same_version

Validate that an extended config file has the same version as the base
This commit is contained in:
Daniel Nephin 2016-01-15 18:07:56 -05:00
commit cce3b29688
3 changed files with 53 additions and 30 deletions

View file

@ -48,7 +48,7 @@ def wait_on_process(proc, returncode=0):
return ProcessResult(stdout.decode('utf-8'), stderr.decode('utf-8'))
def wait_on_condition(condition, delay=0.1, timeout=20):
def wait_on_condition(condition, delay=0.1, timeout=40):
start_time = time.time()
while not condition():
if time.time() - start_time > timeout:
@ -648,14 +648,14 @@ class CLITestCase(DockerClientTestCase):
wait_on_condition(ContainerCountCondition(self.project, 2))
os.kill(proc.pid, signal.SIGINT)
wait_on_condition(ContainerCountCondition(self.project, 0), timeout=30)
wait_on_condition(ContainerCountCondition(self.project, 0))
def test_up_handles_sigterm(self):
proc = start_process(self.base_dir, ['up', '-t', '2'])
wait_on_condition(ContainerCountCondition(self.project, 2))
os.kill(proc.pid, signal.SIGTERM)
wait_on_condition(ContainerCountCondition(self.project, 0), timeout=30)
wait_on_condition(ContainerCountCondition(self.project, 0))
def test_run_service_without_links(self):
self.base_dir = 'tests/fixtures/links-composefile'

View file

@ -25,14 +25,15 @@ V1 = 1
def make_service_dict(name, service_dict, working_dir, filename=None):
"""Test helper function to construct a ServiceExtendsResolver
"""
Test helper function to construct a ServiceExtendsResolver
"""
resolver = config.ServiceExtendsResolver(config.ServiceConfig(
working_dir=working_dir,
filename=filename,
name=name,
config=service_dict), version=1)
resolver = config.ServiceExtendsResolver(
config.ServiceConfig(
working_dir=working_dir,
filename=filename,
name=name,
config=service_dict),
config.ConfigFile(filename=filename, config={}))
return config.process_service(resolver.run())
@ -1888,6 +1889,28 @@ class ExtendsTest(unittest.TestCase):
assert config == expected
def test_extends_with_mixed_versions_is_error(self):
tmpdir = py.test.ensuretemp('test_extends_with_mixed_version')
self.addCleanup(tmpdir.remove)
tmpdir.join('docker-compose.yml').write("""
version: 2
services:
web:
extends:
file: base.yml
service: base
image: busybox
""")
tmpdir.join('base.yml').write("""
base:
volumes: ['/foo']
ports: ['3000:3000']
""")
with pytest.raises(ConfigurationError) as exc:
load_from_filename(str(tmpdir.join('docker-compose.yml')))
assert 'Version mismatch' in exc.exconly()
@pytest.mark.xfail(IS_WINDOWS_PLATFORM, reason='paths use slash')
class ExpandPathTest(unittest.TestCase):