mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-22 13:34:04 +03:00
REfactorign "remove" in favor of "delete"
This commit is contained in:
parent
579e1c2a36
commit
7737bbf758
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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'
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
],
|
||||
)
|
||||
|
@ -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()
|
||||
|
@ -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]:
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user