CSIT-339: Add Keywords for SMT
[csit.git] / resources / libraries / python / VatHistory.py
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:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
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.
13
14 """DUT VAT command history setup library."""
15
16 from robot.api import logger
17
18 from resources.libraries.python.topology import NodeType, DICT__nodes
19
20 __all__ = ["DICT__duts_vat_history", "VatHistory"]
21
22
23 def setup_vat_history(nodes):
24     duts_vat_history = {}
25     for node in nodes.values():
26         if node['type'] == NodeType.DUT:
27             duts_vat_history[node['host']] = []
28     return duts_vat_history
29
30 DICT__duts_vat_history = setup_vat_history(DICT__nodes)
31
32
33 class VatHistory(object):
34     """Contains methods to set up DUT VAT command history."""
35
36     @staticmethod
37     def reset_vat_history(node):
38         """Reset VAT command history for DUT node.
39
40         :param node: DUT node to reset VAT command history for.
41         :type node: dict
42         """
43         if node['type'] == NodeType.DUT:
44             DICT__duts_vat_history[node['host']] = []
45
46     @staticmethod
47     def reset_vat_history_on_all_duts(nodes):
48         """Reset VAT command history for all DUT nodes.
49
50         :param nodes: Nodes to reset VAT command history for.
51         :type nodes: dict
52         """
53         for node in nodes.values():
54             if node['type'] == NodeType.DUT:
55                 VatHistory.reset_vat_history(node)
56
57     @staticmethod
58     def show_vat_history(node):
59         """Show VAT command history for DUT node.
60
61         :param node: DUT node to show VAT command history for.
62         :type node: dict
63         """
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))
71
72     @staticmethod
73     def show_vat_history_on_all_duts(nodes):
74         """Show VAT command history for all DUT nodes.
75
76         :param nodes: Nodes to show VAT command history for.
77         :type nodes: dict
78         """
79         for node in nodes.values():
80             if node['type'] == NodeType.DUT:
81                 VatHistory.show_vat_history(node)
82
83     @staticmethod
84     def add_to_vat_history(node, cmd):
85         """Add command to VAT command history on DUT node.
86
87         :param node: DUT node to add command to VAT command history for.
88         :param cmd: Command to be added to VAT command history.
89         :type node: dict
90         :type cmd: str
91         """
92         if node['type'] == NodeType.DUT:
93             DICT__duts_vat_history[node['host']].append(cmd)