Use publish for AGENT AFTER_CREATE/AFTER_UPDATE
This patch switches callbacks over to the payload object style events for AGENT AFTER_CREATE and AFTER_UPDATE based notifications. To do so a DBEventPayload object is used with the publish() method to pass along the API related data. Change-Id: Ibefa495be41c91957c2e8d797130e569bccc3765
This commit is contained in:
parent
77a8b020c3
commit
6d99fb19ab
@ -13,6 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
import datetime
|
||||
|
||||
from eventlet import greenthread
|
||||
@ -390,6 +391,7 @@ class AgentDbMixin(ext_agent.AgentPluginBase, AgentAvailabilityZoneMixin):
|
||||
try:
|
||||
agent = self._get_agent_by_type_and_host(
|
||||
context, agent_state['agent_type'], agent_state['host'])
|
||||
agent_state_orig = copy.deepcopy(agent_state)
|
||||
if not agent.is_active:
|
||||
status = agent_consts.AGENT_REVIVED
|
||||
if 'resource_versions' not in agent_state:
|
||||
@ -408,6 +410,7 @@ class AgentDbMixin(ext_agent.AgentPluginBase, AgentAvailabilityZoneMixin):
|
||||
agent.update()
|
||||
event_type = events.AFTER_UPDATE
|
||||
except agent_exc.AgentNotFoundByTypeHost:
|
||||
agent_state_orig = None
|
||||
greenthread.sleep(0)
|
||||
res['created_at'] = current_time
|
||||
res['started_at'] = current_time
|
||||
@ -423,9 +426,17 @@ class AgentDbMixin(ext_agent.AgentPluginBase, AgentAvailabilityZoneMixin):
|
||||
|
||||
agent_state['agent_status'] = status
|
||||
agent_state['admin_state_up'] = agent.admin_state_up
|
||||
registry.notify(resources.AGENT, event_type, self, context=context,
|
||||
host=agent_state['host'], plugin=self,
|
||||
agent=agent_state, status=status)
|
||||
registry.publish(resources.AGENT, event_type, self,
|
||||
payload=events.DBEventPayload(
|
||||
context=context, metadata={
|
||||
'host': agent_state['host'],
|
||||
'plugin': self,
|
||||
'status': status
|
||||
},
|
||||
states=(agent_state_orig, ),
|
||||
desired_state=agent_state,
|
||||
resource_id=agent.id
|
||||
))
|
||||
return status, agent_state
|
||||
|
||||
def _get_agents_considered_for_versions(self):
|
||||
|
@ -341,10 +341,10 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
|
||||
@registry.receives(resources.AGENT, [events.AFTER_UPDATE])
|
||||
def _retry_binding_revived_agents(self, resource, event, trigger,
|
||||
**kwargs):
|
||||
context = kwargs['context']
|
||||
host = kwargs['host']
|
||||
agent = kwargs.get('agent', {})
|
||||
payload=None):
|
||||
context = payload.context
|
||||
host = payload.metadata.get('host')
|
||||
agent = payload.desired_state
|
||||
agent_status = agent.get('agent_status')
|
||||
|
||||
agent_type = agent.get('agent_type')
|
||||
|
@ -255,8 +255,12 @@ def map_segment_to_hosts(context, segment_id, hosts):
|
||||
|
||||
|
||||
def _update_segment_host_mapping_for_agent(resource, event, trigger,
|
||||
context, host, plugin, agent,
|
||||
status):
|
||||
payload=None):
|
||||
plugin = payload.metadata.get('plugin')
|
||||
agent = payload.desired_state
|
||||
host = payload.metadata.get('host')
|
||||
context = payload.context
|
||||
|
||||
check_segment_for_agent = getattr(plugin, 'check_segment_for_agent', None)
|
||||
if not check_segment_for_agent:
|
||||
return
|
||||
|
@ -24,6 +24,7 @@ from neutron_lib import exceptions as n_exc
|
||||
from oslo_config import cfg
|
||||
from oslo_db import exception as exc
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
import testscenarios
|
||||
|
||||
from neutron.db import agents_db
|
||||
@ -160,11 +161,16 @@ class TestAgentsDbMixin(TestAgentsDbBase):
|
||||
'neutron.objects.base.NeutronDbObject.modify_fields_from_db'
|
||||
).start()
|
||||
|
||||
counter = {'value': 0}
|
||||
|
||||
def create_obj_side_effect(obj_cls, context, values, populate_id=True):
|
||||
if counter['value'] < 1:
|
||||
counter['value'] += 1
|
||||
raise exc.DBDuplicateEntry()
|
||||
obj_cls.id = uuidutils.generate_uuid()
|
||||
|
||||
with mock.patch('neutron.objects.db.api.create_object') as add_mock:
|
||||
add_mock.side_effect = [
|
||||
exc.DBDuplicateEntry(),
|
||||
mock.Mock()
|
||||
]
|
||||
add_mock.side_effect = create_obj_side_effect
|
||||
self.plugin.create_or_update_agent(self.context, self.agent_status)
|
||||
|
||||
self.assertEqual(add_mock.call_count, 2,
|
||||
|
@ -746,7 +746,11 @@ class TestMl2RevivedAgentsBindPorts(Ml2PluginV2TestCase):
|
||||
|
||||
plugin._retry_binding_revived_agents(
|
||||
resources.AGENT, event, plugin,
|
||||
**{'context': context, 'host': host, 'agent': agent})
|
||||
events.DBEventPayload(
|
||||
context=context, metadata={'host': host}, states=(agent,),
|
||||
desired_state=agent
|
||||
)
|
||||
)
|
||||
|
||||
if (agent_status == agent_consts.AGENT_ALIVE or
|
||||
not admin_state_up or
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
other:
|
||||
- |
|
||||
Use ``publish`` for ``AGENT's`` ``AFTER_CREATE`` and ``AFTER_UPDATE`` events
|
||||
with ``DBEventPayload`` instead of the deprecated notify callback.
|
Loading…
Reference in New Issue
Block a user