From 4fa105c5b4113a9ff4311569709ca99a8fbf5028 Mon Sep 17 00:00:00 2001 From: "Sridhar K. N. Rao" Date: Wed, 10 Nov 2021 21:26:14 +0530 Subject: Minor Fixes. This patch add multiple minor changes. Signed-off-by: Sridhar K. N. Rao Change-Id: Ieda8af0b8145c1ffde6bfdb7a7394776b42df988 --- .../trafficgen-pods/trex/vppconf.py | 70 ---------------------- 1 file changed, 70 deletions(-) delete mode 100644 tools/k8s/test-containers/trafficgen-pods/trex/vppconf.py (limited to 'tools/k8s/test-containers/trafficgen-pods/trex/vppconf.py') diff --git a/tools/k8s/test-containers/trafficgen-pods/trex/vppconf.py b/tools/k8s/test-containers/trafficgen-pods/trex/vppconf.py deleted file mode 100644 index ad7d63d8..00000000 --- a/tools/k8s/test-containers/trafficgen-pods/trex/vppconf.py +++ /dev/null @@ -1,70 +0,0 @@ -import select -import subprocess -import logging -import threading -import sys -import os -import locale -import time -from jinja2 import Environment, FileSystemLoader - -CMD_PREFIX = 'cmd : ' -VERBOSITY = 'info' -_logger = logging.getLogger(__name__) - -def run_task(cmd, logger=_logger, msg=None, check_error=False): - """Run task, report errors and log overall status. - - Run given task using ``subprocess.Popen``. Log the commands - used and any errors generated. Prints stdout to screen if - in verbose mode and returns it regardless. Prints stderr to - screen always. - - :param cmd: Exact command to be executed - :param logger: Logger to write details to - :param msg: Message to be shown to user - :param check_error: Throw exception on error - - :returns: (stdout, stderr) - """ - def handle_error(exception): - """Handle errors by logging and optionally raising an exception. - """ - logger.error( - 'Unable to execute %(cmd)s. Exception: %(exception)s', - {'cmd': ' '.join(cmd), 'exception': exception}) - if check_error: - raise exception - - try: - proc = subprocess.Popen(map(os.path.expanduser, cmd), - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - output = proc.communicate()[0].decode("utf-8") - except OSError as ex: - handle_error(ex) - else: - if proc.returncode: - ex = subprocess.CalledProcessError(proc.returncode, cmd, stderr) - handle_error(ex) - return output - -ifaces = [] -sout = run_task(['/usr/bin/c_sample']) -if sout: - for line in sout.split('\n'): - if 'Path=' in line: - print(line) - field = line.split(' ')[-1].split('=')[-1] - ifaces.append(field) -ifacesdir = { - 'if1' : ifaces[0], - 'if2' : ifaces[1]} - -if len(ifaces) == 2: - file_loader = FileSystemLoader('./') - env = Environment(loader = file_loader) - fileref = env.get_template('./trex_cfg.yaml.j2') - renderedcon = fileref.render(data=ifacesdir) - with open('/etc/trex_cfg.yaml', "w+") as fh: - fh.write(renderedcon) -- cgit 1.2.3-korg