2 Documentation Library to use common Linux Commands and also some configuration on MySQL,Rabbit etc.
5 Library OperatingSystem
6 Resource SSHKeywords.robot
10 [Arguments] ${os_node_cxn} ${package}
11 [Documentation] Install packages in a node
12 Switch Connection ${os_node_cxn}
13 ${output} ${rc}= Execute Command sudo yum install -y ${package} return_rc=True return_stdout=True
15 Should Not Be True ${rc}
17 Local Install Rpm Package
18 [Arguments] ${package}
19 [Documentation] Install packages in local VM
20 ${rc} ${output}= Run And Return Rc And Output sudo yum install -y ${package}
22 Should Not Be True ${rc}
24 Install Local Rpm Package
25 [Arguments] ${os_node_cxn} ${package}
26 [Documentation] Install local rpm packages
27 Switch Connection ${os_node_cxn}
28 Put File /tmp/${ODL_RPM} /tmp/
29 ${output} ${rc}= Execute Command sudo yum localinstall -y /tmp/${package} return_rc=True return_stdout=True
31 Should Not Be True ${rc}
34 [Arguments] ${os_node_cxn} ${conf_file} ${section} ${key} ${value}
35 [Documentation] Crudini edit on a configuration file
36 Switch Connection ${os_node_cxn}
37 ${output} ${rc}= Execute Command sudo crudini --verbose --set --inplace ${conf_file} ${section} ${key} ${value} return_rc=True return_stdout=True
39 Should Not Be True ${rc}
43 [Arguments] ${os_node_cxn} ${conf_file} ${section} ${key}
44 [Documentation] Crudini edit on a configuration file
45 Switch Connection ${os_node_cxn}
46 ${output} ${rc}= Execute Command sudo crudini --verbose --del --inplace ${conf_file} ${section} ${key} return_rc=True return_stdout=True
48 Should Not Be True ${rc}
52 [Arguments] ${os_node_cxn}
53 [Documentation] yum update to the latest versions in the repo
54 Switch Connection ${os_node_cxn}
55 ${output} ${rc}= Execute Command sudo yum update -y return_rc=True return_stdout=True
57 Should Not Be True ${rc}
61 [Arguments] ${os_node_cxn} ${service}
62 [Documentation] Start a service in CentOs
63 Switch Connection ${os_node_cxn}
64 ${output} ${rc}= Execute Command sudo systemctl start ${service} return_rc=True return_stdout=True
66 Should Not Be True ${rc}
70 [Arguments] ${os_node_cxn} ${service}
71 [Documentation] Enable a service in CentOs
72 Switch Connection ${os_node_cxn}
73 ${output} ${rc}= Execute Command sudo systemctl enable ${service} return_rc=True return_stdout=True
75 Should Not Be True ${rc}
79 [Arguments] ${os_node_cxn} ${service}
80 [Documentation] stop a service in CentOs
81 Switch Connection ${os_node_cxn}
82 ${output} ${rc}= Execute Command sudo systemctl stop ${service} return_rc=True return_stdout=True
84 Should Not Be True ${rc}
88 [Arguments] ${os_node_cxn}
89 [Documentation] daemon reload
90 Switch Connection ${os_node_cxn}
91 ${output} ${rc}= Execute Command sudo systemctl daemon-reload return_rc=True return_stdout=True
93 Should Not Be True ${rc}
97 [Arguments] ${os_node_cxn} ${service}
98 [Documentation] Restart a service in CentOs
99 Switch Connection ${os_node_cxn}
100 ${output} ${rc}= Execute Command sudo systemctl restart ${service} return_rc=True return_stdout=True
102 Should Not Be True ${rc}
105 Stop And Disable Firewall
106 [Arguments] ${os_node_cxn}
107 [Documentation] Disable/stop firewalld and iptables for testing
108 Switch Connection ${os_node_cxn}
109 ${output} ${rc}= Execute Command sudo systemctl stop firewalld return_rc=True return_stdout=True
112 Should Not Be True ${rc}
113 ${output} ${rc}= Execute Command sudo systemctl disable firewalld return_rc=True return_stdout=True
116 Should Not Be True ${rc}
117 ${output} ${rc}= Execute Command sudo systemctl stop iptables return_rc=True return_stdout=True
120 ${output} ${rc}= Execute Command sudo systemctl disable iptables return_rc=True return_stdout=True
125 [Arguments] ${os_node_cxn} ${file_or_path} ${perm_value}
126 [Documentation] Chmod on any file in server
127 Switch Connection ${os_node_cxn}
128 ${output} ${rc}= Execute Command sudo chmod ${perm_value} ${file_or_path} return_rc=True return_stdout=True
130 Should Not Be True ${rc}
134 [Arguments] ${os_node_cxn} ${file_or_path} ${user} ${group}
135 [Documentation] Chown on any file in server
136 Switch Connection ${os_node_cxn}
137 ${output} ${rc}= Execute Command sudo chown -R ${user}:${group} ${file_or_path} return_rc=True return_stdout=True
139 Should Not Be True ${rc}
143 [Arguments] ${os_node_cxn} ${file_src} ${file_dst}
144 [Documentation] Copy file in server from src to dest
145 Switch Connection ${os_node_cxn}
146 ${output} ${rc}= Execute Command sudo cp -f ${file_src} ${file_dst} return_rc=True return_stdout=True
148 Should Not Be True ${rc}
152 [Arguments] ${os_node_cxn} ${file_src} ${file_dst}
153 [Documentation] Move or rename a file in server
154 Switch Connection ${os_node_cxn}
155 ${output} ${rc}= Execute Command sudo mv -v -f ${file_src} ${file_dst} return_rc=True return_stdout=True
160 [Arguments] ${os_node_cxn} ${file_name}
161 [Documentation] Execute touch and create a file in server
162 Switch Connection ${os_node_cxn}
163 ${output} ${rc}= Execute Command sudo touch ${file_name} return_rc=True return_stdout=True
165 Should Not Be True ${rc}
169 [Arguments] ${os_node_cxn} ${command} ${run_as_user}
170 [Documentation] Run a command as a differnt user
171 Switch Connection ${os_node_cxn}
172 ${output} ${rc}= Execute Command sudo su -s /bin/sh -c ${command} ${run_as_user} return_rc=True return_stdout=True
174 Should Not Be True ${rc}
178 [Arguments] ${os_node_cxn} ${command}
179 [Documentation] Run a command as a differnt user
180 Switch Connection ${os_node_cxn}
181 ${output} ${rc}= Execute Command ${command} return_rc=True return_stdout=True
183 Should Not Be True ${rc}
186 Create User Pass For Mysql
187 [Arguments] ${os_node_cxn} ${mysql_user} ${mysql_pass}
188 [Documentation] Create an user with password to access Mysql DB
189 Switch Connection ${os_node_cxn}
190 ${output} ${rc}= Execute Command sudo mysqladmin -u ${mysql_user} password ${mysql_pass} return_rc=True return_stdout=True
192 Should Not Be True ${rc}
195 Create Database for Mysql
196 [Arguments] ${os_node_cxn} ${mysql_user} ${mysql_pass} ${db_name}
197 [Documentation] Create a database on MySQL
198 Switch Connection ${os_node_cxn}
199 Write Commands Until Expected Prompt sudo mysql -u${mysql_user} -p${mysql_pass} > 30s
200 ${output}= Write Commands Until Expected Prompt CREATE DATABASE ${db_name} CHARACTER SET utf8; exit; Bye 30s
205 [Arguments] ${os_node_cxn} ${dst_node_ip} ${src_dir} ${dst_dir}
206 Switch Connection ${os_node_cxn}
207 Write Commands Until Expected Prompt sudo rsync -e "ssh -o StrictHostKeyChecking=no" -avz ${src_dir} ${dst_node_ip}:${dst_dir} d: 30s
208 Write Commands Until Expected Prompt ${OS_USER_PASSWORD} ${OS_NODE_PROMPT} 30s
210 Grant Privileges To Mysql Database
211 [Arguments] ${os_node_cxn} ${mysql_user} ${mysql_pass} ${db_name} ${db_user} ${host_name}
213 [Documentation] Grant Privileges on a database in MySQL
214 Switch Connection ${os_node_cxn}
215 Write Commands Until Expected Prompt sudo mysql -u${mysql_user} -p${mysql_pass} > 30s
216 ${output}= Write Commands Until Expected Prompt GRANT ALL PRIVILEGES ON ${db_name} TO '${db_user}'@'${host_name}' identified by '${db_pass}'; exit; Bye 30s
220 Grant Process To Mysql Database
221 [Arguments] ${os_node_cxn} ${mysql_user} ${mysql_pass} ${db_name} ${db_user} ${host_name}
223 [Documentation] Grant Privileges on a database in MySQL
224 Switch Connection ${os_node_cxn}
225 Write Commands Until Expected Prompt sudo mysql -u${mysql_user} -p${mysql_pass} > 30s
226 ${output}= Write Commands Until Expected Prompt GRANT PROCESS ON ${db_name} TO '${db_user}'@'${host_name}' identified by '${db_pass}'; FLUSH PRIVILEGES; exit; Bye 30s
230 Execute MySQL STATUS Query
231 [Arguments] ${os_node_cxn} ${mysql_user} ${mysql_pass} ${attribute}
232 Switch Connection ${os_node_cxn}
233 Write Commands Until Expected Prompt sudo mysql -u${mysql_user} -p${mysql_pass} > 30s
234 ${output}= Write Commands Until Expected Prompt show STATUS LIKE '${attribute}';exit; Bye 30s
239 [Arguments] ${os_node_cxn} ${file_name} ${buffer}
240 [Documentation] Write to file which require sudo access
241 Switch Connection ${os_node_cxn}
242 ${output} ${rc}= Execute Command echo ${buffer} | sudo tee ${file_name} return_rc=True return_stdout=True
244 Should Not Be True ${rc}
248 [Arguments] ${os_node_cxn} ${file_name} ${buffer}
249 [Documentation] Append to file which require sudo access
250 Switch Connection ${os_node_cxn}
251 ${output} ${rc}= Execute Command echo ${buffer} | sudo tee --append ${file_name} return_rc=True return_stdout=True
253 Should Not Be True ${rc}
257 [Arguments] ${os_node_cxn} ${src_file_name} ${link_path}
258 [Documentation] Create Soft Link
259 Switch Connection ${os_node_cxn}
260 ${output} ${rc}= Execute Command sudo ln -s ${src_file_name} ${link_path} return_rc=True return_stdout=True
262 Should Not Be True ${rc}
266 [Arguments] ${os_node_cxn} ${link_path}
267 [Documentation] Unlink a wrong link created
268 Switch Connection ${os_node_cxn}
269 ${output} ${rc}= Execute Command sudo unlink ${link_path} return_rc=True return_stdout=True
271 Should Not Be True ${rc}
275 [Arguments] ${src_file_name}
276 [Documentation] Touch a local file
277 ${rc} ${output}= Run And Return Rc And Output sudo touch ${src_file_name}
279 Should Not Be True ${rc}
282 [Arguments] ${src_file_name} ${buffer}
283 [Documentation] AddEntry to Local File
284 ${rc} ${output}= Run And Return Rc And Output echo ${buffer} | sudo tee ${src_file_name}
286 Should Not Be True ${rc}
289 [Arguments] ${src_file_name} ${buffer}
290 [Documentation] AddEntry to Local File
291 ${rc} ${output}= Run And Return Rc And Output echo ${buffer} | sudo tee -a ${src_file_name}
293 Should Not Be True ${rc}
296 [Arguments] ${src_file_name}
297 [Documentation] Export Varaibles to Env
298 ${rc} ${output}= Run And Return Rc And Output source ${src_file_name}
300 Should Not Be True ${rc}
302 Run Command In Local Node
303 [Arguments] ${command}
304 ${rc} ${output}= Run And Return Rc And Output ${command}
306 Should Not Be True ${rc}
308 Generic HAProxy Entry
309 [Arguments] ${os_node_cxn} ${haproxy_ip} ${port_to_listen} ${proxy_entry}
310 [Documentation] Add an entry in haproxy.cfg for the service
311 Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg ' '
312 Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg frontend vip-${proxy_entry}
313 Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg ' 'bind *:${port_to_listen}
314 Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg ' 'timeout client 90s
315 Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg ' 'default_backend ${proxy_entry}
316 Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg ' '
317 Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg backend ${proxy_entry}
318 Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg ' 'balance roundrobin
319 Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg ' 'server ${proxy_entry}_controller1 ${OS_CONTROL_1_IP}:${port_to_listen} check inter 1s
320 Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg ' 'server ${proxy_entry}_controller2 ${OS_CONTROL_2_IP}:${port_to_listen} check inter 1s
321 Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg ' 'server ${proxy_entry}_controller3 ${OS_CONTROL_3_IP}:${port_to_listen} check inter 1s
322 Run Keyword If 3 < ${NUM_CONTROL_NODES} Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg ' 'server ${proxy_entry}_controller4 ${OS_CONTROL_4_IP}:${port_to_listen} check inter 1s
323 Run Keyword If 4 < ${NUM_CONTROL_NODES} Append To File ${os_node_cxn} /etc/haproxy/haproxy.cfg ' 'server ${proxy_entry}_controller5 ${OS_CONTROL_5_IP}:${port_to_listen} check inter 1s
324 Restart Service ${os_node_cxn} haproxy
327 [Arguments] ${os_node_cxn} ${file_name}
328 [Documentation] Read a file for logging
329 Switch Connection ${os_node_cxn}
330 ${output} ${rc}= Execute Command cat ${file_name} return_rc=True return_stdout=True
332 Should Not Be True ${rc}
334 Disable SeLinux Tempororily
335 [Arguments] ${os_node_cxn}
336 [Documentation] Disable SELinux from command
337 Switch Connection ${os_node_cxn}
338 ${output} ${rc}= Execute Command sudo setenforce 0 return_rc=True return_stdout=True
342 [Arguments] ${os_ip} ${os_user} ${os_password} ${prompt}
343 ${conn_id}= SSHLibrary.Open Connection ${os_ip} prompt=${prompt} timeout=1 hour alias=${os_ip}
344 SSHKeywords.Flexible SSH Login ${os_user} password=${os_password}
345 SSHLibrary.Set Client Configuration timeout=1 hour