blob: 6f724033adea83a11065dc11bf2c2822bc08a49a [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 :
66 main.log.error("Connection failed to the host "+self.user_name+"@"+self.ip_address)
67 main.log.error("Failed to connect to the Onos system")
68 return main.FALSE
69
70
71 def start_serv(self):
72 '''
73 This Function will start RamCloud Servers
74 '''
75 main.log.info( "Starting RAMCloud Server" )
76 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
82 print response
83 time.sleep(5)
84 if re.search("Starting\sRAMCloud\sserver\s(.*)", response):
85 main.log.info(self.name + ": RAMCloud Server Started ")
86 return main.TRUE
87 else:
88 main.log.error(self.name + ": Failed to start RAMCloud Server"+ response)
89 return main.FALSE
90
91
92 def start_coor(self):
93 '''
94 This Function will start RamCloud
95 '''
96 main.log.info( "Starting RAMCloud Coordinator" )
97 self.handle.sendline("")
98 self.handle.expect("\$")
admin6e3ed382014-04-03 18:01:18 -070099 self.handle.sendline(self.home + "/onos.sh rc-coord start")
admine72fefb2014-04-03 17:24:16 -0700100 self.handle.expect("onos.sh rc-coord start")
101 self.handle.expect("\$")
102 response = self.handle.before + self.handle.after
103 time.sleep(5)
104 if re.search("Starting\sRAMCloud\scoordinator\s(.*)", response):
105 main.log.info("RAMCloud Coordinator Started ")
106 return main.TRUE
107 else:
108 main.log.error("Failed to start RAMCloud Coordinator"+ response)
109 return main.FALSE
110
111 def status_serv(self):
112 '''
113 This Function will return the Status of the RAMCloud
114 '''
115 time.sleep(5)
116 self.execute(cmd="\n",prompt="\$",timeout=10)
admin6e3ed382014-04-03 18:01:18 -0700117 response = self.execute(cmd=self.home + "/onos.sh rc-server status ",prompt="\d+\sramcloud\sserver\srunning(.*)",timeout=10)
admine72fefb2014-04-03 17:24:16 -0700118
119
120 self.execute(cmd="\n",prompt="\$",timeout=10)
121 return response
122
123 if re.search("0\sRAMCloud\sserver\srunning(.*)") :
124 main.log.info("RAMCloud not running")
125 return main.TRUE
126 elif re.search("1\sRAMCloud\sserver\srunning(.*)"):
127 main.log.warn("RAMCloud Running")
128 return main.TRUE
129
130 def status_coor(self):
131 '''
132 This Function will return the Status of the RAMCloud
133 '''
134 time.sleep(5)
135 self.execute(cmd="\n",prompt="\$",timeout=10)
admin6e3ed382014-04-03 18:01:18 -0700136 response = self.execute(cmd=self.home + "/onos.sh rc-coord status ",prompt="\d+\sramcloud\scoordinator\sis\srunning(.*)",timeout=10)
admine72fefb2014-04-03 17:24:16 -0700137
138
139 self.execute(cmd="\n",prompt="\$",timeout=10)
140 return response
141
142 if re.search("0\sRAMCloud\scoordinator\sis\srunning(.*)") :
143 main.log.info("RAMCloud Coordinator not running")
144 return main.TRUE
145 elif re.search("1\sRAMCloud\scoordinator\sis\srunning(.*)"):
146 main.log.warn("RAMCloud Coordinator Running")
147 return main.TRUE
148
149 def stop_serv(self):
150 '''
151 This Function will stop the RAMCloud if it is Running
152 '''
153 self.execute(cmd="\n",prompt="\$",timeout=10)
154 time.sleep(5)
admin6e3ed382014-04-03 18:01:18 -0700155 response = self.execute(cmd=slef.home + "/onos.sh rc-server stop ",prompt="Killed\sexisting\sprosess(.*)",timeout=10)
admine72fefb2014-04-03 17:24:16 -0700156 self.execute(cmd="\n",prompt="\$",timeout=10)
157 if re.search("Killed\sexisting\sprosess(.*)",response):
158 main.log.info("RAMCloud Server Stopped")
159 return main.TRUE
160 else:
161 main.log.warn("RAMCloud is not Running")
162 return main.FALSE
163
164
165 def stop_coor(self):
166 '''
167 This Function will stop the RAMCloud if it is Running
168 '''
169 self.execute(cmd="\n",prompt="\$",timeout=10)
170 time.sleep(5)
admin6e3ed382014-04-03 18:01:18 -0700171 response = self.execute(cmd=self.home + "/onos.sh rc-coord stop ",prompt="Killed\sexisting\sprosess(.*)",timeout=10)
admine72fefb2014-04-03 17:24:16 -0700172 self.execute(cmd="\n",prompt="\$",timeout=10)
173 if re.search("Killed\sexisting\sprosess(.*)",response):
174 main.log.info("RAMCloud Coordinator Stopped")
175 return main.TRUE
176 else:
177 main.log.warn("RAMCloud is not Running")
178
179 def disconnect(self):
180 '''
181 Called at the end of the test to disconnect the ssh handle.
182 '''
183 response = ''
184 if self.handle:
185 self.handle.sendline("exit")
186 self.handle.expect("closed")
187 else :
188 main.log.error("Connection failed to the host")
189 response = main.FALSE
190 return response
191
192 def isup(self):
193 '''
194 A more complete status check of ramcloud.
195 Tries 5 times to call start-ramcloud-server.sh status
196 returns TRUE if it sees four occurances of both Up, and Normal
197 '''
198 tries = 5
199 main.log.info("trying %i times" % tries )
200 for i in range(tries):
201 self.execute(cmd="\n",prompt="\$",timeout=10)
202 self.handle.sendline("")
203 self.handle.expect("\$")
admin6e3ed382014-04-03 18:01:18 -0700204 self.handle.sendline(self.home + "/onos.sh rc-server status")
admine72fefb2014-04-03 17:24:16 -0700205 data = self.handle.expect(['1 RAMCloud server running','0 RAMCloud server running',pexpect.TIMEOUT],timeout=30)
206 if data==0:
207 main.log.report("RAMCloud Up and Running!")
208 return main.TRUE
209 elif data==1:
210 main.log.report("RAMCloud is down!")
211
212
213 return main.FALSE