Migrate Get Requests invocations(libraries)
[integration/test.git] / csit / libraries / SwitchClasses / ProVision.py
1 """
2 Provision 3800 Object Definition
3 Authors: james.luhrsen@hp.com
4 Created: 2014-10-02
5 """
6 import re
7 from BaseSwitch import BaseSwitch
8
9
10 class ProVision(BaseSwitch):
11     """
12     ProVision Super Class
13     """
14
15     make = "provision"
16     model = ""
17
18     mgmt_protocol = "telnet"
19     mgmt_ip = ""
20     mgmt_port = ""
21     mgmt_prompt = model + ".*#"
22
23     initialization_type = "reboot"
24
25     of_instance_id = "21"
26
27     @property
28     def connection_configs(self):
29         return [
30             "\rend \
31                  \rconfig \
32                  \rconsole local-terminal none \
33                  \rno page \
34                  \rend\r"
35         ]
36
37     @property
38     def initialization_cmds(self):
39         return [
40             "\rend\rboot system flash primary config odl_test_startup_config\r",
41             "y",
42             "n",
43         ]
44
45     @property
46     def cleanup_cmds(self):
47         return ["end", "config", "no openflow\r", "y"]
48
49     @property
50     def base_openflow_config(self):
51         return (
52             "end",
53             "config",
54             "openflow",
55             "controller-id "
56             + self.of_instance_id
57             + " ip "
58             + self.of_controller_ip
59             + " controller-interface oobm",
60             "instance " + self.of_instance_id,
61             "member vlan 10",
62             "controller-id " + self.of_instance_id + " ",
63             "version 1.3",
64             "enable",
65             "openflow enable",
66             "end",
67         )
68
69     @property
70     def openflow_enable_config(self):
71         return ["end", "config", "openflow enable", "end"]
72
73     @property
74     def openflow_validation_cmd(self):
75         return "show openflow"
76
77     @property
78     def openflow_enable_validations(self):
79         return ["OpenFlow +: Enabled", self.of_instance_id + " +Up +2 +1 +1.3"]
80
81     @property
82     def openflow_disable_config(self):
83         return ["end", "config", "openflow disable", "end"]
84
85     @property
86     def openflow_disable_validations(self):
87         return ["OpenFlow +: Disabled", self.of_instance_id + " +Down +0 +0 +1.3"]
88
89     @property
90     def dump_all_flows(self):
91         return "show openflow instance " + self.of_instance_id + " flows"
92
93     @property
94     def flow_validations(self):
95         return [
96             "(?ms)Flow Table ID : 0.*Flow Table ID : 100.*"
97             + "Source Protocol Address : "
98             + self.ip_src
99             + ".*"
100             + "Target Protocol Address : "
101             + self.ip_dst
102             + ".*"
103             + "Flow Table ID : "
104             + self.table_id
105             + ".*"
106             + self.action,
107             "Source MAC    : " + self.src_mac,
108             "Destination MAC  : " + self.dst_mac,
109         ]
110
111     def create_flow_match_elements(self, flow_xml):
112         super(ProVision, self).create_flow_match_elements(flow_xml)
113         self.src_mac = self.format_mac_with_no_hyphens_and_one_colon(self.src_mac)
114         self.dst_mac = self.format_mac_with_no_hyphens_and_one_colon(self.dst_mac)
115         self.action = self.convert_action_to_provision_format(self.action)
116
117     def format_mac_with_no_hyphens_and_one_colon(self, mac):
118         mac_no_colons = re.sub(":", "", mac)
119         mac_with_hyphen = mac_no_colons[:6] + "-" + mac_no_colons[6:]
120         return mac_with_hyphen
121
122     def convert_action_to_provision_format(self, action):
123         if action == "INPORT":
124             return "Ingress Port"
125         if action == "TABLE":
126             return "Table"
127         if action == "NORMAL":
128             return "Normal"
129         if action == "FLOOD":
130             return "Flood"
131         if action == "ALL":
132             return "All"
133         if action == "CONTROLLER":
134             return "Controller Port"
135         if action == "LOCAL":
136             return "Local"
137         return "UNKNOWN"
138
139     @property
140     def datapath_id_output_command(self):
141         return "show openflow instance " + self.of_instance_id + " | include Datapath"
142
143     connection_index = ""
144
145     def set_connection_index(self, idx):
146         self.connection_index = idx
147
148     datapath_id_output_string = ""
149     datapath_id = ""
150
151     def update_datapath_id(self):
152         if not self.datapath_id_output_string:
153             self.datapath_id = "unknown"
154         else:
155             # Datapath ID              : 000af0921c22bac0
156             # |-----------------(0)---------------------|
157             # |-----------(1)----------| |------(2)-----|
158             matches = re.search(r"(.*: )(\w+)", self.datapath_id_output_string)
159             datapath_id_hex = matches.group(2)
160             self.datapath_id = self.convert_hex_to_decimal_as_string(datapath_id_hex)