mirror of https://github.com/docker/docker-py.git
Merge pull request #1500 from shin-/fix_split_port_empty_string
Raise an error when passing an empty string to split_port
This commit is contained in:
commit
24f75ea212
|
@ -67,6 +67,8 @@ def split_port(port):
|
|||
|
||||
if len(parts) == 1:
|
||||
internal_port, = parts
|
||||
if not internal_port:
|
||||
_raise_invalid_port(port)
|
||||
return to_port_range(internal_port), None
|
||||
if len(parts) == 2:
|
||||
external_port, internal_port = parts
|
||||
|
|
|
@ -8,7 +8,7 @@ import warnings
|
|||
import docker
|
||||
from docker.utils import kwargs_from_env
|
||||
|
||||
from .base import BaseAPIIntegrationTest, BUSYBOX
|
||||
from .base import BaseAPIIntegrationTest
|
||||
|
||||
|
||||
class InformationTest(BaseAPIIntegrationTest):
|
||||
|
@ -25,48 +25,6 @@ class InformationTest(BaseAPIIntegrationTest):
|
|||
self.assertIn('Debug', res)
|
||||
|
||||
|
||||
class LinkTest(BaseAPIIntegrationTest):
|
||||
def test_remove_link(self):
|
||||
# Create containers
|
||||
container1 = self.client.create_container(
|
||||
BUSYBOX, 'cat', detach=True, stdin_open=True
|
||||
)
|
||||
container1_id = container1['Id']
|
||||
self.tmp_containers.append(container1_id)
|
||||
self.client.start(container1_id)
|
||||
|
||||
# Create Link
|
||||
# we don't want the first /
|
||||
link_path = self.client.inspect_container(container1_id)['Name'][1:]
|
||||
link_alias = 'mylink'
|
||||
|
||||
container2 = self.client.create_container(
|
||||
BUSYBOX, 'cat', host_config=self.client.create_host_config(
|
||||
links={link_path: link_alias}
|
||||
)
|
||||
)
|
||||
container2_id = container2['Id']
|
||||
self.tmp_containers.append(container2_id)
|
||||
self.client.start(container2_id)
|
||||
|
||||
# Remove link
|
||||
linked_name = self.client.inspect_container(container2_id)['Name'][1:]
|
||||
link_name = '%s/%s' % (linked_name, link_alias)
|
||||
self.client.remove_container(link_name, link=True)
|
||||
|
||||
# Link is gone
|
||||
containers = self.client.containers(all=True)
|
||||
retrieved = [x for x in containers if link_name in x['Names']]
|
||||
self.assertEqual(len(retrieved), 0)
|
||||
|
||||
# Containers are still there
|
||||
retrieved = [
|
||||
x for x in containers if x['Id'].startswith(container1_id) or
|
||||
x['Id'].startswith(container2_id)
|
||||
]
|
||||
self.assertEqual(len(retrieved), 2)
|
||||
|
||||
|
||||
class LoadConfigTest(BaseAPIIntegrationTest):
|
||||
def test_load_legacy_config(self):
|
||||
folder = tempfile.mkdtemp()
|
||||
|
|
|
@ -1253,3 +1253,45 @@ class ContainerCPUTest(BaseAPIIntegrationTest):
|
|||
self.client.start(container)
|
||||
inspect_data = self.client.inspect_container(container)
|
||||
self.assertEqual(inspect_data['HostConfig']['CpusetCpus'], cpuset_cpus)
|
||||
|
||||
|
||||
class LinkTest(BaseAPIIntegrationTest):
|
||||
def test_remove_link(self):
|
||||
# Create containers
|
||||
container1 = self.client.create_container(
|
||||
BUSYBOX, 'cat', detach=True, stdin_open=True
|
||||
)
|
||||
container1_id = container1['Id']
|
||||
self.tmp_containers.append(container1_id)
|
||||
self.client.start(container1_id)
|
||||
|
||||
# Create Link
|
||||
# we don't want the first /
|
||||
link_path = self.client.inspect_container(container1_id)['Name'][1:]
|
||||
link_alias = 'mylink'
|
||||
|
||||
container2 = self.client.create_container(
|
||||
BUSYBOX, 'cat', host_config=self.client.create_host_config(
|
||||
links={link_path: link_alias}
|
||||
)
|
||||
)
|
||||
container2_id = container2['Id']
|
||||
self.tmp_containers.append(container2_id)
|
||||
self.client.start(container2_id)
|
||||
|
||||
# Remove link
|
||||
linked_name = self.client.inspect_container(container2_id)['Name'][1:]
|
||||
link_name = '%s/%s' % (linked_name, link_alias)
|
||||
self.client.remove_container(link_name, link=True)
|
||||
|
||||
# Link is gone
|
||||
containers = self.client.containers(all=True)
|
||||
retrieved = [x for x in containers if link_name in x['Names']]
|
||||
self.assertEqual(len(retrieved), 0)
|
||||
|
||||
# Containers are still there
|
||||
retrieved = [
|
||||
x for x in containers if x['Id'].startswith(container1_id) or
|
||||
x['Id'].startswith(container2_id)
|
||||
]
|
||||
self.assertEqual(len(retrieved), 2)
|
||||
|
|
|
@ -578,6 +578,9 @@ class PortsTest(unittest.TestCase):
|
|||
self.assertRaises(ValueError,
|
||||
lambda: split_port("localhost:80:"))
|
||||
|
||||
def test_split_port_empty_string(self):
|
||||
self.assertRaises(ValueError, lambda: split_port(""))
|
||||
|
||||
def test_build_port_bindings_with_one_port(self):
|
||||
port_bindings = build_port_bindings(["127.0.0.1:1000:1000"])
|
||||
self.assertEqual(port_bindings["1000"], [("127.0.0.1", "1000")])
|
||||
|
|
Loading…
Reference in New Issue