From 62a72f5098128991bb7f70a2d6d1fdeb9a9e1ef1 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Braun Date: Thu, 20 Aug 2015 16:17:01 +0200 Subject: [PATCH] Create pool in lbaas context with correct tenant_id When creating the pool in the lbaas context we use the same tenant_id that was used to created the network on which the pool is created. Change-Id: Ia06eddc7bd3fc3149f794ed6b862a4bc9bf34b60 Closes-Bug: #1487061 Signed-off-by: Jean-Philippe Braun --- rally/plugins/openstack/context/neutron/lbaas.py | 1 + rally/plugins/openstack/wrappers/network.py | 4 +++- .../openstack/context/neutron/test_lbaas.py | 15 +++++++++++---- .../plugins/openstack/wrappers/test_network.py | 7 +++++-- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/rally/plugins/openstack/context/neutron/lbaas.py b/rally/plugins/openstack/context/neutron/lbaas.py index 6d15fb71..80f92057 100644 --- a/rally/plugins/openstack/context/neutron/lbaas.py +++ b/rally/plugins/openstack/context/neutron/lbaas.py @@ -68,6 +68,7 @@ class Lbaas(context.Context): if self.config["lbaas_version"] == 1: network.setdefault("lb_pools", []).append( net_wrapper.create_v1_pool( + tenant_id, subnet, **self.config["pool"])) else: diff --git a/rally/plugins/openstack/wrappers/network.py b/rally/plugins/openstack/wrappers/network.py index f5cbd1c5..7a3e836a 100644 --- a/rally/plugins/openstack/wrappers/network.py +++ b/rally/plugins/openstack/wrappers/network.py @@ -245,15 +245,17 @@ class NeutronWrapper(NetworkWrapper): "network_id": net["id"], "enable_snat": True} return self.client.create_router({"router": kwargs})["router"] - def create_v1_pool(self, subnet_id, **kwargs): + def create_v1_pool(self, tenant_id, subnet_id, **kwargs): """Create LB Pool (v1). + :param tenant_id: str, pool tenant id :param subnet_id: str, neutron subnet-id :param **kwargs: extra options :returns: neutron lb-pool dict """ pool_args = { "pool": { + "tenant_id": tenant_id, "name": utils.generate_random_name("rally_pool_"), "subnet_id": subnet_id, "lb_method": kwargs.get("lb_method", self.LB_METHOD), diff --git a/tests/unit/plugins/openstack/context/neutron/test_lbaas.py b/tests/unit/plugins/openstack/context/neutron/test_lbaas.py index edd3ae4a..12adb61d 100644 --- a/tests/unit/plugins/openstack/context/neutron/test_lbaas.py +++ b/tests/unit/plugins/openstack/context/neutron/test_lbaas.py @@ -21,8 +21,10 @@ NET = "rally.plugins.openstack.wrappers.network." class LbaasTestCase(test.TestCase): def get_context(self, **kwargs): foo_tenant = {"networks": [{"id": "foo_net", + "tenant_id": "foo_tenant", "subnets": ["foo_subnet"]}]} bar_tenant = {"networks": [{"id": "bar_net", + "tenant_id": "bar_tenant", "subnets": ["bar_subnet"]}]} return {"task": {"uuid": "foo_task"}, "admin": {"endpoint": "foo_admin"}, @@ -62,15 +64,20 @@ class LbaasTestCase(test.TestCase): ("foo_user", "foo_tenant"), ("bar_user", "bar_tenant")] foo_net = {"id": "foo_net", + "tenant_id": "foo_tenant", "subnets": ["foo_subnet"], - "lb_pools": [{"pool": {"id": "foo_pool"}}]} + "lb_pools": [{"pool": {"id": "foo_pool", + "tenant_id": "foo_tenant"}}]} bar_net = {"id": "bar_net", + "tenant_id": "bar_tenant", "subnets": ["bar_subnet"], - "lb_pools": [{"pool": {"id": "bar_pool"}}]} + "lb_pools": [{"pool": {"id": "bar_pool", + "tenant_id": "bar_tenant"}}]} expected_net = [bar_net, foo_net] mock_create = mock.Mock( - side_effect=lambda t, - **kw: {"pool": {"id": str(t.split("_")[0]) + "_pool"}}) + side_effect=lambda t, s, + **kw: {"pool": {"id": str(t.split("_")[0]) + "_pool", + "tenant_id": t}}) actual_net = [] mock_wrap.return_value = mock.Mock(create_v1_pool=mock_create) net_wrapper = mock_wrap(mock_clients.return_value) diff --git a/tests/unit/plugins/openstack/wrappers/test_network.py b/tests/unit/plugins/openstack/wrappers/test_network.py index 1dee0822..8cda76c4 100644 --- a/tests/unit/plugins/openstack/wrappers/test_network.py +++ b/tests/unit/plugins/openstack/wrappers/test_network.py @@ -226,16 +226,19 @@ class NeutronWrapperTestCase(test.TestCase): def test_create_v1_pool(self, mock_generate_random_name): mock_generate_random_name.return_value = "foo_name" subnet = "subnet_id" + tenant = "foo_tenant" service = self.get_wrapper() expected_pool = {"pool": { "id": "pool_id", "name": "foo_name", - "subnet_id": subnet}} + "subnet_id": subnet, + "tenant_id": tenant}} service.client.create_pool.return_value = expected_pool - resultant_pool = service.create_v1_pool(subnet) + resultant_pool = service.create_v1_pool(tenant, subnet) service.client.create_pool.assert_called_once_with({ "pool": {"lb_method": "ROUND_ROBIN", "subnet_id": subnet, + "tenant_id": tenant, "protocol": "HTTP", "name": "foo_name"}}) self.assertEqual(resultant_pool, expected_pool)