mirror of https://github.com/docker/compose.git
Always convert port values in ServicePort to integer
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
bcc4a76ea0
commit
36af86b9b2
|
@ -263,6 +263,22 @@ class ServiceSecret(namedtuple('_ServiceSecret', 'source target uid gid mode')):
|
||||||
|
|
||||||
|
|
||||||
class ServicePort(namedtuple('_ServicePort', 'target published protocol mode external_ip')):
|
class ServicePort(namedtuple('_ServicePort', 'target published protocol mode external_ip')):
|
||||||
|
def __new__(cls, target, published, *args, **kwargs):
|
||||||
|
try:
|
||||||
|
if target:
|
||||||
|
target = int(target)
|
||||||
|
except ValueError:
|
||||||
|
raise ConfigurationError('Invalid target port: {}'.format(target))
|
||||||
|
|
||||||
|
try:
|
||||||
|
if published:
|
||||||
|
published = int(published)
|
||||||
|
except ValueError:
|
||||||
|
raise ConfigurationError('Invalid published port: {}'.format(published))
|
||||||
|
|
||||||
|
return super(ServicePort, cls).__new__(
|
||||||
|
cls, target, published, *args, **kwargs
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse(cls, spec):
|
def parse(cls, spec):
|
||||||
|
|
|
@ -57,15 +57,15 @@ class TestServicePort(object):
|
||||||
def test_parse_simple_target_port(self):
|
def test_parse_simple_target_port(self):
|
||||||
ports = ServicePort.parse(8000)
|
ports = ServicePort.parse(8000)
|
||||||
assert len(ports) == 1
|
assert len(ports) == 1
|
||||||
assert ports[0].target == '8000'
|
assert ports[0].target == 8000
|
||||||
|
|
||||||
def test_parse_complete_port_definition(self):
|
def test_parse_complete_port_definition(self):
|
||||||
port_def = '1.1.1.1:3000:3000/udp'
|
port_def = '1.1.1.1:3000:3000/udp'
|
||||||
ports = ServicePort.parse(port_def)
|
ports = ServicePort.parse(port_def)
|
||||||
assert len(ports) == 1
|
assert len(ports) == 1
|
||||||
assert ports[0].repr() == {
|
assert ports[0].repr() == {
|
||||||
'target': '3000',
|
'target': 3000,
|
||||||
'published': '3000',
|
'published': 3000,
|
||||||
'external_ip': '1.1.1.1',
|
'external_ip': '1.1.1.1',
|
||||||
'protocol': 'udp',
|
'protocol': 'udp',
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ class TestServicePort(object):
|
||||||
assert len(ports) == 1
|
assert len(ports) == 1
|
||||||
assert ports[0].legacy_repr() == port_def + '/tcp'
|
assert ports[0].legacy_repr() == port_def + '/tcp'
|
||||||
assert ports[0].repr() == {
|
assert ports[0].repr() == {
|
||||||
'target': '3000',
|
'target': 3000,
|
||||||
'external_ip': '1.1.1.1',
|
'external_ip': '1.1.1.1',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,14 +86,19 @@ class TestServicePort(object):
|
||||||
assert len(ports) == 2
|
assert len(ports) == 2
|
||||||
reprs = [p.repr() for p in ports]
|
reprs = [p.repr() for p in ports]
|
||||||
assert {
|
assert {
|
||||||
'target': '4000',
|
'target': 4000,
|
||||||
'published': '25000'
|
'published': 25000
|
||||||
} in reprs
|
} in reprs
|
||||||
assert {
|
assert {
|
||||||
'target': '4001',
|
'target': 4001,
|
||||||
'published': '25001'
|
'published': 25001
|
||||||
} in reprs
|
} in reprs
|
||||||
|
|
||||||
|
def test_parse_invalid_port(self):
|
||||||
|
port_def = '4000p'
|
||||||
|
with pytest.raises(ConfigurationError):
|
||||||
|
ServicePort.parse(port_def)
|
||||||
|
|
||||||
|
|
||||||
class TestVolumeSpec(object):
|
class TestVolumeSpec(object):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue