Commit 78f04b80 authored by hardy's avatar hardy

adding features to UE mgt

parent d534142b
......@@ -2,9 +2,12 @@ idefix:
ID: idefix
State : enabled
Kind : quectel
Process : quectel-CM
Process :
Name : quectel-CM
Cmd : /home/oaicicd/quectel-CM/quectel-CM -s oai.ipv4 -4
WakeupScript : ci_ctl_qtel.py /dev/ttyUSB2 wup
DetachScript : ci_ctl_qtel.py /dev/ttyUSB2 detach
PLMN : 22201
UENetwork : wwan0
HostIPAddress : 192.168.18.188
HostUsername : oaicicd
......
......@@ -66,39 +66,24 @@ class Module_UE:
#-----------------$
#this method checks if the specified Process is running on the server hosting the module
def CheckIsModule(self):
#if not it will be started
def CheckCMProcess(self):
HOST=self.HostIPAddress
COMMAND="ps aux | grep " + self.Process + " | grep -v grep "
COMMAND="ps aux | grep " + self.Process['Name'] + " | grep -v grep "
logging.debug(COMMAND)
ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
result = ssh.stdout.readlines()
if len(result)!=0:
logging.debug(self.Process + " process found")
logging.debug(self.Process['Name'] + " process found")
return True
else:
logging.debug(self.Process + " process NOT found")
logging.debug(self.Process['Name'] + " process NOT found")
logging.debug('Starting ' + self.Process['Name'])
logging.debug(self.Process['Cmd'])
ssh = subprocess.Popen(["ssh", "%s" % HOST, self.Process['Cmd']],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
return False
#Wakeup/Detach can probably be improved with encapsulation of the command such def Command(self, command)
#this method wakes up the module by calling the specified python script
# def WakeUp(self):
# mySSH = sshconnection.SSHConnection()
# mySSH.open(self.HostIPAddress, self.HostUsername, self.HostPassword)
# mySSH.command('echo ' + self.HostPassword + ' | sudo -S python3 ' + self.WakeupScript + ' ','\$',5)
# time.sleep(5)
# logging.debug("Module wake-up")
# mySSH.close()
#this method detaches the module by calling the specified python script
# def Detach(self):
# mySSH = sshconnection.SSHConnection()
# mySSH.open(self.HostIPAddress, self.HostUsername, self.HostPassword)
# mySSH.command('echo ' + self.HostPassword + ' | sudo -S python3 ' + self.DetachScript + ' ','\$',5)
# time.sleep(5)
# logging.debug("Module detach")
# mySSH.close()
#tentative: generic command function
#Generic command function, using function pointers dictionary
def Command(self,cmd):
mySSH = sshconnection.SSHConnection()
mySSH.open(self.HostIPAddress, self.HostUsername, self.HostPassword)
......@@ -111,11 +96,18 @@ class Module_UE:
#this method retrieves the Module IP address (not the Host IP address)
def GetModuleIPAddress(self):
HOST=self.HostIPAddress
COMMAND="ip a show dev " + self.UENetwork + " | grep inet | grep " + self.UENetwork
logging.debug(COMMAND)
ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
response = ssh.stdout.readlines()
if len(response)!=0:
response= []
tentative = 10
while (len(response)==0) and (tentative>0):
COMMAND="ip a show dev " + self.UENetwork + " | grep inet | grep " + self.UENetwork
logging.debug(COMMAND)
ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
response = ssh.stdout.readlines()
tentative-=1
sleep(10)
if (tentative==0) and (len(response)==0):
logging.debug('\u001B[1;37;41m Module IP Address Not Found! Time expired \u001B[0m')
else #check response
result = re.search('inet (?P<moduleipaddress>[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)', response[0].decode("utf-8") )
if result is not None:
if result.group('moduleipaddress') is not None:
......@@ -123,10 +115,6 @@ class Module_UE:
logging.debug('\u001B[1mUE Module IP Address is ' + self.UEIPAddress + '\u001B[0m')
else:
logging.debug('\u001B[1;37;41m Module IP Address Not Found! \u001B[0m')
else:
logging.debug('\u001B[1;37;41m Module IP Address Not Found! \u001B[0m')
else:
logging.debug('\u001B[1;37;41m Module IP Address Not Found! \u001B[0m')
......
......@@ -386,7 +386,7 @@ class OaiCiTest():
else: #if an ID is specified, it is a module from the yaml infrastructure file
#RH
Module_UE = cls_module_ue.Module_UE(InfraUE.ci_ue_infra[self.ue_id])
is_module=Module_UE.CheckIsModule()
is_module=Module_UE.CheckCMProcess()
if is_module:
#Module_UE.WakeUp()
Module_UE.Command("wup")
......@@ -1074,7 +1074,7 @@ class OaiCiTest():
cnt += 1
else:#if an ID is specified, it is a module from the yaml infrastructure file
Module_UE = cls_module_ue.Module_UE(InfraUE.ci_ue_infra[self.ue_id])
is_module=Module_UE.CheckIsModule()
is_module=Module_UE.CheckCMProcess()
if is_module:
#Module_UE.Detach()
Module_UE.Command("detach")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment