Remove shim in securitygroups_db
SECURITY_GROUP and SECURITY_GROUP_RULE resources now is using payload style callback. Shim can be removed Change-Id: Icd8e61100b5e2db24a737e852441548eca8f8424
This commit is contained in:
parent
dea5a9d3e3
commit
9ee5722c04
@ -63,16 +63,13 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase,
|
|||||||
return self._create_bulk('security_group', context,
|
return self._create_bulk('security_group', context,
|
||||||
security_groups)
|
security_groups)
|
||||||
|
|
||||||
def _registry_notify(self, res, event, id=None, exc_cls=None, **kwargs):
|
def _registry_publish(self, res, event, id=None, exc_cls=None,
|
||||||
|
payload=None):
|
||||||
# NOTE(armax): a callback exception here will prevent the request
|
# NOTE(armax): a callback exception here will prevent the request
|
||||||
# from being processed. This is a hook point for backend's validation;
|
# from being processed. This is a hook point for backend's validation;
|
||||||
# we raise to propagate the reason for the failure.
|
# we raise to propagate the reason for the failure.
|
||||||
try:
|
try:
|
||||||
if 'payload' in kwargs:
|
registry.publish(res, event, self, payload=payload)
|
||||||
# TODO(boden): remove shim once all callbacks use payloads
|
|
||||||
registry.publish(res, event, self, payload=kwargs['payload'])
|
|
||||||
else:
|
|
||||||
registry.notify(res, event, self, **kwargs)
|
|
||||||
except exceptions.CallbackFailure as e:
|
except exceptions.CallbackFailure as e:
|
||||||
if exc_cls:
|
if exc_cls:
|
||||||
reason = (_('cannot perform %(event)s due to %(reason)s') %
|
reason = (_('cannot perform %(event)s due to %(reason)s') %
|
||||||
@ -87,12 +84,13 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase,
|
|||||||
a given tenant if it does not exist.
|
a given tenant if it does not exist.
|
||||||
"""
|
"""
|
||||||
s = security_group['security_group']
|
s = security_group['security_group']
|
||||||
self._registry_notify(resources.SECURITY_GROUP, events.BEFORE_CREATE,
|
self._registry_publish(resources.SECURITY_GROUP, events.BEFORE_CREATE,
|
||||||
exc_cls=ext_sg.SecurityGroupConflict,
|
exc_cls=ext_sg.SecurityGroupConflict,
|
||||||
payload=events.DBEventPayload(
|
payload=events.DBEventPayload(
|
||||||
context, metadata={'is_default': default_sg},
|
context,
|
||||||
request_body=security_group,
|
metadata={'is_default': default_sg},
|
||||||
desired_state=s))
|
request_body=security_group,
|
||||||
|
desired_state=s))
|
||||||
|
|
||||||
tenant_id = s['tenant_id']
|
tenant_id = s['tenant_id']
|
||||||
stateful = s.get('stateful', True)
|
stateful = s.get('stateful', True)
|
||||||
@ -151,14 +149,14 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase,
|
|||||||
get_context = context.elevated() if default_sg else context
|
get_context = context.elevated() if default_sg else context
|
||||||
sg = sg_obj.SecurityGroup.get_object(get_context, id=sg.id)
|
sg = sg_obj.SecurityGroup.get_object(get_context, id=sg.id)
|
||||||
secgroup_dict = self._make_security_group_dict(sg)
|
secgroup_dict = self._make_security_group_dict(sg)
|
||||||
self._registry_notify(resources.SECURITY_GROUP,
|
self._registry_publish(resources.SECURITY_GROUP,
|
||||||
events.PRECOMMIT_CREATE,
|
events.PRECOMMIT_CREATE,
|
||||||
exc_cls=ext_sg.SecurityGroupConflict,
|
exc_cls=ext_sg.SecurityGroupConflict,
|
||||||
payload=events.DBEventPayload(
|
payload=events.DBEventPayload(
|
||||||
context,
|
context,
|
||||||
resource_id=sg.id,
|
resource_id=sg.id,
|
||||||
metadata={'is_default': default_sg},
|
metadata={'is_default': default_sg},
|
||||||
states=(secgroup_dict,)))
|
states=(secgroup_dict,)))
|
||||||
|
|
||||||
registry.publish(resources.SECURITY_GROUP, events.AFTER_CREATE,
|
registry.publish(resources.SECURITY_GROUP, events.AFTER_CREATE,
|
||||||
self, payload=events.DBEventPayload(
|
self, payload=events.DBEventPayload(
|
||||||
@ -260,11 +258,11 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase,
|
|||||||
if sg['name'] == 'default' and not context.is_admin:
|
if sg['name'] == 'default' and not context.is_admin:
|
||||||
raise ext_sg.SecurityGroupCannotRemoveDefault()
|
raise ext_sg.SecurityGroupCannotRemoveDefault()
|
||||||
|
|
||||||
self._registry_notify(resources.SECURITY_GROUP,
|
self._registry_publish(resources.SECURITY_GROUP,
|
||||||
events.BEFORE_DELETE,
|
events.BEFORE_DELETE,
|
||||||
exc_cls=ext_sg.SecurityGroupInUse, id=id,
|
exc_cls=ext_sg.SecurityGroupInUse, id=id,
|
||||||
payload=events.DBEventPayload(
|
payload=events.DBEventPayload(
|
||||||
context, states=(sg,), resource_id=id))
|
context, states=(sg,), resource_id=id))
|
||||||
|
|
||||||
with db_api.CONTEXT_WRITER.using(context):
|
with db_api.CONTEXT_WRITER.using(context):
|
||||||
# pass security_group_rule_ids to ensure
|
# pass security_group_rule_ids to ensure
|
||||||
@ -276,15 +274,15 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase,
|
|||||||
sg = self._get_security_group(context, id)
|
sg = self._get_security_group(context, id)
|
||||||
sgr_ids = [r['id'] for r in sg.rules]
|
sgr_ids = [r['id'] for r in sg.rules]
|
||||||
sec_group = self._make_security_group_dict(sg)
|
sec_group = self._make_security_group_dict(sg)
|
||||||
self._registry_notify(resources.SECURITY_GROUP,
|
self._registry_publish(resources.SECURITY_GROUP,
|
||||||
events.PRECOMMIT_DELETE,
|
events.PRECOMMIT_DELETE,
|
||||||
exc_cls=ext_sg.SecurityGroupInUse,
|
exc_cls=ext_sg.SecurityGroupInUse,
|
||||||
payload=events.DBEventPayload(
|
payload=events.DBEventPayload(
|
||||||
context, resource_id=id,
|
context, resource_id=id,
|
||||||
states=(sec_group,),
|
states=(sec_group,),
|
||||||
metadata={
|
metadata={
|
||||||
'security_group_rule_ids': sgr_ids
|
'security_group_rule_ids': sgr_ids
|
||||||
}))
|
}))
|
||||||
sg.delete()
|
sg.delete()
|
||||||
|
|
||||||
registry.publish(resources.SECURITY_GROUP, events.AFTER_DELETE,
|
registry.publish(resources.SECURITY_GROUP, events.AFTER_DELETE,
|
||||||
@ -307,10 +305,10 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase,
|
|||||||
if ports:
|
if ports:
|
||||||
raise ext_sg.SecurityGroupInUse(id=id)
|
raise ext_sg.SecurityGroupInUse(id=id)
|
||||||
|
|
||||||
self._registry_notify(resources.SECURITY_GROUP, events.BEFORE_UPDATE,
|
self._registry_publish(resources.SECURITY_GROUP, events.BEFORE_UPDATE,
|
||||||
exc_cls=ext_sg.SecurityGroupConflict,
|
exc_cls=ext_sg.SecurityGroupConflict,
|
||||||
payload=events.DBEventPayload(
|
payload=events.DBEventPayload(
|
||||||
context, resource_id=id, states=(s,)))
|
context, resource_id=id, states=(s,)))
|
||||||
|
|
||||||
with db_api.CONTEXT_WRITER.using(context):
|
with db_api.CONTEXT_WRITER.using(context):
|
||||||
sg = self._get_security_group(context, id)
|
sg = self._get_security_group(context, id)
|
||||||
@ -321,7 +319,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase,
|
|||||||
sg.update_fields(s)
|
sg.update_fields(s)
|
||||||
sg.update()
|
sg.update()
|
||||||
sg_dict = self._make_security_group_dict(sg)
|
sg_dict = self._make_security_group_dict(sg)
|
||||||
self._registry_notify(
|
self._registry_publish(
|
||||||
resources.SECURITY_GROUP,
|
resources.SECURITY_GROUP,
|
||||||
events.PRECOMMIT_UPDATE,
|
events.PRECOMMIT_UPDATE,
|
||||||
exc_cls=ext_sg.SecurityGroupConflict,
|
exc_cls=ext_sg.SecurityGroupConflict,
|
||||||
@ -464,7 +462,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase,
|
|||||||
if port_range_max is not None:
|
if port_range_max is not None:
|
||||||
args['port_range_max'] = port_range_max
|
args['port_range_max'] = port_range_max
|
||||||
|
|
||||||
self._registry_notify(
|
self._registry_publish(
|
||||||
resources.SECURITY_GROUP_RULE,
|
resources.SECURITY_GROUP_RULE,
|
||||||
events.BEFORE_CREATE,
|
events.BEFORE_CREATE,
|
||||||
exc_cls=ext_sg.SecurityGroupConflict,
|
exc_cls=ext_sg.SecurityGroupConflict,
|
||||||
@ -484,7 +482,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase,
|
|||||||
sg_rule = sg_obj.SecurityGroupRule.get_object(context,
|
sg_rule = sg_obj.SecurityGroupRule.get_object(context,
|
||||||
id=sg_rule.id)
|
id=sg_rule.id)
|
||||||
res_rule_dict = self._make_security_group_rule_dict(sg_rule.db_obj)
|
res_rule_dict = self._make_security_group_rule_dict(sg_rule.db_obj)
|
||||||
self._registry_notify(
|
self._registry_publish(
|
||||||
resources.SECURITY_GROUP_RULE,
|
resources.SECURITY_GROUP_RULE,
|
||||||
events.PRECOMMIT_CREATE,
|
events.PRECOMMIT_CREATE,
|
||||||
exc_cls=ext_sg.SecurityGroupConflict,
|
exc_cls=ext_sg.SecurityGroupConflict,
|
||||||
@ -857,15 +855,15 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase,
|
|||||||
|
|
||||||
@db_api.retry_if_session_inactive()
|
@db_api.retry_if_session_inactive()
|
||||||
def delete_security_group_rule(self, context, id):
|
def delete_security_group_rule(self, context, id):
|
||||||
self._registry_notify(resources.SECURITY_GROUP_RULE,
|
self._registry_publish(resources.SECURITY_GROUP_RULE,
|
||||||
events.BEFORE_DELETE,
|
events.BEFORE_DELETE,
|
||||||
exc_cls=ext_sg.SecurityGroupRuleInUse,
|
exc_cls=ext_sg.SecurityGroupRuleInUse,
|
||||||
payload=events.DBEventPayload(
|
payload=events.DBEventPayload(
|
||||||
context, resource_id=id,))
|
context, resource_id=id,))
|
||||||
|
|
||||||
with db_api.CONTEXT_WRITER.using(context):
|
with db_api.CONTEXT_WRITER.using(context):
|
||||||
sgr = self._get_security_group_rule(context, id)
|
sgr = self._get_security_group_rule(context, id)
|
||||||
self._registry_notify(
|
self._registry_publish(
|
||||||
resources.SECURITY_GROUP_RULE,
|
resources.SECURITY_GROUP_RULE,
|
||||||
events.PRECOMMIT_DELETE,
|
events.PRECOMMIT_DELETE,
|
||||||
exc_cls=ext_sg.SecurityGroupRuleInUse,
|
exc_cls=ext_sg.SecurityGroupRuleInUse,
|
||||||
|
Loading…
Reference in New Issue
Block a user