Commit 76ed14e7 authored by Raphael Defosseux's avatar Raphael Defosseux

chore(ci): using pyshark live-capture instead of launching a bg tshark

Signed-off-by: default avatarRaphael Defosseux <raphael.defosseux@eurecom.fr>
parent 63124fc4
...@@ -38,6 +38,8 @@ import os ...@@ -38,6 +38,8 @@ import os
import shutil import shutil
import subprocess import subprocess
import time import time
import pyshark
import threading
from multiprocessing import Process, Lock, SimpleQueue from multiprocessing import Process, Lock, SimpleQueue
from zipfile import ZipFile from zipfile import ZipFile
...@@ -345,7 +347,7 @@ class Containerize(): ...@@ -345,7 +347,7 @@ class Containerize():
self.dockerfileprefix = '.rhel8.2' self.dockerfileprefix = '.rhel8.2'
self.cliBuildOptions = '--no-cache --disable-compression' self.cliBuildOptions = '--no-cache --disable-compression'
# we always build the ran-build image with all targets # we always build the ran-build image with all targets
imageNames = [('ran-build', 'build')] imageNames = [('ran-build', 'build')]
result = re.search('eNB', self.imageKind) result = re.search('eNB', self.imageKind)
# Creating a tupple with the imageName and the DockerFile prefix pattern on obelix # Creating a tupple with the imageName and the DockerFile prefix pattern on obelix
...@@ -739,8 +741,7 @@ class Containerize(): ...@@ -739,8 +741,7 @@ class Containerize():
mySSH.command(cmd, '\$', 5) mySSH.command(cmd, '\$', 5)
response = mySSH.getBefore() response = mySSH.getBefore()
else: else:
logging.info(cmd) response = self.run_cmd_local_host(cmd)
response = subprocess.check_output(cmd, shell=True, universal_newlines=True, stderr=subprocess.STDOUT)
if re.search('Login Succeeded', response) is None: if re.search('Login Succeeded', response) is None:
msg = 'Could not log into local registry' msg = 'Could not log into local registry'
logging.error(msg) logging.error(msg)
...@@ -756,8 +757,7 @@ class Containerize(): ...@@ -756,8 +757,7 @@ class Containerize():
mySSH.command(cmd, '\$', 120) mySSH.command(cmd, '\$', 120)
response = mySSH.getBefore() response = mySSH.getBefore()
else: else:
logging.info(cmd) response = self.run_cmd_local_host(cmd)
response = subprocess.check_output(cmd, shell=True, universal_newlines=True)
if re.search('Status: Downloaded newer image for |Status: Image is up to date for', response) is None: if re.search('Status: Downloaded newer image for |Status: Image is up to date for', response) is None:
logging.debug(response) logging.debug(response)
msg = f'Could not pull {image} from local registry : {tagToUse}' msg = f'Could not pull {image} from local registry : {tagToUse}'
...@@ -772,8 +772,7 @@ class Containerize(): ...@@ -772,8 +772,7 @@ class Containerize():
mySSH.command(cmd, '\$', 5) mySSH.command(cmd, '\$', 5)
response = mySSH.getBefore() response = mySSH.getBefore()
else: else:
logging.info(cmd) response = self.run_cmd_local_host(cmd)
response = subprocess.check_output(cmd, shell=True, universal_newlines=True)
if re.search('Removing login credentials', response) is None: if re.search('Removing login credentials', response) is None:
msg = 'Could not log off from local registry' msg = 'Could not log off from local registry'
logging.error(msg) logging.error(msg)
...@@ -820,8 +819,7 @@ class Containerize(): ...@@ -820,8 +819,7 @@ class Containerize():
if lIpAddr != 'none': if lIpAddr != 'none':
mySSH.command(cmd, '\$', 5) mySSH.command(cmd, '\$', 5)
else: else:
logging.info(cmd) self.run_cmd_local_host(cmd)
subprocess.run(cmd, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
if lIpAddr != 'none': if lIpAddr != 'none':
mySSH.close() mySSH.close()
...@@ -921,7 +919,7 @@ class Containerize(): ...@@ -921,7 +919,7 @@ class Containerize():
if healthyNb == 1: if healthyNb == 1:
cnt = 0 cnt = 0
while (cnt < 20): while (cnt < 20):
mySSH.command('docker logs ' + containerName + ' | egrep --text --color=never -i "wait|sync|Starting"', '\$', 30) mySSH.command('docker logs ' + containerName + ' | egrep --text --color=never -i "wait|sync|Starting"', '\$', 30)
result = re.search('got sync|Starting F1AP at CU', mySSH.getBefore()) result = re.search('got sync|Starting F1AP at CU', mySSH.getBefore())
if result is None: if result is None:
time.sleep(6) time.sleep(6)
...@@ -1048,9 +1046,8 @@ class Containerize(): ...@@ -1048,9 +1046,8 @@ class Containerize():
self.exitStatus = 0 self.exitStatus = 0
logging.debug('\u001B[1m Checking Services to deploy\u001B[0m') logging.debug('\u001B[1m Checking Services to deploy\u001B[0m')
cmd = 'cd ' + self.yamlPath[0] + ' && docker-compose config --services' cmd = 'cd ' + self.yamlPath[0] + ' && docker-compose config --services'
logging.info(cmd)
try: try:
listServices = subprocess.check_output(cmd, shell=True, universal_newlines=True) listServices = self.run_cmd_local_host(cmd)
except Exception as e: except Exception as e:
self.exitStatus = 1 self.exitStatus = 1
HTML.CreateHtmlTestRow('SVC not Found', 'KO', CONST.ALL_PROCESSES_OK) HTML.CreateHtmlTestRow('SVC not Found', 'KO', CONST.ALL_PROCESSES_OK)
...@@ -1065,18 +1062,16 @@ class Containerize(): ...@@ -1065,18 +1062,16 @@ class Containerize():
return return
cmd = 'cd ' + self.yamlPath[0] + ' && cp docker-compose.y*ml docker-compose-ci.yml' cmd = 'cd ' + self.yamlPath[0] + ' && cp docker-compose.y*ml docker-compose-ci.yml'
subprocess.run(cmd, shell=True) self.run_cmd_local_host(cmd)
imageNames = ['oai-enb', 'oai-gnb', 'oai-lte-ue', 'oai-nr-ue', 'oai-lte-ru'] imageNames = ['oai-enb', 'oai-gnb', 'oai-lte-ue', 'oai-nr-ue', 'oai-lte-ru']
for image in imageNames: for image in imageNames:
tagToUse = self.ImageTagToUse(image) tagToUse = self.ImageTagToUse(image)
cmd = f'cd {self.yamlPath[0]} && sed -i -e "s@{image}:develop@{tagToUse}@" docker-compose-ci.yml' cmd = f'cd {self.yamlPath[0]} && sed -i -e "s@{image}:develop@{tagToUse}@" docker-compose-ci.yml'
logging.debug(cmd) self.run_cmd_local_host(cmd)
subprocess.run(cmd, shell=True)
cmd = 'cd ' + self.yamlPath[0] + ' && docker-compose -f docker-compose-ci.yml up -d ' + self.services[0] cmd = 'cd ' + self.yamlPath[0] + ' && docker-compose -f docker-compose-ci.yml up -d ' + self.services[0]
logging.info(cmd)
try: try:
deployStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=100) deployStatus = self.run_cmd_local_host(cmd, 100)
except Exception as e: except Exception as e:
self.exitStatus = 1 self.exitStatus = 1
logging.error('Could not deploy') logging.error('Could not deploy')
...@@ -1087,14 +1082,17 @@ class Containerize(): ...@@ -1087,14 +1082,17 @@ class Containerize():
cmd = 'cd ' + self.yamlPath[0] + ' && docker-compose -f docker-compose-ci.yml ps -a' cmd = 'cd ' + self.yamlPath[0] + ' && docker-compose -f docker-compose-ci.yml ps -a'
count = 0 count = 0
healthy = 0 healthy = 0
restarting = 0
newContainers = [] newContainers = []
while (count < 10): while (count < 10):
count += 1 count += 1
containerStatus = [] containerStatus = []
deployStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=30) deployStatus = self.run_cmd_local_host(cmd, 30, silent=True)
healthy = 0 healthy = 0
restarting = 0
for state in deployStatus.split('\n'): for state in deployStatus.split('\n'):
res = re.search('Name|----------', state) state = state.strip()
res = re.search('Name|NAME|----------', state)
if res is not None: if res is not None:
continue continue
if len(state) == 0: if len(state) == 0:
...@@ -1109,23 +1107,28 @@ class Containerize(): ...@@ -1109,23 +1107,28 @@ class Containerize():
if not found: if not found:
newContainers.append(cName) newContainers.append(cName)
self.deployedContainers.append(cName) self.deployedContainers.append(cName)
if re.search('Up \(healthy\)', state) is not None: if re.search('\(healthy\)', state) is not None:
healthy += 1 healthy += 1
if re.search('rfsim4g-db-init.*Exit 0', state) is not None: if re.search('rfsim4g-db-init.*Exit 0', state) is not None or re.search('rfsim4g-db-init.*Exited \(0\)', state) is not None:
subprocess.check_output('docker rm -f rfsim4g-db-init || true', shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=30) self.run_cmd_local_host('docker rm -f rfsim4g-db-init || true', 30, silent=True)
containerStatus.append(state) if re.search('Restarting', state) is None:
if healthy == self.nb_healthy[0]: containerStatus.append(state)
else:
restarting += 1
if healthy == self.nb_healthy[0] and restarting == 0:
count = 100 count = 100
else: else:
time.sleep(10) time.sleep(10)
imagesInfo = '' imagesInfo = ''
for newCont in newContainers: for newCont in newContainers:
if newCont == 'rfsim4g-db-init':
continue
cmd = 'docker inspect -f "{{.Config.Image}}" ' + newCont cmd = 'docker inspect -f "{{.Config.Image}}" ' + newCont
imageName = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=30) imageName = self.run_cmd_local_host(cmd, 30, silent=True)
imageName = str(imageName).strip() imageName = str(imageName).strip()
cmd = 'docker image inspect --format "{{.RepoTags}}\t{{.Size}} bytes\t{{.Created}}\t{{.Id}}" ' + imageName cmd = 'docker image inspect --format "{{.RepoTags}}\t{{.Size}} bytes\t{{.Created}}\t{{.Id}}" ' + imageName
imagesInfo += subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=30) imagesInfo += self.run_cmd_local_host(cmd, 30, silent=True)
html_queue = SimpleQueue() html_queue = SimpleQueue()
html_cell = '<pre style="background-color:white">\n' html_cell = '<pre style="background-color:white">\n'
...@@ -1157,30 +1160,36 @@ class Containerize(): ...@@ -1157,30 +1160,36 @@ class Containerize():
self.UndeployGenObject(HTML, RAN, UE) self.UndeployGenObject(HTML, RAN, UE)
self.exitStatus = 1 self.exitStatus = 1
def LaunchPySharkCapture(self, lIfs, lFilter, loFile):
capture = pyshark.LiveCapture(interface=lIfs, bpf_filter=lFilter, output_file=loFile, debug=False)
for packet in capture.sniff_continuously():
pass
def CaptureOnDockerNetworks(self): def CaptureOnDockerNetworks(self):
cmd = 'cd ' + self.yamlPath[0] + ' && docker-compose -f docker-compose-ci.yml config | grep com.docker.network.bridge.name | sed -e "s@^.*name: @@"' cmd = 'cd ' + self.yamlPath[0] + ' && docker-compose -f docker-compose-ci.yml config | grep com.docker.network.bridge.name | sed -e "s@^.*name: @@"'
networkNames = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10) networkNames = self.run_cmd_local_host(cmd, silent=True)
if re.search('4g.*rfsimulator', self.yamlPath[0]) is not None: if re.search('4g.*rfsimulator', self.yamlPath[0]) is not None:
# Excluding any traffic from LTE-UE container (192.168.61.30) # Excluding any traffic from LTE-UE container (192.168.61.30)
# From the trf-gen, keeping only PING traffic # From the trf-gen, keeping only PING traffic
cmd = 'sudo nohup tshark -f "(host 192.168.61.11 and icmp) or (not host 192.168.61.11 and not host 192.168.61.30 and not arp and not port 53 and not port 2152)"' capture_filter = '(host 192.168.61.11 and icmp) or (not host 192.168.61.11 and not host 192.168.61.30 and not arp and not port 53 and not port 2152)'
elif re.search('5g.*rfsimulator', self.yamlPath[0]) is not None: elif re.search('5g.*rfsimulator', self.yamlPath[0]) is not None:
# Excluding any traffic from NR-UE containers (192.168.71.150 and 192.168.71.151) # Excluding any traffic from NR-UE containers (192.168.71.150 and 192.168.71.151)
# From the ext-dn, keeping only PING traffic # From the ext-dn, keeping only PING traffic
cmd = 'sudo nohup tshark -f "(host 192.168.72.135 and icmp) or (not host 192.168.72.135 and not host 192.168.71.150 and not host 192.168.71.151 and not arp and not port 53 and not port 2152 and not port 2153)"' capture_filter = '(host 192.168.72.135 and icmp) or (not host 192.168.72.135 and not host 192.168.71.150 and not host 192.168.71.151 and not arp and not port 53 and not port 2152 and not port 2153)'
elif re.search('5g_l2sim', self.yamlPath[0]) is not None: elif re.search('5g_l2sim', self.yamlPath[0]) is not None:
cmd = 'sudo nohup tshark -f "(host 192.168.72.135 and icmp) or (not host 192.168.72.135 and not arp and not port 53 and not port 2152 and not port 2153)"' capture_filter = '(host 192.168.72.135 and icmp) or (not host 192.168.72.135 and not arp and not port 53 and not port 2152 and not port 2153)'
else: else:
return return
interfaces = []
for name in networkNames.split('\n'): for name in networkNames.split('\n'):
if re.search('rfsim', name) is not None or re.search('l2sim', name) is not None: if re.search('rfsim', name) is not None or re.search('l2sim', name) is not None:
cmd += ' -i ' + name interfaces.append(name)
cmd += ' -w /tmp/capture_'
ymlPath = self.yamlPath[0].split('/') ymlPath = self.yamlPath[0].split('/')
cmd += ymlPath[1] + '.pcap > /tmp/tshark.log 2>&1 &' output_file = f'/tmp/capture_{ymlPath[1]}.pcap'
logging.info(cmd)
networkNames = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10)
self.tsharkStarted = True self.tsharkStarted = True
x = threading.Thread(target = self.LaunchPySharkCapture, args = (interfaces,capture_filter,output_file,))
x.daemon = True
x.start()
def UndeployGenObject(self, HTML, RAN, UE): def UndeployGenObject(self, HTML, RAN, UE):
self.exitStatus = 0 self.exitStatus = 0
...@@ -1188,25 +1197,22 @@ class Containerize(): ...@@ -1188,25 +1197,22 @@ class Containerize():
logPath = '../cmake_targets/log/' + ymlPath[1] logPath = '../cmake_targets/log/' + ymlPath[1]
cmd = 'cd ' + self.yamlPath[0] + ' && cp docker-compose.y*ml docker-compose-ci.yml' cmd = 'cd ' + self.yamlPath[0] + ' && cp docker-compose.y*ml docker-compose-ci.yml'
logging.info(cmd) self.run_cmd_local_host(cmd)
subprocess.run(cmd, shell=True)
imageNames = ['oai-enb', 'oai-gnb', 'oai-lte-ue', 'oai-nr-ue', 'oai-lte-ru'] imageNames = ['oai-enb', 'oai-gnb', 'oai-lte-ue', 'oai-nr-ue', 'oai-lte-ru']
for image in imageNames: for image in imageNames:
tagToUse = self.ImageTagToUse(image) tagToUse = self.ImageTagToUse(image)
cmd = f'cd {self.yamlPath[0]} && sed -i -e "s@{image}:develop@{tagToUse}@" docker-compose-ci.yml' cmd = f'cd {self.yamlPath[0]} && sed -i -e "s@{image}:develop@{tagToUse}@" docker-compose-ci.yml'
subprocess.run(cmd, shell=True) self.run_cmd_local_host(cmd)
# check which containers are running for log recovery later # check which containers are running for log recovery later
cmd = 'cd ' + self.yamlPath[0] + ' && docker-compose -f docker-compose-ci.yml ps --all' cmd = 'cd ' + self.yamlPath[0] + ' && docker-compose -f docker-compose-ci.yml ps --all'
logging.info(cmd) deployStatusLogs = self.run_cmd_local_host(cmd, 30)
deployStatusLogs = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=30)
# Stop the containers to shut down objects # Stop the containers to shut down objects
logging.debug('\u001B[1m Stopping containers \u001B[0m') logging.debug('\u001B[1m Stopping containers \u001B[0m')
cmd = 'cd ' + self.yamlPath[0] + ' && docker-compose -f docker-compose-ci.yml stop -t3' cmd = 'cd ' + self.yamlPath[0] + ' && docker-compose -f docker-compose-ci.yml stop -t3'
logging.info(cmd)
try: try:
deployStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=100) deployStatus = self.run_cmd_local_host(cmd, 100)
except Exception as e: except Exception as e:
self.exitStatus = 1 self.exitStatus = 1
logging.error('Could not stop containers') logging.error('Could not stop containers')
...@@ -1216,7 +1222,7 @@ class Containerize(): ...@@ -1216,7 +1222,7 @@ class Containerize():
anyLogs = False anyLogs = False
for state in deployStatusLogs.split('\n'): for state in deployStatusLogs.split('\n'):
res = re.search('Name|----------', state) res = re.search('Name|NAME|----------', state)
if res is not None: if res is not None:
continue continue
if len(state) == 0: if len(state) == 0:
...@@ -1226,17 +1232,14 @@ class Containerize(): ...@@ -1226,17 +1232,14 @@ class Containerize():
anyLogs = True anyLogs = True
cName = res.group('container_name') cName = res.group('container_name')
cmd = 'cd ' + self.yamlPath[0] + ' && docker logs ' + cName + ' > ' + cName + '.log 2>&1' cmd = 'cd ' + self.yamlPath[0] + ' && docker logs ' + cName + ' > ' + cName + '.log 2>&1'
logging.info(cmd) self.run_cmd_local_host(cmd, 30)
subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=30)
if re.search('magma-mme', cName) is not None: if re.search('magma-mme', cName) is not None:
cmd = 'cd ' + self.yamlPath[0] + ' && docker cp -L ' + cName + ':/var/log/mme.log ' + cName + '-full.log' cmd = 'cd ' + self.yamlPath[0] + ' && docker cp -L ' + cName + ':/var/log/mme.log ' + cName + '-full.log'
logging.info(cmd) self.run_cmd_local_host(cmd, 30)
subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=30)
fullStatus = True fullStatus = True
if anyLogs: if anyLogs:
cmd = 'mkdir -p '+ logPath + ' && cp ' + self.yamlPath[0] + '/*.log ' + logPath cmd = 'mkdir -p '+ logPath + ' && cp ' + self.yamlPath[0] + '/*.log ' + logPath
logging.info(cmd) deployStatus = self.run_cmd_local_host(cmd)
deployStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10)
# Analyzing log file(s)! # Analyzing log file(s)!
listOfPossibleRanContainers = ['enb', 'gnb', 'cu', 'du'] listOfPossibleRanContainers = ['enb', 'gnb', 'cu', 'du']
...@@ -1245,7 +1248,7 @@ class Containerize(): ...@@ -1245,7 +1248,7 @@ class Containerize():
cmd = 'ls ' + filenames cmd = 'ls ' + filenames
containerStatus = True containerStatus = True
try: try:
lsStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10) lsStatus = self.run_cmd_local_host(cmd, silent=True)
filenames = str(lsStatus).strip() filenames = str(lsStatus).strip()
except: except:
containerStatus = False containerStatus = False
...@@ -1268,7 +1271,7 @@ class Containerize(): ...@@ -1268,7 +1271,7 @@ class Containerize():
cmd = 'ls ' + filenames cmd = 'ls ' + filenames
containerStatus = True containerStatus = True
try: try:
lsStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10) lsStatus = self.run_cmd_local_host(cmd, silent=True)
filenames = str(lsStatus).strip() filenames = str(lsStatus).strip()
except: except:
containerStatus = False containerStatus = False
...@@ -1285,27 +1288,20 @@ class Containerize(): ...@@ -1285,27 +1288,20 @@ class Containerize():
HTML.CreateHtmlTestRow('UE log Analysis', 'OK', CONST.ALL_PROCESSES_OK) HTML.CreateHtmlTestRow('UE log Analysis', 'OK', CONST.ALL_PROCESSES_OK)
cmd = 'rm ' + self.yamlPath[0] + '/*.log' cmd = 'rm ' + self.yamlPath[0] + '/*.log'
logging.info(cmd) deployStatus = self.run_cmd_local_host(cmd)
deployStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10)
if self.tsharkStarted: if self.tsharkStarted:
self.tsharkStarted = True self.tsharkStarted = True
cmd = 'killall tshark || true'
self.run_cmd_local_host(cmd)
ymlPath = self.yamlPath[0].split('/') ymlPath = self.yamlPath[0].split('/')
cmd = 'sudo chmod 666 /tmp/capture_' + ymlPath[1] + '.pcap' cmd = 'mv /tmp/capture_' + ymlPath[1] + '.pcap ' + logPath + ' || true'
logging.info(cmd) copyStatus = self.run_cmd_local_host(cmd, 100)
copyStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10)
cmd = 'cp /tmp/capture_' + ymlPath[1] + '.pcap ' + logPath
logging.info(cmd)
copyStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10)
cmd = 'sudo rm /tmp/capture_' + ymlPath[1] + '.pcap'
logging.info(cmd)
copyStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10)
self.tsharkStarted = False self.tsharkStarted = False
logging.debug('\u001B[1m Undeploying \u001B[0m') logging.debug('\u001B[1m Undeploying \u001B[0m')
cmd = 'cd ' + self.yamlPath[0] + ' && docker-compose -f docker-compose-ci.yml down' cmd = 'cd ' + self.yamlPath[0] + ' && docker-compose -f docker-compose-ci.yml down'
logging.info(cmd)
try: try:
deployStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=100) deployStatus = self.run_cmd_local_host(cmd, 100)
except Exception as e: except Exception as e:
self.exitStatus = 1 self.exitStatus = 1
logging.error('Could not undeploy') logging.error('Could not undeploy')
...@@ -1316,8 +1312,7 @@ class Containerize(): ...@@ -1316,8 +1312,7 @@ class Containerize():
self.deployedContainers = [] self.deployedContainers = []
# Cleaning any created tmp volume # Cleaning any created tmp volume
cmd = 'docker volume prune --force || true' cmd = 'docker volume prune --force || true'
logging.info(cmd) deployStatus = self.run_cmd_local_host(cmd, 100)
deployStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=100)
if fullStatus: if fullStatus:
HTML.CreateHtmlTestRow('n/a', 'OK', CONST.ALL_PROCESSES_OK) HTML.CreateHtmlTestRow('n/a', 'OK', CONST.ALL_PROCESSES_OK)
...@@ -1333,12 +1328,11 @@ class Containerize(): ...@@ -1333,12 +1328,11 @@ class Containerize():
# if the containers are running, recover the logs! # if the containers are running, recover the logs!
cmd = 'cd ' + self.yamlPath[0] + ' && docker-compose -f docker-compose-ci.yml ps --all' cmd = 'cd ' + self.yamlPath[0] + ' && docker-compose -f docker-compose-ci.yml ps --all'
logging.info(cmd) deployStatus = self.run_cmd_local_host(cmd, 30)
deployStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=30)
cmd = 'docker stats --no-stream --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}" ' cmd = 'docker stats --no-stream --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}" '
anyLogs = False anyLogs = False
for state in deployStatus.split('\n'): for state in deployStatus.split('\n'):
res = re.search('Name|----------', state) res = re.search('Name|NAME|----------', state)
if res is not None: if res is not None:
continue continue
if len(state) == 0: if len(state) == 0:
...@@ -1349,8 +1343,7 @@ class Containerize(): ...@@ -1349,8 +1343,7 @@ class Containerize():
cmd += res.group('container_name') + ' ' cmd += res.group('container_name') + ' '
message = '' message = ''
if anyLogs: if anyLogs:
logging.info(cmd) stats = self.run_cmd_local_host(cmd, 30)
stats = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=30)
for statLine in stats.split('\n'): for statLine in stats.split('\n'):
logging.debug(statLine) logging.debug(statLine)
message += statLine + '\n' message += statLine + '\n'
...@@ -1365,12 +1358,11 @@ class Containerize(): ...@@ -1365,12 +1358,11 @@ class Containerize():
ymlPath = self.yamlPath[0].split('/') ymlPath = self.yamlPath[0].split('/')
logPath = '../cmake_targets/log/' + ymlPath[1] logPath = '../cmake_targets/log/' + ymlPath[1]
cmd = 'mkdir -p ' + logPath cmd = 'mkdir -p ' + logPath
deployStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10) deployStatus = self.run_cmd_local_host(cmd, silent=True)
cmd = 'docker exec ' + self.pingContName + ' /bin/bash -c "ping ' + self.pingOptions + '" 2>&1 | tee ' + logPath + '/ping_' + HTML.testCase_id + '.log || true' cmd = 'docker exec ' + self.pingContName + ' /bin/bash -c "ping ' + self.pingOptions + '" 2>&1 | tee ' + logPath + '/ping_' + HTML.testCase_id + '.log || true'
logging.info(cmd) deployStatus = self.run_cmd_local_host(cmd, 100)
deployStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=100)
result = re.search(', (?P<packetloss>[0-9\.]+)% packet loss, time [0-9\.]+ms', deployStatus) result = re.search(', (?P<packetloss>[0-9\.]+)% packet loss, time [0-9\.]+ms', deployStatus)
if result is None: if result is None:
...@@ -1440,28 +1432,24 @@ class Containerize(): ...@@ -1440,28 +1432,24 @@ class Containerize():
ymlPath = self.yamlPath[0].split('/') ymlPath = self.yamlPath[0].split('/')
logPath = '../cmake_targets/log/' + ymlPath[1] logPath = '../cmake_targets/log/' + ymlPath[1]
cmd = 'mkdir -p ' + logPath cmd = 'mkdir -p ' + logPath
logStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10) logStatus = self.run_cmd_local_host(cmd, silent=True)
# Start the server process # Start the server process
cmd = f'docker exec -d {self.svrContName} /bin/bash -c "nohup iperf {self.svrOptions} > /tmp/iperf_server.log 2>&1"' cmd = f'docker exec -d {self.svrContName} /bin/bash -c "nohup iperf {self.svrOptions} > /tmp/iperf_server.log 2>&1"'
logging.info(cmd) self.run_cmd_local_host(cmd)
subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10)
time.sleep(3) time.sleep(3)
# Start the client process # Start the client process
cmd = f'docker exec {self.cliContName} /bin/bash -c "iperf {self.cliOptions}" 2>&1 | tee {logPath}/iperf_client_{HTML.testCase_id}.log' cmd = f'docker exec {self.cliContName} /bin/bash -c "iperf {self.cliOptions}" 2>&1 | tee {logPath}/iperf_client_{HTML.testCase_id}.log'
logging.info(cmd) clientStatus = self.run_cmd_local_host(cmd, 100)
clientStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=100)
# Stop the server process # Stop the server process
cmd = f'docker exec {self.svrContName} /bin/bash -c "pkill iperf"' cmd = f'docker exec {self.svrContName} /bin/bash -c "pkill iperf"'
logging.info(cmd) self.run_cmd_local_host(cmd)
subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10)
time.sleep(3) time.sleep(3)
serverStatusFilename = f'{logPath}/iperf_server_{HTML.testCase_id}.log' serverStatusFilename = f'{logPath}/iperf_server_{HTML.testCase_id}.log'
cmd = f'docker cp {self.svrContName}:/tmp/iperf_server.log {serverStatusFilename}' cmd = f'docker cp {self.svrContName}:/tmp/iperf_server.log {serverStatusFilename}'
logging.info(cmd) self.run_cmd_local_host(cmd, 30)
subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=30)
# clientStatus was retrieved above. The serverStatus was # clientStatus was retrieved above. The serverStatus was
# written in the background, then copied to the local machine # written in the background, then copied to the local machine
...@@ -1604,3 +1592,12 @@ class Containerize(): ...@@ -1604,3 +1592,12 @@ class Containerize():
mySSH.command('echo ' + password + ' | sudo -S iptables -P FORWARD ACCEPT', '\$', 10) mySSH.command('echo ' + password + ' | sudo -S iptables -P FORWARD ACCEPT', '\$', 10)
mySSH.close() mySSH.close()
def run_cmd_local_host(self, lCmd, lTimeout=10, silent=False):
if not silent:
logging.info(lCmd)
result = subprocess.run(lCmd, shell=True, check=True,
universal_newlines=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
timeout=lTimeout)
return str(result.stdout)
...@@ -70,6 +70,7 @@ import subprocess ...@@ -70,6 +70,7 @@ import subprocess
from multiprocessing import Process, Lock, SimpleQueue from multiprocessing import Process, Lock, SimpleQueue
logging.basicConfig( logging.basicConfig(
level=logging.DEBUG, level=logging.DEBUG,
stream=sys.stdout,
format="[%(asctime)s] %(levelname)8s: %(message)s" format="[%(asctime)s] %(levelname)8s: %(message)s"
) )
......
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