blob: 2ac78357d4481f7668610ffeb26826ed88c9b675 [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
James Leeb4527ad2014-04-07 11:04:08 -070082 print ("RESPONSE IS: "+response)
admine72fefb2014-04-03 17:24:16 -070083 time.sleep(5)
James Leeb4527ad2014-04-07 11:04:08 -070084 if re.search("Killed\sexisting\process", response):
85 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
92 if re.search("Starting\sRAMCloud\sserver",response):
93 main.log.info(self.name + ": RAMCloud Server Started")
94 return main.TRUE
95 else:
96 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 '''
104 main.log.info( "Starting RAMCloud Coordinator" )
105 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
111 time.sleep(5)
112 if re.search("Starting\sRAMCloud\scoordinator\s(.*)", response):
113 main.log.info("RAMCloud Coordinator Started ")
114 return main.TRUE
115 else:
116 main.log.error("Failed to start RAMCloud Coordinator"+ response)
117 return main.FALSE
118
119 def status_serv(self):
120 '''
121 This Function will return the Status of the RAMCloud
122 '''
123 time.sleep(5)
124 self.execute(cmd="\n",prompt="\$",timeout=10)
admin6e3ed382014-04-03 18:01:18 -0700125 response = self.execute(cmd=self.home + "/onos.sh rc-server status ",prompt="\d+\sramcloud\sserver\srunning(.*)",timeout=10)
admine72fefb2014-04-03 17:24:16 -0700126
127
128 self.execute(cmd="\n",prompt="\$",timeout=10)
129 return response
130
131 if re.search("0\sRAMCloud\sserver\srunning(.*)") :
132 main.log.info("RAMCloud not running")
133 return main.TRUE
134 elif re.search("1\sRAMCloud\sserver\srunning(.*)"):
135 main.log.warn("RAMCloud Running")
136 return main.TRUE
137
138 def status_coor(self):
139 '''
140 This Function will return the Status of the RAMCloud
141 '''
142 time.sleep(5)
143 self.execute(cmd="\n",prompt="\$",timeout=10)
admin6e3ed382014-04-03 18:01:18 -0700144 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 -0700145
146
147 self.execute(cmd="\n",prompt="\$",timeout=10)
148 return response
149
150 if re.search("0\sRAMCloud\scoordinator\sis\srunning(.*)") :
151 main.log.info("RAMCloud Coordinator not running")
152 return main.TRUE
153 elif re.search("1\sRAMCloud\scoordinator\sis\srunning(.*)"):
154 main.log.warn("RAMCloud Coordinator Running")
155 return main.TRUE
156
157 def stop_serv(self):
158 '''
159 This Function will stop the RAMCloud if it is Running
160 '''
161 self.execute(cmd="\n",prompt="\$",timeout=10)
162 time.sleep(5)
James Leeb4527ad2014-04-07 11:04:08 -0700163 response = self.execute(cmd=slef.home + "/onos.sh rc-server stop ",prompt="Killed\sexisting\sprocess(.*)",timeout=10)
admine72fefb2014-04-03 17:24:16 -0700164 self.execute(cmd="\n",prompt="\$",timeout=10)
James Leeb4527ad2014-04-07 11:04:08 -0700165 if re.search("Killed\sexisting\sprocess(.*)",response):
admine72fefb2014-04-03 17:24:16 -0700166 main.log.info("RAMCloud Server Stopped")
167 return main.TRUE
168 else:
169 main.log.warn("RAMCloud is not Running")
170 return main.FALSE
171
172
173 def stop_coor(self):
174 '''
175 This Function will stop the RAMCloud if it is Running
176 '''
177 self.execute(cmd="\n",prompt="\$",timeout=10)
178 time.sleep(5)
James Leeb4527ad2014-04-07 11:04:08 -0700179 response = self.execute(cmd=self.home + "/onos.sh rc-coord stop ",prompt="Killed\sexisting\sprocess(.*)",timeout=10)
admine72fefb2014-04-03 17:24:16 -0700180 self.execute(cmd="\n",prompt="\$",timeout=10)
James Leeb4527ad2014-04-07 11:04:08 -0700181 if re.search("Killed\sexisting\sprocess(.*)",response):
admine72fefb2014-04-03 17:24:16 -0700182 main.log.info("RAMCloud Coordinator Stopped")
183 return main.TRUE
184 else:
185 main.log.warn("RAMCloud is not Running")
186
187 def disconnect(self):
188 '''
189 Called at the end of the test to disconnect the ssh handle.
190 '''
191 response = ''
192 if self.handle:
193 self.handle.sendline("exit")
194 self.handle.expect("closed")
195 else :
196 main.log.error("Connection failed to the host")
197 response = main.FALSE
198 return response
199