feat(core): Add 2n-spr topology
[csit.git] / resources / libraries / python / PapiHistory.py
index c4ee4ee..18b2774 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2019 Cisco and/or its affiliates.
+# Copyright (c) 2023 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:
 # 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:
@@ -17,13 +17,13 @@ from robot.api import logger
 
 from resources.libraries.python.topology import NodeType, DICT__nodes
 
 
 from resources.libraries.python.topology import NodeType, DICT__nodes
 
-__all__ = ["DICT__DUTS_PAPI_HISTORY", "PapiHistory"]
+__all__ = [u"DICT__DUTS_PAPI_HISTORY", u"PapiHistory"]
 
 
 DICT__DUTS_PAPI_HISTORY = dict()
 
 
 
 
 DICT__DUTS_PAPI_HISTORY = dict()
 
 
-class PapiHistory(object):
+class PapiHistory:
     """Contains methods to set up DUT PAPI command history.
     """
 
     """Contains methods to set up DUT PAPI command history.
     """
 
@@ -34,7 +34,7 @@ class PapiHistory(object):
         :param node: DUT node to reset PAPI command history for.
         :type node: dict
         """
         :param node: DUT node to reset PAPI command history for.
         :type node: dict
         """
-        DICT__DUTS_PAPI_HISTORY[node['host']] = list()
+        DICT__DUTS_PAPI_HISTORY[node[u"host"]] = list()
 
     @staticmethod
     def reset_papi_history_on_all_duts(nodes):
 
     @staticmethod
     def reset_papi_history_on_all_duts(nodes):
@@ -44,11 +44,11 @@ class PapiHistory(object):
         :type nodes: dict
         """
         for node in nodes.values():
         :type nodes: dict
         """
         for node in nodes.values():
-            if node['type'] == NodeType.DUT:
+            if node[u"type"] == NodeType.DUT:
                 PapiHistory.reset_papi_history(node)
 
     @staticmethod
                 PapiHistory.reset_papi_history(node)
 
     @staticmethod
-    def add_to_papi_history(node, csit_papi_command, papi=True, **kwargs):
+    def add_to_papi_history(node, csit_papi_command, **kwargs):
         """Add command to PAPI command history on DUT node.
 
         Repr strings are used for argument values.
         """Add command to PAPI command history on DUT node.
 
         Repr strings are used for argument values.
@@ -70,31 +70,18 @@ class PapiHistory(object):
         VPP Stats:
             vpp-stats(path=['^/if', '/err/ip4-input', '/sys/node/ip4-input'])
 
         VPP Stats:
             vpp-stats(path=['^/if', '/err/ip4-input', '/sys/node/ip4-input'])
 
-        VAT:
-            sw_interface_set_flags sw_if_index 3 admin-up link-up
-
         :param node: DUT node to add command to PAPI command history for.
         :param csit_papi_command: Command to be added to PAPI command history.
         :param node: DUT node to add command to PAPI command history for.
         :param csit_papi_command: Command to be added to PAPI command history.
-        :param papi: Says if the command to store is PAPi or VAT. Remove when
-            VAT executor is completely removed.
         :param kwargs: Optional key-value arguments.
         :type node: dict
         :type csit_papi_command: str
         :param kwargs: Optional key-value arguments.
         :type node: dict
         :type csit_papi_command: str
-        :type papi: bool
         :type kwargs: dict
         """
         :type kwargs: dict
         """
-        if papi:
-            args = list()
-            for key, val in kwargs.iteritems():
-                args.append("{key}={val!r}".format(key=key, val=val))
-            item = "{cmd}({args})".format(cmd=csit_papi_command,
-                                          args=",".join(args))
-        else:
-            # This else part is here to store VAT commands.
-            # VAT history is not used.
-            # TODO: Remove when VatExecutor is completely removed.
-            item = "{cmd}".format(cmd=csit_papi_command)
-        DICT__DUTS_PAPI_HISTORY[node['host']].append(item)
+        args = list()
+        for key, val in kwargs.items():
+            args.append(f"{key}={val!r}")
+        item = f"{csit_papi_command}({u','.join(args)})"
+        DICT__DUTS_PAPI_HISTORY[node[u"host"]].append(item)
 
     @staticmethod
     def show_papi_history(node):
 
     @staticmethod
     def show_papi_history(node):
@@ -103,12 +90,11 @@ class PapiHistory(object):
         :param node: DUT node to show PAPI command history for.
         :type node: dict
         """
         :param node: DUT node to show PAPI command history for.
         :type node: dict
         """
-        history_list = DICT__DUTS_PAPI_HISTORY[node['host']]
+        history_list = DICT__DUTS_PAPI_HISTORY[node[u"host"]]
         if not history_list:
         if not history_list:
-            history_list = ("No PAPI command executed", )
-        logger.info(
-            "{0} PAPI command history:\n{1}\n".format(
-                node['host'], "\n".join(history_list)))
+            history_list = (u"No PAPI command executed", )
+        history = u'\n'.join(history_list)
+        logger.info(f"{node[u'host']} PAPI command history:\n{history}\n")
 
     @staticmethod
     def show_papi_history_on_all_duts(nodes):
 
     @staticmethod
     def show_papi_history_on_all_duts(nodes):
@@ -118,8 +104,13 @@ class PapiHistory(object):
         :type nodes: dict
         """
         for node in nodes.values():
         :type nodes: dict
         """
         for node in nodes.values():
-            if node['type'] == NodeType.DUT:
+            if node[u"type"] == NodeType.DUT:
                 PapiHistory.show_papi_history(node)
 
 
                 PapiHistory.show_papi_history(node)
 
 
-PapiHistory.reset_papi_history_on_all_duts(DICT__nodes)
+# This module can be imported outside usual Robot test context,
+# e.g. in pylint or by tools generating docs from docstrings.
+# For the tools to work, we need to avoid processing
+# when DICT__nodes value is not usable.
+if DICT__nodes:
+    PapiHistory.reset_papi_history_on_all_duts(DICT__nodes)