summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Hwang <mhwang@research.att.com>2017-09-14 10:56:07 -0400
committerMichael Hwang <mhwang@research.att.com>2017-09-14 10:57:30 -0400
commit66613f4112b0e68f30430944b7d94e6ca14b1f62 (patch)
tree98316d7a0663e3a2e69d7128bbcc8997b60052ad
parent0c209c0c2b6e4bbadf413c048d9c535d3c2d1a0b (diff)
Fix issue where container ports is not list
Container ports was being returned as dict keys for python3 Change-Id: I434049c465094265d8e0ec8c8d6310b682866da8 Issue-Id: DCAEGEN2-91 Signed-off-by: Michael Hwang <mhwang@research.att.com>
-rw-r--r--python-dockering/ChangeLog.md5
-rw-r--r--python-dockering/dockering/config_building.py14
-rw-r--r--python-dockering/setup.py3
-rw-r--r--python-dockering/tests/test_config_building.py8
4 files changed, 24 insertions, 6 deletions
diff --git a/python-dockering/ChangeLog.md b/python-dockering/ChangeLog.md
index 67ae4f8..9c7781d 100644
--- a/python-dockering/ChangeLog.md
+++ b/python-dockering/ChangeLog.md
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
+## [1.3.0]
+
+* Fix issue with returning container ports as dict keys when list was expected
+* Add in functionality to notify Docker containers for policy changes
+
## [1.2.0]
* Add the ability to force reauthentication for Docker login
diff --git a/python-dockering/dockering/config_building.py b/python-dockering/dockering/config_building.py
index d8e3c84..564e5de 100644
--- a/python-dockering/dockering/config_building.py
+++ b/python-dockering/dockering/config_building.py
@@ -20,6 +20,7 @@
"""
Abstraction in Docker container configuration
"""
+import six
from dockering import utils
from dockering.exceptions import DockerConstructionError
@@ -234,6 +235,13 @@ def add_host_config_params_dns(docker_host, host_config_params=None):
return host_config_params
+def _get_container_ports(host_config_params):
+ """Grab list of container ports from host config params"""
+ if "port_bindings" in host_config_params:
+ return list(six.iterkeys(host_config_params["port_bindings"]))
+ else:
+ return None
+
def create_container_config(client, image, envs, host_config_params, tty=False):
"""Create docker container config
@@ -252,11 +260,7 @@ def create_container_config(client, image, envs, host_config_params, tty=False):
host_config = client.create_host_config(**host_config_params)
- if "port_bindings" in host_config_params:
- # TODO: Use six for creating the list of ports - six.iterkeys
- ports = host_config_params["port_bindings"].keys()
- else:
- ports = None
+ ports = _get_container_ports(host_config_params)
command = "" # This is required...
config = client.create_container_config(image, command, detach=True, tty=tty,
diff --git a/python-dockering/setup.py b/python-dockering/setup.py
index 418403e..9a0537e 100644
--- a/python-dockering/setup.py
+++ b/python-dockering/setup.py
@@ -29,6 +29,7 @@ setup(
packages=['dockering'],
zip_safe=False,
install_requires=[
- "docker-py>=1.0.0,<2.0.0"
+ "docker-py>=1.0.0,<2.0.0",
+ "six"
]
)
diff --git a/python-dockering/tests/test_config_building.py b/python-dockering/tests/test_config_building.py
index c9251e2..ff1b409 100644
--- a/python-dockering/tests/test_config_building.py
+++ b/python-dockering/tests/test_config_building.py
@@ -148,3 +148,11 @@ def test_parse_volumes_param():
assert actual == expected
assert None == doc._parse_volumes_param(None)
+
+
+def test_get_container_ports():
+ hcp = {'publish_all_ports': False, 'port_bindings': {'80': {'HostPort':
+ '80'}, '22': {'HostPort': '22'}}}
+ assert sorted(['80', '22']) == sorted(doc._get_container_ports(hcp))
+
+ assert None == doc._get_container_ports({})