Merge "Handle NoneType error from pool_create_args"

This commit is contained in:
Jenkins 2015-06-30 05:04:33 +00:00 committed by Gerrit Code Review
commit abd20df002
2 changed files with 22 additions and 7 deletions

View File

@ -32,6 +32,7 @@ class NeutronLoadbalancerV1(utils.NeutronScenario):
:param pool_create_args: dict, POST /lb/pools request options
"""
pool_create_args = pool_create_args or {}
for net in self.context.get("tenant", {}).get("networks", []):
for subnet_id in net["subnets"]:
self._create_v1_pool(subnet_id, **pool_create_args)

View File

@ -25,9 +25,10 @@ class NeutronLoadbalancerv1TestCase(test.TestCase):
"networks": [{"id": "fake_net",
"subnets": ["fake_subnet"]}]}}
def _validate_create_and_list_pools_scenario(self, pool_create_args):
def _validate_create_and_list_pools_scenario(self, pool_create_args=None):
neutron_scenario = loadbalancer_v1.NeutronLoadbalancerV1(
self._get_context())
pool_data = pool_create_args or {}
neutron_scenario._create_v1_pool = mock.Mock()
neutron_scenario._list_v1_pools = mock.Mock()
neutron_scenario.create_and_list_pools(
@ -35,10 +36,11 @@ class NeutronLoadbalancerv1TestCase(test.TestCase):
for net in self._get_context()["tenant"]["networks"]:
for subnet_id in net["subnets"]:
neutron_scenario._create_v1_pool.assert_called_once_with(
subnet_id, **pool_create_args)
subnet_id, **pool_data)
neutron_scenario._list_v1_pools.assert_called_once_with()
def _validate_create_and_delete_pools_scenario(self, pool_create_args):
def _validate_create_and_delete_pools_scenario(self,
pool_create_args=None):
neutron_scenario = loadbalancer_v1.NeutronLoadbalancerV1(
self._get_context())
pool = {
@ -46,6 +48,7 @@ class NeutronLoadbalancerv1TestCase(test.TestCase):
"id": "pool-id"
}
}
pool_data = pool_create_args or {}
neutron_scenario._create_v1_pool = mock.Mock(return_value=pool)
neutron_scenario._delete_v1_pool = mock.Mock()
neutron_scenario.create_and_delete_pools(
@ -54,12 +57,13 @@ class NeutronLoadbalancerv1TestCase(test.TestCase):
for net in self._get_context()["tenant"]["networks"]:
for subnet_id in net["subnets"]:
self.assertEqual([mock.call(subnet_id=subnet_id,
**pool_create_args)],
**pool_data)],
neutron_scenario._create_v1_pool.mock_calls)
for pool in pools:
self.assertEqual(1, neutron_scenario._delete_v1_pool.call_count)
def _validate_create_and_update_pools_scenario(self, pool_create_args):
def _validate_create_and_update_pools_scenario(self,
pool_create_args=None):
neutron_scenario = loadbalancer_v1.NeutronLoadbalancerV1(
self._get_context())
pool = {
@ -74,19 +78,20 @@ class NeutronLoadbalancerv1TestCase(test.TestCase):
"admin_state_up": True
}
}
pool_data = pool_create_args or {}
pool_update_args = {"name": "_updated", "admin_state_up": True}
neutron_scenario._create_v1_pool = mock.Mock(return_value=pool)
neutron_scenario._update_v1_pool = mock.Mock(
return_value=updated_pool)
neutron_scenario.create_and_update_pools(
pool_create_args=pool_create_args,
pool_create_args=pool_data,
pool_update_args=pool_update_args)
pools = []
for net in self._get_context()["tenant"]["networks"]:
for subnet_id in net["subnets"]:
pools.append(
neutron_scenario._create_v1_pool.assert_called_once_with(
subnet_id, **pool_create_args))
subnet_id, **pool_data))
for pool in pools:
neutron_scenario._update_v1_pool.assert_called_once_with(
neutron_scenario._create_v1_pool.return_value,
@ -95,6 +100,9 @@ class NeutronLoadbalancerv1TestCase(test.TestCase):
def test_create_and_list_pools_default(self):
self._validate_create_and_list_pools_scenario(pool_create_args={})
def test_create_and_list_pools_None(self):
self._validate_create_and_list_pools_scenario()
def test_create_and_list_pools_explicit(self):
self._validate_create_and_list_pools_scenario(
pool_create_args={"name": "given-name"})
@ -102,6 +110,9 @@ class NeutronLoadbalancerv1TestCase(test.TestCase):
def test_create_and_delete_pools_default(self):
self._validate_create_and_delete_pools_scenario(pool_create_args={})
def test_create_and_delete_pools_None(self):
self._validate_create_and_delete_pools_scenario()
def test_create_and_delete_pools_explicit(self):
self._validate_create_and_delete_pools_scenario(
pool_create_args={"name": "given-name"})
@ -109,6 +120,9 @@ class NeutronLoadbalancerv1TestCase(test.TestCase):
def test_create_and_update_pools_default(self):
self._validate_create_and_update_pools_scenario(pool_create_args={})
def test_create_and_update_pools_None(self):
self._validate_create_and_update_pools_scenario()
def test_create_and_update_pools_explicit(self):
self._validate_create_and_update_pools_scenario(
pool_create_args={"name": "given-name"})