diff --git a/qinling/api/controllers/v1/function.py b/qinling/api/controllers/v1/function.py index 18c12909..fa148ecb 100644 --- a/qinling/api/controllers/v1/function.py +++ b/qinling/api/controllers/v1/function.py @@ -391,6 +391,7 @@ class FunctionsController(rest.RestController): # Package type function. 'code' and 'entry' make sense only if # 'package' is provided + update_package = False if (pre_source == constants.PACKAGE_FUNCTION and values.get('package') is not None): if md5sum and md5sum == pre_md5sum: @@ -410,6 +411,7 @@ class FunctionsController(rest.RestController): {"md5sum": md5sum, "source": pre_source} ) values.pop('package') + update_package = True # Swift type function if pre_source == constants.SWIFT_FUNCTION: @@ -423,8 +425,8 @@ class FunctionsController(rest.RestController): func_db = db_api.update_function(id, values) - # Delete function package if needed - if pre_md5sum: + # Delete the old function package if needed + if update_package: self.storage_provider.delete(ctx.projectid, id, pre_md5sum) pecan.response.status = 200 diff --git a/qinling/tests/unit/api/controllers/v1/test_function.py b/qinling/tests/unit/api/controllers/v1/test_function.py index 92c83950..4c682417 100644 --- a/qinling/tests/unit/api/controllers/v1/test_function.py +++ b/qinling/tests/unit/api/controllers/v1/test_function.py @@ -209,11 +209,11 @@ class TestFunctionController(base.APITest): resp.json['faultstring'] ) + @mock.patch('qinling.storage.file_system.FileSystemStorage.delete') @mock.patch('qinling.utils.etcd_util.delete_function') @mock.patch('qinling.rpc.EngineClient.delete_function') - def test_put_cpu_and_memorysize( - self, mock_delete_func, mock_etcd_del - ): + def test_put_cpu_and_memorysize(self, mock_delete_func, mock_etcd_del, + mock_storage_delete): # Test for updating cpu/mem with good input values. db_func = self.create_function(runtime_id=self.runtime_id) @@ -235,6 +235,7 @@ class TestFunctionController(base.APITest): ) mock_delete_func.assert_called_once_with(db_func.id) mock_etcd_del.assert_called_once_with(db_func.id) + self.assertFalse(mock_storage_delete.called) @mock.patch('qinling.utils.etcd_util.delete_function') @mock.patch('qinling.rpc.EngineClient.delete_function')