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):
25 for node in nodes.values():
26 if node['type'] == NodeType.DUT:
27 duts_vat_history[node['host']] = []
28 return duts_vat_history
30 DICT__duts_vat_history = setup_vat_history(DICT__nodes)
33 class VatHistory(object):
34 """Contains methods to set up DUT VAT command history."""
37 def reset_vat_history(node):
38 """Reset VAT command history for DUT node.
40 :param node: DUT node to reset VAT command history for.
43 if node['type'] == NodeType.DUT:
44 DICT__duts_vat_history[node['host']] = []
47 def reset_vat_history_on_all_duts(nodes):
48 """Reset VAT command history for all DUT nodes.
50 :param nodes: Nodes to reset VAT command history for.
53 for node in nodes.values():
54 if node['type'] == NodeType.DUT:
55 VatHistory.reset_vat_history(node)
58 def show_vat_history(node):
59 """Show VAT command history for DUT node.
61 :param node: DUT node to show VAT command history for.
64 if node['type'] == NodeType.DUT:
65 sequence = "\nno VAT command executed"\
66 if len(DICT__duts_vat_history[node['host']]) == 0\
67 else "".join("\n{}".format(cmd)
68 for cmd in DICT__duts_vat_history[node['host']])
69 logger.trace("{0} VAT command history:{1}\n".
70 format(node['host'], sequence))
73 def show_vat_history_on_all_duts(nodes):
74 """Show VAT command history for all DUT nodes.
76 :param nodes: Nodes to show VAT command history for.
79 for node in nodes.values():
80 if node['type'] == NodeType.DUT:
81 VatHistory.show_vat_history(node)
84 def add_to_vat_history(node, cmd):
85 """Add command to VAT command history on DUT node.
87 :param node: DUT node to add command to VAT command history for.
88 :param cmd: Command to be added to VAT command history.
92 if node['type'] == NodeType.DUT:
93 DICT__duts_vat_history[node['host']].append(cmd)