aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python
diff options
context:
space:
mode:
authorTibor Frank <tifrank@cisco.com>2019-03-05 10:08:30 +0100
committerTibor Frank <tifrank@cisco.com>2019-03-06 16:08:55 +0100
commit2251c68ea3d862b08df030231a1ddf618a2cec2b (patch)
tree17e6ff255672ba0a04b257b24aa18e39bc88b0f1 /resources/libraries/python
parent935734b04269b8fe5348e1c2b168dd5c6cd9339a (diff)
CSIT-1451: PapiHistory
Change-Id: Idb51f377fe0c196fbe24aab21c294dad595adcd2 Signed-off-by: Tibor Frank <tifrank@cisco.com>
Diffstat (limited to 'resources/libraries/python')
-rw-r--r--resources/libraries/python/PapiExecutor.py5
-rw-r--r--resources/libraries/python/PapiHistory.py102
-rw-r--r--resources/libraries/python/VatExecutor.py8
-rw-r--r--resources/libraries/python/VatHistory.py102
4 files changed, 109 insertions, 108 deletions
diff --git a/resources/libraries/python/PapiExecutor.py b/resources/libraries/python/PapiExecutor.py
index 0313284405..928144e058 100644
--- a/resources/libraries/python/PapiExecutor.py
+++ b/resources/libraries/python/PapiExecutor.py
@@ -20,12 +20,10 @@ from robot.api import logger
from resources.libraries.python.Constants import Constants
from resources.libraries.python.ssh import SSH, SSHTimeout
+from resources.libraries.python.PapiHistory import PapiHistory
__all__ = ["PapiExecutor", "PapiResponse"]
-# TODO: Implement Papi History
-# from resources.libraries.python.PapiHistory import PapiHistory
-
class PapiResponse(object):
"""Class for metadata specifying the Papi reply, stdout, stderr and return
@@ -148,6 +146,7 @@ class PapiExecutor(object):
:returns: self, so that method chaining is possible.
:rtype: PapiExecutor
"""
+ PapiHistory.add_to_papi_history(self._node, command, **kwargs)
self._api_command_list.append(dict(api_name=command, api_args=kwargs))
return self
diff --git a/resources/libraries/python/PapiHistory.py b/resources/libraries/python/PapiHistory.py
new file mode 100644
index 0000000000..13c483b4bc
--- /dev/null
+++ b/resources/libraries/python/PapiHistory.py
@@ -0,0 +1,102 @@
+# Copyright (c) 2019 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:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""DUT PAPI command history setup library."""
+
+from robot.api import logger
+
+from resources.libraries.python.topology import NodeType, DICT__nodes
+
+__all__ = ["DICT__DUTS_PAPI_HISTORY", "PapiHistory"]
+
+
+DICT__DUTS_PAPI_HISTORY = dict()
+
+
+class PapiHistory(object):
+ """Contains methods to set up DUT PAPI command history.
+ """
+
+ @staticmethod
+ def reset_papi_history(node):
+ """Reset PAPI command history for DUT node.
+
+ :param node: DUT node to reset PAPI command history for.
+ :type node: dict
+ """
+ DICT__DUTS_PAPI_HISTORY[node['host']] = list()
+
+ @staticmethod
+ def reset_papi_history_on_all_duts(nodes):
+ """Reset PAPI command history for all DUT nodes.
+
+ :param nodes: Nodes to reset PAPI command history for.
+ :type nodes: dict
+ """
+ for node in nodes.values():
+ if node['type'] == NodeType.DUT:
+ PapiHistory.reset_papi_history(node)
+
+ @staticmethod
+ def add_to_papi_history(node, cmd, papi=True, **kwargs):
+ """Add command to PAPI command history on DUT node.
+
+ :param node: DUT node to add command to PAPI command history for.
+ :param cmd: 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 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))
+ 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)
+
+ @staticmethod
+ def show_papi_history(node):
+ """Show PAPI command history for DUT node.
+
+ :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))
+
+ @staticmethod
+ def show_papi_history_on_all_duts(nodes):
+ """Show PAPI command history for all DUT nodes.
+
+ :param nodes: Nodes to show PAPI command history for.
+ :type nodes: dict
+ """
+ for node in nodes.values():
+ if node['type'] == NodeType.DUT:
+ PapiHistory.show_papi_history(node)
+
+
+PapiHistory.reset_papi_history_on_all_duts(DICT__nodes)
diff --git a/resources/libraries/python/VatExecutor.py b/resources/libraries/python/VatExecutor.py
index 0e40266f1c..c13e990b63 100644
--- a/resources/libraries/python/VatExecutor.py
+++ b/resources/libraries/python/VatExecutor.py
@@ -21,7 +21,7 @@ from robot.api import logger
from resources.libraries.python.ssh import SSH, SSHTimeout
from resources.libraries.python.Constants import Constants
-from resources.libraries.python.VatHistory import VatHistory
+from resources.libraries.python.PapiHistory import PapiHistory
__all__ = ['VatExecutor']
@@ -109,7 +109,9 @@ class VatExecutor(object):
remote_file_path = vat_name
with open(vat_name, 'r') as vat_file:
for line in vat_file:
- VatHistory.add_to_vat_history(node, line.replace('\n', ''))
+ PapiHistory.add_to_papi_history(node,
+ line.replace('\n', ''),
+ papi=False)
else:
remote_file_path = '{0}/{1}/{2}'.format(Constants.REMOTE_FW_DIR,
Constants.RESOURCES_TPL_VAT,
@@ -283,7 +285,7 @@ class VatTerminal(object):
:returns: Command output in python representation of JSON format or
None if not in JSON mode.
"""
- VatHistory.add_to_vat_history(self._node, cmd)
+ PapiHistory.add_to_papi_history(self._node, cmd, papi=False)
logger.debug("Executing command in VAT terminal: {0}".format(cmd))
try:
out = self._ssh.interactive_terminal_exec_command(self._tty, cmd,
diff --git a/resources/libraries/python/VatHistory.py b/resources/libraries/python/VatHistory.py
deleted file mode 100644
index ffc1644f1b..0000000000
--- a/resources/libraries/python/VatHistory.py
+++ /dev/null
@@ -1,102 +0,0 @@
-# Copyright (c) 2016 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:
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""DUT VAT command history setup library."""
-
-from robot.api import logger
-
-from resources.libraries.python.topology import NodeType, DICT__nodes
-
-__all__ = ["DICT__DUTS_VAT_HISTORY", "VatHistory"]
-
-
-def setup_vat_history(nodes):
- """Setup VAT history for DUT nodes.
-
- :param nodes: DUT nodes to setup VAT history for.
- :type nodes: dict
- """
- duts_vat_history = {}
- try:
- for node in nodes.values():
- if node['type'] == NodeType.DUT:
- duts_vat_history[node['host']] = []
- return duts_vat_history
- except AttributeError:
- # Necessary for the generation of source code documentation.
- pass
-
-DICT__DUTS_VAT_HISTORY = setup_vat_history(DICT__nodes)
-
-
-class VatHistory(object):
- """Contains methods to set up DUT VAT command history."""
-
- @staticmethod
- def reset_vat_history(node):
- """Reset VAT command history for DUT node.
-
- :param node: DUT node to reset VAT command history for.
- :type node: dict
- """
- if node['type'] == NodeType.DUT:
- DICT__DUTS_VAT_HISTORY[node['host']] = []
-
- @staticmethod
- def reset_vat_history_on_all_duts(nodes):
- """Reset VAT command history for all DUT nodes.
-
- :param nodes: Nodes to reset VAT command history for.
- :type nodes: dict
- """
- for node in nodes.values():
- if node['type'] == NodeType.DUT:
- VatHistory.reset_vat_history(node)
-
- @staticmethod
- def show_vat_history(node):
- """Show VAT command history for DUT node.
-
- :param node: DUT node to show VAT command history for.
- :type node: dict
- """
- if node['type'] == NodeType.DUT:
- sequence = "\nno VAT command executed"
- if DICT__DUTS_VAT_HISTORY[node['host']]:
- sequence = "".join(["\n{}".format(
- cmd) for cmd in DICT__DUTS_VAT_HISTORY[node['host']]])
- logger.trace(
- "{0} VAT command history:{1}\n".format(node['host'], sequence))
-
- @staticmethod
- def show_vat_history_on_all_duts(nodes):
- """Show VAT command history for all DUT nodes.
-
- :param nodes: Nodes to show VAT command history for.
- :type nodes: dict
- """
- for node in nodes.values():
- if node['type'] == NodeType.DUT:
- VatHistory.show_vat_history(node)
-
- @staticmethod
- def add_to_vat_history(node, cmd):
- """Add command to VAT command history on DUT node.
-
- :param node: DUT node to add command to VAT command history for.
- :param cmd: Command to be added to VAT command history.
- :type node: dict
- :type cmd: str
- """
- if node['type'] == NodeType.DUT:
- DICT__DUTS_VAT_HISTORY[node['host']].append(cmd)