From 388cb2644bd87712b53e984d07e72ab3ac1c2866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Mon, 1 Mar 2021 13:07:31 +0100 Subject: [PATCH] fixing up service_multi --- .../PhysicalMachines/service_multi.py | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/server/src/uds/services/PhysicalMachines/service_multi.py b/server/src/uds/services/PhysicalMachines/service_multi.py index 4e90653e6..ad63eae69 100644 --- a/server/src/uds/services/PhysicalMachines/service_multi.py +++ b/server/src/uds/services/PhysicalMachines/service_multi.py @@ -133,21 +133,14 @@ class IPMachinesService(IPServiceBase): for i, ip in enumerate(values['ipList']) if str(ip).strip() ] # Allow duplicates right now - active = {IPServiceBase.getIp(v) for v in values['ipList']} - # self._ips.sort() - # Remove non existing "locked" ips from storage now - skipKey = self.storage.getKey('ips') + # Current stored data, if it exists + d = self.storage.readData('ips') + old_ips = pickle.loads(d) if d and isinstance(d, bytes) else [] + # dissapeared ones + dissapeared = set(old_ips) - set(self._ips) with transaction.atomic(): - for key, data, _ in self.storage.filter(forUpdate=True): - if key == skipKey: # Avoid "ips" key - continue - # If not in current active list of ips, remove it - if data.decode() not in active: - logger.info( - 'IP %s locked but not in active list. Removed', - data.decode(), - ) - self.storage.remove(data.decode()) + for removable in dissapeared: + self.storage.remove(removable.split('~')[0]) self._token = self.token.value.strip() self._port = self.port.value @@ -205,7 +198,8 @@ class IPMachinesService(IPServiceBase): for ip in self._ips: theIP = IPServiceBase.getIp(ip) theMAC = IPServiceBase.getMac(ip) - if self.storage.readData(theIP) is None: + locked = self.storage.getPickle(theIP) + if not locked or locked < consideredFreeTime: if self._port > 0 and self._skipTimeOnFailure > 0 and self.cache.get('port{}'.format(theIP)): continue # The check failed not so long ago, skip it... self.storage.putPickle(theIP, now)