From 293cb129edfa088a6a77f8d505d9654c41ffea15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez?= Date: Tue, 17 Dec 2019 12:26:55 +0100 Subject: [PATCH] Fixing actor issues --- actor/src/udsactor/client.py | 12 ++++++------ actor/src/udsactor/http/clients_pool.py | 4 +++- actor/src/udsactor/log.py | 4 ++-- actor/src/udsactor/service.py | 23 ++++++++++++++--------- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/actor/src/udsactor/client.py b/actor/src/udsactor/client.py index 0c7adc5db..22f85d7f4 100644 --- a/actor/src/udsactor/client.py +++ b/actor/src/udsactor/client.py @@ -72,7 +72,7 @@ class UDSClientQApp(QApplication): self._app.start() self._initialized = True - def end(self, sessionManager=None) -> None: + def end(self, sessionManager=None) -> None: # pylint: disable=unused-argument if not self._initialized: return @@ -87,12 +87,12 @@ class UDSClientQApp(QApplication): QMessageBox.information(None, 'Message', message) -class UDSActorClient(threading.Thread): +class UDSActorClient(threading.Thread): # pylint: disable=too-many-instance-attributes _running: bool _forceLogoff: bool _qApp: UDSClientQApp _listener: client.HTTPServerThread - _loginInfo: typing.Optional[types.LoginResultInfoType] + _loginInfo: typing.Optional['types.LoginResultInfoType'] _notified: bool _sessionStartTime: datetime.datetime api: rest.UDSClientApi @@ -118,7 +118,7 @@ class UDSActorClient(threading.Thread): self.stop() def checkDeadLine(self): - if self._userInfo is None or not self._userInfo.dead_line: # No deadline check + if self._loginInfo is None or not self._loginInfo.dead_line: # No deadline check return remainingTime = self._loginInfo.dead_line - (datetime.datetime.now() - self._sessionStartTime).total_seconds() @@ -135,7 +135,7 @@ class UDSActorClient(threading.Thread): self._forceLogoff = True def checkIdle(self): - if self._userInfo is None or not self._userInfo.max_idle: # No idle check + if self._loginInfo is None or not self._loginInfo.max_idle: # No idle check return idleTime = platform.operations.getIdleDuration() @@ -147,7 +147,7 @@ class UDSActorClient(threading.Thread): logger.debug('User has been idle for: {}'.format(idleTime)) - if not self._idleNotified and remainingTime < 120: # With two minutes, show a warning message + if not self._notified and remainingTime < 120: # With two minutes, show a warning message self._notified = True self._showMessage('You have been idle for too long. The session will end if you don\'t resume operations.') diff --git a/actor/src/udsactor/http/clients_pool.py b/actor/src/udsactor/http/clients_pool.py index b0c72ebba..e554e23bb 100644 --- a/actor/src/udsactor/http/clients_pool.py +++ b/actor/src/udsactor/http/clients_pool.py @@ -78,8 +78,10 @@ class UDSActorClientPool: self._post('message', {'message': message}) def ping(self) -> bool: + if not self._clientUrl: + return True # No clients, ping ok self._post('ping', {}, timeout=1) - return bool(self._clientUrl) # if no clients available + return bool(self._clientUrl) # There was clients, but they are now lost!!! def screenshot(self) -> typing.Optional[str]: # Screenshot are returned as base64 for r in self._post('screenshot', {}, timeout=3): diff --git a/actor/src/udsactor/log.py b/actor/src/udsactor/log.py index 2770561e8..3fa682a9d 100644 --- a/actor/src/udsactor/log.py +++ b/actor/src/udsactor/log.py @@ -78,9 +78,9 @@ class Logger: return msg = message % args - # If remote logger is available, notify message to it + # If remote logger is available, notify message to it (except DEBUG messages OFC) try: - if self.remoteLogger: + if self.remoteLogger and level <= DEBUG: self.remoteLogger.log(self.own_token, level, msg) except Exception as e: self.localLogger.log(DEBUG, 'Log to broker: {}'.format(e)) diff --git a/actor/src/udsactor/service.py b/actor/src/udsactor/service.py index 7f72de690..3ae9bc070 100644 --- a/actor/src/udsactor/service.py +++ b/actor/src/udsactor/service.py @@ -138,12 +138,15 @@ class CommonService: # pylint: disable=too-many-instance-attributes if srvInterface: # Rery while RESTConnectionError (that is, cannot connect) counter = 8 + logged = False while self._isAlive: counter -= 1 try: self._certificate = self._api.ready(self._cfg.own_token, self._secret, srvInterface.ip, rest.LISTEN_PORT) except rest.RESTConnectionError as e: - logger.info('Error connecting with UDS Broker') + if not logged: # Only log connection problems ONCE + logged = True + logger.error('Error connecting with UDS Broker') self.doWait(5000) continue except Exception as e: @@ -165,7 +168,7 @@ class CommonService: # pylint: disable=too-many-instance-attributes self._cfg = self._cfg._replace(config=self._cfg.config._replace(os=None), data=None) platform.store.writeConfig(self._cfg) - logger.debug('Done setReady') + logger.info('Service ready') self._startHttpServer() def configureMachine(self) -> bool: @@ -325,14 +328,16 @@ class CommonService: # pylint: disable=too-many-instance-attributes self.reboot() def loop(self): - # Main common luop + # Main common loop + try: + # Checks if ips has changed + self.checkIpsChanged() - # Checks if ips has changed - self.checkIpsChanged() - - # Now check if every registered client is already there (if logged in OFC) - if self._loggedIn and self._clientsPool.ping(): - self.logout('client_unavailable') + # Now check if every registered client is already there (if logged in OFC) + if self._loggedIn and not self._clientsPool.ping(): + self.logout('client_unavailable') + except Exception as e: + logger.error('Exception on main service loop: %s', e) # ****************************************************** # Methods that can be overriden by linux & windows Actor