diff --git a/neutron/db/securitygroups_db.py b/neutron/db/securitygroups_db.py index dd51624d136..1be85e5c1ef 100644 --- a/neutron/db/securitygroups_db.py +++ b/neutron/db/securitygroups_db.py @@ -888,19 +888,16 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase, if default_group: return default_group.security_group_id - @registry.receives(resources.PORT, [events.BEFORE_CREATE, - events.BEFORE_UPDATE]) + @registry.receives(resources.PORT, [events.BEFORE_UPDATE]) def _ensure_default_security_group_handler_port( self, resource, event, trigger, context, **kwargs): - if event == events.BEFORE_UPDATE: - tenant_id = kwargs['original_' + resource]['tenant_id'] - else: - tenant_id = kwargs[resource]['tenant_id'] - if tenant_id: - self._ensure_default_security_group(context, tenant_id) + project_id = kwargs['original_' + resource]['tenant_id'] + if project_id: + self._ensure_default_security_group(context, project_id) + @registry.receives(resources.PORT, [events.BEFORE_CREATE]) @registry.receives(resources.NETWORK, [events.BEFORE_CREATE]) - def _ensure_default_security_group_handler_net( + def _ensure_default_security_group_handler_before_create( self, resource, event, trigger, payload=None): # TODO(boden): refactor into single callback method diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index 76e29072269..b6718585786 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -1414,8 +1414,10 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, if not attrs.get('status'): attrs['status'] = const.PORT_STATUS_DOWN - registry.notify(resources.PORT, events.BEFORE_CREATE, self, - context=context, port=attrs) + registry.publish(resources.PORT, events.BEFORE_CREATE, self, + payload=events.DBEventPayload( + context, + states=(attrs,))) def _create_port_db(self, context, port): attrs = port[port_def.RESOURCE_NAME] @@ -1441,9 +1443,11 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, attrs.get(addr_apidef.ADDRESS_PAIRS))) self._process_port_create_extra_dhcp_opts(context, result, dhcp_opts) - kwargs = {'context': context, 'port': result} - registry.notify( - resources.PORT, events.PRECOMMIT_CREATE, self, **kwargs) + registry.publish(resources.PORT, events.PRECOMMIT_CREATE, self, + payload=events.DBEventPayload( + context, + resource_id=result['id'], + states=(result,))) self.mechanism_manager.create_port_precommit(mech_context) self._setup_dhcp_agent_provisioning_component(context, result) @@ -1610,9 +1614,12 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, self._process_port_create_extra_dhcp_opts(context, port_dict, dhcp_opts) # send PRECOMMIT_CREATE notification - kwargs = {'context': context, 'port': db_port_obj} - registry.notify( - resources.PORT, events.PRECOMMIT_CREATE, self, **kwargs) + registry.publish(resources.PORT, events.PRECOMMIT_CREATE, self, + payload=events.DBEventPayload( + context, + resource_id=db_port_obj['id'], + states=(db_port_obj,))) + self.mechanism_manager.create_port_precommit(mech_context) # handle DHCP agent provisioning diff --git a/neutron/services/qos/qos_plugin.py b/neutron/services/qos/qos_plugin.py index deeafe43b54..d000571c8f3 100644 --- a/neutron/services/qos/qos_plugin.py +++ b/neutron/services/qos/qos_plugin.py @@ -241,9 +241,9 @@ class QoSPlugin(qos.QoSPluginBase): return list(set(ports_with_policy + ports_with_net_policy)) def _validate_create_port_callback(self, resource, event, trigger, - **kwargs): - context = kwargs['context'] - port_id = kwargs['port']['id'] + payload=None): + context = payload.context + port_id = payload.resource_id port = ports_object.Port.get_object(context, id=port_id) policy_id = port.qos_policy_id or port.qos_network_policy_id diff --git a/neutron/tests/unit/services/qos/test_qos_plugin.py b/neutron/tests/unit/services/qos/test_qos_plugin.py index ccbafc6c9ea..a1f794e44ac 100644 --- a/neutron/tests/unit/services/qos/test_qos_plugin.py +++ b/neutron/tests/unit/services/qos/test_qos_plugin.py @@ -1307,7 +1307,10 @@ class TestQosPluginDB(base.BaseQosTestCase): with mock.patch.object(self.qos_plugin, 'validate_policy_for_port') \ as mock_validate_policy: self.qos_plugin._validate_create_port_callback( - 'PORT', 'precommit_create', 'test_plugin', **kwargs) + "PORT", "precommit_create", "test_plugin", + payload=events.DBEventPayload( + self.context, + resource_id=kwargs['port']['id'],)) qos_policy = None if port_qos: