blob: 34ba84d5a0cc25ed7d8156e76bf130c6afb404fd [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]
52
53 self.name = self.options['name']
54 self.handle = super(RamCloudCliDriver, self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd)
55
56 self.ssh_handle = self.handle
57 if self.handle :
58 return main.TRUE
59 else :
60 main.log.error("Connection failed to the host "+self.user_name+"@"+self.ip_address)
61 main.log.error("Failed to connect to the Onos system")
62 return main.FALSE
63
64
65 def start_serv(self):
66 '''
67 This Function will start RamCloud Servers
68 '''
69 main.log.info( "Starting RAMCloud Server" )
70 self.handle.sendline("")
71 self.handle.expect("\$")
72 self.handle.sendline(self.home + "/onos.sh rc-server start")
73 self.handle.expect("onos.sh rc-server start")
74 self.handle.expect("\$")
75 response = self.handle.before + self.handle.after
76 print response
77 time.sleep(5)
78 if re.search("Starting\sRAMCloud\sserver\s(.*)", response):
79 main.log.info(self.name + ": RAMCloud Server Started ")
80 return main.TRUE
81 else:
82 main.log.error(self.name + ": Failed to start RAMCloud Server"+ response)
83 return main.FALSE
84
85
86 def start_coor(self):
87 '''
88 This Function will start RamCloud
89 '''
90 main.log.info( "Starting RAMCloud Coordinator" )
91 self.handle.sendline("")
92 self.handle.expect("\$")
93 self.handle.sendline("~/ONOS/onos.sh rc-coord start")
94 self.handle.expect("onos.sh rc-coord start")
95 self.handle.expect("\$")
96 response = self.handle.before + self.handle.after
97 time.sleep(5)
98 if re.search("Starting\sRAMCloud\scoordinator\s(.*)", response):
99 main.log.info("RAMCloud Coordinator Started ")
100 return main.TRUE
101 else:
102 main.log.error("Failed to start RAMCloud Coordinator"+ response)
103 return main.FALSE
104
105 def status_serv(self):
106 '''
107 This Function will return the Status of the RAMCloud
108 '''
109 time.sleep(5)
110 self.execute(cmd="\n",prompt="\$",timeout=10)
111 response = self.execute(cmd="~/ONOS/onos.sh rc-server status ",prompt="\d+\sramcloud\sserver\srunning(.*)",timeout=10)
112
113
114 self.execute(cmd="\n",prompt="\$",timeout=10)
115 return response
116
117 if re.search("0\sRAMCloud\sserver\srunning(.*)") :
118 main.log.info("RAMCloud not running")
119 return main.TRUE
120 elif re.search("1\sRAMCloud\sserver\srunning(.*)"):
121 main.log.warn("RAMCloud Running")
122 return main.TRUE
123
124 def status_coor(self):
125 '''
126 This Function will return the Status of the RAMCloud
127 '''
128 time.sleep(5)
129 self.execute(cmd="\n",prompt="\$",timeout=10)
130 response = self.execute(cmd="~/ONOS/onos.sh rc-coord status ",prompt="\d+\sramcloud\scoordinator\sis\srunning(.*)",timeout=10)
131
132
133 self.execute(cmd="\n",prompt="\$",timeout=10)
134 return response
135
136 if re.search("0\sRAMCloud\scoordinator\sis\srunning(.*)") :
137 main.log.info("RAMCloud Coordinator not running")
138 return main.TRUE
139 elif re.search("1\sRAMCloud\scoordinator\sis\srunning(.*)"):
140 main.log.warn("RAMCloud Coordinator Running")
141 return main.TRUE
142
143 def stop_serv(self):
144 '''
145 This Function will stop the RAMCloud if it is Running
146 '''
147 self.execute(cmd="\n",prompt="\$",timeout=10)
148 time.sleep(5)
149 response = self.execute(cmd="~/ONOS/onos.sh rc-server stop ",prompt="Killed\sexisting\sprosess(.*)",timeout=10)
150 self.execute(cmd="\n",prompt="\$",timeout=10)
151 if re.search("Killed\sexisting\sprosess(.*)",response):
152 main.log.info("RAMCloud Server Stopped")
153 return main.TRUE
154 else:
155 main.log.warn("RAMCloud is not Running")
156 return main.FALSE
157
158
159 def stop_coor(self):
160 '''
161 This Function will stop the RAMCloud if it is Running
162 '''
163 self.execute(cmd="\n",prompt="\$",timeout=10)
164 time.sleep(5)
165 response = self.execute(cmd="~/ONOS/onos.sh rc-coord stop ",prompt="Killed\sexisting\sprosess(.*)",timeout=10)
166 self.execute(cmd="\n",prompt="\$",timeout=10)
167 if re.search("Killed\sexisting\sprosess(.*)",response):
168 main.log.info("RAMCloud Coordinator Stopped")
169 return main.TRUE
170 else:
171 main.log.warn("RAMCloud is not Running")
172
173 def disconnect(self):
174 '''
175 Called at the end of the test to disconnect the ssh handle.
176 '''
177 response = ''
178 if self.handle:
179 self.handle.sendline("exit")
180 self.handle.expect("closed")
181 else :
182 main.log.error("Connection failed to the host")
183 response = main.FALSE
184 return response
185
186 def isup(self):
187 '''
188 A more complete status check of ramcloud.
189 Tries 5 times to call start-ramcloud-server.sh status
190 returns TRUE if it sees four occurances of both Up, and Normal
191 '''
192 tries = 5
193 main.log.info("trying %i times" % tries )
194 for i in range(tries):
195 self.execute(cmd="\n",prompt="\$",timeout=10)
196 self.handle.sendline("")
197 self.handle.expect("\$")
198 self.handle.sendline("~/ONOS/onos.sh rc-server status")
199 data = self.handle.expect(['1 RAMCloud server running','0 RAMCloud server running',pexpect.TIMEOUT],timeout=30)
200 if data==0:
201 main.log.report("RAMCloud Up and Running!")
202 return main.TRUE
203 elif data==1:
204 main.log.report("RAMCloud is down!")
205
206
207 return main.FALSE