mirror of https://github.com/docker/compose.git
Allow port publish ranges
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
3c232e42c1
commit
ceec0595bd
|
@ -319,8 +319,16 @@ class ServicePort(namedtuple('_ServicePort', 'target published protocol mode ext
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ConfigurationError('Invalid target port: {}'.format(target))
|
raise ConfigurationError('Invalid target port: {}'.format(target))
|
||||||
|
|
||||||
try:
|
|
||||||
if published:
|
if published:
|
||||||
|
if isinstance(published, six.string_types) and '-' in published: # "x-y:z" format
|
||||||
|
a, b = published.split('-', 1)
|
||||||
|
try:
|
||||||
|
int(a)
|
||||||
|
int(b)
|
||||||
|
except ValueError:
|
||||||
|
raise ConfigurationError('Invalid published port: {}'.format(published))
|
||||||
|
else:
|
||||||
|
try:
|
||||||
published = int(published)
|
published = int(published)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ConfigurationError('Invalid published port: {}'.format(published))
|
raise ConfigurationError('Invalid published port: {}'.format(published))
|
||||||
|
|
|
@ -100,11 +100,37 @@ class TestServicePort(object):
|
||||||
'published': 25001
|
'published': 25001
|
||||||
} in reprs
|
} in reprs
|
||||||
|
|
||||||
|
def test_parse_port_publish_range(self):
|
||||||
|
ports = ServicePort.parse('4440-4450:4000')
|
||||||
|
assert len(ports) == 1
|
||||||
|
reprs = [p.repr() for p in ports]
|
||||||
|
assert {
|
||||||
|
'target': 4000,
|
||||||
|
'published': '4440-4450'
|
||||||
|
} in reprs
|
||||||
|
|
||||||
def test_parse_invalid_port(self):
|
def test_parse_invalid_port(self):
|
||||||
port_def = '4000p'
|
port_def = '4000p'
|
||||||
with pytest.raises(ConfigurationError):
|
with pytest.raises(ConfigurationError):
|
||||||
ServicePort.parse(port_def)
|
ServicePort.parse(port_def)
|
||||||
|
|
||||||
|
def test_parse_invalid_publish_range(self):
|
||||||
|
port_def = '-4000:4000'
|
||||||
|
with pytest.raises(ConfigurationError):
|
||||||
|
ServicePort.parse(port_def)
|
||||||
|
|
||||||
|
port_def = 'asdf:4000'
|
||||||
|
with pytest.raises(ConfigurationError):
|
||||||
|
ServicePort.parse(port_def)
|
||||||
|
|
||||||
|
port_def = '1234-12f:4000'
|
||||||
|
with pytest.raises(ConfigurationError):
|
||||||
|
ServicePort.parse(port_def)
|
||||||
|
|
||||||
|
port_def = '1234-1235-1239:4000'
|
||||||
|
with pytest.raises(ConfigurationError):
|
||||||
|
ServicePort.parse(port_def)
|
||||||
|
|
||||||
|
|
||||||
class TestVolumeSpec(object):
|
class TestVolumeSpec(object):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue