From 97e5ff1b6ab41c199e447cc3cd2a2f5b9ca87e34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Mon, 2 Sep 2019 10:17:50 +0200 Subject: [PATCH] fixed initialization order for IPMachinesDeployed --- server/src/uds/core/managers/user_service.py | 1 + .../src/uds/core/services/user_deployment.py | 4 +-- server/src/uds/core/util/auto_attributes.py | 26 +++++++++++-------- .../PhysicalMachines/IPMachineDeployed.py | 13 ++++++---- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/server/src/uds/core/managers/user_service.py b/server/src/uds/core/managers/user_service.py index 67421aef..d2764643 100644 --- a/server/src/uds/core/managers/user_service.py +++ b/server/src/uds/core/managers/user_service.py @@ -679,6 +679,7 @@ class UserServiceManager: userServiceInstance = userService.getInstance() ip = userServiceInstance.getIp() userService.logIP(ip) # Update known ip + logger.debug('IP: %s', ip) if self.checkUuid(userService) is False: # The service is not the expected one serviceNotReadyCode = 0x0004 diff --git a/server/src/uds/core/services/user_deployment.py b/server/src/uds/core/services/user_deployment.py index 59fe4596..7d57d777 100644 --- a/server/src/uds/core/services/user_deployment.py +++ b/server/src/uds/core/services/user_deployment.py @@ -382,7 +382,7 @@ class UserDeployment(Environmentable, Serializable): # pylint: disable=too-many to the core. Take that into account and handle exceptions inside this method. """ - raise NotImplementedError('Base deploy for cache invoked! for class {0}'.format(self.__class__.__name__)) + raise Exception('Base deploy for cache invoked! for class {0}'.format(self.__class__.__name__)) def deployForUser(self, user: 'User') -> str: """ @@ -573,8 +573,8 @@ class UserDeployment(Environmentable, Serializable): # pylint: disable=too-many """ This method is invoked for "reset" an user service This method is not intended to be a task right now, (so its one step method) + base method does nothing """ - raise NotImplementedError('reset method for class {0} not provided!'.format(self.__class__.__name__)) def __str__(self): """ diff --git a/server/src/uds/core/util/auto_attributes.py b/server/src/uds/core/util/auto_attributes.py index b958402a..45875ddd 100644 --- a/server/src/uds/core/util/auto_attributes.py +++ b/server/src/uds/core/util/auto_attributes.py @@ -64,7 +64,6 @@ class Attribute: self._value = self._type(value) -# noinspection PyMissingConstructor class AutoAttributes(Serializable): """ Easy creation of attributes to marshal & unmarshal at modules @@ -74,21 +73,21 @@ class AutoAttributes(Serializable): Access attrs as "self._attr1, self._attr2" """ - _dict: typing.Dict + attrs: typing.Dict def __init__(self, **kwargs): super().__init__() - self.dict = {} + self.attrs = {} self.declare(**kwargs) def __getattribute__(self, name): - if name.startswith('_') and name[1:] in self.dict: - return self.dict[name[1:]].getValue() + if name.startswith('_') and name[1:] in self.attrs: + return self.attrs[name[1:]].getValue() return object.__getattribute__(self, name) def __setattr__(self, name, value): - if name.startswith('_') and name[1:] in self.dict: - self.dict[name[1:]].setValue(value) + if name.startswith('_') and name[1:] in self.attrs: + self.attrs[name[1:]].setValue(value) else: object.__setattr__(self, name, value) @@ -96,10 +95,12 @@ class AutoAttributes(Serializable): d = {} for key, typ in kwargs.items(): d[key] = Attribute(typ) - self.dict = d + self.attrs = d def marshal(self) -> bytes: - return typing.cast(bytes, encoders.encode(b'\2'.join([b'%s\1%s' % (k.encode('utf8'), pickle.dumps(v, protocol=0)) for k, v in self.dict.items()]), 'bz2')) + for k, v in self.attrs.items(): + logger.debug('Marshall Autoattributes: %s=%s', k, v.getValue()) + return typing.cast(bytes, encoders.encode(b'\2'.join([b'%s\1%s' % (k.encode('utf8'), pickle.dumps(v, protocol=0)) for k, v in self.attrs.items()]), 'bz2')) def unmarshal(self, data: bytes): if not data: # Can be empty @@ -113,10 +114,13 @@ class AutoAttributes(Serializable): for pair in data.split(b'\2'): k, v = pair.split(b'\1') # logger.debug('k: %s --- v: %s', k, v) - self.dict[k.decode('utf8')] = pickle.loads(v) + self.attrs[k.decode('utf8')] = pickle.loads(v) + + for k, v in self.attrs.items(): + logger.debug('Marshall Autoattributes: %s=%s', k, v.getValue()) def __str__(self): str_ = '' diff --git a/server/src/uds/services/PhysicalMachines/IPMachineDeployed.py b/server/src/uds/services/PhysicalMachines/IPMachineDeployed.py index 4fb3dddf..bc9fd044 100644 --- a/server/src/uds/services/PhysicalMachines/IPMachineDeployed.py +++ b/server/src/uds/services/PhysicalMachines/IPMachineDeployed.py @@ -30,27 +30,30 @@ """ @author: Adolfo Gómez, dkmaster at dkmon dot com """ -from __future__ import unicode_literals +import logging from django.utils.translation import ugettext_lazy as _ from uds.core import services from uds.core.util.state import State from uds.core.util.auto_attributes import AutoAttributes -import logging logger = logging.getLogger(__name__) -class IPMachineDeployed(AutoAttributes, services.UserDeployment): +class IPMachineDeployed(services.UserDeployment, AutoAttributes): suggestedTime = 10 + _ip: str + _reason: str + _state: str + def __init__(self, environment, **kwargs): AutoAttributes.__init__(self, ip=str, reason=str, state=str) services.UserDeployment.__init__(self, environment, **kwargs) self._state = State.FINISHED def setIp(self, ip): - logger.debug('Setting IP to %s (ignored)' % ip) + logger.debug('Setting IP to %s (ignored)', ip) def getIp(self): return self._ip.split('~')[0] @@ -78,7 +81,7 @@ class IPMachineDeployed(AutoAttributes, services.UserDeployment): return self._state def deployForUser(self, user): - logger.debug("Starting deploy of {0} for user {1}".format(self._ip, user)) + logger.debug("Starting deploy of %s for user %s", self._ip, user) return self.__deploy() def checkState(self):