From 4c4cbc963b99080682ea10c00c31cd7540e8ebd2 Mon Sep 17 00:00:00 2001
From: Raphael Defosseux <raphael.defosseux@eurecom.fr>
Date: Fri, 22 Apr 2022 12:28:04 +0200
Subject: [PATCH] fix(ci): little fixes after migration to new infra:  - Better
 mechanism for qlog cleaning  - Faster attachment check  - html.py is
 confusing for some python3 installation -- renaming it

Signed-off-by: Raphael Defosseux <raphael.defosseux@eurecom.fr>
---
 ci-scripts/cls_log_mgt.py               | 23 ++++++++++++++---------
 ci-scripts/cls_module_ue.py             |  7 ++++---
 ci-scripts/{html.py => cls_oai_html.py} |  0
 ci-scripts/cls_oaicitest.py             |  4 ++--
 ci-scripts/cls_physim.py                |  2 +-
 ci-scripts/cls_physim1.py               |  2 +-
 ci-scripts/main.py                      |  4 ++--
 7 files changed, 24 insertions(+), 18 deletions(-)
 rename ci-scripts/{html.py => cls_oai_html.py} (100%)

diff --git a/ci-scripts/cls_log_mgt.py b/ci-scripts/cls_log_mgt.py
index 905a1055122..e29e9168b70 100644
--- a/ci-scripts/cls_log_mgt.py
+++ b/ci-scripts/cls_log_mgt.py
@@ -64,10 +64,10 @@ class Log_Mgt:
 		if m is not None:
 			return int(m.group(1))
 
-	def __RemoveOldest(self):
+	def __RemoveOldest(self, days):
 		mySSH = sshconnection.SSHConnection()
 		mySSH.open(self.IPAddress, self.Username, self.Password)
-		COMMAND='echo ' + self.Password + ' | sudo -S find ' + self.path + ' -type f -mtime +14 -delete'
+		COMMAND='echo ' + self.Password + ' | sudo -S find ' + self.path + ' -type f -mtime +' +  str(days) + ' -delete'
 		mySSH.command(COMMAND,'\$',20)
 		mySSH.close()
 
@@ -79,13 +79,18 @@ class Log_Mgt:
 
 
 	def LogRotation(self):
-		used_space = self.__CheckUsedSpace() #avail space in target folder
-		if used_space > 80 :
-			logging.debug('\u001B[1;37;41m  Used Disk > 80%, on '  + self.Username+'@'+self.IPAddress + '\u001B[0m')
-			logging.debug('\u001B[1;37;41m  Removing Artifacts older than 14 days \u001B[0m')
-			self.__RemoveOldest()
-		else:
-			logging.debug('Used Disk < 80%, on '  + self.Username+'@'+self.IPAddress +', no cleaning required')
+		doLoop = True
+		nbDays = 14
+		while doLoop and nbDays > 2:
+			used_space = self.__CheckUsedSpace() #avail space in target folder
+			if used_space > 80 :
+				logging.debug('\u001B[1;37;41m  Used Disk (' + str(used_space) + '%) > 80%, on '  + self.Username+'@'+self.IPAddress + '\u001B[0m')
+				logging.debug('\u001B[1;37;41m  Removing Artifacts older than ' + nbDays + ' days \u001B[0m')
+				self.__RemoveOldest(nbDays)
+				nbDays -= 1
+			else:
+				logging.debug('Used Disk (' + str(used_space) + '%) < 80%, on '  + self.Username+'@'+self.IPAddress +', no cleaning required')
+				doLoop = False
 
 
 			
diff --git a/ci-scripts/cls_module_ue.py b/ci-scripts/cls_module_ue.py
index fb107007980..dcf75a34fcd 100644
--- a/ci-scripts/cls_module_ue.py
+++ b/ci-scripts/cls_module_ue.py
@@ -107,14 +107,15 @@ class Module_UE:
 	def GetModuleIPAddress(self):
 		HOST=self.HostUsername+'@'+self.HostIPAddress
 		response= []
