Browse Source

Merge "Payloads for PORT: BEFORE_CREATE and PRECOMMIT_CREATE"

changes/06/794606/2
Zuul 5 days ago
committed by Gerrit Code Review
parent
commit
b4c4944373
4 changed files with 28 additions and 21 deletions
  1. +6
    -9
      neutron/db/securitygroups_db.py
  2. +15
    -8
      neutron/plugins/ml2/plugin.py
  3. +3
    -3
      neutron/services/qos/qos_plugin.py
  4. +4
    -1
      neutron/tests/unit/services/qos/test_qos_plugin.py

+ 6
- 9
neutron/db/securitygroups_db.py View File

@ -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


+ 15
- 8
neutron/plugins/ml2/plugin.py View File

@ -1415,8 +1415,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]
@ -1442,9 +1444,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)
@ -1613,9 +1617,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


+ 3
- 3
neutron/services/qos/qos_plugin.py View File

@ -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


+ 4
- 1
neutron/tests/unit/services/qos/test_qos_plugin.py View File

@ -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:


Loading…
Cancel
Save