Commit 4ae28aba authored by Robert Schmidt's avatar Robert Schmidt

Custom_Command: add option to fail if returncode is non-zero

parent e3520f95
......@@ -429,6 +429,7 @@ def GetParametersFromXML(action):
elif action == 'Custom_Command':
RAN.node = test.findtext('node')
RAN.command = test.findtext('command')
RAN.command_fail = test.findtext('command_fail') in ['True', 'true', 'Yes', 'yes']
else:
logging.warning(f"unknown action {action} from option-parsing point-of-view")
......@@ -752,6 +753,8 @@ elif re.match('^TesteNB$', mode, re.IGNORECASE) or re.match('^TestUE$', mode, re
elif action == 'Custom_Command':
logging.info(f"Executing custom command")
RAN.CustomCommand(HTML)
if RAN.prematureExit:
CiTestObj.AutoTerminateeNB(HTML,RAN,EPC,CONTAINERS)
elif action == 'Initialize_eNB':
RAN.InitializeeNB(HTML, EPC)
if RAN.prematureExit:
......
......@@ -99,6 +99,7 @@ class RANManagement():
self.cmd_prefix = '' # prefix before {lte,nr}-softmodem
self.node = ''
self.command = ''
self.command_fail = False
#-----------------------------------------------------------
......@@ -259,19 +260,22 @@ class RANManagement():
self.checkBuildeNB(lIpAddr, lUserName, lPassWord, lSourcePath, self.backgroundBuildTestId[int(self.eNB_instance)], HTML)
def CustomCommand(self, HTML):
if self.node == '' or self.node == "localhost":
cmd = cls_cmd.LocalCmd()
else:
cmd = cls_cmd.RemoteCmd(self.node)
cmd = cls_cmd.getConnection(self.node)
ret = cmd.run(self.command)
cmd.close()
logging.debug(f'CustomCommand: {self.command} returnCode: {ret.returncode} output: {ret.stdout}')
html_queue = SimpleQueue()
logging.debug(f'CustomCommand: {self.command} returnCode: {ret.returncode}')
status = 'OK'
if ret.returncode != 0:
html_queue.put(ret.stdout)
message = ''
if ret.returncode != 0 and not self.command_fail:
message = ret.stdout
logging.warning(f'CustomCommand output: {message}')
status = 'Warning'
HTML.CreateHtmlTestRow(self.command, status, 1, html_queue)
if ret.returncode != 0 and self.command_fail:
message = ret.stdout
logging.error(f'CustomCommand failed: output: {message}')
status = 'KO'
self.prematureExit = True
HTML.CreateHtmlTestRowQueue(self.command, status, [message])
def checkBuildeNB(self, lIpAddr, lUserName, lPassWord, lSourcePath, testcaseId, HTML):
HTML.testCase_id=testcaseId
......
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