Skip to content

Commit

Permalink
Merge pull request wizhaoredhat#5 from SalDaniele/debug_output
Browse files Browse the repository at this point in the history
Add Debug output and cleanup whitespace
  • Loading branch information
wizhaoredhat authored Aug 22, 2023
2 parents 11aa070 + b3ab6ad commit 0d2ef13
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
13 changes: 13 additions & 0 deletions arguments.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
import os
from logger import logger, configure_logger
import logging
import argparse

def parse_args() -> argparse.Namespace:

parser = argparse.ArgumentParser(description='Build a custom image and store in the specified repository')
parser.add_argument('config', metavar='config', type=str, help='Yaml file with test configuration (see config.yaml)')
parser.add_argument('-v', '--verbosity', choices=['debug', 'info', 'warning', 'error', 'critical'], default='info', help='Set the logging level (default: info)')

args = parser.parse_args()

log_levels = {
'debug': logging.DEBUG,
'info': logging.INFO,
'warning': logging.WARNING,
'error': logging.ERROR,
'critical': logging.CRITICAL
}
args.verbosity = log_levels[args.verbosity]
configure_logger(args.verbosity)

if not os.path.exists(args.config):
raise ValueError("Must provide a valid config.yaml file (see config.yaml)")

Expand Down
22 changes: 13 additions & 9 deletions iperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def setup(self):
# Create the server pods
super().setup()
cmd = f"exec -t {self.pod_name} -- {IPERF_EXE} -s -p {self.port} --one-off --json"

logger.info(f"Running {cmd}")

def server(self, cmd: str):
Expand All @@ -82,8 +82,8 @@ def stop(self):
r = self.exec_thread.join()
if r.returncode != 0:
logger.error(f"Error occured while stopping Iperf server: errcode: {r.returncode} err {r.error}")
logger.info(r)
logger.debug(f"IperfServer.stop(): {r.out}")

def output(self):
pass

Expand Down Expand Up @@ -133,7 +133,8 @@ def stop(self):
logger.info(f"Stopping execution on {self.pod_name}")
r = self.exec_thread.join()
if r.returncode != 0:
logger.info(r)
logger.error(r)
logger.debug(f"IperfClient.stop(): {r.out}")
data = json.loads(r.out)
self._output = self.generate_output(data)

Expand All @@ -144,7 +145,7 @@ def generate_output(self, data: dict) -> dict:
"result": data
}
return json_dump

def output(self):
# Store json output as run logs
with open(self.log_path + self.ts.get_test_str() + ".json", "w") as output_file:
Expand All @@ -161,7 +162,7 @@ def output(self):
self.print_tcp_results(self._output["result"])
if self.test_type == TestType.IPERF_UDP:
self.print_udp_results(self._output["result"])

def print_tcp_results(self, data: dict):
sum_sent = data["end"]["sum_sent"]
sum_received = data["end"]["sum_received"]
Expand All @@ -170,13 +171,15 @@ def print_tcp_results(self, data: dict):
bitrate_sent = sum_sent["bits_per_second"] / 1e9
transfer_received = sum_received["bytes"] / (1024 ** 3)
bitrate_received = sum_received["bits_per_second"] / 1e9
mss = data['start']['tcp_mss_default']

logger.info(
f"\n [ ID] Interval Transfer Bitrate\n"
f" [SENT] 0.00-{sum_sent['seconds']:.2f} sec {transfer_sent:.2f} GBytes {bitrate_sent:.2f} Gbits/sec sender\n"
f" [REC] 0.00-{sum_received['seconds']:.2f} sec {transfer_received:.2f} GBytes {bitrate_received:.2f} Gbits/sec receiver"
f" [REC] 0.00-{sum_received['seconds']:.2f} sec {transfer_received:.2f} GBytes {bitrate_received:.2f} Gbits/sec receiver\n"
f" MSS = {mss}"
)

def print_udp_results(self, data: dict):
sum_data = data["end"]["sum"]

Expand Down Expand Up @@ -208,10 +211,11 @@ def get_target_ip(self) -> str:
server_ip = self.server.get_pod_ip()
logger.debug(f"get_target_ip() Connection to server at {server_ip}")
return server_ip

def get_podman_ip(self, pod_name: str) -> str:
cmd = "podman inspect --format '{{.NetworkSettings.IPAddress}}' " + pod_name
ret = self.lh.run(cmd)
logger.debug(f"get_podman_ip(): {ret.out}")
if ret.returncode != 0:
logger.error(f"Failed to inspect pod {pod_name} for IPAddress: {ret.err}")
sys.exit(-1)
Expand Down
3 changes: 1 addition & 2 deletions measureCpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ def stop(self):
r = self.exec_thread.join()
if r.returncode != 0:
logger.info(r)
#logger.info(r.out)
logger.debug(f"measureCpu.stop(): {r.out}")
data = jc.parse('mpstat', r.out)
#logger.info(data)
p_idle = data[0]['percent_idle']
logger.info(f"Idle on {self.node_name} = {p_idle}%")

Expand Down
1 change: 1 addition & 0 deletions measurePower.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def stop(self):
r = self.exec_thread.join()
if r.returncode != 0:
logger.info(r)
logger.debug(f"MeasurePower.out(): {r.out}")
logger.info(f"measurePower results: {r.out}")

def output(self):
Expand Down
2 changes: 1 addition & 1 deletion testSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _test_id_to_connection_mode(self, test_case_id) -> ConnectionMode:
if test_case_id in (25, 26):
return ConnectionMode.EXTERNAL_IP
return ConnectionMode.POD_IP

def get_test_info_dict(self) -> dict:
json_dump = {
"test_case_id": self.test_case_id,
Expand Down
6 changes: 3 additions & 3 deletions trafficFlowTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def enable_measure_power_plugin(self, node_server_name: str, node_client_name: s
c = MeasurePower(self._tft, node_client_name, tenant)
self.monitors.append(s)
self.monitors.append(c)

def run_tests(self, duration: int):
for tasks in self.servers + self.clients + self.monitors:
tasks.setup()
Expand All @@ -81,7 +81,7 @@ def run_tests(self, duration: int):

for tasks in self.servers + self.clients + self.monitors:
tasks.output()

def create_log_path(self, tests: dict) -> str:
log_path = self.log_path
# Create directory for logging
Expand Down Expand Up @@ -136,6 +136,6 @@ def run(self):
self.enable_measure_cpu_plugin(node_server_name, node_client_name, True)
if plugins['name'] == "measure_power":
self.enable_measure_power_plugin(node_server_name, node_client_name, True)

self.run_tests(duration)
self.cleanup_previous_testspace(tests['namespace'])

0 comments on commit 0d2ef13

Please sign in to comment.