use callback payloads for PROVISIONING_COMPLETE
This patch switches over to callback payloads for PROVISIONING_COMPLETE events. NeutronLibImpact Change-Id: I769a5a59926cc42dcf0cdda5964bd42c8a864a34
This commit is contained in:
@ -13,6 +13,7 @@
|
||||
# under the License.
|
||||
#
|
||||
|
||||
from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
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):
|
||||
LOG.debug("Provisioning complete for %(otype)s %(oid)s triggered by "
|
||||
"entity %(entity)s.", log_dict)
|
||||
registry.notify(object_type, PROVISIONING_COMPLETE,
|
||||
'neutron.db.provisioning_blocks',
|
||||
context=context, object_id=object_id)
|
||||
registry.publish(object_type, PROVISIONING_COMPLETE,
|
||||
'neutron.db.provisioning_blocks',
|
||||
payload=events.DBEventPayload(
|
||||
context, resource_id=object_id))
|
||||
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
|
@ -284,10 +284,9 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
|
||||
@registry.receives(resources.PORT,
|
||||
[provisioning_blocks.PROVISIONING_COMPLETE])
|
||||
def _port_provisioned(self, rtype, event, trigger, context, object_id,
|
||||
**kwargs):
|
||||
port_id = object_id
|
||||
port = db.get_port(context, port_id)
|
||||
def _port_provisioned(self, rtype, event, trigger, payload=None):
|
||||
port_id = payload.resource_id
|
||||
port = db.get_port(payload.context, port_id)
|
||||
port_binding = p_utils.get_port_binding_by_status_and_host(
|
||||
getattr(port, 'port_bindings', []), const.ACTIVE)
|
||||
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
|
||||
# unbound port and the port became bound with new provisioning
|
||||
# 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):
|
||||
LOG.debug("Port %s had new provisioning blocks added so it "
|
||||
"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 "
|
||||
"not transition to active.", port_id)
|
||||
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
|
||||
def _start_rpc_notifiers(self):
|
||||
|
@ -91,7 +91,11 @@ class TestStatusBarriers(testlib_api.SqlTestCase):
|
||||
resources.PORT, 'entity1')
|
||||
self.provisioned.assert_called_once_with(
|
||||
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):
|
||||
pb.add_provisioning_component(self.ctx, self.port.id, resources.PORT,
|
||||
|
@ -974,8 +974,10 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase):
|
||||
mock.patch('neutron.plugins.ml2.plugin.db.get_port').start()
|
||||
provisioning_blocks.add_provisioning_component(
|
||||
self.context, port['port']['id'], 'port', 'DHCP')
|
||||
plugin._port_provisioned('port', 'evt', 'trigger',
|
||||
self.context, port['port']['id'])
|
||||
plugin._port_provisioned(
|
||||
'port', 'evt', 'trigger',
|
||||
payload=events.DBEventPayload(
|
||||
context, resource_id=port['port']['id']))
|
||||
self.assertFalse(ups.called)
|
||||
|
||||
def test__port_provisioned_no_binding(self):
|
||||
@ -990,8 +992,9 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase):
|
||||
admin_state_up=True, status='ACTIVE',
|
||||
device_id=device_id,
|
||||
device_owner=DEVICE_OWNER_COMPUTE).create()
|
||||
self.assertIsNone(plugin._port_provisioned('port', 'evt', 'trigger',
|
||||
self.context, port_id))
|
||||
self.assertIsNone(plugin._port_provisioned(
|
||||
'port', 'evt', 'trigger', payload=events.DBEventPayload(
|
||||
self.context, resource_id=port_id)))
|
||||
|
||||
def test__port_provisioned_port_admin_state_down(self):
|
||||
plugin = directory.get_plugin()
|
||||
@ -1008,7 +1011,8 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase):
|
||||
with mock.patch('neutron.plugins.ml2.plugin.db.get_port',
|
||||
return_value=port):
|
||||
plugin._port_provisioned('port', 'evt', 'trigger',
|
||||
self.context, port_id)
|
||||
payload=events.DBEventPayload(
|
||||
self.context, resource_id=port_id))
|
||||
self.assertFalse(ups.called)
|
||||
|
||||
def test_port_after_create_outside_transaction(self):
|
||||
|
Reference in New Issue
Block a user