Merge "use callback payloads for PROVISIONING_COMPLETE"

This commit is contained in:
Zuul
2019-08-01 21:32:15 +00:00
committed by Gerrit Code Review
4 changed files with 25 additions and 15 deletions

View File

@@ -13,6 +13,7 @@
# under the License. # under the License.
# #
from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources from neutron_lib.callbacks import resources
from neutron_lib.db import api as db_api from neutron_lib.db import api as db_api
@@ -137,9 +138,10 @@ def provisioning_complete(context, object_id, object_type, entity):
context, standard_attr_id=standard_attr_id): context, standard_attr_id=standard_attr_id):
LOG.debug("Provisioning complete for %(otype)s %(oid)s triggered by " LOG.debug("Provisioning complete for %(otype)s %(oid)s triggered by "
"entity %(entity)s.", log_dict) "entity %(entity)s.", log_dict)
registry.notify(object_type, PROVISIONING_COMPLETE, registry.publish(object_type, PROVISIONING_COMPLETE,
'neutron.db.provisioning_blocks', 'neutron.db.provisioning_blocks',
context=context, object_id=object_id) payload=events.DBEventPayload(
context, resource_id=object_id))
@db_api.retry_if_session_inactive() @db_api.retry_if_session_inactive()

View File

@@ -284,10 +284,9 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
@registry.receives(resources.PORT, @registry.receives(resources.PORT,
[provisioning_blocks.PROVISIONING_COMPLETE]) [provisioning_blocks.PROVISIONING_COMPLETE])
def _port_provisioned(self, rtype, event, trigger, context, object_id, def _port_provisioned(self, rtype, event, trigger, payload=None):
**kwargs): port_id = payload.resource_id
port_id = object_id port = db.get_port(payload.context, port_id)
port = db.get_port(context, port_id)
port_binding = p_utils.get_port_binding_by_status_and_host( port_binding = p_utils.get_port_binding_by_status_and_host(
getattr(port, 'port_bindings', []), const.ACTIVE) getattr(port, 'port_bindings', []), const.ACTIVE)
if not port or not port_binding: if not port or not port_binding:
@@ -306,7 +305,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
# one last time to detect the case where we were triggered by an # one last time to detect the case where we were triggered by an
# unbound port and the port became bound with new provisioning # unbound port and the port became bound with new provisioning
# blocks before 'get_port' was called above # blocks before 'get_port' was called above
if provisioning_blocks.is_object_blocked(context, port_id, if provisioning_blocks.is_object_blocked(payload.context, port_id,
resources.PORT): resources.PORT):
LOG.debug("Port %s had new provisioning blocks added so it " LOG.debug("Port %s had new provisioning blocks added so it "
"will not transition to active.", port_id) "will not transition to active.", port_id)
@@ -315,7 +314,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
LOG.debug("Port %s is administratively disabled so it will " LOG.debug("Port %s is administratively disabled so it will "
"not transition to active.", port_id) "not transition to active.", port_id)
return return
self.update_port_status(context, port_id, const.PORT_STATUS_ACTIVE) self.update_port_status(
payload.context, port_id, const.PORT_STATUS_ACTIVE)
@log_helpers.log_method_call @log_helpers.log_method_call
def _start_rpc_notifiers(self): def _start_rpc_notifiers(self):

View File

@@ -91,7 +91,11 @@ class TestStatusBarriers(testlib_api.SqlTestCase):
resources.PORT, 'entity1') resources.PORT, 'entity1')
self.provisioned.assert_called_once_with( self.provisioned.assert_called_once_with(
resources.PORT, pb.PROVISIONING_COMPLETE, mock.ANY, resources.PORT, pb.PROVISIONING_COMPLETE, mock.ANY,
context=self.ctx, object_id=port2.id) payload=mock.ANY)
payload = self.provisioned.mock_calls[0][2]['payload']
self.assertEqual(self.ctx, payload.context)
self.assertEqual(port2.id, payload.resource_id)
def test_not_provisioned_when_wrong_component_reports(self): def test_not_provisioned_when_wrong_component_reports(self):
pb.add_provisioning_component(self.ctx, self.port.id, resources.PORT, pb.add_provisioning_component(self.ctx, self.port.id, resources.PORT,

View File

@@ -974,8 +974,10 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase):
mock.patch('neutron.plugins.ml2.plugin.db.get_port').start() mock.patch('neutron.plugins.ml2.plugin.db.get_port').start()
provisioning_blocks.add_provisioning_component( provisioning_blocks.add_provisioning_component(
self.context, port['port']['id'], 'port', 'DHCP') self.context, port['port']['id'], 'port', 'DHCP')
plugin._port_provisioned('port', 'evt', 'trigger', plugin._port_provisioned(
self.context, port['port']['id']) 'port', 'evt', 'trigger',
payload=events.DBEventPayload(
context, resource_id=port['port']['id']))
self.assertFalse(ups.called) self.assertFalse(ups.called)
def test__port_provisioned_no_binding(self): def test__port_provisioned_no_binding(self):
@@ -990,8 +992,9 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase):
admin_state_up=True, status='ACTIVE', admin_state_up=True, status='ACTIVE',
device_id=device_id, device_id=device_id,
device_owner=DEVICE_OWNER_COMPUTE).create() device_owner=DEVICE_OWNER_COMPUTE).create()
self.assertIsNone(plugin._port_provisioned('port', 'evt', 'trigger', self.assertIsNone(plugin._port_provisioned(
self.context, port_id)) 'port', 'evt', 'trigger', payload=events.DBEventPayload(
self.context, resource_id=port_id)))
def test__port_provisioned_port_admin_state_down(self): def test__port_provisioned_port_admin_state_down(self):
plugin = directory.get_plugin() plugin = directory.get_plugin()
@@ -1008,7 +1011,8 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase):
with mock.patch('neutron.plugins.ml2.plugin.db.get_port', with mock.patch('neutron.plugins.ml2.plugin.db.get_port',
return_value=port): return_value=port):
plugin._port_provisioned('port', 'evt', 'trigger', plugin._port_provisioned('port', 'evt', 'trigger',
self.context, port_id) payload=events.DBEventPayload(
self.context, resource_id=port_id))
self.assertFalse(ups.called) self.assertFalse(ups.called)
def test_port_after_create_outside_transaction(self): def test_port_after_create_outside_transaction(self):