5 Library ./UtilLibrary.py
6 Resource KarafKeywords.txt
9 ${start} sudo mn --controller=remote,ip=${CONTROLLER} --topo tree,1 --switch ovsk,protocols=OpenFlow13
13 [Documentation] Basic setup/cleanup work that can be done safely before any system
15 Log Start the test on the base edition
17 ${mininet_conn_id}= Open Connection ${MININET} prompt=${LINUX_PROMPT} timeout=30s
18 Set Suite Variable ${mininet_conn_id}
19 Login With Public Key ${MININET_USER} ${USER_HOME}/.ssh/${SSH_KEY} any
20 Execute Command sudo ovs-vsctl set-manager ptcp:6644
25 [Arguments] ${MININET} ${cmd}=${start} ${custom}=${OVSDB_CONFIG_DIR}/ovsdb.py ${user}=${MININET_USER} ${prompt}=${LINUX_PROMPT} ${prompt_timeout}=30s
26 [Documentation] Basic setup to start mininet with custom topology
27 Log Start the test on the base edition
29 ${mininet_conn_id}= Open Connection ${MININET} prompt=${LINUX_PROMPT} timeout=30s
30 Set Suite Variable ${mininet_conn_id}
31 Login With Public Key ${MININET_USER} ${USER_HOME}/.ssh/id_rsa any
35 [Return] ${mininet_conn_id}
38 [Arguments] ${mininet_conn_id} ${prompt}=${LINUX_PROMPT}
39 [Documentation] Basic setup to stop/clean mininet
40 Switch Connection ${mininet_conn_id}
42 Read Until ${LINUX_PROMPT}
46 [Documentation] Cleanup/Shutdown work that should be done at the completion of all
48 Log Stop the test on the base edition
49 Switch Connection ${mininet_conn_id}
52 Read Until ${LINUX_PROMPT}
55 Ensure All Nodes Are In Response
56 [Arguments] ${URI} ${node_list}
57 [Documentation] A GET is made to the supplied ${URI} and every item in the ${node_list}
58 ... is verified to exist in the repsonse. This keyword currently implies that it's node
59 ... specific but any list of strings can be given in ${node_list}. Refactoring of this
60 ... to make it more generic should be done. (see keyword "Check For Elements At URI")
61 : FOR ${node} IN @{node_list}
62 \ ${resp} RequestsLibrary.Get session ${URI}
63 \ Should Be Equal As Strings ${resp.status_code} 200
64 \ Should Contain ${resp.content} ${node}
68 [Documentation] A GET on the /node/${node} API is made and specific flow stat
69 ... strings are checked for existence.
70 ${resp} RequestsLibrary.Get session ${OPERATIONAL_NODES_API}/node/${node}
71 Should Be Equal As Strings ${resp.status_code} 200
72 Should Contain ${resp.content} flow-capable-node-connector-statistics
73 Should Contain ${resp.content} flow-table-statistics
75 Check That Port Count Is Ok
76 [Arguments] ${node} ${count}
77 [Documentation] A GET on the /port API is made and the specified port ${count} is
78 ... verified. A more generic Keyword "Check For Specific Number Of Elements At URI"
79 ... also does this work and further consolidation should be done.
80 ${resp} RequestsLibrary.Get session ${REST_CONTEXT}/${CONTAINER}/port
82 Should Be Equal As Strings ${resp.status_code} 200
83 Should Contain X Times ${resp.content} ${node} ${count}
85 Check For Specific Number Of Elements At URI
86 [Arguments] ${uri} ${element} ${expected_count}
87 [Documentation] A GET is made to the specified ${URI} and the specific count of a
88 ... given element is done (as supplied by ${element} and ${expected_count})
89 ${resp} RequestsLibrary.Get session ${uri}
91 Should Be Equal As Strings ${resp.status_code} 200
92 Should Contain X Times ${resp.content} ${element} ${expected_count}
94 Check For Elements At URI
95 [Arguments] ${uri} ${elements}
96 [Documentation] A GET is made at the supplied ${URI} and every item in the list of
97 ... ${elements} is verified to exist in the response
98 ${resp} RequestsLibrary.Get session ${uri}
100 Should Be Equal As Strings ${resp.status_code} 200
101 : FOR ${i} IN @{elements}
102 \ Should Contain ${resp.content} ${i}
104 Check For Elements Not At URI
105 [Arguments] ${uri} ${elements}
106 [Documentation] A GET is made at the supplied ${URI} and every item in the list of
107 ... ${elements} is verified to NOT exist in the response
108 ${resp} RequestsLibrary.Get session ${uri}
110 Should Be Equal As Strings ${resp.status_code} 200
111 : FOR ${i} IN @{elements}
112 \ Should Not Contain ${resp.content} ${i}
115 [Arguments] ${mininet_system}=${MININET}
116 Run Command On Remote System ${mininet_system} sudo mn -c
117 Run Command On Remote System ${mininet_system} sudo ps -elf | egrep 'usr/local/bin/mn' | egrep python | awk '{print "sudo kill -9",$4}' | sh
120 [Arguments] ${mininet_system}=${MININET}
121 [Documentation] Cleans up the OVS instance and remove any existing common known bridges.
122 ${output}= Run Command On Remote System ${mininet_system} sudo ovs-vsctl list-br
124 : FOR ${i} IN ${output}
125 \ Run Command On Remote System ${mininet_system} sudo ovs-vsctl --if-exists del-br ${i}
126 Run Command On Remote System ${mininet_system} sudo ovs-vsctl del-manager
128 Extract Value From Content
129 [Arguments] ${content} ${index} ${strip}=nostrip
130 [Documentation] Will take the given response content and return the value at the given index as a string
131 ${value}= Get Json Value ${content} ${index}
132 ${value}= Convert To String ${value}
133 ${value}= Run Keyword If '${strip}' == 'strip' Strip Quotes ${value}
136 Get Process ID Based On Regex On Remote System
137 [Arguments] ${remote_system} ${regex_string_to_match_on}
138 [Documentation] Uses ps to find a process that matches the supplied regex. Returns the PID of that process
139 ... The ${regex_string_to_match_on} should produce a unique process otherwise the PID returned may not be
141 # doing the extra -v grep in this command to exclude the grep process itself from the output
142 ${output}= Run Command On Remote System ${remote_system} ps -elf | grep -v grep | grep ${regex_string_to_match_on} | awk '{print $4}'
143 # ${output} contains the system prompt and all we want is the value of the number
144 ${pid}= Fetch From Left ${output} \r
147 Get Process Thread Count On Remote System
148 [Arguments] ${remote_system} ${pid}
149 [Documentation] Executes the ps command to retrieve the lightweight process (aka thread) count.
150 ${output}= Run Command On Remote System ${remote_system} ps --no-headers -o nlwp ${pid}
151 # ${output} contains the system prompt and all we want is the value of the number
152 ${thread_count}= Fetch From Left ${output} \r
153 [Return] ${thread_count}
156 [Arguments] ${string_to_strip}
157 [Documentation] Will strip ALL quotes from given string and return the new string
158 ${string_to_return}= Replace String ${string_to_strip} " \ count=-1
159 [Return] ${string_to_return}
161 Run Command On Remote System
162 [Arguments] ${remote_system} ${cmd} ${user}=${MININET_USER} ${prompt}=${LINUX_PROMPT} ${prompt_timeout}=30s
163 [Documentation] Reduces the common work of running a command on a remote system to a single higher level
164 ... robot keyword, taking care to log in with a public key and. The command given is written
165 ... and the output returned. No test conditions are checked.
166 Log Attempting to execute ${cmd} on ${remote_system} by ${user} with ${keyfile_pass} and ${prompt}
167 ${conn_id}= SSHLibrary.Open Connection ${remote_system} prompt=${prompt} timeout=${prompt_timeout}
168 Login With Public Key ${user} ${USER_HOME}/.ssh/${SSH_KEY} ${KEYFILE_PASS}
169 SSHLibrary.Write ${cmd}
170 ${output}= SSHLibrary.Read Until ${prompt}
171 SSHLibrary.Close Connection
175 Verify File Exists On Remote System
176 [Arguments] ${remote_system} ${file} ${user}=${MININET_USER} ${prompt}=${LINUX_PROMPT} ${prompt_timeout}=5s
177 [Documentation] Will create connection with public key and will PASS if the given ${file} exists,
178 ... otherwise will FAIL
179 ${conn_id}= Open Connection ${remote_system} prompt=${prompt} timeout=${prompt_timeout}
180 Login With Public Key ${user} ${USER_HOME}/.ssh/${SSH_KEY} any
181 SSHLibrary.File Should Exist ${file}
184 Verify Controller Is Not Dead
185 [Arguments] ${controller_ip}=${CONTROLLER}
186 [Documentation] Will execute any tests to verify the controller is not dead. Some checks are
187 ... Out Of Memory Execptions.
188 Check Karaf Log File Does Not Have Messages ${controller_ip} java.lang.OutOfMemoryError
190 Verify Controller Has No Null Pointer Exceptions
191 [Arguments] ${controller_ip}=${CONTROLLER}
192 [Documentation] Will execute any tests to verify the controller is not having any null pointer eceptions.
193 Check Karaf Log File Does Not Have Messages ${controller_ip} java.lang.NullPointerException
197 [Documentation] Get the Epoc time from MM/DD/YYYY HH:MM:SS
198 ${epoch_time}= Convert Date ${time} epoch exclude_milles=True date_format=%m/%d/%Y %H:%M:%S
199 ${epoch_time}= Convert To Integer ${epoch_time}
200 [Return] ${epoch_time}
202 Remove Space on String
203 [Arguments] ${str} ${count}=-1
204 [Documentation] Remove the empty space from given string.count is optional,if its given
205 ... that many occurence of space will be removed from left
206 ${x}= Convert To String ${str}
207 ${x}= Replace String ${str} ${SPACE} ${EMPTY} count=${count}
210 Split Value from String
211 [Arguments] ${str} ${splitter}
212 [Documentation] Split the String based on given splitter and return as list
213 @{x}= Split String ${str} ${splitter}
216 Concatenate the String
217 [Arguments] ${str1} ${str2}
218 [Documentation] Catenate the two non-string objects and return as String
219 ${str1}= Convert to String ${str1}
220 ${str2}= Convert to String ${str2}
221 ${output}= Catenate ${str1} ${str2}
224 Remove All Elements At URI
226 ${resp} RequestsLibrary.Delete session ${uri}
227 Should Be Equal As Strings ${resp.status_code} 200
229 Add Elements To URI From File
230 [Arguments] ${dest_uri} ${data_file}
231 ${body} OperatingSystem.Get File ${data_file}
232 ${resp} RequestsLibrary.Put session ${dest_uri} data=${body} headers=${headers}
233 Should Be Equal As Strings ${resp.status_code} 200
235 Post Elements To URI From File
236 [Arguments] ${dest_uri} ${data_file}
237 ${body} OperatingSystem.Get File ${data_file}
238 ${resp} RequestsLibrary.Post session ${dest_uri} data=${body} headers=${headers}
239 Should Be Equal As Strings ${resp.status_code} 200