From b6945279bc144558b449fda2fb8804be74732837 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Thu, 1 Aug 2024 12:01:07 +0200 Subject: [PATCH] refs #522 remove duplicated initialisation code --- src/cfg/ogagent.cfg | 2 +- .../server/ogAdmClient/__init__.py | 42 +------------------ 2 files changed, 2 insertions(+), 42 deletions(-) diff --git a/src/cfg/ogagent.cfg b/src/cfg/ogagent.cfg index 38f8d86..be977a2 100644 --- a/src/cfg/ogagent.cfg +++ b/src/cfg/ogagent.cfg @@ -23,7 +23,7 @@ log=DEBUG [ogAdmClient] #path=test_modules/server ## this URL will probably be left equal to the other one, but let's see -remote=https://192.168.1.249/opengnsys/rest/__ogAdmClient +remote=https://192.168.2.10/opengnsys/rest log=DEBUG #servidorAdm=192.168.2.1 diff --git a/src/test_modules/server/ogAdmClient/__init__.py b/src/test_modules/server/ogAdmClient/__init__.py index c91f73b..0e7673c 100644 --- a/src/test_modules/server/ogAdmClient/__init__.py +++ b/src/test_modules/server/ogAdmClient/__init__.py @@ -94,8 +94,6 @@ class ogAdmClientWorker(ServerWorker): Sends OGAgent stopping notification to OpenGnsys server """ logger.debug('onDeactivation') - self.REST.sendMessage('stopped', {'mac': self.interface.mac, 'ip': self.interface.ip, - 'ostype': operations.os_type, 'osversion': operations.os_version}) def processClientMessage(self, message, data): logger.debug('Got OpenGnsys message from client: {}, data {}'.format(message, data)) @@ -250,7 +248,7 @@ with open (subprocs_log, 'ab') as fd: ## TODO improve this logging def tomaIPlocal(self): try: self.IPlocal = self.interfaceAdmin ('getIpAddress'); - logger.info (self.IPlocal) + logger.info ('local IP is "{}"'.format (self.IPlocal)) except Exception as e: logger.error (e) logger.error ('No se ha podido recuperar la dirección IP del cliente') @@ -467,7 +465,6 @@ with open (subprocs_log, 'ab') as fd: ## TODO improve this logging """ Sends OGAgent activation notification to OpenGnsys server """ - t = 0 # Count of time # Generate random secret to send on activation self.random = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(self.length)) # Ensure cfg has required configuration variables or an exception will be thrown @@ -485,43 +482,6 @@ with open (subprocs_log, 'ab') as fd: ## TODO improve this logging raise e self.REST = REST(url) - # Get network interfaces until they are active or timeout (5 minutes) - for t in range(0, 300): - try: - # Get the first network interface - self.interface = list(operations.getNetworkInfo())[0] - except Exception as e: - # Wait 1 sec. and retry - logger.warn (e) - time.sleep(1) - finally: - # Exit loop if interface is active - if self.interface: - if t > 0: - logger.debug("Fetch connection data after {} tries".format(t)) - break - # Raise error after timeout - if not self.interface: - raise Exception ('not self.interface') - - # Loop to send initialization message - init_retries = 100 - for t in range(0, init_retries): - try: - self.REST.sendMessage('started', {'mac': self.interface.mac, 'ip': self.interface.ip, - 'secret': self.random, 'ostype': operations.os_type, - 'osversion': operations.os_version, - 'agent_version': VERSION}) - break - except Exception as e: - logger.warn (str (e)) - time.sleep(3) - # Raise error after timeout - if t < init_retries-1: - logger.debug('Successful connection after {} tries'.format(t)) - elif t == init_retries-1: - raise Exception('Initialization error: Cannot connect to remote server') - if (not self.tomaIPlocal()): raise Exception ('Se han generado errores. No se puede continuar la ejecución de este módulo')