mirror of https://github.com/docker/compose.git
Provide valid serialization of depends_on when format is not 2.1
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
ab97716a95
commit
76678747c7
|
@ -56,9 +56,16 @@ def denormalize_service_dict(service_dict, version):
|
|||
service_dict = service_dict.copy()
|
||||
|
||||
if 'restart' in service_dict:
|
||||
service_dict['restart'] = types.serialize_restart_spec(service_dict['restart'])
|
||||
service_dict['restart'] = types.serialize_restart_spec(
|
||||
service_dict['restart']
|
||||
)
|
||||
|
||||
if version == V1 and 'network_mode' not in service_dict:
|
||||
service_dict['network_mode'] = 'bridge'
|
||||
|
||||
if 'depends_on' in service_dict and version != V2_1:
|
||||
service_dict['depends_on'] = sorted([
|
||||
svc for svc in service_dict['depends_on'].keys()
|
||||
])
|
||||
|
||||
return service_dict
|
||||
|
|
|
@ -22,6 +22,7 @@ from compose.config.config import V3_0
|
|||
from compose.config.environment import Environment
|
||||
from compose.config.errors import ConfigurationError
|
||||
from compose.config.errors import VERSION_EXPLANATION
|
||||
from compose.config.serialize import denormalize_service_dict
|
||||
from compose.config.types import VolumeSpec
|
||||
from compose.const import IS_WINDOWS_PLATFORM
|
||||
from compose.utils import nanoseconds_from_time_seconds
|
||||
|
@ -3269,3 +3270,33 @@ def get_config_filename_for_files(filenames, subdir=None):
|
|||
return os.path.basename(filename)
|
||||
finally:
|
||||
shutil.rmtree(project_dir)
|
||||
|
||||
|
||||
class SerializeTest(unittest.TestCase):
|
||||
def test_denormalize_depends_on_v3(self):
|
||||
service_dict = {
|
||||
'image': 'busybox',
|
||||
'command': 'true',
|
||||
'depends_on': {
|
||||
'service2': {'condition': 'service_started'},
|
||||
'service3': {'condition': 'service_started'},
|
||||
}
|
||||
}
|
||||
|
||||
assert denormalize_service_dict(service_dict, V3_0) == {
|
||||
'image': 'busybox',
|
||||
'command': 'true',
|
||||
'depends_on': ['service2', 'service3']
|
||||
}
|
||||
|
||||
def test_denormalize_depends_on_v2_1(self):
|
||||
service_dict = {
|
||||
'image': 'busybox',
|
||||
'command': 'true',
|
||||
'depends_on': {
|
||||
'service2': {'condition': 'service_started'},
|
||||
'service3': {'condition': 'service_started'},
|
||||
}
|
||||
}
|
||||
|
||||
assert denormalize_service_dict(service_dict, V2_1) == service_dict
|
||||
|
|
Loading…
Reference in New Issue