2 Library RequestsLibrary
9 [Documentation] Using the connection index for the given switch, will execute the command string
10 ... "datapath_id_output_command" which will store the output in switch.datapath_id_output_string.
11 ... The switch object method "update_datapath_id" is called which is assumed to place the ODL
12 ... friendly (decimal) version of the datapath id in to switch.datapath_id and the value is also
13 ... returned from this keyword.
15 Configure Connection Index And Prompt Wrapper ${switch}
16 Read Wrapper ${switch}
17 ${switch.datapath_id_output_string}= Execute Command Wrapper
19 ... ${switch.datapath_id_output_command}
20 Log ${switch.datapath_id_output_string}
21 Call Method ${switch} update_datapath_id
22 RETURN ${switch.datapath_id}
24 Verify Switch In Operational Data Store
25 [Documentation] Verifies the existence of the switch.datapath_id in the operational datastore.
27 ${resp}= RequestsLibrary.GET On Session session url=${REST_CONTEXT}
29 Should Match Regexp ${resp.text} openflow:${switch.datapath_id}
31 Verify Switch Not In Operational Data Store
32 [Documentation] Verifies that the given switch.datapath_id is not in the operational datastore.
34 ${resp}= RequestsLibrary.GET On Session session url=${REST_CONTEXT}
36 Should Not Match Regexp ${resp.text} openflow:${switch.datapath_id}
38 Iterate Switch Commands From List
39 [Documentation] Each string in the @{cmd_list} argument is executed on the switch.connection_index.
40 [Arguments] ${switch} ${cmd_list}
41 Configure Connection Index And Prompt Wrapper ${switch}
42 FOR ${cmd} IN @{cmd_list}
44 Read Wrapper ${switch}
45 Execute Command Wrapper ${switch} ${cmd}
49 [Documentation] The commands neccessary to configure openflow on the given switch object should exist in the switch.base_openflow_config attribute. \ Also, the commands/logic to verify that openflow is working are checked in this keyword and come
50 ... from switch.openflow_validation_cmd output where the validation strings are
51 ... stored in switch.openflow_enable_validations
53 Log Applying configs to configure openflow on the given switch.
54 Configure Connection Index And Prompt Wrapper ${switch}
55 Iterate Switch Commands From List ${switch} ${switch.base_openflow_config}
56 Read Wrapper ${switch}
57 Wait Until Keyword Succeeds
60 ... Validate Switch Output
62 ... ${switch.openflow_validation_cmd}
63 ... ${switch.openflow_enable_validations}
64 Read Wrapper ${switch}
66 Validate Switch Output
67 [Documentation] A generic keyword that will execute one command on the switch, and check for each string in the @{validations} argument. \ There is a boolean flag ${should_exist} that can be used to check that the validations are or are NOT in the output of the command executed.
68 [Arguments] ${switch} ${cmd} ${validations} ${should_exist}=true
69 Configure Connection Index And Prompt Wrapper ${switch}
70 Read Wrapper ${switch}
71 ${tmp}= Execute Command Wrapper ${switch} /sbin/ifconfig
73 ${output}= Execute Command Wrapper ${switch} ${cmd}
75 FOR ${str} IN @{validations}
76 IF "${should_exist}" == "true"
77 Should Match Regexp ${output} ${str}
79 IF "${should_exist}" == "false"
80 Should Not Match Regexp ${output} ${str}
85 [Documentation] executes the switch.openflow_enable_config on the given switch and validates that openflow is operational with the switch.openflow_validation_command against all the strings in the switch.openflow_enable_validations list.
87 Log Will toggle openflow to be ON
88 Iterate Switch Commands From List ${switch} ${switch.openflow_enable_config}
89 Read Wrapper ${switch}
90 Wait Until Keyword Succeeds
93 ... Validate Switch Output
95 ... ${switch.openflow_validation_cmd}
96 ... ${switch.openflow_enable_validations}
99 [Documentation] executes the switch.openflow_disable_config on the given switch and validates that openflow is NOT operational with the switch.openflow_validation_command against all the strings in the switch.openflow_disable_validations list.
100 [Arguments] ${switch}
101 Log Will toggle openflow to be OFF
102 Iterate Switch Commands From List ${switch} ${switch.openflow_disable_config}
103 Read Wrapper ${switch}
104 Wait Until Keyword Succeeds
107 ... Validate Switch Output
109 ... ${switch.openflow_validation_cmd}
110 ... ${switch.openflow_disable_validations}
112 Open Connection Wrapper
113 [Documentation] Some switches require telnet access and others require ssh access. \ Based on the
114 ... switch.mgmt_protocol, the connection open will be handled by the right robot
115 ... library (Telnet or SSHLibrary). \ The connection_index is returned.
116 [Arguments] ${switch}
117 IF "${switch.mgmt_protocol}" == "ssh"
118 Call Method ${switch} set_ssh_key ${USER_HOME}/.ssh/${SSH_KEY}
120 IF "${switch.mgmt_protocol}" == "ssh"
121 Call Method ${switch} set_mgmt_user ${TOOLS_SYSTEM_USER}
123 IF "${switch.mgmt_protocol}" == "ssh"
124 ${connection_index}= SSHLibrary.Open Connection
125 ... ${switch.mgmt_ip}
126 ... prompt=${switch.mgmt_prompt}
129 ${connection_index}= Set Variable ${None}
131 IF "${switch.mgmt_protocol}" == "ssh"
132 Login With Public Key ${switch.mgmt_user} ${switch.ssh_key} any
134 IF "${switch.mgmt_protocol}" == "telnet"
135 ${connection_index}= Telnet.Open Connection ${switch.mgmt_ip}
137 ${connection_index}= Set Variable ${connection_index}
139 RETURN ${connection_index}
141 Configure Connection Index And Prompt Wrapper
142 [Documentation] when using multiple switch connections (e.g. more than one switch device) this keyword will switch the current connection index and prompt so that the following
143 ... Read or Write actions happen on the correct device.
144 [Arguments] ${switch}
145 IF "${switch.mgmt_protocol}" == "ssh"
146 SSHLibrary.Switch Connection ${switch.connection_index}
148 IF "${switch.mgmt_protocol}" == "ssh"
149 SSHLibrary.Set Client Configuration prompt=${switch.mgmt_prompt} timeout=5s
151 IF "${switch.mgmt_protocol}" == "telnet"
152 Telnet.Switch Connection ${switch.connection_index}
154 IF "${switch.mgmt_protocol}" == "telnet"
155 Telnet.Set Prompt ${switch.mgmt_prompt} True
159 [Documentation] Wraps the Read command so that depending on the switch.mgmt_protocol the right
160 ... library (Telnet or SSHLibrary) is used.
161 [Arguments] ${switch}
162 IF "${switch.mgmt_protocol}" == "ssh" SSHLibrary.Read
163 IF "${switch.mgmt_protocol}" == "telnet" Telnet.Read
166 [Documentation] Wraps the Write Bare command so that depending on the switch.mgmt_protocol the right
167 ... library (Telnet or SSHLibrary) is used.
168 [Arguments] ${switch} ${cmd}
169 IF "${switch.mgmt_protocol}" == "ssh" SSHLibrary.Write Bare ${cmd}
170 IF "${switch.mgmt_protocol}" == "telnet" Telnet.Write Bare ${cmd}
172 Execute Command Wrapper
173 [Documentation] Wraps the Execute Command keyword so that depending on the switch.mgmt_protocol the right
174 ... library (Telnet or SSHLibrary) is used.
175 [Arguments] ${switch} ${cmd}
176 IF "${switch.mgmt_protocol}" == "ssh"
177 ${output}= SSHLibrary.Execute Command ${cmd}
179 ${output}= Set Variable ${None}
181 IF "${switch.mgmt_protocol}" == "telnet"
182 ${output}= Telnet.Execute Command ${cmd}
184 ${output}= Set Variable ${output}
189 [Documentation] Will Open a connection to the switch, which will set the switch.connection_index.
190 ... For each switch.connection_configs string, a write bare will be executed on the
191 ... switch connection. \ The write bare is done becuase some switch consoles require
192 ... extra input (CR/LF, etc.) that are needed. \ The connection_configs strings should
193 ... be sufficient to put the switch console in to a usuable state so that further
194 ... interactions with the switch can be used with the robot keyword "Execute
196 [Arguments] ${switch}
197 ${connection_index}= Open Connection Wrapper ${switch}
198 Call Method ${switch} set_connection_index ${connection_index}
199 Configure Connection Index And Prompt Wrapper ${switch}
200 FOR ${cmd} IN @{switch.connection_configs}
201 Write Bare Wrapper ${switch} ${cmd}
203 Read Wrapper ${switch}
207 [Documentation] will execute and command strings stored in switch.cleanup_cmds
208 [Arguments] ${switch}
209 Iterate Switch Commands From List ${switch} ${switch.cleanup_cmds}
212 [Documentation] Will connect and execute all switch.initialization_cmds on the given switch.
213 ... In some cases, this may be a reboot. \ If so, the switch.initialization_type can
214 ... be set to "reboot" and further logic is invoked to wait for the reboot to complete
215 ... and a reconnect to the switch is made.
216 [Arguments] ${switch}
217 Connect To Switch ${switch}
218 Configure Connection Index And Prompt Wrapper ${switch}
219 FOR ${cmd} IN @{switch.initialization_cmds}
220 Write Bare Wrapper ${switch} ${cmd}
222 Run Keyword And Ignore Error Read Wrapper ${switch}
224 IF "${switch.initialization_type}" == "reboot"
225 Wait For Switch Reboot ${switch}
227 IF "${switch.initialization_type}" == "reboot"
228 Connect To Switch ${switch}
231 Wait For Switch Reboot
232 [Documentation] If a switch has been set to reboot, it may take some time. \ This keyword will first
233 ... make sure the switch has gone down (10 pings over 10 seconds should not see
234 ... a 100% success, although it may respond for a short time after the reload is
235 ... issued). \ Then a poll is done with a single ping request every 5s until a success
236 ... is found, at which point it is assumed the switch is up and ready.
237 [Arguments] ${switch}
238 ${output}= Run ping ${switch.mgmt_ip} -c 10 -W 1
241 ... 10 packets transmitted, 10 received, 0% packet loss
242 ... Does not appear that switch has rebooted
243 Wait Until Keyword Succeeds 240s 5s Ping ${switch.mgmt_ip}
247 ${output}= Run ping ${ip} -c 1 -W 1
248 Should Contain ${output} 1 packets transmitted, 1 received