Commit 50730831 authored by Raphael Defosseux's avatar Raphael Defosseux

CI: fixing the detection for the end of execution on pods

Signed-off-by: default avatarRaphael Defosseux <raphael.defosseux@eurecom.fr>
parent 3e31d9e7
...@@ -154,6 +154,7 @@ class PhySim: ...@@ -154,6 +154,7 @@ class PhySim:
sys.exit(-1) sys.exit(-1)
else: else:
logging.debug('\u001B[1m Podman Login to OC Cluster Registry Successfully\u001B[0m') logging.debug('\u001B[1m Podman Login to OC Cluster Registry Successfully\u001B[0m')
time.sleep(2)
mySSH.command('oc create -f openshift/oai-physim-image-stream.yml', '\$', 6) mySSH.command('oc create -f openshift/oai-physim-image-stream.yml', '\$', 6)
if mySSH.getBefore().count('(AlreadyExists):') == 0 and mySSH.getBefore().count('created') == 0: if mySSH.getBefore().count('(AlreadyExists):') == 0 and mySSH.getBefore().count('created') == 0:
logging.error(f'\u001B[1m Image Stream "oai-physim" Creation Failed on OC Cluster {ocProjectName}\u001B[0m') logging.error(f'\u001B[1m Image Stream "oai-physim" Creation Failed on OC Cluster {ocProjectName}\u001B[0m')
...@@ -161,7 +162,9 @@ class PhySim: ...@@ -161,7 +162,9 @@ class PhySim:
sys.exit(-1) sys.exit(-1)
else: else:
logging.debug(f'\u001B[1m Image Stream "oai-physim" created on OC project {ocProjectName}\u001B[0m') logging.debug(f'\u001B[1m Image Stream "oai-physim" created on OC project {ocProjectName}\u001B[0m')
time.sleep(2)
mySSH.command(f'sudo podman tag oai-physim:{imageTag} default-route-openshift-image-registry.apps.5glab.nsa.eurecom.fr/{self.OCProjectName}/oai-physim:{imageTag}', '\$', 6) mySSH.command(f'sudo podman tag oai-physim:{imageTag} default-route-openshift-image-registry.apps.5glab.nsa.eurecom.fr/{self.OCProjectName}/oai-physim:{imageTag}', '\$', 6)
time.sleep(2)
mySSH.command(f'sudo podman push default-route-openshift-image-registry.apps.5glab.nsa.eurecom.fr/{self.OCProjectName}/oai-physim:{imageTag} --tls-verify=false', '\$', 30) mySSH.command(f'sudo podman push default-route-openshift-image-registry.apps.5glab.nsa.eurecom.fr/{self.OCProjectName}/oai-physim:{imageTag} --tls-verify=false', '\$', 30)
if mySSH.getBefore().count('Storing signatures') == 0: if mySSH.getBefore().count('Storing signatures') == 0:
logging.error('\u001B[1m Image "oai-physim" push to OC Cluster Registry Failed\u001B[0m') logging.error('\u001B[1m Image "oai-physim" push to OC Cluster Registry Failed\u001B[0m')
...@@ -171,6 +174,7 @@ class PhySim: ...@@ -171,6 +174,7 @@ class PhySim:
logging.debug('\u001B[1m Image "oai-physim" push to OC Cluster Registry Successfully\u001B[0m') logging.debug('\u001B[1m Image "oai-physim" push to OC Cluster Registry Successfully\u001B[0m')
# Using helm charts deployment # Using helm charts deployment
time.sleep(5)
mySSH.command(f'sed -i -e "s#TAG#{imageTag}#g" ./charts/physims/values.yaml', '\$', 6) mySSH.command(f'sed -i -e "s#TAG#{imageTag}#g" ./charts/physims/values.yaml', '\$', 6)
mySSH.command('helm install physim ./charts/physims/ | tee -a cmake_targets/log/physim_helm_summary.txt 2>&1', '\$', 6) mySSH.command('helm install physim ./charts/physims/ | tee -a cmake_targets/log/physim_helm_summary.txt 2>&1', '\$', 6)
if mySSH.getBefore().count('STATUS: deployed') == 0: if mySSH.getBefore().count('STATUS: deployed') == 0:
...@@ -203,11 +207,10 @@ class PhySim: ...@@ -203,11 +207,10 @@ class PhySim:
# doing a deep copy! # doing a deep copy!
tmpPodNames = podNames.copy() tmpPodNames = podNames.copy()
while(count < 28 and isFinished == False): while(count < 28 and isFinished == False):
time.sleep(58) time.sleep(60)
for podName in tmpPodNames: for podName in tmpPodNames:
mySSH.command(f'oc logs --tail=1 {podName} 2>&1', '\$', 6, silent=True, resync=True) mySSH.command2(f'oc logs --tail=1 {podName} 2>&1', 6, silent=True)
time.sleep(2) if mySSH.cmd2Results.count('FINISHED') != 0:
if mySSH.getBefore().count('FINISHED') != 0:
logging.debug(podName + ' is finished') logging.debug(podName + ' is finished')
tmpPodNames.remove(podName) tmpPodNames.remove(podName)
if not tmpPodNames: if not tmpPodNames:
......
...@@ -35,6 +35,7 @@ import pexpect # pexpect ...@@ -35,6 +35,7 @@ import pexpect # pexpect
import logging import logging
import time # sleep import time # sleep
import re import re
import subprocess
import sys import sys
#----------------------------------------------------------- #-----------------------------------------------------------
...@@ -44,6 +45,9 @@ class SSHConnection(): ...@@ -44,6 +45,9 @@ class SSHConnection():
def __init__(self): def __init__(self):
self.ssh = '' self.ssh = ''
self.picocom_closure = False self.picocom_closure = False
self.ipaddress = ''
self.username = ''
self.cmd2Results = ''
def disablePicocomClosure(self): def disablePicocomClosure(self):
self.picocom_closure = False self.picocom_closure = False
...@@ -98,6 +102,8 @@ class SSHConnection(): ...@@ -98,6 +102,8 @@ class SSHConnection():
pass pass
else: else:
sys.exit('SSH Connection Failed') sys.exit('SSH Connection Failed')
self.ipaddress = ipaddress
self.username = username
...@@ -146,10 +152,23 @@ class SSHConnection(): ...@@ -146,10 +152,23 @@ class SSHConnection():
logging.debug('Expected Line : ' + expectedline) logging.debug('Expected Line : ' + expectedline)
sys.exit(self.sshresponse) sys.exit(self.sshresponse)
def command2(self, commandline, timeout, silent=False):
if not silent:
logging.debug(commandline)
self.cmd2Results = ''
myHost = self.username + '@' + self.ipaddress
# CAUTION: THIS METHOD IMPLIES THAT THERE ARE VALID SSH KEYS
# BETWEEN THE PYTHON EXECUTOR NODE AND THE REMOTE HOST
# OTHERWISE IT WON'T WORK
lSsh = subprocess.Popen(["ssh", "%s" % myHost, commandline],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
self.cmd2Results = str(lSsh.stdout.readlines())
def close(self): def close(self):
self.ssh.timeout = 5 self.ssh.timeout = 5
self.ssh.sendline('exit') self.ssh.sendline('exit')
self.sshresponse = self.ssh.expect([pexpect.EOF, pexpect.TIMEOUT]) self.sshresponse = self.ssh.expect([pexpect.EOF, pexpect.TIMEOUT])
self.ipaddress = ''
self.username = ''
if self.sshresponse == 0: if self.sshresponse == 0:
pass pass
elif self.sshresponse == 1: elif self.sshresponse == 1:
......
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