self.assertEqual(ext_net['network'][l3.EXTERNAL],
True)
- def _test_notify_op_agent(self, target_func, *args):
- l3_rpc_agent_api_str = (
- 'neutron.api.rpc.agentnotifiers.l3_rpc_agent_api.L3AgentNotifyAPI')
- oldNotify = l3_rpc_agent_api.L3AgentNotify
- try:
- with mock.patch(l3_rpc_agent_api_str) as notifyApi:
- l3_rpc_agent_api.L3AgentNotify = notifyApi
- kargs = [item for item in args]
- kargs.append(notifyApi)
- target_func(*kargs)
- except Exception:
- l3_rpc_agent_api.L3AgentNotify = oldNotify
- raise
- else:
- l3_rpc_agent_api.L3AgentNotify = oldNotify
-
- def _test_router_gateway_op_agent(self, notifyApi):
+ def test_router_delete_subnet_inuse_returns_409(self):
with self.router() as r:
with self.subnet() as s:
- self._set_net_external(s['subnet']['network_id'])
- self._add_external_gateway_to_router(
- r['router']['id'],
- s['subnet']['network_id'])
- self._remove_external_gateway_from_router(
- r['router']['id'],
- s['subnet']['network_id'])
- self.assertEqual(
- 2, notifyApi.routers_updated.call_count)
-
- def test_router_gateway_op_agent(self):
- self._test_notify_op_agent(self._test_router_gateway_op_agent)
-
- def _test_interfaces_op_agent(self, r, notifyApi):
- with self.port(no_delete=True) as p:
- self._router_interface_action('add',
- r['router']['id'],
- None,
- p['port']['id'])
- # clean-up
- self._router_interface_action('remove',
- r['router']['id'],
- None,
- p['port']['id'])
- self.assertEqual(2, notifyApi.routers_updated.call_count)
+ self._router_interface_action('add',
+ r['router']['id'],
+ s['subnet']['id'],
+ None)
+ # subnet cannot be delete as it's attached to a router
+ self._delete('subnets', s['subnet']['id'],
+ expected_code=exc.HTTPConflict.code)
+ # remove interface so test can exit without errors
+ self._router_interface_action('remove',
+ r['router']['id'],
+ s['subnet']['id'],
+ None)
- def test_interfaces_op_agent(self):
- with self.router() as r:
- self._test_notify_op_agent(
- self._test_interfaces_op_agent, r)
- def _test_floatingips_op_agent(self, notifyApi):
- with self.floatingip_with_assoc():
- pass
- # add gateway, add interface, associate, deletion of floatingip,
- # delete gateway, delete interface
- self.assertEqual(6, notifyApi.routers_updated.call_count)
+class L3AgentDbTestCase(L3NatTestCaseBase):
+ """Unit tests for methods called by the L3 agent."""
- def test_floatingips_op_agent(self):
- self._test_notify_op_agent(self._test_floatingips_op_agent)
+ def setUp(self):
+ self.plugin = TestL3NatPlugin()
+ super(L3AgentDbTestCase, self).setUp()
def test_l3_agent_routers_query_interfaces(self):
with self.router() as r:
None,
p['port']['id'])
- plugin = TestL3NatPlugin()
- routers = plugin.get_sync_data(context.get_admin_context(),
- None)
+ routers = self.plugin.get_sync_data(
+ context.get_admin_context(), None)
self.assertEqual(1, len(routers))
interfaces = routers[0][l3_constants.INTERFACE_KEY]
self.assertEqual(1, len(interfaces))
'subnet_id': subnet['subnet']['id']},
{'ip_address': '9.0.1.5',
'subnet_id': subnet['subnet']['id']}]}}
- plugin = TestL3NatPlugin()
ctx = context.get_admin_context()
- plugin.update_port(ctx, p['port']['id'], port)
- routers = plugin.get_sync_data(ctx, None)
+ self.plugin.update_port(ctx, p['port']['id'], port)
+ routers = self.plugin.get_sync_data(ctx, None)
self.assertEqual(1, len(routers))
interfaces = routers[0].get(l3_constants.INTERFACE_KEY, [])
self.assertEqual(1, len(interfaces))
self._add_external_gateway_to_router(
r['router']['id'],
s['subnet']['network_id'])
- plugin = TestL3NatPlugin()
- routers = plugin.get_sync_data(context.get_admin_context(),
- [r['router']['id']])
+ routers = self.plugin.get_sync_data(
+ context.get_admin_context(), [r['router']['id']])
self.assertEqual(1, len(routers))
gw_port = routers[0]['gw_port']
self.assertEqual(s['subnet']['id'], gw_port['subnet']['id'])
def test_l3_agent_routers_query_floatingips(self):
with self.floatingip_with_assoc() as fip:
- plugin = TestL3NatPlugin()
- routers = plugin.get_sync_data(context.get_admin_context(),
- [fip['floatingip']['router_id']])
+ routers = self.plugin.get_sync_data(
+ context.get_admin_context(), [fip['floatingip']['router_id']])
self.assertEqual(1, len(routers))
floatingips = routers[0][l3_constants.FLOATINGIP_KEY]
self.assertEqual(1, len(floatingips))
self.assertTrue(floatingips[0]['fixed_ip_address'] is not None)
self.assertTrue(floatingips[0]['router_id'] is not None)
- def test_router_delete_subnet_inuse_returns_409(self):
+ def _test_notify_op_agent(self, target_func, *args):
+ l3_rpc_agent_api_str = (
+ 'neutron.api.rpc.agentnotifiers.l3_rpc_agent_api.L3AgentNotifyAPI')
+ oldNotify = l3_rpc_agent_api.L3AgentNotify
+ try:
+ with mock.patch(l3_rpc_agent_api_str) as notifyApi:
+ l3_rpc_agent_api.L3AgentNotify = notifyApi
+ kargs = [item for item in args]
+ kargs.append(notifyApi)
+ target_func(*kargs)
+ except Exception:
+ l3_rpc_agent_api.L3AgentNotify = oldNotify
+ raise
+ else:
+ l3_rpc_agent_api.L3AgentNotify = oldNotify
+
+ def _test_router_gateway_op_agent(self, notifyApi):
with self.router() as r:
with self.subnet() as s:
- self._router_interface_action('add',
- r['router']['id'],
- s['subnet']['id'],
- None)
- # subnet cannot be delete as it's attached to a router
- self._delete('subnets', s['subnet']['id'],
- expected_code=exc.HTTPConflict.code)
- # remove interface so test can exit without errors
- self._router_interface_action('remove',
- r['router']['id'],
- s['subnet']['id'],
- None)
+ self._set_net_external(s['subnet']['network_id'])
+ self._add_external_gateway_to_router(
+ r['router']['id'],
+ s['subnet']['network_id'])
+ self._remove_external_gateway_from_router(
+ r['router']['id'],
+ s['subnet']['network_id'])
+ self.assertEqual(
+ 2, notifyApi.routers_updated.call_count)
+
+ def test_router_gateway_op_agent(self):
+ self._test_notify_op_agent(self._test_router_gateway_op_agent)
+
+ def _test_interfaces_op_agent(self, r, notifyApi):
+ with self.port(no_delete=True) as p:
+ self._router_interface_action('add',
+ r['router']['id'],
+ None,
+ p['port']['id'])
+ # clean-up
+ self._router_interface_action('remove',
+ r['router']['id'],
+ None,
+ p['port']['id'])
+ self.assertEqual(2, notifyApi.routers_updated.call_count)
+
+ def test_interfaces_op_agent(self):
+ with self.router() as r:
+ self._test_notify_op_agent(
+ self._test_interfaces_op_agent, r)
+
+ def _test_floatingips_op_agent(self, notifyApi):
+ with self.floatingip_with_assoc():
+ pass
+ # add gateway, add interface, associate, deletion of floatingip,
+ # delete gateway, delete interface
+ self.assertEqual(6, notifyApi.routers_updated.call_count)
+
+ def test_floatingips_op_agent(self):
+ self._test_notify_op_agent(self._test_floatingips_op_agent)
class L3NatDBTestCaseXML(L3NatDBTestCase):