blob: 52f8e7dc1a9703752fd144c0bc1c79edee277857 [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
69
70
71 def start_serv(self):
72 '''
73 This Function will start RamCloud Servers
74 '''
Jon Hallde47ebc2014-04-07 12:31:03 -070075 main.log.info(self.name+": Starting RAMCloud Server" )
admine72fefb2014-04-03 17:24:16 -070076 self.handle.sendline("")
Jon Hallebaa5c52014-04-14 17:36:55 -070077 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -070078 self.handle.sendline("cd "+self.home)
79 self.handle.sendline("./onos.sh rc-server start")
Jon Hallebaa5c52014-04-14 17:36:55 -070080 self.handle.expect(["onos.sh rc-server start",pexpect.EOF,pexpect.TIMEOUT])
81 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
admine72fefb2014-04-03 17:24:16 -070082 response = self.handle.before + self.handle.after
James Lee342b4392014-04-08 09:22:57 -070083 #print ("RESPONSE IS: "+response)
admine72fefb2014-04-03 17:24:16 -070084 time.sleep(5)
James Lee342b4392014-04-08 09:22:57 -070085 if re.search("Killed\sexisting\sprocess", response):
James Leeb4527ad2014-04-07 11:04:08 -070086 main.log.info(self.name + ": Previous RAMCloud killed. ")
87 if re.search("Starting\sRAMCloud\sserver",response):
88 main.log.info(self.name + ": RAMCloud Server Started")
89 return main.TRUE
90 else:
91 main.log.info(self.name + ": Failed to start RAMCloud Server"+response)
92 return main.FALSE
James Lee342b4392014-04-08 09:22:57 -070093 elif re.search("Starting\sRAMCloud\sserver",response):
Jon Hall5b4e1e82014-04-07 15:25:50 -070094 main.log.info(self.name + ": RAMCloud Server Started")
95 return main.TRUE
96 else:
James Leeb4527ad2014-04-07 11:04:08 -070097 main.log.info(self.name + ": Failed to start RAMCloud Server"+response)
admine72fefb2014-04-03 17:24:16 -070098 return main.FALSE
99
100
101 def start_coor(self):
102 '''
103 This Function will start RamCloud
104 '''
Jon Hallde47ebc2014-04-07 12:31:03 -0700105 main.log.info(self.name+": Starting RAMCloud Coordinator" )
admine72fefb2014-04-03 17:24:16 -0700106 self.handle.sendline("")
Jon Hallebaa5c52014-04-14 17:36:55 -0700107 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -0700108 self.handle.sendline("cd "+self.home)
109 self.handle.sendline("./onos.sh rc-coord start")
Jon Hallebaa5c52014-04-14 17:36:55 -0700110 self.handle.expect(["onos.sh rc-coord start",pexpect.EOF,pexpect.TIMEOUT])
111 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
admine72fefb2014-04-03 17:24:16 -0700112 response = self.handle.before + self.handle.after
Jon Hallde47ebc2014-04-07 12:31:03 -0700113 if re.search("Starting\sRAMCloud\scoordinator\s", response):
114 if re.search("Killed\sexisting\sprocess", response):
115 main.log.warn(self.name+": Process was already running, killing existing process")
116 main.log.info(self.name+": RAMCloud Coordinator Started ")
admine72fefb2014-04-03 17:24:16 -0700117 return main.TRUE
118 else:
Jon Hallde47ebc2014-04-07 12:31:03 -0700119 main.log.error(self.name+": Failed to start RAMCloud Coordinator"+ response)
admine72fefb2014-04-03 17:24:16 -0700120 return main.FALSE
121
122 def status_serv(self):
123 '''
124 This Function will return the Status of the RAMCloud
125 '''
James Lee342b4392014-04-08 09:22:57 -0700126 main.log.info(self.name + ": Getting RC-Server Status")
127 self.handle.sendline("")
Jon Hallebaa5c52014-04-14 17:36:55 -0700128 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -0700129 self.handle.sendline("cd "+self.home)
130 self.handle.sendline("./onos.sh rc-server status")
Jon Hallebaa5c52014-04-14 17:36:55 -0700131 self.handle.expect(["onos.sh rc-server status",pexpect.EOF,pexpect.TIMEOUT])
132 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
James Lee342b4392014-04-08 09:22:57 -0700133 response = self.handle.before + self.handle.after
admine72fefb2014-04-03 17:24:16 -0700134
James Lee342b4392014-04-08 09:22:57 -0700135 if re.search("0\sRAMCloud\sserver\srunning", response) :
Jon Hallde47ebc2014-04-07 12:31:03 -0700136 main.log.info(self.name+": RAMCloud not running")
admine72fefb2014-04-03 17:24:16 -0700137 return main.TRUE
James Lee342b4392014-04-08 09:22:57 -0700138 elif re.search("1\sRAMCloud\sserver\srunning",response):
Jon Hallde47ebc2014-04-07 12:31:03 -0700139 main.log.warn(self.name+": RAMCloud Running")
admine72fefb2014-04-03 17:24:16 -0700140 return main.TRUE
Jon Hallde47ebc2014-04-07 12:31:03 -0700141 else:
142 main.log.info( self.name+": WARNING: status recieved unknown response")
143 return main.FALSE
admine72fefb2014-04-03 17:24:16 -0700144
145 def status_coor(self):
146 '''
147 This Function will return the Status of the RAMCloud
148 '''
Jon Hallebaa5c52014-04-14 17:36:55 -0700149 main.log.info(self.name + ": Getting RC-Coord Status")
150 self.handle.sendline("")
151 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -0700152 self.handle.sendline("cd "+self.home)
153 self.handle.sendline("./onos.sh rc-coord status")
Jon Hallebaa5c52014-04-14 17:36:55 -0700154 i=self.handle.expect(["onos.sh rc-coord status",pexpect.EOF,pexpect.TIMEOUT])
155 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
156 response = self.handle.before + self.handle.after
Jon Hallde47ebc2014-04-07 12:31:03 -0700157 #return response
admine72fefb2014-04-03 17:24:16 -0700158
Jon Hallde47ebc2014-04-07 12:31:03 -0700159 if re.search("0\sRAMCloud\scoordinator\srunning", response) :
160 main.log.warn(self.name+": RAMCloud Coordinator not running")
admine72fefb2014-04-03 17:24:16 -0700161 return main.TRUE
Jon Hallde47ebc2014-04-07 12:31:03 -0700162 elif re.search("1\sRAMCloud\scoordinator\srunning", response):
163 main.log.info(self.name+": RAMCloud Coordinator Running")
admine72fefb2014-04-03 17:24:16 -0700164 return main.TRUE
Jon Hallde47ebc2014-04-07 12:31:03 -0700165 else:
166 main.log.warn( self.name+": coordinator status recieved unknown response")
167 return main.FALSE
admine72fefb2014-04-03 17:24:16 -0700168
169 def stop_serv(self):
170 '''
171 This Function will stop the RAMCloud if it is Running
James Lee342b4392014-04-08 09:22:57 -0700172 '''
173 main.log.info(self.name + ": Stopping RC-Server")
174 self.handle.sendline("")
Jon Hallebaa5c52014-04-14 17:36:55 -0700175 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -0700176 self.handle.sendline("cd "+self.home)
177 self.handle.sendline("./onos.sh rc-server stop")
Jon Hallebaa5c52014-04-14 17:36:55 -0700178 self.handle.expect(["onos.sh rc-server stop",pexpect.EOF,pexpect.TIMEOUT])
179 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
James Lee342b4392014-04-08 09:22:57 -0700180 response = self.handle.before + self.handle.after
181 if re.search("Killed\sexisting\sprocess",response):
admine72fefb2014-04-03 17:24:16 -0700182 main.log.info("RAMCloud Server Stopped")
183 return main.TRUE
184 else:
Jon Hallde47ebc2014-04-07 12:31:03 -0700185 main.log.warn(self.name+": RAMCloud is not Running")
admine72fefb2014-04-03 17:24:16 -0700186 return main.FALSE
admin6c96b8e2014-05-15 11:11:58 -0700187
188 def del_db(self):
189 '''
190 This function will clean out the database
191 '''
192 main.log.info(self.name + ": Deleting RC Database")
193 self.handle.sendline("")
194 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
195 self.handle.sendline("cd "+self.home)
196 self.handle.sendline("./onos.sh rc deldb")
197 self.handle.expect(["[y/N]",pexpect.EOF,pexpect.TIMEOUT])
198 self.handle.sendline("y")
199 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
200 response = self.handle.before + self.handle.after
201 main.log.info(response)
202 if re.search("DONE",response):
203 main.log.info("RAMCloud Database Cleaned")
204 return main.TRUE
205 else:
206 main.log.warn("Something wrong in Cleaning Database")
207 return main.FALSE
admine72fefb2014-04-03 17:24:16 -0700208
209
210 def stop_coor(self):
211 '''
212 This Function will stop the RAMCloud if it is Running
213 '''
Jon Hallebaa5c52014-04-14 17:36:55 -0700214 main.log.info(self.name + ": Stopping RC-Coord")
215 self.handle.sendline("")
216 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -0700217 self.handle.sendline("cd "+self.home)
218 self.handle.sendline( "./onos.sh rc-coord stop")
Jon Hallebaa5c52014-04-14 17:36:55 -0700219 self.handle.expect(["onos.sh rc-coord stop",pexpect.EOF,pexpect.TIMEOUT])
220 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
221 response = self.handle.before + self.handle.after
Jon Hallde47ebc2014-04-07 12:31:03 -0700222 if re.search("Killed\sexisting\sprocess",response):
223 main.log.info(self.name+": RAMCloud Coordinator Stopped")
admine72fefb2014-04-03 17:24:16 -0700224 return main.TRUE
225 else:
Jon Hallde47ebc2014-04-07 12:31:03 -0700226 main.log.warn(self.name+": RAMCloud was not Running")
Jon Hall4121fdc2014-04-08 15:20:03 -0700227 return main.FALSE
admine72fefb2014-04-03 17:24:16 -0700228
229 def disconnect(self):
230 '''
231 Called at the end of the test to disconnect the ssh handle.
232 '''
233 response = ''
234 if self.handle:
235 self.handle.sendline("exit")
Jon Hallebaa5c52014-04-14 17:36:55 -0700236 self.handle.expect(["closed",pexpect.EOF,pexpect.TIMEOUT])
admine72fefb2014-04-03 17:24:16 -0700237 else :
Jon Hallde47ebc2014-04-07 12:31:03 -0700238 main.log.error("Connection failed to the host when trying to disconnect from RAMCloud component")
admine72fefb2014-04-03 17:24:16 -0700239 response = main.FALSE
240 return response