Switch external network create event to precommit

This addresses a TODO to convert the notification event to
PRECOMMIT_CREATE instead of BEFORE_CREATE and AFTER_CREATE since
both of these are occuring in a transaction which violates the AFTER
semantics.

Change-Id: Idba21275ade85a1a4afadee00de9ccbaec49b2f9
This commit is contained in:
Kevin Benton 2017-02-07 00:55:51 -08:00
parent 49b269adc6
commit 5dabde032f
2 changed files with 9 additions and 18 deletions

View File

@ -103,27 +103,20 @@ class External_net_db_mixin(object):
if not external_set:
return
# TODO(armax): these notifications should switch to *_COMMIT
# when the event becomes available, as this block is expected
# to be called within a plugin's session
if external:
try:
registry.notify(
resources.EXTERNAL_NETWORK, events.BEFORE_CREATE,
self, context=context,
request=req_data, network=net_data)
except c_exc.CallbackFailure as e:
# raise the underlying exception
raise e.errors[0].error
context.session.add(
ext_net_models.ExternalNetwork(network_id=net_data['id']))
context.session.add(rbac_db.NetworkRBAC(
object_id=net_data['id'], action='access_as_external',
target_tenant='*', tenant_id=net_data['tenant_id']))
registry.notify(
resources.EXTERNAL_NETWORK, events.AFTER_CREATE,
self, context=context,
request=req_data, network=net_data)
try:
registry.notify(
resources.EXTERNAL_NETWORK, events.PRECOMMIT_CREATE,
self, context=context,
request=req_data, network=net_data)
except c_exc.CallbackFailure as e:
# raise the underlying exception
raise e.errors[0].error
net_data[external_net.EXTERNAL] = external
def _process_l3_update(self, context, net_data, req_data, allow_all=True):

View File

@ -81,9 +81,7 @@ class AutoAllocatedTopologyMixin(common_db_mixin.CommonDbMixin):
new = super(AutoAllocatedTopologyMixin, cls).__new__(cls, *args,
**kwargs)
registry.subscribe(_ensure_external_network_default_value_callback,
resources.EXTERNAL_NETWORK, events.BEFORE_CREATE)
registry.subscribe(_ensure_external_network_default_value_callback,
resources.EXTERNAL_NETWORK, events.AFTER_CREATE)
resources.EXTERNAL_NETWORK, events.PRECOMMIT_CREATE)
registry.subscribe(_ensure_external_network_default_value_callback,
resources.EXTERNAL_NETWORK, events.BEFORE_UPDATE)
return new