From 6543e0472d3a9530c665975643335fc35185ba46 Mon Sep 17 00:00:00 2001 From: Liping Mao Date: Thu, 10 Nov 2016 17:49:25 +0800 Subject: [PATCH] container connect both bridge and kuryr network in Rally docker_client.create_container will connect to bridge network by default. Change-Id: I1d54203a5de60958c094aaeec4182c4253730bf3 Closes-bug: #1640720 --- rally-jobs/plugins/context/docker_networks.py | 2 ++ rally-jobs/plugins/scenarios/kuryr.py | 8 ++++---- rally-jobs/plugins/scenarios/utils.py | 9 +++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/rally-jobs/plugins/context/docker_networks.py b/rally-jobs/plugins/context/docker_networks.py index 6e9edac5..ab4bd2fa 100644 --- a/rally-jobs/plugins/context/docker_networks.py +++ b/rally-jobs/plugins/context/docker_networks.py @@ -70,9 +70,11 @@ class DockerNetworkContext(context.Context): driver="kuryr", ipam=ipam) self.context["netid"] = res.get("Id") + self.context["netname"] = "kuryr_network" else: res = docker_client.create_network(name="docker_network") self.context["netid"] = res.get("Id") + self.context["netname"] = "docker_network" LOG.debug("Container network id is '%s'" % self.context["netid"]) except Exception as e: msg = "Can't create docker network: %s" % e.message diff --git a/rally-jobs/plugins/scenarios/kuryr.py b/rally-jobs/plugins/scenarios/kuryr.py index 5351afc6..d5f30624 100644 --- a/rally-jobs/plugins/scenarios/kuryr.py +++ b/rally-jobs/plugins/scenarios/kuryr.py @@ -24,7 +24,7 @@ class Kuryr(utils.KuryrScenario): def __init__(self, context=None, admin_clients=None, clients=None): super(Kuryr, self).__init__(context, admin_clients, clients) - @scenario.configure(context={"cleanup": ["kuryr"]}) + @scenario.configure() def list_networks(self, network_list_args=None): """List the networks. @@ -40,7 +40,7 @@ class Kuryr(utils.KuryrScenario): """ self._list_networks(network_list_args or {}) - @scenario.configure(context={"cleanup": ["kuryr"]}) + @scenario.configure() def create_and_delete_networks_with_kuryr(self, network_create_args=None): """Create and delete a network with kuryr. @@ -53,7 +53,7 @@ class Kuryr(utils.KuryrScenario): network_create_args=network_create_args or {}) self._delete_network(network) - @scenario.configure(context={"cleanup": ["kuryr"]}) + @scenario.configure() def create_and_delete_networks_without_kuryr(self, network_create_args=None): """Create and delete a network without kuryr. @@ -67,7 +67,7 @@ class Kuryr(utils.KuryrScenario): network_create_args=network_create_args or {}) self._delete_network(network) - @scenario.configure(context={"cleanup": ["kuryr"]}) + @scenario.configure() def start_and_stop_containers(self, container_create_args=None): """Start and stop container on docker network. diff --git a/rally-jobs/plugins/scenarios/utils.py b/rally-jobs/plugins/scenarios/utils.py index 86fa58a3..0c63dfef 100644 --- a/rally-jobs/plugins/scenarios/utils.py +++ b/rally-jobs/plugins/scenarios/utils.py @@ -79,14 +79,15 @@ class KuryrScenario(scenario.OpenStackScenario): @atomic.action_timer("kuryr.start_container") def _start_container(self, container_create_args=None): """Start Container on docker network.""" + network_config = self.docker_client.create_networking_config( + {self.context.get("netname"): + self.docker_client.create_endpoint_config()}) container = self.docker_client.create_container( image='kuryr/busybox', - command='/bin/sleep 600') + command='/bin/sleep 600', + networking_config=network_config) container_id = container.get('Id') self.docker_client.start(container=container_id) - net_id = self.context.get("netid") - self.docker_client.connect_container_to_network(container_id, - net_id) return container_id @atomic.action_timer("kuryr.stop_container")