use payloads for AGENT BEFORE_DELETE callbacks
This patch switches BEFORE_DELETE callback events for AGENT resources over to the payload style args use a DBEventPayload object. In addition, the _delete_mac_associated_with_agent is now refactored into it's own method to allow the context parameter to be parsed by retry_if_session_inactive. NeutronLibImpact Change-Id: I0af951f4346f9290c2eba6aad17f772fbf27bb2f
This commit is contained in:
parent
00de8f9a9e
commit
6a24efcb70
|
@ -266,8 +266,9 @@ class AgentDbMixin(ext_agent.AgentPluginBase, AgentAvailabilityZoneMixin):
|
||||||
@db_api.retry_if_session_inactive()
|
@db_api.retry_if_session_inactive()
|
||||||
def delete_agent(self, context, id):
|
def delete_agent(self, context, id):
|
||||||
agent = self._get_agent(context, id)
|
agent = self._get_agent(context, id)
|
||||||
registry.notify(resources.AGENT, events.BEFORE_DELETE, self,
|
registry.publish(resources.AGENT, events.BEFORE_DELETE, self,
|
||||||
context=context, agent=agent)
|
payload=events.DBEventPayload(
|
||||||
|
context, states=(agent,), resource_id=id))
|
||||||
agent.delete()
|
agent.delete()
|
||||||
|
|
||||||
@db_api.retry_if_session_inactive()
|
@db_api.retry_if_session_inactive()
|
||||||
|
|
|
@ -59,10 +59,8 @@ class DVRDbMixin(ext_dvr.DVRMacAddressPluginBase):
|
||||||
return self._plugin
|
return self._plugin
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@registry.receives(resources.AGENT, [events.BEFORE_DELETE])
|
|
||||||
@db_api.retry_if_session_inactive()
|
@db_api.retry_if_session_inactive()
|
||||||
def _delete_mac_associated_with_agent(resource, event, trigger, context,
|
def _db_delete_mac_associated_with_agent(context, agent):
|
||||||
agent, **kwargs):
|
|
||||||
host = agent['host']
|
host = agent['host']
|
||||||
plugin = directory.get_plugin()
|
plugin = directory.get_plugin()
|
||||||
if [a for a in plugin.get_agents(context, filters={'host': [host]})
|
if [a for a in plugin.get_agents(context, filters={'host': [host]})
|
||||||
|
@ -78,6 +76,14 @@ class DVRDbMixin(ext_dvr.DVRMacAddressPluginBase):
|
||||||
dvr_macs = plugin.get_dvr_mac_address_list(context)
|
dvr_macs = plugin.get_dvr_mac_address_list(context)
|
||||||
plugin.notifier.dvr_mac_address_update(context, dvr_macs)
|
plugin.notifier.dvr_mac_address_update(context, dvr_macs)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@registry.receives(resources.AGENT, [events.BEFORE_DELETE])
|
||||||
|
def _delete_mac_associated_with_agent(resource, event,
|
||||||
|
trigger, payload=None):
|
||||||
|
|
||||||
|
DVRDbMixin._db_delete_mac_associated_with_agent(
|
||||||
|
payload.context, payload.latest_state)
|
||||||
|
|
||||||
@db_api.context_manager.reader
|
@db_api.context_manager.reader
|
||||||
def _get_dvr_mac_address_by_host(self, context, host):
|
def _get_dvr_mac_address_by_host(self, context, host):
|
||||||
dvr_obj = router.DVRMacAddress.get_object(context, host=host)
|
dvr_obj = router.DVRMacAddress.get_object(context, host=host)
|
||||||
|
|
|
@ -94,8 +94,9 @@ class DvrDbMixinTestCase(test_plugin.Ml2PluginV2TestCase):
|
||||||
agent2 = {'host': 'host_1', 'id': 'a2'}
|
agent2 = {'host': 'host_1', 'id': 'a2'}
|
||||||
with mock.patch.object(plugin, 'get_agents', return_value=[agent2]):
|
with mock.patch.object(plugin, 'get_agents', return_value=[agent2]):
|
||||||
with mock.patch.object(plugin, 'notifier') as notifier:
|
with mock.patch.object(plugin, 'notifier') as notifier:
|
||||||
registry.notify(resources.AGENT, events.BEFORE_DELETE, self,
|
registry.publish(resources.AGENT, events.BEFORE_DELETE, self,
|
||||||
context=self.ctx, agent=agent1)
|
payload=events.DBEventPayload(
|
||||||
|
self.ctx, states=(agent1,)))
|
||||||
mac_list = self.mixin.get_dvr_mac_address_list(self.ctx)
|
mac_list = self.mixin.get_dvr_mac_address_list(self.ctx)
|
||||||
for mac in mac_list:
|
for mac in mac_list:
|
||||||
self.assertIsInstance(mac, dict)
|
self.assertIsInstance(mac, dict)
|
||||||
|
@ -110,8 +111,9 @@ class DvrDbMixinTestCase(test_plugin.Ml2PluginV2TestCase):
|
||||||
self._create_dvr_mac_entry('host_2', mac_2)
|
self._create_dvr_mac_entry('host_2', mac_2)
|
||||||
agent = {'host': 'host_1', 'id': 'a1'}
|
agent = {'host': 'host_1', 'id': 'a1'}
|
||||||
with mock.patch.object(plugin, 'notifier') as notifier:
|
with mock.patch.object(plugin, 'notifier') as notifier:
|
||||||
registry.notify(resources.AGENT, events.BEFORE_DELETE, self,
|
registry.publish(resources.AGENT, events.BEFORE_DELETE, self,
|
||||||
context=self.ctx, agent=agent)
|
payload=events.DBEventPayload(
|
||||||
|
self.ctx, states=(agent,)))
|
||||||
mac_list = self.mixin.get_dvr_mac_address_list(self.ctx)
|
mac_list = self.mixin.get_dvr_mac_address_list(self.ctx)
|
||||||
self.assertEqual(1, len(mac_list))
|
self.assertEqual(1, len(mac_list))
|
||||||
for mac in mac_list:
|
for mac in mac_list:
|
||||||
|
|
Loading…
Reference in New Issue