Fix for deleting audit template

We need to update sqlalchemy/api and sqlalchemy/models (and appropriate tests)
to support deleting audit templates and recreating them with the same names.

Change-Id: Icf54cf1ed989a3f2ad689e25be4474b16a3a3eb2
Related-Bug: #1510179
This commit is contained in:
Alexander Chadin
2016-04-04 18:34:20 +03:00
parent 99ff6d3348
commit 3e07844844
4 changed files with 16 additions and 13 deletions

View File

@@ -308,6 +308,13 @@ class Connection(api.BaseConnection):
if not values.get('uuid'):
values['uuid'] = utils.generate_uuid()
query = model_query(models.AuditTemplate)
query = query.filter_by(name=values.get('name'),
deleted_at=None)
if len(query.all()) > 0:
raise exception.AuditTemplateAlreadyExists(uuid=values['uuid'])
audit_template = models.AuditTemplate()
audit_template.update(values)
@@ -349,14 +356,10 @@ class Connection(api.BaseConnection):
def get_audit_template_by_name(self, context, audit_template_name):
query = model_query(models.AuditTemplate)
query = query.filter_by(name=audit_template_name)
query = query.filter_by(name=audit_template_name,
deleted_at=None)
try:
audit_template = query.one()
if not context.show_deleted:
if audit_template.deleted_at is not None:
raise exception.AuditTemplateNotFound(
audit_template=audit_template_name)
return audit_template
return query.one()
except exc.MultipleResultsFound:
raise exception.Conflict(
_('Multiple audit templates exist with the same name.'

View File

@@ -116,7 +116,6 @@ class AuditTemplate(Base):
__tablename__ = 'audit_templates'
__table_args__ = (
schema.UniqueConstraint('uuid', name='uniq_audit_templates0uuid'),
schema.UniqueConstraint('name', name='uniq_audit_templates0name'),
table_args()
)
id = Column(Integer, primary_key=True)