Adds unique constraint on deleted_at

After deleting a resource, while trying to create again with same
name, it was throwing error as DuplicateEntity.
Fixing this issue by adding unique constraint on deleted_at.

Change-Id: I0e31346a471556f08c4fc5a6cc7bc130a133c24d
Closes-bug: #1680689
This commit is contained in:
Dharmendra Kushwaha 2017-04-19 11:05:01 +00:00 committed by dharmendra
parent b6f4562732
commit 2aec2ae7e5
7 changed files with 87 additions and 6 deletions

View File

@ -1 +1 @@
c256228ed37c
e7993093baf1

View File

@ -0,0 +1,47 @@
# Copyright 2017 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
"""add unique constraint on deleted_at
Revision ID: e7993093baf1
Revises: c256228ed37c
Create Date: 2017-04-19 10:57:22.157326
"""
# revision identifiers, used by Alembic.
revision = 'e7993093baf1'
down_revision = 'c256228ed37c'
from alembic import op
def _drop_unique_constraint(table):
op.drop_constraint(
constraint_name='uniq_%s0tenant_id0name' % table,
table_name=table, type_='unique')
def _add_unique_constraint(table):
op.create_unique_constraint(
constraint_name='uniq_%s0tenant_id0name0deleted_at' % table,
table_name=table,
columns=['tenant_id', 'name', 'deleted_at'])
def upgrade(active_plugins=None, options=None):
for table in ['vnf', 'vnfd', 'vims', 'ns', 'nsd']:
_drop_unique_constraint(table)
_add_unique_constraint(table)

View File

@ -62,7 +62,8 @@ class Vim(model_base.BASE,
schema.UniqueConstraint(
"tenant_id",
"name",
name="uniq_vim0tenant_id0name"),
"deleted_at",
name="uniq_vim0tenant_id0name0deleted_at"),
)

View File

@ -77,7 +77,8 @@ class VNFD(model_base.BASE, models_v1.HasId, models_v1.HasTenant,
schema.UniqueConstraint(
"tenant_id",
"name",
name="uniq_vnfd0tenant_id0name"),
"deleted_at",
name="uniq_vnfd0tenant_id0name0deleted_at"),
)
@ -141,7 +142,8 @@ class VNF(model_base.BASE, models_v1.HasId, models_v1.HasTenant,
schema.UniqueConstraint(
"tenant_id",
"name",
name="uniq_vnf0tenant_id0name"),
"deleted_at",
name="uniq_vnf0tenant_id0name0deleted_at"),
)
@ -255,7 +257,8 @@ class VNFMPluginDb(vnfm.VNFMPluginBase, db_base.CommonDbMixin):
name=vnfd.get('name'),
description=vnfd.get('description'),
mgmt_driver=mgmt_driver,
template_source=template_source)
template_source=template_source,
deleted_at=None)
context.session.add(vnfd_db)
for (key, value) in vnfd.get('attributes', {}).items():
attribute_db = VNFDAttribute(

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import time
import yaml
from tacker.plugins.common import constants as evt_constants
@ -152,3 +152,14 @@ class VimTestCreate(base.BaseTackerTest):
domain_name},
'is_default': False}}
return data, vim_arg
def test_re_create_delete_local_vim(self):
name = 'test_vim'
description = 'Test vim description'
vim_type = 'openstack'
ks_version = 'v3'
self._test_create_delete_vim('local-vim.yaml', name, description,
vim_type, ks_version)
time.sleep(1)
self._test_create_delete_vim('local-vim.yaml', name, description,
vim_type, ks_version)

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import time
import unittest
import yaml
@ -138,6 +139,15 @@ class VnfTestToscaCreate(base.BaseTackerTest):
'test_tosca_vnf_with_cirros_inline',
'inline')
def test_re_create_delete_vnf(self):
self._test_create_delete_vnf_tosca('sample-tosca-vnfd.yaml',
'test_vnf',
'inline')
time.sleep(1)
self._test_create_delete_vnf_tosca('sample-tosca-vnfd.yaml',
'test_vnf',
'inline')
def test_create_delete_vnf_static_ip(self):
vnfd_id, vnf_id = self._test_create_vnf(
'sample-tosca-vnfd-static-ip.yaml',

View File

@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import time
from oslo_config import cfg
import yaml
@ -54,3 +56,10 @@ class VnfdTestCreate(base.BaseTackerTest):
self._test_create_list_delete_tosca_vnfd(
'sample-tosca-vnfd-large-template.yaml',
'sample-tosca-vnfd-large-template')
def test_tosca_re_create_delete_vnfd(self):
self._test_create_list_delete_tosca_vnfd('sample-tosca-vnfd.yaml',
'test_vnfd')
time.sleep(1)
self._test_create_list_delete_tosca_vnfd('sample-tosca-vnfd.yaml',
'test_vnfd')