1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-21 18:03:54 +03:00

Removed not needed "new format" flag

This commit is contained in:
Adolfo Gómez García 2024-05-04 22:08:33 +02:00
parent 0570a1ae27
commit 7b5e87dd15
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23
3 changed files with 0 additions and 28 deletions

View File

@ -89,8 +89,6 @@ class DynamicUserService(services.UserService, autoserializable.AutoSerializable
_reason = autoserializable.StringField(default='')
_queue = autoserializable.ListField[types.services.Operation]() # Default is empty list
_is_flagged_for_destroy = autoserializable.BoolField(default=False)
# In order to allow migrating from old data, we will mark if the _queue has our format or the old one
_queue_has_new_format = autoserializable.BoolField(default=False)
# Extra info, not serializable, to keep information in case of exception and debug it
_error_debug_info: typing.Optional[str] = None
@ -185,10 +183,6 @@ class DynamicUserService(services.UserService, autoserializable.AutoSerializable
There is almos not penalty on keeping this here, as it's only an small check
We also could have used marshal/unmarshal, but this is more clear and easy to maintain
"""
if self._queue_has_new_format is False:
self.migrate_old_queue()
self._queue_has_new_format = True
if not self._queue:
return types.services.Operation.FINISH
@ -201,7 +195,6 @@ class DynamicUserService(services.UserService, autoserializable.AutoSerializable
Ensures that we mark it as new format
"""
self._queue = queue
self._queue_has_new_format = True
@typing.final
def _generate_name(self) -> str:
@ -802,13 +795,6 @@ class DynamicUserService(services.UserService, autoserializable.AutoSerializable
# ERROR, FINISH and UNKNOWN are not here, as they are final states not needing to be checked
def migrate_old_queue(self) -> None:
"""
If format has to be converted, override this method and do the conversion here
Remember to replace self_queue with the new one
"""
pass
@staticmethod
def _op2str(op: types.services.Operation) -> str:
return op.name

View File

@ -171,8 +171,6 @@ class ProxmoxUserserviceLinked(DynamicUserService):
self._queue = [
OldOperation.from_int(i).to_operation() for i in pickle.loads(vals[7])
] # nosec: controled data
# Also, mark as it is using new queue format
self._queue_has_new_format = True
self.mark_for_upgrade() # Flag so manager can save it again with new format
@ -238,9 +236,3 @@ class ProxmoxUserserviceLinked(DynamicUserService):
UserServiceManager().send_script(self.db_obj(), script)
except Exception as e:
logger.info('Exception sending loggin to %s: %s', self.db_obj(), e)
def migrate_old_queue(self) -> None:
"""
Migrates the old queue to the new one
"""
self._queue = [OldOperation.from_int(i).to_operation() for i in self._queue]

View File

@ -135,12 +135,8 @@ class ProxmoxDeploymentSerializationTest(UDSTransactionTestCase):
instance = _create_instance(SERIALIZED_DEPLOYMENT_DATA[LAST_VERSION])
self.assertEqual(instance._queue, TEST_QUEUE_NEW)
# Ensure that has been imported already
self.assertEqual(instance._queue_has_new_format, True)
# Now, access current operation, that will trigger the upgrade
instance._current_op()
self.assertEqual(instance._queue_has_new_format, True)
# And essure quee is as new format should be
self.assertEqual(instance._queue, TEST_QUEUE_NEW)
@ -156,7 +152,6 @@ class ProxmoxDeploymentSerializationTest(UDSTransactionTestCase):
instance._queue,
TEST_QUEUE_NEW,
)
self.assertEqual(instance._queue_has_new_format, True)
# Append something remarshall and check
instance._queue.insert(0, types.services.Operation.RESET)
@ -166,7 +161,6 @@ class ProxmoxDeploymentSerializationTest(UDSTransactionTestCase):
instance._queue,
[types.services.Operation.RESET] + TEST_QUEUE_NEW,
)
self.assertEqual(instance._queue_has_new_format, True)
def test_autoserialization_fields(self) -> None:
# This test is designed to ensure that all fields are autoserializable