Remove extra s from --add-host
linting... six.string_types list-of-strings in examples disallow extra_hosts support for list-of-dicts A more thorough sets of tests for extra_hosts Provide better examples As per @aanand's [comment](https://github.com/docker/compose/pull/1158/files#r28326312) I think it'd be better to check `if not isinstance(extra_hosts_line, six.string_types)` and raise an error saying `extra_hosts_config must be either a list of strings or a string->string mapping`. We shouldn't need to do anything special with the list-of-dicts case. order result to work with assert use set() instead of sort() Signed-off-by: CJ <lim@chernjie.com>
This commit is contained in:
parent
8098b65576
commit
25ee3f0033
3 changed files with 65 additions and 37 deletions
|
|
@ -626,20 +626,25 @@ def split_port(port):
|
|||
|
||||
|
||||
def build_extra_hosts(extra_hosts_config):
|
||||
if extra_hosts_config is None:
|
||||
return None
|
||||
if not extra_hosts_config:
|
||||
return {}
|
||||
|
||||
if isinstance(extra_hosts_config, basestring):
|
||||
extra_hosts_config = [extra_hosts_config]
|
||||
|
||||
extra_hosts_dict = {}
|
||||
for extra_hosts_line in extra_hosts_config:
|
||||
if isinstance(extra_hosts_line, dict):
|
||||
# already interpreted as a dict (depends on pyyaml version)
|
||||
extra_hosts_dict.update(extra_hosts_line)
|
||||
else:
|
||||
# not already interpreted as a dict
|
||||
if isinstance(extra_hosts_config, list):
|
||||
extra_hosts_dict = {}
|
||||
for extra_hosts_line in extra_hosts_config:
|
||||
if not isinstance(extra_hosts_line, six.string_types):
|
||||
raise ConfigError(
|
||||
"extra_hosts_config \"%s\" must be either a list of strings or a string->string mapping," %
|
||||
extra_hosts_config
|
||||
)
|
||||
host, ip = extra_hosts_line.split(':')
|
||||
extra_hosts_dict.update({host.strip(): ip.strip()})
|
||||
extra_hosts_config = extra_hosts_dict
|
||||
|
||||
return extra_hosts_dict
|
||||
if isinstance(extra_hosts_config, dict):
|
||||
return extra_hosts_config
|
||||
|
||||
raise ConfigError(
|
||||
"extra_hosts_config \"%s\" must be either a list of strings or a string->string mapping," %
|
||||
extra_hosts_config
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue