1 # Copyright (c) 2016 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """DUT VAT command history setup library."""
16 from robot.api import logger
18 from resources.libraries.python.topology import NodeType, DICT__nodes
20 __all__ = ["DICT__duts_vat_history", "VatHistory"]
23 def setup_vat_history(nodes):
26 for node in nodes.values():
27 if node['type'] == NodeType.DUT:
28 duts_vat_history[node['host']] = []
29 return duts_vat_history
30 except AttributeError:
31 # Necessary for the generation of source code documentation.
34 DICT__duts_vat_history = setup_vat_history(DICT__nodes)
37 class VatHistory(object):
38 """Contains methods to set up DUT VAT command history."""
41 def reset_vat_history(node):
42 """Reset VAT command history for DUT node.
44 :param node: DUT node to reset VAT command history for.
47 if node['type'] == NodeType.DUT:
48 DICT__duts_vat_history[node['host']] = []
51 def reset_vat_history_on_all_duts(nodes):
52 """Reset VAT command history for all DUT nodes.
54 :param nodes: Nodes to reset VAT command history for.
57 for node in nodes.values():
58 if node['type'] == NodeType.DUT:
59 VatHistory.reset_vat_history(node)
62 def show_vat_history(node):
63 """Show VAT command history for DUT node.
65 :param node: DUT node to show VAT command history for.
68 if node['type'] == NodeType.DUT:
69 sequence = "\nno VAT command executed"\
70 if len(DICT__duts_vat_history[node['host']]) == 0\
71 else "".join("\n{}".format(cmd)
72 for cmd in DICT__duts_vat_history[node['host']])
73 logger.trace("{0} VAT command history:{1}\n".
74 format(node['host'], sequence))
77 def show_vat_history_on_all_duts(nodes):
78 """Show VAT command history for all DUT nodes.
80 :param nodes: Nodes to show VAT command history for.
83 for node in nodes.values():
84 if node['type'] == NodeType.DUT:
85 VatHistory.show_vat_history(node)
88 def add_to_vat_history(node, cmd):
89 """Add command to VAT command history on DUT node.
91 :param node: DUT node to add command to VAT command history for.
92 :param cmd: Command to be added to VAT command history.
96 if node['type'] == NodeType.DUT:
97 DICT__duts_vat_history[node['host']].append(cmd)