mirror of https://github.com/docker/compose.git
Fix format of 'restart' option in 'config' output
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
parent
6064d200f9
commit
756ef14edc
|
@ -19,12 +19,14 @@ yaml.SafeDumper.add_representer(types.VolumeSpec, serialize_config_type)
|
||||||
|
|
||||||
|
|
||||||
def serialize_config(config):
|
def serialize_config(config):
|
||||||
services = {service.pop('name'): service for service in config.services}
|
denormalized_services = [
|
||||||
|
denormalize_service_dict(service_dict, config.version)
|
||||||
if config.version == V1:
|
for service_dict in config.services
|
||||||
for service_dict in services.values():
|
]
|
||||||
if 'network_mode' not in service_dict:
|
services = {
|
||||||
service_dict['network_mode'] = 'bridge'
|
service_dict.pop('name'): service_dict
|
||||||
|
for service_dict in denormalized_services
|
||||||
|
}
|
||||||
|
|
||||||
output = {
|
output = {
|
||||||
'version': V2_0,
|
'version': V2_0,
|
||||||
|
@ -38,3 +40,15 @@ def serialize_config(config):
|
||||||
default_flow_style=False,
|
default_flow_style=False,
|
||||||
indent=2,
|
indent=2,
|
||||||
width=80)
|
width=80)
|
||||||
|
|
||||||
|
|
||||||
|
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'])
|
||||||
|
|
||||||
|
if version == V1 and 'network_mode' not in service_dict:
|
||||||
|
service_dict['network_mode'] = 'bridge'
|
||||||
|
|
||||||
|
return service_dict
|
||||||
|
|
|
@ -7,6 +7,8 @@ from __future__ import unicode_literals
|
||||||
import os
|
import os
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
from compose.config.config import V1
|
from compose.config.config import V1
|
||||||
from compose.config.errors import ConfigurationError
|
from compose.config.errors import ConfigurationError
|
||||||
from compose.const import IS_WINDOWS_PLATFORM
|
from compose.const import IS_WINDOWS_PLATFORM
|
||||||
|
@ -89,6 +91,13 @@ def parse_restart_spec(restart_config):
|
||||||
return {'Name': name, 'MaximumRetryCount': int(max_retry_count)}
|
return {'Name': name, 'MaximumRetryCount': int(max_retry_count)}
|
||||||
|
|
||||||
|
|
||||||
|
def serialize_restart_spec(restart_spec):
|
||||||
|
parts = [restart_spec['Name']]
|
||||||
|
if restart_spec['MaximumRetryCount']:
|
||||||
|
parts.append(six.text_type(restart_spec['MaximumRetryCount']))
|
||||||
|
return ':'.join(parts)
|
||||||
|
|
||||||
|
|
||||||
def parse_extra_hosts(extra_hosts_config):
|
def parse_extra_hosts(extra_hosts_config):
|
||||||
if not extra_hosts_config:
|
if not extra_hosts_config:
|
||||||
return {}
|
return {}
|
||||||
|
|
|
@ -190,6 +190,33 @@ class CLITestCase(DockerClientTestCase):
|
||||||
}
|
}
|
||||||
assert output == expected
|
assert output == expected
|
||||||
|
|
||||||
|
def test_config_restart(self):
|
||||||
|
self.base_dir = 'tests/fixtures/restart'
|
||||||
|
result = self.dispatch(['config'])
|
||||||
|
assert yaml.load(result.stdout) == {
|
||||||
|
'version': '2.0',
|
||||||
|
'services': {
|
||||||
|
'never': {
|
||||||
|
'image': 'busybox',
|
||||||
|
'restart': 'no',
|
||||||
|
},
|
||||||
|
'always': {
|
||||||
|
'image': 'busybox',
|
||||||
|
'restart': 'always',
|
||||||
|
},
|
||||||
|
'on-failure': {
|
||||||
|
'image': 'busybox',
|
||||||
|
'restart': 'on-failure',
|
||||||
|
},
|
||||||
|
'on-failure-5': {
|
||||||
|
'image': 'busybox',
|
||||||
|
'restart': 'on-failure:5',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'networks': {},
|
||||||
|
'volumes': {},
|
||||||
|
}
|
||||||
|
|
||||||
def test_config_v1(self):
|
def test_config_v1(self):
|
||||||
self.base_dir = 'tests/fixtures/v1-config'
|
self.base_dir = 'tests/fixtures/v1-config'
|
||||||
result = self.dispatch(['config'])
|
result = self.dispatch(['config'])
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
version: "2"
|
||||||
|
services:
|
||||||
|
never:
|
||||||
|
image: busybox
|
||||||
|
restart: "no"
|
||||||
|
always:
|
||||||
|
image: busybox
|
||||||
|
restart: always
|
||||||
|
on-failure:
|
||||||
|
image: busybox
|
||||||
|
restart: on-failure
|
||||||
|
on-failure-5:
|
||||||
|
image: busybox
|
||||||
|
restart: "on-failure:5"
|
Loading…
Reference in New Issue