blob: f900ddcf0d85d2249f46dbacd1e643281469f69e [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("")
77 self.handle.expect("\$")
78 self.handle.sendline(self.home + "/onos.sh rc-server start")
79 self.handle.expect("onos.sh rc-server start")
80 self.handle.expect("\$")
81 response = self.handle.before + self.handle.after
James Lee342b4392014-04-08 09:22:57 -070082 #print ("RESPONSE IS: "+response)
admine72fefb2014-04-03 17:24:16 -070083 time.sleep(5)
James Lee342b4392014-04-08 09:22:57 -070084 if re.search("Killed\sexisting\sprocess", response):
James Leeb4527ad2014-04-07 11:04:08 -070085 main.log.info(self.name + ": Previous RAMCloud killed. ")
86 if re.search("Starting\sRAMCloud\sserver",response):
87 main.log.info(self.name + ": RAMCloud Server Started")
88 return main.TRUE
89 else:
90 main.log.info(self.name + ": Failed to start RAMCloud Server"+response)
91 return main.FALSE
James Lee342b4392014-04-08 09:22:57 -070092 elif re.search("Starting\sRAMCloud\sserver",response):
Jon Hall5b4e1e82014-04-07 15:25:50 -070093 main.log.info(self.name + ": RAMCloud Server Started")
94 return main.TRUE
95 else:
James Leeb4527ad2014-04-07 11:04:08 -070096 main.log.info(self.name + ": Failed to start RAMCloud Server"+response)
admine72fefb2014-04-03 17:24:16 -070097 return main.FALSE
98
99
100 def start_coor(self):
101 '''
102 This Function will start RamCloud
103 '''
Jon Hallde47ebc2014-04-07 12:31:03 -0700104 main.log.info(self.name+": Starting RAMCloud Coordinator" )
admine72fefb2014-04-03 17:24:16 -0700105 self.handle.sendline("")
106 self.handle.expect("\$")
admin6e3ed382014-04-03 18:01:18 -0700107 self.handle.sendline(self.home + "/onos.sh rc-coord start")
admine72fefb2014-04-03 17:24:16 -0700108 self.handle.expect("onos.sh rc-coord start")
109 self.handle.expect("\$")
110 response = self.handle.before + self.handle.after
Jon Hallde47ebc2014-04-07 12:31:03 -0700111 if re.search("Starting\sRAMCloud\scoordinator\s", response):
112 if re.search("Killed\sexisting\sprocess", response):
113 main.log.warn(self.name+": Process was already running, killing existing process")
114 main.log.info(self.name+": RAMCloud Coordinator Started ")
admine72fefb2014-04-03 17:24:16 -0700115 return main.TRUE
116 else:
Jon Hallde47ebc2014-04-07 12:31:03 -0700117 main.log.error(self.name+": Failed to start RAMCloud Coordinator"+ response)
admine72fefb2014-04-03 17:24:16 -0700118 return main.FALSE
119
120 def status_serv(self):
121 '''
122 This Function will return the Status of the RAMCloud
123 '''
James Lee342b4392014-04-08 09:22:57 -0700124 main.log.info(self.name + ": Getting RC-Server Status")
125 self.handle.sendline("")
126 self.handle.expect("\$")
127 self.handle.sendline(self.home + "/onos.sh rc-server status")
128 self.handle.expect("onos.sh rc-server status")
129 self.handle.expect("\$")
130 response = self.handle.before + self.handle.after
admine72fefb2014-04-03 17:24:16 -0700131
James Lee342b4392014-04-08 09:22:57 -0700132 if re.search("0\sRAMCloud\sserver\srunning", response) :
Jon Hallde47ebc2014-04-07 12:31:03 -0700133 main.log.info(self.name+": RAMCloud not running")
admine72fefb2014-04-03 17:24:16 -0700134 return main.TRUE
James Lee342b4392014-04-08 09:22:57 -0700135 elif re.search("1\sRAMCloud\sserver\srunning",response):
Jon Hallde47ebc2014-04-07 12:31:03 -0700136 main.log.warn(self.name+": RAMCloud Running")
admine72fefb2014-04-03 17:24:16 -0700137 return main.TRUE
Jon Hallde47ebc2014-04-07 12:31:03 -0700138 else:
139 main.log.info( self.name+": WARNING: status recieved unknown response")
140 return main.FALSE
admine72fefb2014-04-03 17:24:16 -0700141
142 def status_coor(self):
143 '''
144 This Function will return the Status of the RAMCloud
145 '''
admine72fefb2014-04-03 17:24:16 -0700146 self.execute(cmd="\n",prompt="\$",timeout=10)
Jon Hallde47ebc2014-04-07 12:31:03 -0700147 response = self.execute(cmd=self.home + "/onos.sh rc-coord status ",prompt="\d+\sRAMCloud\scoordinator\srunning",timeout=10)
admine72fefb2014-04-03 17:24:16 -0700148 self.execute(cmd="\n",prompt="\$",timeout=10)
Jon Hallde47ebc2014-04-07 12:31:03 -0700149 #return response
admine72fefb2014-04-03 17:24:16 -0700150
Jon Hallde47ebc2014-04-07 12:31:03 -0700151 if re.search("0\sRAMCloud\scoordinator\srunning", response) :
152 main.log.warn(self.name+": RAMCloud Coordinator not running")
admine72fefb2014-04-03 17:24:16 -0700153 return main.TRUE
Jon Hallde47ebc2014-04-07 12:31:03 -0700154 elif re.search("1\sRAMCloud\scoordinator\srunning", response):
155 main.log.info(self.name+": RAMCloud Coordinator Running")
admine72fefb2014-04-03 17:24:16 -0700156 return main.TRUE
Jon Hallde47ebc2014-04-07 12:31:03 -0700157 else:
158 main.log.warn( self.name+": coordinator status recieved unknown response")
159 return main.FALSE
admine72fefb2014-04-03 17:24:16 -0700160
161 def stop_serv(self):
162 '''
163 This Function will stop the RAMCloud if it is Running
James Lee342b4392014-04-08 09:22:57 -0700164 '''
165 main.log.info(self.name + ": Stopping RC-Server")
166 self.handle.sendline("")
167 self.handle.expect("\$")
168 self.handle.sendline(self.home + "/onos.sh rc-server stop")
169 self.handle.expect("onos.sh rc-server stop")
170 self.handle.expect("\$")
171 response = self.handle.before + self.handle.after
172 if re.search("Killed\sexisting\sprocess",response):
admine72fefb2014-04-03 17:24:16 -0700173 main.log.info("RAMCloud Server Stopped")
174 return main.TRUE
175 else:
Jon Hallde47ebc2014-04-07 12:31:03 -0700176 main.log.warn(self.name+": RAMCloud is not Running")
admine72fefb2014-04-03 17:24:16 -0700177 return main.FALSE
178
179
180 def stop_coor(self):
181 '''
182 This Function will stop the RAMCloud if it is Running
183 '''
184 self.execute(cmd="\n",prompt="\$",timeout=10)
185 time.sleep(5)
Jon Hallde47ebc2014-04-07 12:31:03 -0700186 response = self.execute(cmd=self.home + "/onos.sh rc-coord stop ",prompt="Killed\sexisting\sprocess",timeout=10)
admine72fefb2014-04-03 17:24:16 -0700187 self.execute(cmd="\n",prompt="\$",timeout=10)
Jon Hallde47ebc2014-04-07 12:31:03 -0700188 if re.search("Killed\sexisting\sprocess",response):
189 main.log.info(self.name+": RAMCloud Coordinator Stopped")
admine72fefb2014-04-03 17:24:16 -0700190 return main.TRUE
191 else:
Jon Hallde47ebc2014-04-07 12:31:03 -0700192 main.log.warn(self.name+": RAMCloud was not Running")
Jon Hall4121fdc2014-04-08 15:20:03 -0700193 return main.FALSE
admine72fefb2014-04-03 17:24:16 -0700194
195 def disconnect(self):
196 '''
197 Called at the end of the test to disconnect the ssh handle.
198 '''
199 response = ''
200 if self.handle:
201 self.handle.sendline("exit")
202 self.handle.expect("closed")
203 else :
Jon Hallde47ebc2014-04-07 12:31:03 -0700204 main.log.error("Connection failed to the host when trying to disconnect from RAMCloud component")
admine72fefb2014-04-03 17:24:16 -0700205 response = main.FALSE
206 return response