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):
24 """Setup VAT history for DUT nodes.
26 :param nodes: DUT nodes to setup VAT history for.
31 for node in nodes.values():
32 if node['type'] == NodeType.DUT:
33 duts_vat_history[node['host']] = []
34 return duts_vat_history
35 except AttributeError:
36 # Necessary for the generation of source code documentation.
39 DICT__DUTS_VAT_HISTORY = setup_vat_history(DICT__nodes)
42 class VatHistory(object):
43 """Contains methods to set up DUT VAT command history."""
46 def reset_vat_history(node):
47 """Reset VAT command history for DUT node.
49 :param node: DUT node to reset VAT command history for.
52 if node['type'] == NodeType.DUT:
53 DICT__DUTS_VAT_HISTORY[node['host']] = []
56 def reset_vat_history_on_all_duts(nodes):
57 """Reset VAT command history for all DUT nodes.
59 :param nodes: Nodes to reset VAT command history for.
62 for node in nodes.values():
63 if node['type'] == NodeType.DUT:
64 VatHistory.reset_vat_history(node)
67 def show_vat_history(node):
68 """Show VAT command history for DUT node.
70 :param node: DUT node to show VAT command history for.
73 if node['type'] == NodeType.DUT:
74 sequence = "\nno VAT command executed"\
75 if len(DICT__DUTS_VAT_HISTORY[node['host']]) == 0\
76 else "".join("\n{}".format(cmd)
77 for cmd in DICT__DUTS_VAT_HISTORY[node['host']])
78 logger.trace("{0} VAT command history:{1}\n".
79 format(node['host'], sequence))
82 def show_vat_history_on_all_duts(nodes):
83 """Show VAT command history for all DUT nodes.
85 :param nodes: Nodes to show VAT command history for.
88 for node in nodes.values():
89 if node['type'] == NodeType.DUT:
90 VatHistory.show_vat_history(node)
93 def add_to_vat_history(node, cmd):
94 """Add command to VAT command history on DUT node.
96 :param node: DUT node to add command to VAT command history for.
97 :param cmd: Command to be added to VAT command history.
101 if node['type'] == NodeType.DUT:
102 DICT__DUTS_VAT_HISTORY[node['host']].append(cmd)