-		tentative = 3 
+		tentative = 8
 		while (len(response)==0) and (tentative>0):
 			COMMAND="ip a show dev " + self.UENetwork + " | grep --colour=never inet | grep " + self.UENetwork
-			logging.debug(COMMAND)
+			if tentative == 8:
+				logging.debug(COMMAND)
 			ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
 			response = ssh.stdout.readlines()
 			tentative-=1
-			time.sleep(10)
+			time.sleep(2)
 		if (tentative==0) and (len(response)==0):
 			logging.debug('\u001B[1;37;41m Module IP Address Not Found! Time expired \u001B[0m')
 			return -1
diff --git a/ci-scripts/html.py b/ci-scripts/cls_oai_html.py
similarity index 100%
rename from ci-scripts/html.py
rename to ci-scripts/cls_oai_html.py
diff --git a/ci-scripts/cls_oaicitest.py b/ci-scripts/cls_oaicitest.py
index 33910f1f9bd..9d5ae840387 100644
--- a/ci-scripts/cls_oaicitest.py
+++ b/ci-scripts/cls_oaicitest.py
@@ -439,7 +439,7 @@ class OaiCiTest():
 					while cnt < 4:
 						Module_UE.Command("wup")
 						logging.debug("Waiting for IP address to be assigned")
-						time.sleep(20)
+						time.sleep(5)
 						logging.debug("Retrieve IP address")
 						status=Module_UE.GetModuleIPAddress()
 						if status==0:
@@ -1111,7 +1111,7 @@ class OaiCiTest():
 			while cnt < 4:
 				Module_UE.Command("wup")
 				logging.debug("Waiting for IP address to be assigned")
-				time.sleep(20)
+				time.sleep(5)
 				logging.debug("Retrieve IP address")
 				status=Module_UE.GetModuleIPAddress()
 				if status==0:
diff --git a/ci-scripts/cls_physim.py b/ci-scripts/cls_physim.py
index 33792f6ca4c..ecd8f63af12 100644
--- a/ci-scripts/cls_physim.py
+++ b/ci-scripts/cls_physim.py
@@ -32,7 +32,7 @@ import logging
 #to create a SSH object locally in the methods
 import sshconnection
 #to update the HTML object
-import html
+import cls_oai_html
 from multiprocessing import SimpleQueue
 #for log folder maintenance
 import os
diff --git a/ci-scripts/cls_physim1.py b/ci-scripts/cls_physim1.py
index 54329790cd9..3907fc2a34d 100644
--- a/ci-scripts/cls_physim1.py
+++ b/ci-scripts/cls_physim1.py
@@ -33,7 +33,7 @@
 #-----------------------------------------------------------
 import logging
 import sshconnection as SSH
-import html
+import cls_oai_html
 import os
 import re
 import time
diff --git a/ci-scripts/main.py b/ci-scripts/main.py
index 65f9fbb0daf..03947bdfc96 100644
--- a/ci-scripts/main.py
+++ b/ci-scripts/main.py
@@ -49,7 +49,7 @@ import cls_physim1          #class PhySim for physical simulators deploy and run
 import sshconnection 
 import epc
 import ran
-import html
+import cls_oai_html
 
 
 #-----------------------------------------------------------
@@ -518,7 +518,7 @@ CiTestObj = cls_oaicitest.OaiCiTest()
 SSH = sshconnection.SSHConnection()
 EPC = epc.EPCManagement()
 RAN = ran.RANManagement()
-HTML = html.HTMLManagement()
+HTML = cls_oai_html.HTMLManagement()
 CONTAINERS = cls_containerize.Containerize()
 SCA = cls_static_code_analysis.StaticCodeAnalysis()
 PHYSIM = cls_physim1.PhySim()
-- 
GitLab