From bb82dd048d6a3455d196566a9f2778e904f1f3e7 Mon Sep 17 00:00:00 2001 From: ashwini-orchestral Date: Fri, 17 Sep 2021 15:25:30 +0000 Subject: [PATCH 01/12] Action delete API rework - support for action file deletion --- st2api/st2api/controllers/v1/actions.py | 41 +++++++----- .../tests/unit/controllers/v1/test_actions.py | 63 +++++++++++++++++++ st2client/st2client/commands/action.py | 37 +++++------ st2client/st2client/models/core.py | 15 +++++ st2client/tests/unit/test_models.py | 50 +++++++++++++++ st2common/st2common/openapi.yaml | 16 +++++ st2common/st2common/openapi.yaml.j2 | 16 +++++ 7 files changed, 201 insertions(+), 37 deletions(-) diff --git a/st2api/st2api/controllers/v1/actions.py b/st2api/st2api/controllers/v1/actions.py index 1e8bf7c7b5..ec37c91d34 100644 --- a/st2api/st2api/controllers/v1/actions.py +++ b/st2api/st2api/controllers/v1/actions.py @@ -206,7 +206,7 @@ def put(self, action, ref_or_id, requester_user): return action_api - def delete(self, ref_or_id, requester_user): + def delete(self, files_remove_request, ref_or_id, requester_user): """ Delete an action. @@ -240,6 +240,7 @@ def delete(self, ref_or_id, requester_user): pack_name = action_db["pack"] entry_point = action_db["entry_point"] metadata_file = action_db["metadata_file"] + remove_files = files_remove_request.remove_files try: Action.delete(action_db) @@ -252,20 +253,30 @@ def delete(self, ref_or_id, requester_user): ) abort(http_client.INTERNAL_SERVER_ERROR, six.text_type(e)) return - try: - delete_action_files_from_pack( - pack_name=pack_name, - entry_point=entry_point, - metadata_file=metadata_file, - ) - except Exception as e: - LOG.error( - "Exception encountered during deleting resource files from disk." - "Exception was %s", - e, - ) - abort(http_client.INTERNAL_SERVER_ERROR, six.text_type(e)) - return + + if remove_files: + try: + delete_action_files_from_pack( + pack_name=pack_name, + entry_point=entry_point, + metadata_file=metadata_file, + ) + except PermissionError as e: + LOG.error("No permission to delete resource files from disk.") + action_db.id = None + Action.add_or_update(action_db) + abort(http_client.FORBIDDEN, six.text_type(e)) + return + except Exception as e: + LOG.error( + "Exception encountered during deleting resource files from disk. " + "Exception was %s", + e, + ) + action_db.id = None + Action.add_or_update(action_db) + abort(http_client.INTERNAL_SERVER_ERROR, six.text_type(e)) + return extra = {"action_db": action_db} LOG.audit("Action deleted. Action.id=%s" % (action_db.id), extra=extra) diff --git a/st2api/tests/unit/controllers/v1/test_actions.py b/st2api/tests/unit/controllers/v1/test_actions.py index cd1d8b555c..8877739f6e 100644 --- a/st2api/tests/unit/controllers/v1/test_actions.py +++ b/st2api/tests/unit/controllers/v1/test_actions.py @@ -626,6 +626,60 @@ def test_delete(self): del_resp = self.__do_delete(self.__get_action_id(post_resp)) self.assertEqual(del_resp.status_int, 204) + @mock.patch.object( + action_validator, "validate_action", mock.MagicMock(return_value=True) + ) + def test_delete_permission_error_and_action_reregistered_to_database(self): + post_resp = self.__do_post(ACTION_1) + + with mock.patch( + "st2api.controllers.v1.actions.delete_action_files_from_pack" + ) as mock_remove_files: + msg = "No permission to delete action files from disk" + mock_remove_files.side_effect = PermissionError(msg) + payload = {"remove_files": True} + del_resp = self.__do_delete_action_with_files( + payload, self.__get_action_id(post_resp), expect_errors=True + ) + self.assertEqual(del_resp.status_int, 403) + self.assertEqual(del_resp.json["faultstring"], msg) + + # retrieving reregistered action + get_resp = self.__do_get_actions_by_url_parameter("name", ACTION_1["name"]) + expected_uid = post_resp.json["uid"] + actual_uid = get_resp.json[0]["uid"] + self.assertEqual(actual_uid, expected_uid) + action_id = get_resp.json[0]["id"] + del_resp = self.__do_delete(action_id) + self.assertEqual(del_resp.status_int, 204) + + @mock.patch.object( + action_validator, "validate_action", mock.MagicMock(return_value=True) + ) + def test_delete_exception_and_action_reregistered_to_database(self): + post_resp = self.__do_post(ACTION_1) + + with mock.patch( + "st2api.controllers.v1.actions.delete_action_files_from_pack" + ) as mock_remove_files: + msg = "Exception encountered during removing files from disk" + mock_remove_files.side_effect = Exception(msg) + payload = {"remove_files": True} + del_resp = self.__do_delete_action_with_files( + payload, self.__get_action_id(post_resp), expect_errors=True + ) + self.assertEqual(del_resp.status_int, 500) + self.assertEqual(del_resp.json["faultstring"], msg) + + # retrieving reregistered action + get_resp = self.__do_get_actions_by_url_parameter("name", ACTION_1["name"]) + expected_uid = post_resp.json["uid"] + actual_uid = get_resp.json[0]["uid"] + self.assertEqual(actual_uid, expected_uid) + action_id = get_resp.json[0]["id"] + del_resp = self.__do_delete(action_id) + self.assertEqual(del_resp.status_int, 204) + @mock.patch.object( action_validator, "validate_action", mock.MagicMock(return_value=True) ) @@ -802,3 +856,12 @@ def __do_delete(self, action_id, expect_errors=False): return self.app.delete( "/v1/actions/%s" % action_id, expect_errors=expect_errors ) + + def __do_delete_action_with_files( + self, files_remove_request, action_id, expect_errors=False + ): + return self.app.delete_json( + "/v1/actions/%s" % action_id, + files_remove_request, + expect_errors=expect_errors, + ) diff --git a/st2client/st2client/commands/action.py b/st2client/st2client/commands/action.py index 29963fd2de..f9da7b02bd 100644 --- a/st2client/st2client/commands/action.py +++ b/st2client/st2client/commands/action.py @@ -30,7 +30,7 @@ from six.moves import range -from st2client import models +from st2client.models.action import Action, Execution from st2client.commands import resource from st2client.commands.resource import ResourceNotFoundError from st2client.commands.resource import ResourceViewCommand @@ -198,7 +198,7 @@ def format_execution_status(instance): class ActionBranch(resource.ResourceBranch): def __init__(self, description, app, subparsers, parent_parser=None): super(ActionBranch, self).__init__( - models.Action, + Action, description, app, subparsers, @@ -282,31 +282,24 @@ def __init__(self, resource, *args, **kwargs): super(ActionDeleteCommand, self).__init__(resource, *args, **kwargs) self.parser.add_argument( - "-f", - "--force", + "-rf", + "--remove-files", action="store_true", - dest="force", - help="Auto yes flag to delete action files from disk.", + dest="remove_files", + help="Remove action files from disk.", ) @add_auth_token_to_kwargs_from_cli def run(self, args, **kwargs): resource_id = getattr(args, self.pk_argument_name, None) instance = self.get_resource(resource_id, **kwargs) - msg = ( - 'Resource with id "%s" has been successfully deleted from database and disk.' - % (resource_id) - ) - user_input = "" - if not args.force: - user_input = input( - "The resource files on disk will be deleted. Do you want to continue? (y/n): " - ) - if args.force or user_input.lower() == "y" or user_input.lower() == "yes": - self.manager.delete(instance, **kwargs) - print(msg) + if args.remove_files: + remove_files = True else: - print("Action is not deleted.") + remove_files = False + + self.manager.delete_action(instance, remove_files, **kwargs) + print('Resource with id "%s" has been successfully deleted.' % (resource_id)) def run_and_print(self, args, **kwargs): resource_id = getattr(args, self.pk_argument_name) @@ -1082,7 +1075,7 @@ def _format_for_common_representation(self, task): task_name_key = "context.orquesta.task_name" # Use Execution as the object so that the formatter lookup does not change. # AKA HACK! - return models.action.Execution( + return Execution( **{ "id": task.id, "status": task.status, @@ -1240,7 +1233,7 @@ def run(self, args, **kwargs): action=action, runner=runner, args=args ) - execution = models.Execution() + execution = Execution() execution.action = action_ref execution.parameters = action_parameters execution.user = args.user @@ -1267,7 +1260,7 @@ def run(self, args, **kwargs): class ActionExecutionBranch(resource.ResourceBranch): def __init__(self, description, app, subparsers, parent_parser=None): super(ActionExecutionBranch, self).__init__( - models.Execution, + Execution, description, app, subparsers, diff --git a/st2client/st2client/models/core.py b/st2client/st2client/models/core.py index 7f94cc94f8..45034b6c6b 100644 --- a/st2client/st2client/models/core.py +++ b/st2client/st2client/models/core.py @@ -376,6 +376,21 @@ def delete(self, instance, **kwargs): return True + @add_auth_token_to_kwargs_from_env + def delete_action(self, instance, remove_files, **kwargs): + url = "/%s/%s" % (self.resource.get_url_path_name(), instance.id) + payload = {"remove_files": remove_files} + response = self.client.delete(url, data=orjson.dumps(payload), **kwargs) + if response.status_code not in [ + http_client.OK, + http_client.NO_CONTENT, + http_client.NOT_FOUND, + ]: + self.handle_error(response) + return False + + return True + @add_auth_token_to_kwargs_from_env def delete_by_id(self, instance_id, **kwargs): url = "/%s/%s" % (self.resource.get_url_path_name(), instance_id) diff --git a/st2client/tests/unit/test_models.py b/st2client/tests/unit/test_models.py index 8a137afa13..665942ddcb 100644 --- a/st2client/tests/unit/test_models.py +++ b/st2client/tests/unit/test_models.py @@ -355,6 +355,56 @@ def test_resource_delete_failed(self): instance = mgr.get_by_name("abc") self.assertRaises(Exception, mgr.delete, instance) + @mock.patch.object( + httpclient.HTTPClient, + "get", + mock.MagicMock( + return_value=base.FakeResponse( + json.dumps([base.RESOURCES[0]]), 200, "OK", {} + ) + ), + ) + @mock.patch.object( + httpclient.HTTPClient, + "delete", + mock.MagicMock(return_value=base.FakeResponse("", 204, "NO CONTENT")), + ) + def test_resource_delete_action(self): + mgr = models.ResourceManager(base.FakeResource, base.FAKE_ENDPOINT) + instance = mgr.get_by_name("abc") + mgr.delete_action(instance, True) + + @mock.patch.object( + httpclient.HTTPClient, + "delete", + mock.MagicMock(return_value=base.FakeResponse("", 404, "NOT FOUND")), + ) + def test_resource_delete_action_404(self): + mgr = models.ResourceManager(base.FakeResource, base.FAKE_ENDPOINT) + instance = base.FakeResource.deserialize(base.RESOURCES[0]) + mgr.delete_action(instance, False) + + @mock.patch.object( + httpclient.HTTPClient, + "get", + mock.MagicMock( + return_value=base.FakeResponse( + json.dumps([base.RESOURCES[0]]), 200, "OK", {} + ) + ), + ) + @mock.patch.object( + httpclient.HTTPClient, + "delete", + mock.MagicMock( + return_value=base.FakeResponse("", 500, "INTERNAL SERVER ERROR") + ), + ) + def test_resource_delete_action_failed(self): + mgr = models.ResourceManager(base.FakeResource, base.FAKE_ENDPOINT) + instance = mgr.get_by_name("abc") + self.assertRaises(Exception, mgr.delete_action, instance, True) + @mock.patch("requests.get") @mock.patch("sseclient.SSEClient") def test_stream_resource_listen(self, mock_sseclient, mock_requests): diff --git a/st2common/st2common/openapi.yaml b/st2common/st2common/openapi.yaml index 723c6f5235..e80ee7ba8d 100644 --- a/st2common/st2common/openapi.yaml +++ b/st2common/st2common/openapi.yaml @@ -413,6 +413,11 @@ paths: description: Entity reference or id type: string required: true + - name: files_remove_request + in: body + description: Flag to remove action files from disk + schema: + $ref: '#/definitions/ActionDeleteRequest' x-parameters: - name: user in: context @@ -4684,6 +4689,9 @@ definitions: allOf: - $ref: '#/definitions/Action' - $ref: '#/definitions/DataFilesSubSchema' + ActionDeleteRequest: + allOf: + - $ref: '#/definitions/ActionDeleteSchema' ActionParameters: type: object properties: @@ -5384,6 +5392,14 @@ definitions: items: type: string additionalProperties: false + ActionDeleteSchema: + type: object + properties: + remove_files: + type: boolean + description: Force delete action files from disk + default: false + additionalProperties: false TokenRequest: type: object properties: diff --git a/st2common/st2common/openapi.yaml.j2 b/st2common/st2common/openapi.yaml.j2 index b41602587b..bb23d0dd20 100644 --- a/st2common/st2common/openapi.yaml.j2 +++ b/st2common/st2common/openapi.yaml.j2 @@ -409,6 +409,11 @@ paths: description: Entity reference or id type: string required: true + - name: files_remove_request + in: body + description: Flag to remove action files from disk + schema: + $ref: '#/definitions/ActionDeleteRequest' x-parameters: - name: user in: context @@ -4680,6 +4685,9 @@ definitions: allOf: - $ref: '#/definitions/Action' - $ref: '#/definitions/DataFilesSubSchema' + ActionDeleteRequest: + allOf: + - $ref: '#/definitions/ActionDeleteSchema' ActionParameters: type: object properties: @@ -5380,6 +5388,14 @@ definitions: items: type: string additionalProperties: false + ActionDeleteSchema: + type: object + properties: + remove_files: + type: boolean + description: Force delete action files from disk + default: false + additionalProperties: false TokenRequest: type: object properties: From 7831b14503b4169f373f66a7915e570fee3d3536 Mon Sep 17 00:00:00 2001 From: ashwini-orchestral <72917414+ashwini-orchestral@users.noreply.github.com> Date: Mon, 20 Sep 2021 23:01:28 +0530 Subject: [PATCH 02/12] Minor fix in parameter of action delete API mehtod --- st2api/st2api/controllers/v1/actions.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/st2api/st2api/controllers/v1/actions.py b/st2api/st2api/controllers/v1/actions.py index ec37c91d34..88e5993e49 100644 --- a/st2api/st2api/controllers/v1/actions.py +++ b/st2api/st2api/controllers/v1/actions.py @@ -206,7 +206,7 @@ def put(self, action, ref_or_id, requester_user): return action_api - def delete(self, files_remove_request, ref_or_id, requester_user): + def delete(self, options, ref_or_id, requester_user): """ Delete an action. @@ -240,7 +240,6 @@ def delete(self, files_remove_request, ref_or_id, requester_user): pack_name = action_db["pack"] entry_point = action_db["entry_point"] metadata_file = action_db["metadata_file"] - remove_files = files_remove_request.remove_files try: Action.delete(action_db) @@ -254,7 +253,7 @@ def delete(self, files_remove_request, ref_or_id, requester_user): abort(http_client.INTERNAL_SERVER_ERROR, six.text_type(e)) return - if remove_files: + if options.remove_files: try: delete_action_files_from_pack( pack_name=pack_name, From d4eea167085460d54beafb72dfb52d8845e74d14 Mon Sep 17 00:00:00 2001 From: ashwini-orchestral <72917414+ashwini-orchestral@users.noreply.github.com> Date: Mon, 20 Sep 2021 23:07:54 +0530 Subject: [PATCH 03/12] Adding new unit tests and refactoring existing unit test --- .../tests/unit/controllers/v1/test_actions.py | 49 ++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/st2api/tests/unit/controllers/v1/test_actions.py b/st2api/tests/unit/controllers/v1/test_actions.py index 8877739f6e..a7d19de87b 100644 --- a/st2api/tests/unit/controllers/v1/test_actions.py +++ b/st2api/tests/unit/controllers/v1/test_actions.py @@ -618,13 +618,52 @@ def test_post_override_runner_param_allowed(self): post_resp = self.__do_post(ACTION_15) self.assertEqual(post_resp.status_int, 201) + @mock.patch("st2api.controllers.v1.actions.delete_action_files_from_pack") @mock.patch.object( action_validator, "validate_action", mock.MagicMock(return_value=True) ) - def test_delete(self): + def test_delete(self, mock_remove_files): post_resp = self.__do_post(ACTION_1) - del_resp = self.__do_delete(self.__get_action_id(post_resp)) + action_id = self.__get_action_id(post_resp) + del_resp = self.__do_delete(action_id) + self.assertEqual(del_resp.status_int, 204) + mock_remove_files.assert_not_called() + get_resp = self.__do_get_one(action_id, expect_errors=True) + expected_msg = 'Resource with a reference or id "%s" not found' % action_id + actual_msg = get_resp.json["faultstring"] + self.assertEqual(actual_msg, expected_msg) + + @mock.patch("st2api.controllers.v1.actions.delete_action_files_from_pack") + @mock.patch.object( + action_validator, "validate_action", mock.MagicMock(return_value=True) + ) + def test_delete_remove_files_false(self, mock_remove_files): + post_resp = self.__do_post(ACTION_1) + action_id = self.__get_action_id(post_resp) + payload = {"remove_files": False} + del_resp = self.__do_delete_action_with_files(payload, action_id) + self.assertEqual(del_resp.status_int, 204) + mock_remove_files.assert_not_called() + get_resp = self.__do_get_one(action_id, expect_errors=True) + expected_msg = 'Resource with a reference or id "%s" not found' % action_id + actual_msg = get_resp.json["faultstring"] + self.assertEqual(actual_msg, expected_msg) + + @mock.patch("st2api.controllers.v1.actions.delete_action_files_from_pack") + @mock.patch.object( + action_validator, "validate_action", mock.MagicMock(return_value=True) + ) + def test_delete_remove_files_true(self, mock_remove_files): + post_resp = self.__do_post(ACTION_1) + action_id = self.__get_action_id(post_resp) + payload = {"remove_files": True} + del_resp = self.__do_delete_action_with_files(payload, action_id) self.assertEqual(del_resp.status_int, 204) + self.assertTrue(mock_remove_files.called) + get_resp = self.__do_get_one(action_id, expect_errors=True) + expected_msg = 'Resource with a reference or id "%s" not found' % action_id + actual_msg = get_resp.json["faultstring"] + self.assertEqual(actual_msg, expected_msg) @mock.patch.object( action_validator, "validate_action", mock.MagicMock(return_value=True) @@ -857,11 +896,9 @@ def __do_delete(self, action_id, expect_errors=False): "/v1/actions/%s" % action_id, expect_errors=expect_errors ) - def __do_delete_action_with_files( - self, files_remove_request, action_id, expect_errors=False - ): + def __do_delete_action_with_files(self, options, action_id, expect_errors=False): return self.app.delete_json( "/v1/actions/%s" % action_id, - files_remove_request, + options, expect_errors=expect_errors, ) From 5f35b884638b6e45bce6d3df31b7d9e5543f58c3 Mon Sep 17 00:00:00 2001 From: ashwini-orchestral <72917414+ashwini-orchestral@users.noreply.github.com> Date: Mon, 20 Sep 2021 23:10:49 +0530 Subject: [PATCH 04/12] Minor fix in arguments of CLI action delete command --- st2client/st2client/commands/action.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/st2client/st2client/commands/action.py b/st2client/st2client/commands/action.py index f9da7b02bd..925ab44b78 100644 --- a/st2client/st2client/commands/action.py +++ b/st2client/st2client/commands/action.py @@ -286,6 +286,7 @@ def __init__(self, resource, *args, **kwargs): "--remove-files", action="store_true", dest="remove_files", + default=False, help="Remove action files from disk.", ) @@ -293,11 +294,7 @@ def __init__(self, resource, *args, **kwargs): def run(self, args, **kwargs): resource_id = getattr(args, self.pk_argument_name, None) instance = self.get_resource(resource_id, **kwargs) - if args.remove_files: - remove_files = True - else: - remove_files = False - + remove_files = args.remove_files self.manager.delete_action(instance, remove_files, **kwargs) print('Resource with id "%s" has been successfully deleted.' % (resource_id)) From c33099b3eea50a76844a7f0d6baa1773e0036ec2 Mon Sep 17 00:00:00 2001 From: ashwini-orchestral <72917414+ashwini-orchestral@users.noreply.github.com> Date: Mon, 20 Sep 2021 23:18:20 +0530 Subject: [PATCH 05/12] Minor fix in action delete API request json body --- st2common/st2common/openapi.yaml.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2common/st2common/openapi.yaml.j2 b/st2common/st2common/openapi.yaml.j2 index bb23d0dd20..9e54479495 100644 --- a/st2common/st2common/openapi.yaml.j2 +++ b/st2common/st2common/openapi.yaml.j2 @@ -409,7 +409,7 @@ paths: description: Entity reference or id type: string required: true - - name: files_remove_request + - name: options in: body description: Flag to remove action files from disk schema: From c5a8798a3e91826d150acd867d4ae79e351f5518 Mon Sep 17 00:00:00 2001 From: ashwini-orchestral <72917414+ashwini-orchestral@users.noreply.github.com> Date: Mon, 20 Sep 2021 23:19:25 +0530 Subject: [PATCH 06/12] Minor fix in action delete API request json body --- st2common/st2common/openapi.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2common/st2common/openapi.yaml b/st2common/st2common/openapi.yaml index e80ee7ba8d..27873ede3e 100644 --- a/st2common/st2common/openapi.yaml +++ b/st2common/st2common/openapi.yaml @@ -413,7 +413,7 @@ paths: description: Entity reference or id type: string required: true - - name: files_remove_request + - name: options in: body description: Flag to remove action files from disk schema: From 1a4226ef6f88a53807567989ad6b3c50a1fe7d08 Mon Sep 17 00:00:00 2001 From: ashwini-orchestral <72917414+ashwini-orchestral@users.noreply.github.com> Date: Tue, 21 Sep 2021 16:38:22 +0530 Subject: [PATCH 07/12] Changing CLI action delete command optional argument `-rf` to `-r` --- st2client/st2client/commands/action.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2client/st2client/commands/action.py b/st2client/st2client/commands/action.py index 925ab44b78..41fca2da88 100644 --- a/st2client/st2client/commands/action.py +++ b/st2client/st2client/commands/action.py @@ -282,7 +282,7 @@ def __init__(self, resource, *args, **kwargs): super(ActionDeleteCommand, self).__init__(resource, *args, **kwargs) self.parser.add_argument( - "-rf", + "-r", "--remove-files", action="store_true", dest="remove_files", From 430d86f7a90b859b2101c831b93eca71b2d916a9 Mon Sep 17 00:00:00 2001 From: ashwini-orchestral <72917414+ashwini-orchestral@users.noreply.github.com> Date: Tue, 21 Sep 2021 16:48:37 +0530 Subject: [PATCH 08/12] Updating CHANGELOG.rst according to rework in action delete API modification to have backward compatibility --- CHANGELOG.rst | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 478156beb4..676df63b7d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,12 +7,16 @@ in development Changed ~~~~~~~ -* Modified action delete api. Action delete api removes related action/workflow files on disk - along with de-registering them from database. Prompts on CLI for user permission before - removing disk files. +* Modified action delete API to delete action files from disk along with backward compatibility. - ``-f`` and ``--force`` arguments added for action delete CLI command as auto yes flag and - will delete related files on disk without prompting for user permission. #5304 + From CLI ``st2 action delete .`` will delete only action database entry. + From CLI ``st2 action delete --remove-files .`` or ``st2 action delete -r .`` + will delete action database entry along with files from disk. + + API action DELETE method with ``{"remove_files": true}`` argument in json body will remove database + entry of action along with files from disk. + API action DELETE method with ``{"remove_files": false}`` or no additional argument in json body will remove + only action database entry. #5304, #5351, #5360 Contributed by @mahesh-orch. From e4bf1b41885f5dd2f0fa18e6214108385d8d7e2a Mon Sep 17 00:00:00 2001 From: ashwini-orchestral <72917414+ashwini-orchestral@users.noreply.github.com> Date: Tue, 21 Sep 2021 17:55:23 +0530 Subject: [PATCH 09/12] Minor fix in description of ActionDeleteSchema `remove-files` argument --- st2common/st2common/openapi.yaml.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2common/st2common/openapi.yaml.j2 b/st2common/st2common/openapi.yaml.j2 index 9e54479495..f2368cd74c 100644 --- a/st2common/st2common/openapi.yaml.j2 +++ b/st2common/st2common/openapi.yaml.j2 @@ -5393,7 +5393,7 @@ definitions: properties: remove_files: type: boolean - description: Force delete action files from disk + description: Flag to delete action files from disk default: false additionalProperties: false TokenRequest: From 8539a44039b9b71f4d0f32f58e8b21bc8cb0de5d Mon Sep 17 00:00:00 2001 From: ashwini-orchestral <72917414+ashwini-orchestral@users.noreply.github.com> Date: Tue, 21 Sep 2021 17:56:26 +0530 Subject: [PATCH 10/12] Minor fix in description of ActionDeleteSchema `remove-files` argument --- st2common/st2common/openapi.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2common/st2common/openapi.yaml b/st2common/st2common/openapi.yaml index 27873ede3e..0ca1430c34 100644 --- a/st2common/st2common/openapi.yaml +++ b/st2common/st2common/openapi.yaml @@ -5397,7 +5397,7 @@ definitions: properties: remove_files: type: boolean - description: Force delete action files from disk + description: Flag to delete action files from disk default: false additionalProperties: false TokenRequest: From eb269136e89324afc29509d073e46efd10173b87 Mon Sep 17 00:00:00 2001 From: ashwini-orchestral <72917414+ashwini-orchestral@users.noreply.github.com> Date: Tue, 21 Sep 2021 18:19:27 +0530 Subject: [PATCH 11/12] Minor fix - adding comment in st2api/tests/unit/controllers/v1/test_actions.py --- st2api/tests/unit/controllers/v1/test_actions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/st2api/tests/unit/controllers/v1/test_actions.py b/st2api/tests/unit/controllers/v1/test_actions.py index a7d19de87b..e7ce1ab699 100644 --- a/st2api/tests/unit/controllers/v1/test_actions.py +++ b/st2api/tests/unit/controllers/v1/test_actions.py @@ -628,6 +628,7 @@ def test_delete(self, mock_remove_files): del_resp = self.__do_delete(action_id) self.assertEqual(del_resp.status_int, 204) mock_remove_files.assert_not_called() + # asserting ACTION_1 database entry has removed get_resp = self.__do_get_one(action_id, expect_errors=True) expected_msg = 'Resource with a reference or id "%s" not found' % action_id actual_msg = get_resp.json["faultstring"] From 691431e5a66c24b46e927a3c44c16d56e9f40d48 Mon Sep 17 00:00:00 2001 From: ashwini-orchestral <72917414+ashwini-orchestral@users.noreply.github.com> Date: Tue, 21 Sep 2021 19:23:02 +0530 Subject: [PATCH 12/12] Lint-black/flake8 fix in st2api/tests/unit/controllers/v1/test_actions.py --- st2api/tests/unit/controllers/v1/test_actions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/st2api/tests/unit/controllers/v1/test_actions.py b/st2api/tests/unit/controllers/v1/test_actions.py index e7ce1ab699..f28db5d52f 100644 --- a/st2api/tests/unit/controllers/v1/test_actions.py +++ b/st2api/tests/unit/controllers/v1/test_actions.py @@ -628,6 +628,7 @@ def test_delete(self, mock_remove_files): del_resp = self.__do_delete(action_id) self.assertEqual(del_resp.status_int, 204) mock_remove_files.assert_not_called() + # asserting ACTION_1 database entry has removed get_resp = self.__do_get_one(action_id, expect_errors=True) expected_msg = 'Resource with a reference or id "%s" not found' % action_id