Merge "use callback payloads for ROUTER_CONTROLLER events"
This commit is contained in:
commit
6945fc9f30
@ -88,11 +88,12 @@ class DriverController(object):
|
||||
drv = self._get_provider_for_create(context, router)
|
||||
self._stm.add_resource_association(context, plugin_constants.L3,
|
||||
drv.name, router['id'])
|
||||
registry.notify(
|
||||
registry.publish(
|
||||
resources.ROUTER_CONTROLLER, events.PRECOMMIT_ADD_ASSOCIATION,
|
||||
trigger, context=context, router=router,
|
||||
router_db=router_db, old_driver=None,
|
||||
new_driver=drv, **kwargs)
|
||||
trigger, payload=events.DBEventPayload(
|
||||
context, request_body=router, states=(router_db,),
|
||||
metadata={'old_driver': None, 'new_driver': drv},
|
||||
resource_id=router_db.get('id')))
|
||||
|
||||
@registry.receives(resources.ROUTER, [events.PRECOMMIT_DELETE],
|
||||
priority_group.PRIORITY_ROUTER_CONTROLLER)
|
||||
@ -100,10 +101,13 @@ class DriverController(object):
|
||||
router_id, **kwargs):
|
||||
"""Remove the association between a router and a service provider."""
|
||||
drv = self.get_provider_for_router(context, router_id)
|
||||
registry.notify(
|
||||
registry.publish(
|
||||
resources.ROUTER_CONTROLLER, events.PRECOMMIT_DELETE_ASSOCIATIONS,
|
||||
trigger, context=context, router_id=router_id,
|
||||
old_driver=drv, new_driver=None, **kwargs)
|
||||
trigger, payload=events.DBEventPayload(
|
||||
context,
|
||||
metadata={'old_driver': drv, 'new_driver': None},
|
||||
resource_id=router_id))
|
||||
|
||||
self._stm.del_resource_associations(context, [router_id])
|
||||
|
||||
@registry.receives(resources.ROUTER, [events.PRECOMMIT_UPDATE],
|
||||
@ -190,11 +194,13 @@ class DriverController(object):
|
||||
self._stm.add_resource_association(
|
||||
context, plugin_constants.L3,
|
||||
driver_name, router_id)
|
||||
registry.notify(
|
||||
registry.publish(
|
||||
resources.ROUTER_CONTROLLER,
|
||||
events.PRECOMMIT_ADD_ASSOCIATION,
|
||||
self, context=context, router_id=router_id,
|
||||
router=router, old_driver=None, new_driver=driver)
|
||||
self, payload=events.DBEventPayload(
|
||||
context, states=(router,),
|
||||
metadata={'old_driver': None, 'new_driver': driver},
|
||||
resource_id=router_id))
|
||||
return self.drivers[driver_name]
|
||||
|
||||
def _get_provider_for_create(self, context, router):
|
||||
|
@ -15,6 +15,7 @@
|
||||
import mock
|
||||
from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib import constants
|
||||
from neutron_lib import context
|
||||
from neutron_lib import exceptions as lib_exc
|
||||
@ -75,7 +76,7 @@ class TestDriverController(testlib_api.SqlTestCase):
|
||||
self.assertFalse(self.dc.drivers['dvr'].owns_router(self.ctx, r2))
|
||||
self.assertFalse(self.dc.drivers['dvr'].owns_router(self.ctx, None))
|
||||
|
||||
@mock.patch('neutron_lib.callbacks.registry.notify')
|
||||
@mock.patch('neutron_lib.callbacks.registry.publish')
|
||||
def test__set_router_provider_flavor_specified(self, mock_cb):
|
||||
self._return_provider_for_flavor('dvrha')
|
||||
router_db = mock.Mock()
|
||||
@ -84,10 +85,12 @@ class TestDriverController(testlib_api.SqlTestCase):
|
||||
router = dict(id=router_id, flavor_id=flavor_id)
|
||||
self.dc._set_router_provider('router', 'PRECOMMIT_CREATE', self,
|
||||
self.ctx, router, router_db)
|
||||
mock_cb.assert_called_with('router_controller',
|
||||
mock_cb.assert_called_with(resources.ROUTER_CONTROLLER,
|
||||
events.PRECOMMIT_ADD_ASSOCIATION, mock.ANY,
|
||||
context=self.ctx, router=mock.ANY, router_db=mock.ANY,
|
||||
old_driver=mock.ANY, new_driver=mock.ANY)
|
||||
payload=mock.ANY)
|
||||
payload = mock_cb.mock_calls[0][2]['payload']
|
||||
self.assertEqual(router, payload.request_body)
|
||||
self.assertEqual(router_db, payload.latest_state)
|
||||
self.assertEqual(flavor_id, router_db.flavor_id)
|
||||
self.assertEqual(self.dc.drivers['dvrha'],
|
||||
self.dc.get_provider_for_router(self.ctx,
|
||||
@ -141,7 +144,7 @@ class TestDriverController(testlib_api.SqlTestCase):
|
||||
"%(distributed_flag)s",
|
||||
{'ha_flag': False, 'distributed_flag': False})
|
||||
|
||||
@mock.patch('neutron_lib.callbacks.registry.notify')
|
||||
@mock.patch('neutron_lib.callbacks.registry.publish')
|
||||
def test__set_router_provider_attr_lookups(self, mock_cb):
|
||||
# ensure correct drivers are looked up based on attrs
|
||||
router_id1 = uuidutils.generate_uuid()
|
||||
@ -174,43 +177,45 @@ class TestDriverController(testlib_api.SqlTestCase):
|
||||
for driver, body in cases:
|
||||
self.dc._set_router_provider('router', 'PRECOMMIT_CREATE', self,
|
||||
self.ctx, body, mock.Mock())
|
||||
mock_cb.assert_called_with('router_controller',
|
||||
mock_cb.assert_called_with(
|
||||
resources.ROUTER_CONTROLLER,
|
||||
events.PRECOMMIT_ADD_ASSOCIATION, mock.ANY,
|
||||
context=self.ctx, router=mock.ANY, router_db=mock.ANY,
|
||||
old_driver=mock.ANY, new_driver=mock.ANY)
|
||||
payload=mock.ANY)
|
||||
self.assertEqual(self.dc.drivers[driver],
|
||||
self.dc.get_provider_for_router(self.ctx,
|
||||
body['id']),
|
||||
'Expecting %s for body %s' % (driver, body))
|
||||
|
||||
@mock.patch('neutron_lib.callbacks.registry.notify')
|
||||
@mock.patch('neutron_lib.callbacks.registry.publish')
|
||||
def test__clear_router_provider(self, mock_cb):
|
||||
# ensure correct drivers are looked up based on attrs
|
||||
router_id1 = uuidutils.generate_uuid()
|
||||
body = dict(id=router_id1, distributed=True, ha=True)
|
||||
self.dc._set_router_provider('router', 'PRECOMMIT_CREATE', self,
|
||||
self.ctx, body, mock.Mock())
|
||||
mock_cb.assert_called_with('router_controller',
|
||||
mock_cb.assert_called_with(resources.ROUTER_CONTROLLER,
|
||||
events.PRECOMMIT_ADD_ASSOCIATION, mock.ANY,
|
||||
context=self.ctx, router=mock.ANY, router_db=mock.ANY,
|
||||
old_driver=mock.ANY, new_driver=mock.ANY)
|
||||
payload=mock.ANY)
|
||||
payload = mock_cb.mock_calls[0][2]['payload']
|
||||
self.assertEqual(self.ctx, payload.context)
|
||||
self.assertIn('old_driver', payload.metadata)
|
||||
self.assertIn('new_driver', payload.metadata)
|
||||
self.assertIsNotNone(payload.latest_state)
|
||||
self.assertEqual(self.dc.drivers['dvrha'],
|
||||
self.dc.get_provider_for_router(self.ctx,
|
||||
body['id']))
|
||||
self.dc._clear_router_provider('router', 'PRECOMMIT_DELETE', self,
|
||||
self.ctx, body['id'])
|
||||
mock_cb.assert_called_with('router_controller',
|
||||
mock_cb.assert_called_with(resources.ROUTER_CONTROLLER,
|
||||
events.PRECOMMIT_DELETE_ASSOCIATIONS, mock.ANY,
|
||||
context=self.ctx, router_id=mock.ANY, old_driver=mock.ANY,
|
||||
new_driver=mock.ANY)
|
||||
payload=mock.ANY)
|
||||
with testtools.ExpectedException(ValueError):
|
||||
# if association was cleared, get_router will be called
|
||||
self.fake_l3.get_router.side_effect = ValueError
|
||||
self.dc.get_provider_for_router(self.ctx, body['id'])
|
||||
mock_cb.assert_called_with('router_controller',
|
||||
events.PRECOMMIT_ADD_ASSOCIATION, mock.ANY, context=self.ctx,
|
||||
router_id=body['id'], router=mock.ANY, old_driver=mock.ANY,
|
||||
new_driver=mock.ANY)
|
||||
mock_cb.assert_called_with(resources.ROUTER_CONTROLLER,
|
||||
events.PRECOMMIT_ADD_ASSOCIATION,
|
||||
mock.ANY, payload=mock.ANY)
|
||||
|
||||
def test__flavor_plugin(self):
|
||||
directory.add_plugin(p_cons.FLAVORS, mock.Mock())
|
||||
|
Loading…
Reference in New Issue
Block a user