blob: 5b1950877d0199001ee1f7bb3d48a0f3b3a42986 [file] [log] [blame]
admine72fefb2014-04-03 17:24:16 -07001#!/usr/bin/env python
2'''
3Created on 31-May-2013
4
5@author: Anil Kumar (anilkumar.s@paxterrasolutions.com)
6
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
12
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20
21
22RamCloudCliDriver is the basic driver which will handle the RamCloud server functions
23'''
24
25import pexpect
26import struct
27import fcntl
28import os
29import signal
30import re
31import sys
32import core.teston
33import time
34
35sys.path.append("../")
36from drivers.common.clidriver import CLI
37
38class RamCloudCliDriver(CLI):
39 '''
40RamCloudCliDriver is the basic driver which will handle the RamCloud server functions
41 '''
42 def __init__(self):
43 super(CLI, self).__init__()
44 self.handle = self
45 self.wrapped = sys.modules[__name__]
46
47 def connect(self, **connectargs):
48 # Here the main is the TestON instance after creating all the log handles.
49 self.port = None
50 for key in connectargs:
51 vars(self)[key] = connectargs[key]
admin6e3ed382014-04-03 18:01:18 -070052 self.home = "~/ONOS"
53 for key in self.options:
54 if key == "ONOShome":
55 self.home = self.options['ONOShome']
56 break
57
admine72fefb2014-04-03 17:24:16 -070058
59 self.name = self.options['name']
admin6e3ed382014-04-03 18:01:18 -070060 self.handle = super(RamCloudCliDriver, self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd, home = self.home)
admine72fefb2014-04-03 17:24:16 -070061
62 self.ssh_handle = self.handle
63 if self.handle :
64 return main.TRUE
65 else :
Jon Hallde47ebc2014-04-07 12:31:03 -070066 main.log.error(self.name+": Connection failed to the host "+self.user_name+"@"+self.ip_address)
67 main.log.error(self.name+": Failed to connect to the Onos system")
admine72fefb2014-04-03 17:24:16 -070068 return main.FALSE
admin680b78c2014-08-08 11:46:45 -070069
70 def kill_serv(self):
71 import re
72 try:
73 self.handle.sendline("ps -ef |grep 'master/server' |awk 'NR==1 {print $2}' |xargs sudo kill -9")
74 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
75 self.handle.sendline("ps -ef |grep 'master/server' |wc -l")
76 self.handle.expect(["wc -l",pexpect.EOF,pexpect.TIMEOUT])
77 response = self.handle.after
78 if re.search("1",response):
79 return "RAMCloud Server Killed!"
80 else:
81 return "ERROR!!! RAMCLOUd SERVER MAY NOT HAVE BEEN KILLED PROPERLY!!!"
82 except pexpect.EOF:
83 main.log.error(self.name + ": EOF exception found")
84 main.log.error(self.hane + ": " + self.handle.before)
85 main.cleanup()
86 main.exit()
87 except:
88 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
89 main.log.error( traceback.print_exc() )
90 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
91 main.cleanup()
92 main.exit()
93
94 def kill_coord(self):
95 import re
96 try:
97 self.handle.sendline("ps -ef |grep 'master/coordinator' |awk 'NR==1 {print $2}' |xargs sudo kill -9")
98 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
99 self.handle.sendline("ps -ef |grep 'master/coordinator' |wc -l")
100 self.handle.expect(["wc -l",pexpect.EOF,pexpect.TIMEOUT])
101 response = self.handle.after
102 if re.search("1",response):
103 return "RAMCloud Coordinator Killed!"
104 else:
105 return "ERROR!!! RAMCLOUD COORDINATOR MAY NOT HAVE BEEN KILLED PROPERLY!!!"
106 except pexpect.EOF:
107 main.log.error(self.name + ": EOF exception found")
108 main.log.error(self.hane + ": " + self.handle.before)
109 main.cleanup()
110 main.exit()
111 except:
112 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
113 main.log.error( traceback.print_exc() )
114 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
115 main.cleanup()
116 main.exit()
117
admine72fefb2014-04-03 17:24:16 -0700118
119
120 def start_serv(self):
121 '''
122 This Function will start RamCloud Servers
123 '''
Jon Hallde47ebc2014-04-07 12:31:03 -0700124 main.log.info(self.name+": Starting RAMCloud Server" )
admine72fefb2014-04-03 17:24:16 -0700125 self.handle.sendline("")
Jon Hallebaa5c52014-04-14 17:36:55 -0700126 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -0700127 self.handle.sendline("cd "+self.home)
128 self.handle.sendline("./onos.sh rc-server start")
Jon Hallebaa5c52014-04-14 17:36:55 -0700129 self.handle.expect(["onos.sh rc-server start",pexpect.EOF,pexpect.TIMEOUT])
130 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
admine72fefb2014-04-03 17:24:16 -0700131 response = self.handle.before + self.handle.after
James Lee342b4392014-04-08 09:22:57 -0700132 #print ("RESPONSE IS: "+response)
admine72fefb2014-04-03 17:24:16 -0700133 time.sleep(5)
James Lee342b4392014-04-08 09:22:57 -0700134 if re.search("Killed\sexisting\sprocess", response):
James Leeb4527ad2014-04-07 11:04:08 -0700135 main.log.info(self.name + ": Previous RAMCloud killed. ")
136 if re.search("Starting\sRAMCloud\sserver",response):
137 main.log.info(self.name + ": RAMCloud Server Started")
138 return main.TRUE
139 else:
140 main.log.info(self.name + ": Failed to start RAMCloud Server"+response)
141 return main.FALSE
James Lee342b4392014-04-08 09:22:57 -0700142 elif re.search("Starting\sRAMCloud\sserver",response):
Jon Hall5b4e1e82014-04-07 15:25:50 -0700143 main.log.info(self.name + ": RAMCloud Server Started")
144 return main.TRUE
145 else:
James Leeb4527ad2014-04-07 11:04:08 -0700146 main.log.info(self.name + ": Failed to start RAMCloud Server"+response)
admine72fefb2014-04-03 17:24:16 -0700147 return main.FALSE
148
149
150 def start_coor(self):
151 '''
152 This Function will start RamCloud
153 '''
Jon Hallde47ebc2014-04-07 12:31:03 -0700154 main.log.info(self.name+": Starting RAMCloud Coordinator" )
admine72fefb2014-04-03 17:24:16 -0700155 self.handle.sendline("")
Jon Hallebaa5c52014-04-14 17:36:55 -0700156 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -0700157 self.handle.sendline("cd "+self.home)
158 self.handle.sendline("./onos.sh rc-coord start")
Jon Hallebaa5c52014-04-14 17:36:55 -0700159 self.handle.expect(["onos.sh rc-coord start",pexpect.EOF,pexpect.TIMEOUT])
160 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
admine72fefb2014-04-03 17:24:16 -0700161 response = self.handle.before + self.handle.after
Jon Hallde47ebc2014-04-07 12:31:03 -0700162 if re.search("Starting\sRAMCloud\scoordinator\s", response):
163 if re.search("Killed\sexisting\sprocess", response):
164 main.log.warn(self.name+": Process was already running, killing existing process")
165 main.log.info(self.name+": RAMCloud Coordinator Started ")
admine72fefb2014-04-03 17:24:16 -0700166 return main.TRUE
167 else:
Jon Hallde47ebc2014-04-07 12:31:03 -0700168 main.log.error(self.name+": Failed to start RAMCloud Coordinator"+ response)
admine72fefb2014-04-03 17:24:16 -0700169 return main.FALSE
170
171 def status_serv(self):
172 '''
173 This Function will return the Status of the RAMCloud
174 '''
James Lee342b4392014-04-08 09:22:57 -0700175 main.log.info(self.name + ": Getting RC-Server Status")
176 self.handle.sendline("")
Jon Hallebaa5c52014-04-14 17:36:55 -0700177 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -0700178 self.handle.sendline("cd "+self.home)
179 self.handle.sendline("./onos.sh rc-server status")
Jon Hallebaa5c52014-04-14 17:36:55 -0700180 self.handle.expect(["onos.sh rc-server status",pexpect.EOF,pexpect.TIMEOUT])
181 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
James Lee342b4392014-04-08 09:22:57 -0700182 response = self.handle.before + self.handle.after
admine72fefb2014-04-03 17:24:16 -0700183
James Lee342b4392014-04-08 09:22:57 -0700184 if re.search("0\sRAMCloud\sserver\srunning", response) :
Jon Hallde47ebc2014-04-07 12:31:03 -0700185 main.log.info(self.name+": RAMCloud not running")
adminc3e8afc2014-06-17 14:10:33 -0700186 return main.FALSE
James Lee342b4392014-04-08 09:22:57 -0700187 elif re.search("1\sRAMCloud\sserver\srunning",response):
Jon Hallde47ebc2014-04-07 12:31:03 -0700188 main.log.warn(self.name+": RAMCloud Running")
admine72fefb2014-04-03 17:24:16 -0700189 return main.TRUE
Jon Hallde47ebc2014-04-07 12:31:03 -0700190 else:
191 main.log.info( self.name+": WARNING: status recieved unknown response")
192 return main.FALSE
admine72fefb2014-04-03 17:24:16 -0700193
194 def status_coor(self):
195 '''
196 This Function will return the Status of the RAMCloud
197 '''
Jon Hallebaa5c52014-04-14 17:36:55 -0700198 main.log.info(self.name + ": Getting RC-Coord Status")
199 self.handle.sendline("")
200 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -0700201 self.handle.sendline("cd "+self.home)
202 self.handle.sendline("./onos.sh rc-coord status")
Jon Hallebaa5c52014-04-14 17:36:55 -0700203 i=self.handle.expect(["onos.sh rc-coord status",pexpect.EOF,pexpect.TIMEOUT])
204 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
205 response = self.handle.before + self.handle.after
Jon Hallde47ebc2014-04-07 12:31:03 -0700206 #return response
admine72fefb2014-04-03 17:24:16 -0700207
Jon Hallde47ebc2014-04-07 12:31:03 -0700208 if re.search("0\sRAMCloud\scoordinator\srunning", response) :
209 main.log.warn(self.name+": RAMCloud Coordinator not running")
adminc3e8afc2014-06-17 14:10:33 -0700210 return main.FALSE
Jon Hallde47ebc2014-04-07 12:31:03 -0700211 elif re.search("1\sRAMCloud\scoordinator\srunning", response):
212 main.log.info(self.name+": RAMCloud Coordinator Running")
admine72fefb2014-04-03 17:24:16 -0700213 return main.TRUE
Jon Hallde47ebc2014-04-07 12:31:03 -0700214 else:
215 main.log.warn( self.name+": coordinator status recieved unknown response")
216 return main.FALSE
admine72fefb2014-04-03 17:24:16 -0700217
218 def stop_serv(self):
219 '''
220 This Function will stop the RAMCloud if it is Running
James Lee342b4392014-04-08 09:22:57 -0700221 '''
222 main.log.info(self.name + ": Stopping RC-Server")
223 self.handle.sendline("")
Jon Hallebaa5c52014-04-14 17:36:55 -0700224 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -0700225 self.handle.sendline("cd "+self.home)
226 self.handle.sendline("./onos.sh rc-server stop")
Jon Hallebaa5c52014-04-14 17:36:55 -0700227 self.handle.expect(["onos.sh rc-server stop",pexpect.EOF,pexpect.TIMEOUT])
228 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
James Lee342b4392014-04-08 09:22:57 -0700229 response = self.handle.before + self.handle.after
230 if re.search("Killed\sexisting\sprocess",response):
admine72fefb2014-04-03 17:24:16 -0700231 main.log.info("RAMCloud Server Stopped")
232 return main.TRUE
233 else:
Jon Hallde47ebc2014-04-07 12:31:03 -0700234 main.log.warn(self.name+": RAMCloud is not Running")
admine72fefb2014-04-03 17:24:16 -0700235 return main.FALSE
admin6c96b8e2014-05-15 11:11:58 -0700236
237 def del_db(self):
238 '''
239 This function will clean out the database
240 '''
241 main.log.info(self.name + ": Deleting RC Database")
242 self.handle.sendline("")
243 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
244 self.handle.sendline("cd "+self.home)
245 self.handle.sendline("./onos.sh rc deldb")
admin1723f1c2014-05-19 16:08:39 -0700246 self.handle.expect(["\[y/N\]",pexpect.EOF,pexpect.TIMEOUT])
admin6c96b8e2014-05-15 11:11:58 -0700247 self.handle.sendline("y")
248 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
249 response = self.handle.before + self.handle.after
admin1723f1c2014-05-19 16:08:39 -0700250 if re.search("DONE",response) or re.search("Terminated",response):
admin6c96b8e2014-05-15 11:11:58 -0700251 main.log.info("RAMCloud Database Cleaned")
252 return main.TRUE
253 else:
254 main.log.warn("Something wrong in Cleaning Database")
admin1723f1c2014-05-19 16:08:39 -0700255 main.log.warn(self.handle.before)
admin6c96b8e2014-05-15 11:11:58 -0700256 return main.FALSE
admine72fefb2014-04-03 17:24:16 -0700257
258
259 def stop_coor(self):
260 '''
261 This Function will stop the RAMCloud if it is Running
262 '''
Jon Hallebaa5c52014-04-14 17:36:55 -0700263 main.log.info(self.name + ": Stopping RC-Coord")
264 self.handle.sendline("")
265 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -0700266 self.handle.sendline("cd "+self.home)
267 self.handle.sendline( "./onos.sh rc-coord stop")
Jon Hallebaa5c52014-04-14 17:36:55 -0700268 self.handle.expect(["onos.sh rc-coord stop",pexpect.EOF,pexpect.TIMEOUT])
269 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
270 response = self.handle.before + self.handle.after
Jon Hallde47ebc2014-04-07 12:31:03 -0700271 if re.search("Killed\sexisting\sprocess",response):
272 main.log.info(self.name+": RAMCloud Coordinator Stopped")
admine72fefb2014-04-03 17:24:16 -0700273 return main.TRUE
274 else:
Jon Hallde47ebc2014-04-07 12:31:03 -0700275 main.log.warn(self.name+": RAMCloud was not Running")
Jon Hall4121fdc2014-04-08 15:20:03 -0700276 return main.FALSE
admine72fefb2014-04-03 17:24:16 -0700277
278 def disconnect(self):
279 '''
280 Called at the end of the test to disconnect the ssh handle.
281 '''
282 response = ''
283 if self.handle:
284 self.handle.sendline("exit")
Jon Hallebaa5c52014-04-14 17:36:55 -0700285 self.handle.expect(["closed",pexpect.EOF,pexpect.TIMEOUT])
admine72fefb2014-04-03 17:24:16 -0700286 else :
Jon Hallde47ebc2014-04-07 12:31:03 -0700287 main.log.error("Connection failed to the host when trying to disconnect from RAMCloud component")
admine72fefb2014-04-03 17:24:16 -0700288 response = main.FALSE
289 return response