Merge "Create pool in lbaas context with correct tenant_id"

This commit is contained in:
Jenkins
2015-08-24 18:24:52 +00:00
committed by Gerrit Code Review
4 changed files with 20 additions and 7 deletions

View File

@@ -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:

View File

@@ -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),

View File

@@ -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)

View File

@@ -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)