Browse Source

Delete underlying resources when deleting function version

The workers and etcd records should be removed when deleting the
function version.

Change-Id: I04e1d2952227bcc5cf1dad3ac1a6d53bde636c10
Story: 2002100
Task: 19778
changes/10/570510/1
Lingxian Kong 3 years ago
parent
commit
2237daf334
  1. 4
      qinling/api/controllers/v1/function_version.py
  2. 13
      qinling/tests/unit/api/controllers/v1/test_function_version.py

4
qinling/api/controllers/v1/function_version.py

@ -235,6 +235,10 @@ class FunctionVersionsController(rest.RestController):
'The function versioin is still associated with webhook.'
)
# Delete resources for function version
self.engine_client.delete_function(function_id, version=version)
etcd_util.delete_function(function_id, version=version)
self.storage_provider.delete(ctx.projectid, function_id, None,
version=version)

13
qinling/tests/unit/api/controllers/v1/test_function_version.py

@ -121,16 +121,23 @@ class TestFunctionVersionController(base.APITest):
self.assertEqual(200, resp.status_int)
self.assertEqual("version 1", resp.json.get('description'))
@mock.patch('qinling.utils.etcd_util.delete_function')
@mock.patch('qinling.rpc.EngineClient.delete_function')
@mock.patch('qinling.storage.file_system.FileSystemStorage.delete')
def test_delete(self, mock_delete):
def test_delete(self, mock_package_delete, mock_engine_delete,
mock_etcd_delete):
db_api.increase_function_version(self.func_id, 0,
description="version 1")
resp = self.app.delete('/v1/functions/%s/versions/1' % self.func_id)
self.assertEqual(204, resp.status_int)
mock_delete.assert_called_once_with(unit_base.DEFAULT_PROJECT_ID,
self.func_id, None, version=1)
mock_engine_delete.assert_called_once_with(self.func_id, version=1)
mock_etcd_delete.assert_called_once_with(self.func_id, version=1)
mock_package_delete.assert_called_once_with(
unit_base.DEFAULT_PROJECT_ID,
self.func_id, None, version=1
)
# We need to set context as it was removed after the API call
context.set_ctx(self.ctx)

Loading…
Cancel
Save