From a201f3d3a5fdb9ccb86d57664cfd1de4bf484d36 Mon Sep 17 00:00:00 2001 From: Peter Mikus Date: Thu, 5 May 2022 13:08:10 +0200 Subject: fix(uti): Add TG type export - This is actually bug not a feature. - AB to be added later - Tested on TREX and iPerf3 Signed-off-by: Peter Mikus Change-Id: Ib6f2d13e3b9401a9fb5759e42a8a310ee11b9d41 --- resources/libraries/python/Constants.py | 2 +- resources/libraries/python/Iperf3.py | 27 +++++++++++- resources/libraries/python/TrafficGenerator.py | 33 ++++++++++++++- resources/libraries/python/model/ExportResult.py | 54 +++++++++++++++++++----- resources/libraries/python/model/export_json.py | 3 +- 5 files changed, 105 insertions(+), 14 deletions(-) (limited to 'resources/libraries/python') diff --git a/resources/libraries/python/Constants.py b/resources/libraries/python/Constants.py index 2ecf50b770..a7bda2124b 100644 --- a/resources/libraries/python/Constants.py +++ b/resources/libraries/python/Constants.py @@ -120,7 +120,7 @@ class Constants: """Constants used in CSIT.""" # Version for CSIT data model. See docs/model/. - MODEL_VERSION = u"1.0.0" + MODEL_VERSION = u"1.0.1" # Global off-switch in case JSON export is large or slow. EXPORT_JSON = get_optimistic_bool_from_env(u"EXPORT_JSON") diff --git a/resources/libraries/python/Iperf3.py b/resources/libraries/python/Iperf3.py index ed186f0757..12d0633abc 100644 --- a/resources/libraries/python/Iperf3.py +++ b/resources/libraries/python/Iperf3.py @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Cisco and/or its affiliates. +# Copyright (c) 2022 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -33,6 +33,31 @@ class Iperf3: # Computed affinity for iPerf client. self._c_affinity = None + @staticmethod + def get_iperf_type(node): + """Log and return the installed traffic generator type. + + :param node: Node from topology file. + :type node: dict + :returns: Traffic generator type string. + :rtype: str + """ + return "IPERF" + + @staticmethod + def get_iperf_version(node): + """Log and return the installed traffic generator version. + + :param node: Node from topology file. + :type node: dict + :returns: Traffic generator version string. + :rtype: str + """ + command = f"iperf3 --version | head -1" + message = u"Get iPerf version failed!" + stdout, _ = exec_cmd_no_error(node, command, message=message) + return stdout.strip() + def initialize_iperf_server( self, node, pf_key, interface, bind, bind_gw, bind_mask, namespace=None, cpu_skip_cnt=0, cpu_cnt=1, instances=1): diff --git a/resources/libraries/python/TrafficGenerator.py b/resources/libraries/python/TrafficGenerator.py index 03e3890959..5d9a0568f1 100644 --- a/resources/libraries/python/TrafficGenerator.py +++ b/resources/libraries/python/TrafficGenerator.py @@ -252,7 +252,38 @@ class TrafficGenerator(AbstractMeasurer): f"{self._node[u'subtype']} not running in {expected_mode} mode!" ) - # TODO: pylint says disable=too-many-locals. + @staticmethod + def get_tg_type(tg_node): + """Log and return the installed traffic generator type. + + :param tg_node: Node from topology file. + :type tg_node: dict + :returns: Traffic generator type string. + :rtype: str + :raises RuntimeError: If command returns nonzero return code. + """ + return str(check_subtype(tg_node)) + + @staticmethod + def get_tg_version(tg_node): + """Log and return the installed traffic generator version. + + :param tg_node: Node from topology file. + :type tg_node: dict + :returns: Traffic generator version string. + :rtype: str + :raises RuntimeError: If command returns nonzero return code. + """ + subtype = check_subtype(tg_node) + if subtype == NodeSubTypeTG.TREX: + command = f"cat {Constants.TREX_INSTALL_DIR}/VERSION" + message = u"Get T-Rex version failed!" + stdout, _ = exec_cmd_no_error(tg_node, command, message=message) + return stdout.strip() + else: + return "none" + + # TODO: pylint disable=too-many-locals. def initialize_traffic_generator( self, tg_node, tg_if1, tg_if2, tg_if1_adj_node, tg_if1_adj_if, tg_if2_adj_node, tg_if2_adj_if, osi_layer, tg_if1_dst_mac=None, diff --git a/resources/libraries/python/model/ExportResult.py b/resources/libraries/python/model/ExportResult.py index d74a6ab5df..16c6b89fb3 100644 --- a/resources/libraries/python/model/ExportResult.py +++ b/resources/libraries/python/model/ExportResult.py @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Cisco and/or its affiliates. +# Copyright (c) 2022 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -39,18 +39,13 @@ def export_dut_type_and_version(dut_type=u"unknown", dut_version=u"unknown"): else: # We want to set a variable in higher level suite setup # to be available to test setup several levels lower. - # Documentation [0] looks like "children" is a keyword argument, - # but code [1] lines 1458 and 1511-1512 show - # it is just last stringy argument. - # [0] http://robotframework.org/robotframework/ - # 3.1.2/libraries/BuiltIn.html#Set%20Suite%20Variable - # [1] https://github.com/robotframework/robotframework/blob/ - # v3.1.2/src/robot/libraries/BuiltIn.py BuiltIn().set_suite_variable( u"\\${DUT_TYPE}", dut_type, u"children=True" ) if dut_version == u"unknown": - dut_version = BuiltIn().get_variable_value(u"\\${DUT_VERSION}", u"unknown") + dut_version = BuiltIn().get_variable_value( + u"\\${DUT_VERSION}", u"unknown" + ) if dut_type == u"unknown": raise RuntimeError(u"Dut version not provided.") else: @@ -58,10 +53,49 @@ def export_dut_type_and_version(dut_type=u"unknown", dut_version=u"unknown"): u"\\${DUT_VERSION}", dut_version, u"children=True" ) data = get_export_data() - data[u"dut_type"] = dut_type + data[u"dut_type"] = dut_type.lower() data[u"dut_version"] = dut_version +def export_tg_type_and_version(tg_type=u"unknown", tg_version=u"unknown"): + """Export the arguments as tg type and version. + + Robot tends to convert "none" into None, hence the unusual default values. + + If either argument is missing, the value from robot variable is used. + If argument is present, the value is also stored to robot suite variable. + + :param tg_type: TG type, e.g. TREX. + :param tg_version: TG version as determined by the caller. + :type tg_type: Optional[str] + :type tg_version: Optiona[str] + :raises RuntimeError: If value is neither in argument not robot variable. + """ + if tg_type == u"unknown": + tg_type = BuiltIn().get_variable_value(u"\\${TG_TYPE}", u"unknown") + if tg_type == u"unknown": + raise RuntimeError(u"TG type not provided.") + else: + # We want to set a variable in higher level suite setup + # to be available to test setup several levels lower. + BuiltIn().set_suite_variable( + u"\\${TG_TYPE}", tg_type, u"children=True" + ) + if tg_version == u"unknown": + tg_version = BuiltIn().get_variable_value( + u"\\${TG_VERSION}", u"unknown" + ) + if tg_type == u"unknown": + raise RuntimeError(u"TG version not provided.") + else: + BuiltIn().set_suite_variable( + u"\\${TG_VERSION}", tg_version, u"children=True" + ) + data = get_export_data() + data[u"tg_type"] = tg_type.lower() + data[u"tg_version"] = tg_version + + def append_mrr_value(mrr_value, unit): """Store mrr value to proper place so it is dumped into json. diff --git a/resources/libraries/python/model/export_json.py b/resources/libraries/python/model/export_json.py index b5d4328084..840c49fa70 100644 --- a/resources/libraries/python/model/export_json.py +++ b/resources/libraries/python/model/export_json.py @@ -34,7 +34,7 @@ from robot.libraries.BuiltIn import BuiltIn from resources.libraries.python.Constants import Constants from resources.libraries.python.model.ExportResult import ( - export_dut_type_and_version + export_dut_type_and_version, export_tg_type_and_version ) from resources.libraries.python.model.mem2raw import write_raw_output from resources.libraries.python.model.raw2info import convert_content_to_info @@ -167,6 +167,7 @@ class export_json(): self.raw_data[u"hosts"] = set() self.raw_data[u"log"] = list() export_dut_type_and_version() + export_tg_type_and_version() def start_suite_teardown_export(self): """Set new file path, initialize data for the suite teardown. -- cgit 1.2.3-korg