mirror of
https://github.com/dkmstr/openuds.git
synced 2025-01-18 06:03:54 +03:00
Remove last "autoattributes" use.
Will remove the class probably on 5.0, when sure no data is left behind using it (Probably, first will rename it just in case it's needed on some environment can recover it fast, or import conditionally...)
This commit is contained in:
parent
34005c2af3
commit
3d02a99b42
@ -38,9 +38,8 @@ import dns.resolver
|
||||
|
||||
from uds.core import services
|
||||
from uds.core.types.states import State
|
||||
from uds.core.util.auto_attributes import AutoAttributes
|
||||
from uds.core.util import net
|
||||
from uds.core.util import log
|
||||
from uds.core.util import log, autoserializable, auto_attributes
|
||||
|
||||
from .types import HostInfo
|
||||
|
||||
@ -51,19 +50,25 @@ if typing.TYPE_CHECKING:
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class IPMachineDeployed(services.UserService, AutoAttributes):
|
||||
suggested_delay = 10
|
||||
|
||||
# This class is used for serialization of old data
|
||||
class OldIPSerialData(auto_attributes.AutoAttributes):
|
||||
_ip: str
|
||||
_reason: str
|
||||
_state: str
|
||||
|
||||
def __init__(self, environment, **kwargs):
|
||||
AutoAttributes.__init__(self, ip=str, reason=str, state=str)
|
||||
services.UserService.__init__(self, environment, **kwargs)
|
||||
def __init__(self):
|
||||
auto_attributes.AutoAttributes.__init__(self, ip=str, reason=str, state=str)
|
||||
self._ip = ''
|
||||
self._reason = ''
|
||||
self._state = State.FINISHED
|
||||
|
||||
class IPMachineUserService(services.UserService, autoserializable.AutoSerializable):
|
||||
suggested_delay = 10
|
||||
|
||||
_ip = autoserializable.StringField(default='')
|
||||
_reason = autoserializable.StringField(default='')
|
||||
_state = autoserializable.StringField(default=State.FINISHED)
|
||||
|
||||
# Utility overrides for type checking...
|
||||
def service(self) -> 'IPServiceBase':
|
||||
return typing.cast('IPServiceBase', super().service())
|
||||
@ -170,3 +175,18 @@ class IPMachineDeployed(services.UserService, AutoAttributes):
|
||||
|
||||
def cancel(self) -> str:
|
||||
return self.destroy()
|
||||
|
||||
def unmarshal(self, data: bytes) -> None:
|
||||
if autoserializable.is_autoserializable_data(data):
|
||||
return super().unmarshal(data)
|
||||
|
||||
_auto_data = OldIPSerialData()
|
||||
_auto_data.unmarshal(data)
|
||||
|
||||
# Fill own data from restored data
|
||||
self._ip = _auto_data._ip
|
||||
self._reason = _auto_data._reason
|
||||
self._state = _auto_data._state
|
||||
|
||||
# Flag for upgrade
|
||||
self.mark_for_upgrade(True)
|
||||
|
@ -44,7 +44,7 @@ from uds.core.ui import gui
|
||||
from uds.core.util import ensure, log, net
|
||||
from uds.core.util.model import sql_stamp_seconds
|
||||
|
||||
from .deployment import IPMachineDeployed
|
||||
from .deployment import IPMachineUserService
|
||||
from .service_base import IPServiceBase
|
||||
from .types import HostInfo
|
||||
|
||||
@ -148,7 +148,7 @@ class IPMachinesService(IPServiceBase):
|
||||
needs_osmanager = False # If the service needs a s.o. manager (managers are related to agents provided by services itselfs, i.e. virtual machines with agent)
|
||||
must_assign_manually = False # If true, the system can't do an automatic assignation of a deployed user service from this service
|
||||
|
||||
user_service_type = IPMachineDeployed
|
||||
user_service_type = IPMachineUserService
|
||||
|
||||
services_type_provided = types.services.ServiceType.VDI
|
||||
|
||||
@ -331,7 +331,7 @@ class IPMachinesService(IPServiceBase):
|
||||
user: 'models.User',
|
||||
userDeployment: 'services.UserService',
|
||||
) -> str:
|
||||
userservice_instance: IPMachineDeployed = typing.cast(IPMachineDeployed, userDeployment)
|
||||
userservice_instance: IPMachineUserService = typing.cast(IPMachineUserService, userDeployment)
|
||||
host = HostInfo.from_str(assignable_id)
|
||||
|
||||
now = sql_stamp_seconds()
|
||||
|
@ -40,7 +40,7 @@ from uds.core.ui import gui
|
||||
from uds.core.util import net
|
||||
from uds.core import exceptions, types
|
||||
|
||||
from .deployment import IPMachineDeployed
|
||||
from .deployment import IPMachineUserService
|
||||
from .service_base import IPServiceBase
|
||||
from .types import HostInfo
|
||||
|
||||
@ -73,7 +73,7 @@ class IPSingleMachineService(IPServiceBase):
|
||||
needs_osmanager = False # If the service needs a s.o. manager (managers are related to agents provided by services itselfs, i.e. virtual machines with agent)
|
||||
must_assign_manually = False # If true, the system can't do an automatic assignation of a deployed user service from this service
|
||||
|
||||
user_service_type = IPMachineDeployed
|
||||
user_service_type = IPMachineUserService
|
||||
|
||||
services_type_provided = types.services.ServiceType.VDI
|
||||
|
||||
|
@ -0,0 +1,61 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Copyright (c) 2022 Virtual Cable S.L.U.
|
||||
# All rights reserved.
|
||||
#
|
||||
|
||||
"""
|
||||
Author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
import typing
|
||||
|
||||
# We use commit/rollback
|
||||
|
||||
from tests.utils.test import UDSTestCase
|
||||
from uds.core.util import autoserializable
|
||||
from uds.core.environment import Environment
|
||||
from uds.core.managers import crypto
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
from uds.services.PhysicalMachines import provider, deployment
|
||||
|
||||
|
||||
class IPMachineUserServiceSerializationTest(UDSTestCase):
|
||||
def test_marshalling(self):
|
||||
obj = deployment.OldIPSerialData()
|
||||
obj._ip = '1.1.1.1'
|
||||
obj._state = 'state'
|
||||
obj._reason = 'reason'
|
||||
|
||||
def _check_fields(instance: deployment.IPMachineUserService) -> None:
|
||||
self.assertEqual(instance._ip, '1.1.1.1')
|
||||
self.assertEqual(instance._state, 'state')
|
||||
self.assertEqual(instance._reason, 'reason')
|
||||
|
||||
data = obj.marshal()
|
||||
|
||||
instance = deployment.IPMachineUserService(environment=Environment.testing_environment(), service=None)
|
||||
instance.unmarshal(data)
|
||||
|
||||
marshaled_data = instance.marshal()
|
||||
|
||||
# Ensure remarshalled flag is set
|
||||
self.assertTrue(instance.needs_upgrade())
|
||||
instance.mark_for_upgrade(False) # reset flag
|
||||
|
||||
# Ensure fields has been marshalled using new format
|
||||
self.assertTrue(autoserializable.is_autoserializable_data(marshaled_data))
|
||||
|
||||
# Check fields
|
||||
_check_fields(instance)
|
||||
|
||||
# Reunmarshall again and check that remarshalled flag is not set
|
||||
instance = deployment.IPMachineUserService(environment=Environment.testing_environment(), service=None)
|
||||
instance.unmarshal(marshaled_data)
|
||||
self.assertFalse(instance.needs_upgrade())
|
||||
|
||||
# Check fields again
|
||||
_check_fields(instance)
|
Loading…
x
Reference in New Issue
Block a user