2 Documentation Library to use common Linux Commands and also some configuration on MySQL,Rabbit etc.
6 Library OperatingSystem
7 Resource SSHKeywords.robot
12 [Documentation] Install packages in a node
13 [Arguments] ${os_node_cxn} ${package}
14 Switch Connection ${os_node_cxn}
15 ${output} ${rc}= Execute Command sudo yum install -y ${package} return_rc=True return_stdout=True
17 Should Not Be True ${rc}
19 Local Install Rpm Package
20 [Documentation] Install packages in local VM
21 [Arguments] ${package}
22 ${rc} ${output}= Run And Return Rc And Output sudo yum install -y ${package}
24 Should Not Be True ${rc}
26 Install Local Rpm Package
27 [Documentation] Install local rpm packages
28 [Arguments] ${os_node_cxn} ${package}
29 Switch Connection ${os_node_cxn}
30 Put File /tmp/${ODL_RPM} /tmp/
31 ${output} ${rc}= Execute Command
32 ... sudo yum localinstall -y /tmp/${package}
34 ... return_stdout=True
36 Should Not Be True ${rc}
39 [Documentation] Crudini edit on a configuration file
40 [Arguments] ${os_node_cxn} ${conf_file} ${section} ${key} ${value}
41 Switch Connection ${os_node_cxn}
42 ${output} ${rc}= Execute Command
43 ... sudo crudini --verbose --set --inplace ${conf_file} ${section} ${key} ${value}
45 ... return_stdout=True
47 Should Not Be True ${rc}
51 [Documentation] Crudini edit on a configuration file
52 [Arguments] ${os_node_cxn} ${conf_file} ${section} ${key}
53 Switch Connection ${os_node_cxn}
54 ${output} ${rc}= Execute Command
55 ... sudo crudini --verbose --del --inplace ${conf_file} ${section} ${key}
57 ... return_stdout=True
59 Should Not Be True ${rc}
63 [Documentation] yum update to the latest versions in the repo
64 [Arguments] ${os_node_cxn}
65 Switch Connection ${os_node_cxn}
66 ${output} ${rc}= Execute Command sudo yum update -y return_rc=True return_stdout=True
68 Should Not Be True ${rc}
72 [Documentation] Start a service in CentOs
73 [Arguments] ${os_node_cxn} ${service}
74 Switch Connection ${os_node_cxn}
75 ${output} ${rc}= Execute Command sudo systemctl start ${service} return_rc=True return_stdout=True
77 Should Not Be True ${rc}
81 [Documentation] Enable a service in CentOs
82 [Arguments] ${os_node_cxn} ${service}
83 Switch Connection ${os_node_cxn}
84 ${output} ${rc}= Execute Command sudo systemctl enable ${service} return_rc=True return_stdout=True
86 Should Not Be True ${rc}
90 [Documentation] stop a service in CentOs
91 [Arguments] ${os_node_cxn} ${service}
92 Switch Connection ${os_node_cxn}
93 ${output} ${rc}= Execute Command sudo systemctl stop ${service} return_rc=True return_stdout=True
95 Should Not Be True ${rc}
99 [Documentation] daemon reload
100 [Arguments] ${os_node_cxn}
101 Switch Connection ${os_node_cxn}
102 ${output} ${rc}= Execute Command sudo systemctl daemon-reload return_rc=True return_stdout=True
104 Should Not Be True ${rc}
108 [Documentation] Restart a service in CentOs
109 [Arguments] ${os_node_cxn} ${service}
110 Switch Connection ${os_node_cxn}
111 ${output} ${rc}= Execute Command sudo systemctl restart ${service} return_rc=True return_stdout=True
113 Should Not Be True ${rc}
116 Stop And Disable Firewall
117 [Documentation] Disable/stop firewalld and iptables for testing
118 [Arguments] ${os_node_cxn}
119 Switch Connection ${os_node_cxn}
120 ${output} ${rc}= Execute Command sudo systemctl stop firewalld return_rc=True return_stdout=True
123 Should Not Be True ${rc}
124 ${output} ${rc}= Execute Command sudo systemctl disable firewalld return_rc=True return_stdout=True
127 Should Not Be True ${rc}
128 ${output} ${rc}= Execute Command sudo systemctl stop iptables return_rc=True return_stdout=True
131 ${output} ${rc}= Execute Command sudo systemctl disable iptables return_rc=True return_stdout=True
136 [Documentation] Chmod on any file in server
137 [Arguments] ${os_node_cxn} ${file_or_path} ${perm_value}
138 Switch Connection ${os_node_cxn}
139 ${output} ${rc}= Execute Command
140 ... sudo chmod ${perm_value} ${file_or_path}
142 ... return_stdout=True
144 Should Not Be True ${rc}
148 [Documentation] Chown on any file in server
149 [Arguments] ${os_node_cxn} ${file_or_path} ${user} ${group}
150 Switch Connection ${os_node_cxn}
151 ${output} ${rc}= Execute Command
152 ... sudo chown -R ${user}:${group} ${file_or_path}
154 ... return_stdout=True
156 Should Not Be True ${rc}
160 [Documentation] Copy file in server from src to dest
161 [Arguments] ${os_node_cxn} ${file_src} ${file_dst}
162 Switch Connection ${os_node_cxn}
163 ${output} ${rc}= Execute Command
164 ... sudo cp -f ${file_src} ${file_dst}
166 ... return_stdout=True
168 Should Not Be True ${rc}
172 [Documentation] Move or rename a file in server
173 [Arguments] ${os_node_cxn} ${file_src} ${file_dst}
174 Switch Connection ${os_node_cxn}
175 ${output} ${rc}= Execute Command
176 ... sudo mv -v -f ${file_src} ${file_dst}
178 ... return_stdout=True
183 [Documentation] Execute touch and create a file in server
184 [Arguments] ${os_node_cxn} ${file_name}
185 Switch Connection ${os_node_cxn}
186 ${output} ${rc}= Execute Command sudo touch ${file_name} return_rc=True return_stdout=True
188 Should Not Be True ${rc}
192 [Documentation] Run a command as a differnt user
193 [Arguments] ${os_node_cxn} ${command} ${run_as_user}
194 Switch Connection ${os_node_cxn}
195 ${output} ${rc}= Execute Command
196 ... sudo su -s /bin/sh -c ${command} ${run_as_user}
198 ... return_stdout=True
200 Should Not Be True ${rc}
204 [Documentation] Run a command as a differnt user
205 [Arguments] ${os_node_cxn} ${command}
206 Switch Connection ${os_node_cxn}
207 ${output} ${rc}= Execute Command ${command} return_rc=True return_stdout=True
209 Should Not Be True ${rc}
212 Create User Pass For Mysql
213 [Documentation] Create an user with password to access Mysql DB
214 [Arguments] ${os_node_cxn} ${mysql_user} ${mysql_pass}
215 Switch Connection ${os_node_cxn}
216 ${output} ${rc}= Execute Command
217 ... sudo mysqladmin -u ${mysql_user} password ${mysql_pass}
219 ... return_stdout=True
221 Should Not Be True ${rc}
224 Create Database for Mysql
225 [Documentation] Create a database on MySQL
226 [Arguments] ${os_node_cxn} ${mysql_user} ${mysql_pass} ${db_name}
227 Switch Connection ${os_node_cxn}
228 Write Commands Until Expected Prompt sudo mysql -u${mysql_user} -p${mysql_pass} > 30s
229 ${output}= Write Commands Until Expected Prompt
230 ... CREATE DATABASE ${db_name} CHARACTER SET utf8; exit;
237 [Arguments] ${os_node_cxn} ${dst_node_ip} ${src_dir} ${dst_dir}
238 Switch Connection ${os_node_cxn}
239 Write Commands Until Expected Prompt
240 ... sudo rsync -e "ssh -o StrictHostKeyChecking=no" -avz ${src_dir} ${dst_node_ip}:${dst_dir}
243 Write Commands Until Expected Prompt ${OS_USER_PASSWORD} ${OS_NODE_PROMPT} 30s
245 Grant Privileges To Mysql Database
246 [Documentation] Grant Privileges on a database in MySQL
247 [Arguments] ${os_node_cxn} ${mysql_user} ${mysql_pass} ${db_name} ${db_user} ${host_name}
249 Switch Connection ${os_node_cxn}
250 Write Commands Until Expected Prompt sudo mysql -u${mysql_user} -p${mysql_pass} > 30s
251 ${output}= Write Commands Until Expected Prompt
252 ... GRANT ALL PRIVILEGES ON ${db_name} TO '${db_user}'@'${host_name}' identified by '${db_pass}'; exit;
258 Grant Process To Mysql Database
259 [Documentation] Grant Privileges on a database in MySQL
260 [Arguments] ${os_node_cxn} ${mysql_user} ${mysql_pass} ${db_name} ${db_user} ${host_name}
262 Switch Connection ${os_node_cxn}
263 Write Commands Until Expected Prompt sudo mysql -u${mysql_user} -p${mysql_pass} > 30s
264 ${output}= Write Commands Until Expected Prompt
265 ... GRANT PROCESS ON ${db_name} TO '${db_user}'@'${host_name}' identified by '${db_pass}'; FLUSH PRIVILEGES; exit;
271 Execute MySQL STATUS Query
272 [Arguments] ${os_node_cxn} ${mysql_user} ${mysql_pass} ${attribute}
273 Switch Connection ${os_node_cxn}
274 Write Commands Until Expected Prompt sudo mysql -u${mysql_user} -p${mysql_pass} > 30s
275 ${output}= Write Commands Until Expected Prompt show STATUS LIKE '${attribute}';exit; Bye 30s
280 [Documentation] Write to file which require sudo access
281 [Arguments] ${os_node_cxn} ${file_name} ${buffer}
282 Switch Connection ${os_node_cxn}
283 ${output} ${rc}= Execute Command
284 ... echo ${buffer} | sudo tee ${file_name}
286 ... return_stdout=True
288 Should Not Be True ${rc}
292 [Documentation] Append to file which require sudo access
293 [Arguments] ${os_node_cxn} ${file_name} ${buffer}
294 Switch Connection ${os_node_cxn}
295 ${output} ${rc}= Execute Command
296 ... echo ${buffer} | sudo tee --append ${file_name}
298 ... return_stdout=True
300 Should Not Be True ${rc}
304 [Documentation] Create Soft Link
305 [Arguments] ${os_node_cxn} ${src_file_name} ${link_path}
306 Switch Connection ${os_node_cxn}
307 ${output} ${rc}= Execute Command
308 ... sudo ln -s ${src_file_name} ${link_path}
310 ... return_stdout=True
312 Should Not Be True ${rc}
316 [Documentation] Unlink a wrong link created
317 [Arguments] ${os_node_cxn} ${link_path}
318 Switch Connection ${os_node_cxn}
319 ${output} ${rc}= Execute Command sudo unlink ${link_path} return_rc=True return_stdout=True
321 Should Not Be True ${rc}
325 [Documentation] Touch a local file
326 [Arguments] ${src_file_name}
327 ${rc} ${output}= Run And Return Rc And Output sudo touch ${src_file_name}
329 Should Not Be True ${rc}
332 [Documentation] AddEntry to Local File
333 [Arguments] ${src_file_name} ${buffer}
334 ${rc} ${output}= Run And Return Rc And Output echo ${buffer} | sudo tee ${src_file_name}
336 Should Not Be True ${rc}
339 [Documentation] AddEntry to Local File
340 [Arguments] ${src_file_name} ${buffer}
341 ${rc} ${output}= Run And Return Rc And Output echo ${buffer} | sudo tee -a ${src_file_name}
343 Should Not Be True ${rc}
346 [Documentation] Export Varaibles to Env
347 [Arguments] ${src_file_name}
348 ${rc} ${output}= Run And Return Rc And Output source ${src_file_name}
350 Should Not Be True ${rc}
352 Run Command In Local Node
353 [Arguments] ${command}
354 ${rc} ${output}= Run And Return Rc And Output ${command}
356 Should Not Be True ${rc}
358 Generic HAProxy Entry
359 [Documentation] Add an entry in haproxy.cfg for the service
360 [Arguments] ${os_node_cxn} ${haproxy_ip} ${port_to_listen} ${proxy_entry}
361 Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg ' '
362 Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg frontend vip-${proxy_entry}
363 Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg ' 'bind *:${port_to_listen}
364 Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg ' 'timeout client 90s
365 Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg ' 'default_backend ${proxy_entry}
366 Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg ' '
367 Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg backend ${proxy_entry}
368 Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg ' 'balance roundrobin
371 ... /etc/haproxy/haproxy.cfg
372 ... ' 'server ${proxy_entry}_controller1 ${OS_CONTROL_1_IP}:${port_to_listen} check inter 1s
375 ... /etc/haproxy/haproxy.cfg
376 ... ' 'server ${proxy_entry}_controller2 ${OS_CONTROL_2_IP}:${port_to_listen} check inter 1s
379 ... /etc/haproxy/haproxy.cfg
380 ... ' 'server ${proxy_entry}_controller3 ${OS_CONTROL_3_IP}:${port_to_listen} check inter 1s
381 IF 3 < ${NUM_CONTROL_NODES}
384 ... /etc/haproxy/haproxy.cfg
385 ... ' 'server ${proxy_entry}_controller4 ${OS_CONTROL_4_IP}:${port_to_listen} check inter 1s
387 IF 4 < ${NUM_CONTROL_NODES}
390 ... /etc/haproxy/haproxy.cfg
391 ... ' 'server ${proxy_entry}_controller5 ${OS_CONTROL_5_IP}:${port_to_listen} check inter 1s
393 Restart Service ${os_node_cxn} haproxy
396 [Documentation] Read a file for logging
397 [Arguments] ${os_node_cxn} ${file_name}
398 Switch Connection ${os_node_cxn}
399 ${output} ${rc}= Execute Command cat ${file_name} return_rc=True return_stdout=True
401 Should Not Be True ${rc}
403 Disable SeLinux Tempororily
404 [Documentation] Disable SELinux from command
405 [Arguments] ${os_node_cxn}
406 Switch Connection ${os_node_cxn}
407 ${output} ${rc}= Execute Command sudo setenforce 0 return_rc=True return_stdout=True
411 [Arguments] ${os_ip} ${os_user} ${os_password} ${prompt}
412 ${conn_id}= SSHLibrary.Open Connection ${os_ip} prompt=${prompt} timeout=1 hour alias=${os_ip}
413 SSHKeywords.Flexible SSH Login ${os_user} password=${os_password}
414 SSHLibrary.Set Client Configuration timeout=1 hour