From 7737bbf7582c6a4473c29cfbde583fb733733e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Sun, 5 May 2024 18:49:44 +0200 Subject: [PATCH] REfactorign "remove" in favor of "delete" --- .../services/generics/dynamic/publication.py | 14 +++++++------- .../services/generics/dynamic/userservice.py | 18 ++++++++++-------- .../services/generics/fixed/userservice.py | 6 +++--- server/src/uds/core/types/services.py | 4 ++-- .../uds/services/Proxmox/deployment_linked.py | 2 +- server/src/uds/services/Proxmox/publication.py | 4 ++-- .../tests/core/services/generics/fixtures.py | 8 ++++---- .../proxmox/test_serialization_publication.py | 4 ++-- .../proxmox/test_userservice_linked.py | 4 ++-- server/tests/utils/__init__.py | 2 +- 10 files changed, 34 insertions(+), 32 deletions(-) diff --git a/server/src/uds/core/services/generics/dynamic/publication.py b/server/src/uds/core/services/generics/dynamic/publication.py index bc7c708ec..c74186d41 100644 --- a/server/src/uds/core/services/generics/dynamic/publication.py +++ b/server/src/uds/core/services/generics/dynamic/publication.py @@ -71,8 +71,8 @@ class DynamicPublication(services.Publication, autoserializable.AutoSerializable Operation.FINISH, ] _destroy_queue: typing.ClassVar[list[Operation]] = [ - Operation.REMOVE, - Operation.REMOVE_COMPLETED, + Operation.DELETE, + Operation.DELETE_COMPLETED, Operation.FINISH, ] @@ -266,7 +266,7 @@ class DynamicPublication(services.Publication, autoserializable.AutoSerializable op = self._current_op() # If already removing, do nothing - if op == Operation.REMOVE: + if op == Operation.DELETE: return types.states.TaskState.RUNNING if op == Operation.ERROR: @@ -550,8 +550,8 @@ _EXECUTORS: typing.Final[ Operation.SUSPEND_COMPLETED: DynamicPublication.op_unsupported, Operation.RESET: DynamicPublication.op_unsupported, Operation.RESET_COMPLETED: DynamicPublication.op_unsupported, - Operation.REMOVE: DynamicPublication.op_remove, - Operation.REMOVE_COMPLETED: DynamicPublication.op_remove_completed, + Operation.DELETE: DynamicPublication.op_remove, + Operation.DELETE_COMPLETED: DynamicPublication.op_remove_completed, Operation.WAIT: DynamicPublication.op_unsupported, Operation.NOP: DynamicPublication.op_nop, Operation.DESTROY_VALIDATOR: DynamicPublication.op_destroy_validator, @@ -575,8 +575,8 @@ _CHECKERS: typing.Final[ Operation.SUSPEND_COMPLETED: DynamicPublication.op_unsupported_checker, Operation.RESET: DynamicPublication.op_unsupported_checker, Operation.RESET_COMPLETED: DynamicPublication.op_unsupported_checker, - Operation.REMOVE: DynamicPublication.op_remove_checker, - Operation.REMOVE_COMPLETED: DynamicPublication.op_remove_completed_checker, + Operation.DELETE: DynamicPublication.op_remove_checker, + Operation.DELETE_COMPLETED: DynamicPublication.op_remove_completed_checker, Operation.WAIT: DynamicPublication.op_unsupported_checker, Operation.NOP: DynamicPublication.op_nop_checker, Operation.DESTROY_VALIDATOR: DynamicPublication.op_destroy_validator_checker, diff --git a/server/src/uds/core/services/generics/dynamic/userservice.py b/server/src/uds/core/services/generics/dynamic/userservice.py index a1c9169ee..d228b2250 100644 --- a/server/src/uds/core/services/generics/dynamic/userservice.py +++ b/server/src/uds/core/services/generics/dynamic/userservice.py @@ -56,7 +56,10 @@ def must_have_vmid(fnc: typing.Callable[[typing.Any], None]) -> typing.Callable[ @functools.wraps(fnc) def wrapper(self: 'DynamicUserService') -> None: if self._vmid == '': - raise exceptions.FatalError(f'No machine id on {self._name} for {fnc}') + # Change current operation to NOP and return + # This is so we do not invoque the "checker" method again an nonexisent vmid + self._queue[0] = types.services.Operation.NOP + return # May not have an vmid on some situations (as first copying disks, and so on) return fnc(self) return wrapper @@ -125,8 +128,8 @@ class DynamicUserService(services.UserService, autoserializable.AutoSerializable _destroy_queue: typing.ClassVar[list[types.services.Operation]] = [ types.services.Operation.STOP, types.services.Operation.STOP_COMPLETED, - types.services.Operation.REMOVE, - types.services.Operation.REMOVE_COMPLETED, + types.services.Operation.DELETE, + types.services.Operation.DELETE_COMPLETED, types.services.Operation.FINISH, ] @@ -623,7 +626,6 @@ class DynamicUserService(services.UserService, autoserializable.AutoSerializable # If does not have vmid, we can finish right now if self._vmid == '': self._set_queue([types.services.Operation.FINISH]) # so we can finish right now - return def op_custom(self, operation: types.services.Operation) -> None: """ @@ -823,8 +825,8 @@ _EXECUTORS: typing.Final[ types.services.Operation.SUSPEND_COMPLETED: DynamicUserService.op_suspend_completed, types.services.Operation.RESET: DynamicUserService.op_reset, types.services.Operation.RESET_COMPLETED: DynamicUserService.op_reset_completed, - types.services.Operation.REMOVE: DynamicUserService.op_remove, - types.services.Operation.REMOVE_COMPLETED: DynamicUserService.op_remove_completed, + types.services.Operation.DELETE: DynamicUserService.op_remove, + types.services.Operation.DELETE_COMPLETED: DynamicUserService.op_remove_completed, types.services.Operation.WAIT: DynamicUserService.op_wait, types.services.Operation.NOP: DynamicUserService.op_nop, types.services.Operation.DESTROY_VALIDATOR: DynamicUserService.op_destroy_validator, @@ -850,8 +852,8 @@ _CHECKERS: typing.Final[ types.services.Operation.SUSPEND_COMPLETED: DynamicUserService.op_suspend_completed_checker, types.services.Operation.RESET: DynamicUserService.op_reset_checker, types.services.Operation.RESET_COMPLETED: DynamicUserService.op_reset_completed_checker, - types.services.Operation.REMOVE: DynamicUserService.op_remove_checker, - types.services.Operation.REMOVE_COMPLETED: DynamicUserService.op_remove_completed_checker, + types.services.Operation.DELETE: DynamicUserService.op_remove_checker, + types.services.Operation.DELETE_COMPLETED: DynamicUserService.op_remove_completed_checker, types.services.Operation.WAIT: DynamicUserService.op_wait_checker, types.services.Operation.NOP: DynamicUserService.op_nop_checker, types.services.Operation.DESTROY_VALIDATOR: DynamicUserService.op_destroy_validator_checker, diff --git a/server/src/uds/core/services/generics/fixed/userservice.py b/server/src/uds/core/services/generics/fixed/userservice.py index 183ba4fc4..13415ea85 100644 --- a/server/src/uds/core/services/generics/fixed/userservice.py +++ b/server/src/uds/core/services/generics/fixed/userservice.py @@ -79,7 +79,7 @@ class FixedUserService(services.UserService, autoserializable.AutoSerializable, Operation.FINISH, ] _destroy_queue: typing.ClassVar[list[Operation]] = [ - Operation.REMOVE, + Operation.DELETE, Operation.SNAPSHOT_RECOVER, Operation.FINISH, ] @@ -511,7 +511,7 @@ _EXECUTORS: typing.Final[ Operation.CREATE: FixedUserService.op_create, Operation.START: FixedUserService.op_start, Operation.STOP: FixedUserService.op_stop, - Operation.REMOVE: FixedUserService.op_remove, + Operation.DELETE: FixedUserService.op_remove, Operation.SNAPSHOT_CREATE: FixedUserService.op_snapshot_create, Operation.SNAPSHOT_RECOVER: FixedUserService.op_snapshot_recover, Operation.PROCESS_TOKEN: FixedUserService.op_process_tocken, @@ -527,7 +527,7 @@ _CHECKERS: typing.Final[ Operation.CREATE: FixedUserService.op_create_checker, Operation.START: FixedUserService.op_start_checker, Operation.STOP: FixedUserService.op_stop_checker, - Operation.REMOVE: FixedUserService.op_removed_checker, + Operation.DELETE: FixedUserService.op_removed_checker, Operation.SNAPSHOT_CREATE: FixedUserService.op_snapshot_create_checker, Operation.SNAPSHOT_RECOVER: FixedUserService.op_snapshot_recover_checker, Operation.PROCESS_TOKEN: FixedUserService.op_process_token_checker, diff --git a/server/src/uds/core/types/services.py b/server/src/uds/core/types/services.py index f31df893f..6aeb8e70b 100644 --- a/server/src/uds/core/types/services.py +++ b/server/src/uds/core/types/services.py @@ -139,8 +139,8 @@ class Operation(enum.IntEnum): SUSPEND_COMPLETED = 1010 RESET = 1011 RESET_COMPLETED = 1012 - REMOVE = 1013 - REMOVE_COMPLETED = 1014 + DELETE = 1013 + DELETE_COMPLETED = 1014 WAIT = 1100 # This is a "wait" operation, used to wait for something to happen NOP = 1101 diff --git a/server/src/uds/services/Proxmox/deployment_linked.py b/server/src/uds/services/Proxmox/deployment_linked.py index c8e8e8f50..daa5128e2 100644 --- a/server/src/uds/services/Proxmox/deployment_linked.py +++ b/server/src/uds/services/Proxmox/deployment_linked.py @@ -83,7 +83,7 @@ class OldOperation(enum.IntEnum): OldOperation.START: types.services.Operation.START, OldOperation.STOP: types.services.Operation.STOP, OldOperation.SHUTDOWN: types.services.Operation.SHUTDOWN, - OldOperation.REMOVE: types.services.Operation.REMOVE, + OldOperation.REMOVE: types.services.Operation.DELETE, OldOperation.WAIT: types.services.Operation.WAIT, OldOperation.ERROR: types.services.Operation.ERROR, OldOperation.FINISH: types.services.Operation.FINISH, diff --git a/server/src/uds/services/Proxmox/publication.py b/server/src/uds/services/Proxmox/publication.py index 2b080024d..37cf3a039 100644 --- a/server/src/uds/services/Proxmox/publication.py +++ b/server/src/uds/services/Proxmox/publication.py @@ -84,8 +84,8 @@ class ProxmoxPublication(DynamicPublication, autoserializable.AutoSerializable): self._queue = ( # If removing [ - types.services.Operation.REMOVE, - types.services.Operation.REMOVE_COMPLETED, + types.services.Operation.DELETE, + types.services.Operation.DELETE_COMPLETED, types.services.Operation.FINISH, ] if _operation == 'd' diff --git a/server/tests/core/services/generics/fixtures.py b/server/tests/core/services/generics/fixtures.py index 5e1126664..596dfb905 100644 --- a/server/tests/core/services/generics/fixtures.py +++ b/server/tests/core/services/generics/fixtures.py @@ -215,8 +215,8 @@ ALL_TESTEABLE_OPERATIONS = [ types.services.Operation.SUSPEND_COMPLETED, types.services.Operation.RESET, types.services.Operation.RESET_COMPLETED, - types.services.Operation.REMOVE, - types.services.Operation.REMOVE_COMPLETED, + types.services.Operation.DELETE, + types.services.Operation.DELETE_COMPLETED, types.services.Operation.WAIT, types.services.Operation.NOP, types.services.Operation.DESTROY_VALIDATOR, @@ -242,8 +242,8 @@ PUB_TESTEABLE_OPERATIONS = [ types.services.Operation.STOP_COMPLETED, # 7 types.services.Operation.SHUTDOWN, # 8 types.services.Operation.SHUTDOWN_COMPLETED, # 9 - types.services.Operation.REMOVE, # 10 - types.services.Operation.REMOVE_COMPLETED, # 11 + types.services.Operation.DELETE, # 10 + types.services.Operation.DELETE_COMPLETED, # 11 types.services.Operation.NOP, # 12 types.services.Operation.DESTROY_VALIDATOR, # 13 types.services.Operation.CUSTOM_1, # 14 diff --git a/server/tests/services/proxmox/test_serialization_publication.py b/server/tests/services/proxmox/test_serialization_publication.py index 36fefa7f8..1c5201e3f 100644 --- a/server/tests/services/proxmox/test_serialization_publication.py +++ b/server/tests/services/proxmox/test_serialization_publication.py @@ -82,8 +82,8 @@ class ProxmoxPublicationSerializationTest(UDSTestCase): self.assertEqual( instance._queue, [ - types.services.Operation.REMOVE, - types.services.Operation.REMOVE_COMPLETED, + types.services.Operation.DELETE, + types.services.Operation.DELETE_COMPLETED, types.services.Operation.FINISH, ], ) diff --git a/server/tests/services/proxmox/test_userservice_linked.py b/server/tests/services/proxmox/test_userservice_linked.py index 2550ea61d..24d2706eb 100644 --- a/server/tests/services/proxmox/test_userservice_linked.py +++ b/server/tests/services/proxmox/test_userservice_linked.py @@ -271,8 +271,8 @@ class TestProxmoxLinkedUserService(UDSTransactionTestCase): self.assertIn(types.services.Operation.STOP, userservice._queue) self.assertIn(types.services.Operation.STOP_COMPLETED, userservice._queue) - self.assertIn(types.services.Operation.REMOVE, userservice._queue) - self.assertIn(types.services.Operation.REMOVE_COMPLETED, userservice._queue) + self.assertIn(types.services.Operation.DELETE, userservice._queue) + self.assertIn(types.services.Operation.DELETE_COMPLETED, userservice._queue) for counter in limited_iterator(lambda: state == types.states.TaskState.RUNNING, limit=128): state = userservice.check_state() diff --git a/server/tests/utils/__init__.py b/server/tests/utils/__init__.py index 89e04781d..910c677af 100644 --- a/server/tests/utils/__init__.py +++ b/server/tests/utils/__init__.py @@ -170,7 +170,7 @@ def search_item_by_attr(lst: list[T], attribute: str, value: typing.Any) -> T: for item in lst: if getattr(item, attribute) == value: return item - raise ValueError(f'Item with id {value} not found in list') + raise ValueError(f'Item with {attribute}=="{value}" not found in list {str(lst)[:100]}') def filter_list_by_attr(lst: list[T], attribute: str, value: typing.Any) -> list[T]: """