Delete check of function alias

This commit add function alias check of delete function and delete
function version, if there is alias associated with the function or
function version, the function or function version  deletion will
fail.

Change-Id: Ic45f5e0bcf30266fccd7b1ed649e79f94eaccdc3
Story: #2002143
Task: 23265
This commit is contained in:
Dong Ma 2018-07-25 17:13:28 +00:00
parent ce6d7e0f64
commit 12fa9199d4
5 changed files with 54 additions and 1 deletions

View File

@ -281,6 +281,10 @@ class FunctionsController(rest.RestController):
raise exc.NotAllowedException(
'The function is still associated with webhook(s).'
)
if len(func_db.aliases) > 0:
raise exc.NotAllowedException(
'The function is still associated with function alias(es).'
)
# Even admin user can not delete other project's function because
# the trust associated can only be removed by function owner.

View File

@ -243,7 +243,17 @@ class FunctionVersionsController(rest.RestController):
)
if len(version_webhook) > 0:
raise exc.NotAllowedException(
'The function versioin is still associated with webhook.'
'The function version is still associated with webhook.'
)
filters = rest_utils.get_filters(
function_id=version_db.function_id,
function_version=version_db.version_number
)
version_aliases = db_api.get_function_aliases(**filters)
if len(version_aliases) > 0:
raise exc.NotAllowedException(
'The function version is still associated with alias.'
)
# Delete resources for function version

View File

@ -164,3 +164,7 @@ Function.versions = relationship(
lazy='select',
cascade="all, delete-orphan"
)
Function.aliases = relationship(
"FunctionAlias",
uselist=True
)

View File

@ -377,6 +377,23 @@ class TestFunctionController(base.APITest):
self.assertEqual(403, resp.status_int)
def test_delete_with_alias(self):
db_func = self.create_function(runtime_id=self.runtime_id)
func_id = db_func.id
name = self.rand_name(name="alias", prefix=self.prefix)
body = {
'function_id': func_id,
'name': name
}
db_api.create_function_alias(**body)
resp = self.app.delete(
'/v1/functions/%s' % func_id,
expect_errors=True
)
self.assertEqual(403, resp.status_int)
@mock.patch('qinling.rpc.EngineClient.scaleup_function')
def test_scale_up(self, scaleup_function_mock):
db_func = self.create_function(runtime_id=self.runtime_id)

View File

@ -190,6 +190,24 @@ class TestFunctionVersionController(base.APITest):
self.assertEqual(403, resp.status_int)
def test_delete_with_alias(self):
db_api.increase_function_version(self.func_id, 0,
description="version 1")
name = self.rand_name(name="alias", prefix=self.prefix)
body = {
'function_id': self.func_id,
'function_version': 1,
'name': name
}
db_api.create_function_alias(**body)
resp = self.app.delete(
'/v1/functions/%s/versions/1' % self.func_id,
expect_errors=True
)
self.assertEqual(403, resp.status_int)
@mock.patch('qinling.rpc.EngineClient.scaleup_function')
def test_scale_up(self, scaleup_function_mock):
db_api.increase_function_version(self.func_id, 0)