X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FPapiHistory.py;h=cacfbd6b194ff760aa2d504838b6e0c0b2f465a1;hb=79f5ba9bf7656972dd988508eff9465562dde42c;hp=13c483b4bceeca1423fa2c274e9413e61b076b77;hpb=2251c68ea3d862b08df030231a1ddf618a2cec2b;p=csit.git diff --git a/resources/libraries/python/PapiHistory.py b/resources/libraries/python/PapiHistory.py index 13c483b4bc..cacfbd6b19 100644 --- a/resources/libraries/python/PapiHistory.py +++ b/resources/libraries/python/PapiHistory.py @@ -17,13 +17,13 @@ from robot.api import logger 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() -class PapiHistory(object): +class PapiHistory: """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 """ - DICT__DUTS_PAPI_HISTORY[node['host']] = list() + DICT__DUTS_PAPI_HISTORY[node[u"host"]] = list() @staticmethod def reset_papi_history_on_all_duts(nodes): @@ -44,34 +44,56 @@ class PapiHistory(object): :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 - def add_to_papi_history(node, cmd, papi=True, **kwargs): + def add_to_papi_history(node, csit_papi_command, papi=True, **kwargs): """Add command to PAPI command history on DUT node. + Repr strings are used for argument values. + + The argument name 'csit_papi_command' must be unique enough as it cannot + be repeated in kwargs. + + Examples of PAPI history items: + + Request without parameters: + show_threads() + + Request with parameters: + ipsec_select_backend(index=1,protocol=1) + + Dump: + sw_interface_rx_placement_dump(sw_if_index=4) + + 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 cmd: Command to be added to PAPI command history. + :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 cmd: str + :type csit_papi_command: str :type papi: bool :type kwargs: dict """ if papi: args = list() - for key, val in kwargs.iteritems(): - args.append("{key}={val}".format(key=key, val=val)) - item = "{cmd}({args})".format(cmd=cmd, args=",".join(args)) + for key, val in kwargs.items(): + args.append(f"{key}={val!r}") + item = f"{csit_papi_command}({u','.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=cmd) - DICT__DUTS_PAPI_HISTORY[node['host']].append(item) + item = f"{csit_papi_command}" + DICT__DUTS_PAPI_HISTORY[node[u"host"]].append(item) @staticmethod def show_papi_history(node): @@ -80,12 +102,11 @@ class PapiHistory(object): :param node: DUT node to show PAPI command history for. :type node: dict """ - history = "\nNo PAPI command executed" - if DICT__DUTS_PAPI_HISTORY[node['host']]: - history = "".join(["\n{}".format( - cmd) for cmd in DICT__DUTS_PAPI_HISTORY[node['host']]]) - logger.trace( - "{0} PAPI command history:\n{1}\n".format(node['host'], history)) + history_list = DICT__DUTS_PAPI_HISTORY[node[u"host"]] + if not 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): @@ -95,7 +116,7 @@ class PapiHistory(object): :type nodes: dict """ for node in nodes.values(): - if node['type'] == NodeType.DUT: + if node[u"type"] == NodeType.DUT: PapiHistory.show_papi_history(node)