Merge "Delete check of function alias"

This commit is contained in:
Zuul 2018-08-07 02:41:11 +00:00 committed by Gerrit Code Review
commit 9d6bd96f9c
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

@ -165,3 +165,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)