admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | ''' |
| 3 | Created 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 | |
| 22 | RamCloudCliDriver is the basic driver which will handle the RamCloud server functions |
| 23 | ''' |
| 24 | |
| 25 | import pexpect |
| 26 | import struct |
| 27 | import fcntl |
| 28 | import os |
| 29 | import signal |
| 30 | import re |
| 31 | import sys |
| 32 | import core.teston |
| 33 | import time |
| 34 | |
| 35 | sys.path.append("../") |
| 36 | from drivers.common.clidriver import CLI |
| 37 | |
| 38 | class RamCloudCliDriver(CLI): |
| 39 | ''' |
| 40 | RamCloudCliDriver 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] |
admin | 6e3ed38 | 2014-04-03 18:01:18 -0700 | [diff] [blame] | 52 | self.home = "~/ONOS" |
| 53 | for key in self.options: |
| 54 | if key == "ONOShome": |
| 55 | self.home = self.options['ONOShome'] |
| 56 | break |
| 57 | |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 58 | |
| 59 | self.name = self.options['name'] |
admin | 6e3ed38 | 2014-04-03 18:01:18 -0700 | [diff] [blame] | 60 | 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) |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 61 | |
| 62 | self.ssh_handle = self.handle |
| 63 | if self.handle : |
| 64 | return main.TRUE |
| 65 | else : |
Jon Hall | de47ebc | 2014-04-07 12:31:03 -0700 | [diff] [blame] | 66 | 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") |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 68 | return main.FALSE |
| 69 | |
| 70 | |
| 71 | def start_serv(self): |
| 72 | ''' |
| 73 | This Function will start RamCloud Servers |
| 74 | ''' |
Jon Hall | de47ebc | 2014-04-07 12:31:03 -0700 | [diff] [blame] | 75 | main.log.info(self.name+": Starting RAMCloud Server" ) |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 76 | self.handle.sendline("") |
Jon Hall | ebaa5c5 | 2014-04-14 17:36:55 -0700 | [diff] [blame] | 77 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 78 | self.handle.sendline(self.home + "/onos.sh rc-server start") |
Jon Hall | ebaa5c5 | 2014-04-14 17:36:55 -0700 | [diff] [blame] | 79 | self.handle.expect(["onos.sh rc-server start",pexpect.EOF,pexpect.TIMEOUT]) |
| 80 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 81 | response = self.handle.before + self.handle.after |
James Lee | 342b439 | 2014-04-08 09:22:57 -0700 | [diff] [blame] | 82 | #print ("RESPONSE IS: "+response) |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 83 | time.sleep(5) |
James Lee | 342b439 | 2014-04-08 09:22:57 -0700 | [diff] [blame] | 84 | if re.search("Killed\sexisting\sprocess", response): |
James Lee | b4527ad | 2014-04-07 11:04:08 -0700 | [diff] [blame] | 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 |
James Lee | 342b439 | 2014-04-08 09:22:57 -0700 | [diff] [blame] | 92 | elif re.search("Starting\sRAMCloud\sserver",response): |
Jon Hall | 5b4e1e8 | 2014-04-07 15:25:50 -0700 | [diff] [blame] | 93 | main.log.info(self.name + ": RAMCloud Server Started") |
| 94 | return main.TRUE |
| 95 | else: |
James Lee | b4527ad | 2014-04-07 11:04:08 -0700 | [diff] [blame] | 96 | main.log.info(self.name + ": Failed to start RAMCloud Server"+response) |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 97 | return main.FALSE |
| 98 | |
| 99 | |
| 100 | def start_coor(self): |
| 101 | ''' |
| 102 | This Function will start RamCloud |
| 103 | ''' |
Jon Hall | de47ebc | 2014-04-07 12:31:03 -0700 | [diff] [blame] | 104 | main.log.info(self.name+": Starting RAMCloud Coordinator" ) |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 105 | self.handle.sendline("") |
Jon Hall | ebaa5c5 | 2014-04-14 17:36:55 -0700 | [diff] [blame] | 106 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
admin | 6e3ed38 | 2014-04-03 18:01:18 -0700 | [diff] [blame] | 107 | self.handle.sendline(self.home + "/onos.sh rc-coord start") |
Jon Hall | ebaa5c5 | 2014-04-14 17:36:55 -0700 | [diff] [blame] | 108 | self.handle.expect(["onos.sh rc-coord start",pexpect.EOF,pexpect.TIMEOUT]) |
| 109 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 110 | response = self.handle.before + self.handle.after |
Jon Hall | de47ebc | 2014-04-07 12:31:03 -0700 | [diff] [blame] | 111 | 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 ") |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 115 | return main.TRUE |
| 116 | else: |
Jon Hall | de47ebc | 2014-04-07 12:31:03 -0700 | [diff] [blame] | 117 | main.log.error(self.name+": Failed to start RAMCloud Coordinator"+ response) |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 118 | return main.FALSE |
| 119 | |
| 120 | def status_serv(self): |
| 121 | ''' |
| 122 | This Function will return the Status of the RAMCloud |
| 123 | ''' |
James Lee | 342b439 | 2014-04-08 09:22:57 -0700 | [diff] [blame] | 124 | main.log.info(self.name + ": Getting RC-Server Status") |
| 125 | self.handle.sendline("") |
Jon Hall | ebaa5c5 | 2014-04-14 17:36:55 -0700 | [diff] [blame] | 126 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
James Lee | 342b439 | 2014-04-08 09:22:57 -0700 | [diff] [blame] | 127 | self.handle.sendline(self.home + "/onos.sh rc-server status") |
Jon Hall | ebaa5c5 | 2014-04-14 17:36:55 -0700 | [diff] [blame] | 128 | self.handle.expect(["onos.sh rc-server status",pexpect.EOF,pexpect.TIMEOUT]) |
| 129 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
James Lee | 342b439 | 2014-04-08 09:22:57 -0700 | [diff] [blame] | 130 | response = self.handle.before + self.handle.after |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 131 | |
James Lee | 342b439 | 2014-04-08 09:22:57 -0700 | [diff] [blame] | 132 | if re.search("0\sRAMCloud\sserver\srunning", response) : |
Jon Hall | de47ebc | 2014-04-07 12:31:03 -0700 | [diff] [blame] | 133 | main.log.info(self.name+": RAMCloud not running") |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 134 | return main.TRUE |
James Lee | 342b439 | 2014-04-08 09:22:57 -0700 | [diff] [blame] | 135 | elif re.search("1\sRAMCloud\sserver\srunning",response): |
Jon Hall | de47ebc | 2014-04-07 12:31:03 -0700 | [diff] [blame] | 136 | main.log.warn(self.name+": RAMCloud Running") |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 137 | return main.TRUE |
Jon Hall | de47ebc | 2014-04-07 12:31:03 -0700 | [diff] [blame] | 138 | else: |
| 139 | main.log.info( self.name+": WARNING: status recieved unknown response") |
| 140 | return main.FALSE |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 141 | |
| 142 | def status_coor(self): |
| 143 | ''' |
| 144 | This Function will return the Status of the RAMCloud |
| 145 | ''' |
Jon Hall | ebaa5c5 | 2014-04-14 17:36:55 -0700 | [diff] [blame] | 146 | main.log.info(self.name + ": Getting RC-Coord Status") |
| 147 | self.handle.sendline("") |
| 148 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
| 149 | self.handle.sendline(self.home + "/onos.sh rc-coord status") |
| 150 | i=self.handle.expect(["onos.sh rc-coord status",pexpect.EOF,pexpect.TIMEOUT]) |
| 151 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
| 152 | response = self.handle.before + self.handle.after |
Jon Hall | de47ebc | 2014-04-07 12:31:03 -0700 | [diff] [blame] | 153 | #return response |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 154 | |
Jon Hall | de47ebc | 2014-04-07 12:31:03 -0700 | [diff] [blame] | 155 | if re.search("0\sRAMCloud\scoordinator\srunning", response) : |
| 156 | main.log.warn(self.name+": RAMCloud Coordinator not running") |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 157 | return main.TRUE |
Jon Hall | de47ebc | 2014-04-07 12:31:03 -0700 | [diff] [blame] | 158 | elif re.search("1\sRAMCloud\scoordinator\srunning", response): |
| 159 | main.log.info(self.name+": RAMCloud Coordinator Running") |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 160 | return main.TRUE |
Jon Hall | de47ebc | 2014-04-07 12:31:03 -0700 | [diff] [blame] | 161 | else: |
| 162 | main.log.warn( self.name+": coordinator status recieved unknown response") |
| 163 | return main.FALSE |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 164 | |
| 165 | def stop_serv(self): |
| 166 | ''' |
| 167 | This Function will stop the RAMCloud if it is Running |
James Lee | 342b439 | 2014-04-08 09:22:57 -0700 | [diff] [blame] | 168 | ''' |
| 169 | main.log.info(self.name + ": Stopping RC-Server") |
| 170 | self.handle.sendline("") |
Jon Hall | ebaa5c5 | 2014-04-14 17:36:55 -0700 | [diff] [blame] | 171 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
James Lee | 342b439 | 2014-04-08 09:22:57 -0700 | [diff] [blame] | 172 | self.handle.sendline(self.home + "/onos.sh rc-server stop") |
Jon Hall | ebaa5c5 | 2014-04-14 17:36:55 -0700 | [diff] [blame] | 173 | self.handle.expect(["onos.sh rc-server stop",pexpect.EOF,pexpect.TIMEOUT]) |
| 174 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
James Lee | 342b439 | 2014-04-08 09:22:57 -0700 | [diff] [blame] | 175 | response = self.handle.before + self.handle.after |
| 176 | if re.search("Killed\sexisting\sprocess",response): |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 177 | main.log.info("RAMCloud Server Stopped") |
| 178 | return main.TRUE |
| 179 | else: |
Jon Hall | de47ebc | 2014-04-07 12:31:03 -0700 | [diff] [blame] | 180 | main.log.warn(self.name+": RAMCloud is not Running") |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 181 | return main.FALSE |
| 182 | |
| 183 | |
| 184 | def stop_coor(self): |
| 185 | ''' |
| 186 | This Function will stop the RAMCloud if it is Running |
| 187 | ''' |
Jon Hall | ebaa5c5 | 2014-04-14 17:36:55 -0700 | [diff] [blame] | 188 | main.log.info(self.name + ": Stopping RC-Coord") |
| 189 | self.handle.sendline("") |
| 190 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
| 191 | self.handle.sendline(self.home + "/onos.sh rc-coord stop") |
| 192 | self.handle.expect(["onos.sh rc-coord stop",pexpect.EOF,pexpect.TIMEOUT]) |
| 193 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
| 194 | response = self.handle.before + self.handle.after |
Jon Hall | de47ebc | 2014-04-07 12:31:03 -0700 | [diff] [blame] | 195 | if re.search("Killed\sexisting\sprocess",response): |
| 196 | main.log.info(self.name+": RAMCloud Coordinator Stopped") |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 197 | return main.TRUE |
| 198 | else: |
Jon Hall | de47ebc | 2014-04-07 12:31:03 -0700 | [diff] [blame] | 199 | main.log.warn(self.name+": RAMCloud was not Running") |
Jon Hall | 4121fdc | 2014-04-08 15:20:03 -0700 | [diff] [blame] | 200 | return main.FALSE |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 201 | |
| 202 | def disconnect(self): |
| 203 | ''' |
| 204 | Called at the end of the test to disconnect the ssh handle. |
| 205 | ''' |
| 206 | response = '' |
| 207 | if self.handle: |
| 208 | self.handle.sendline("exit") |
Jon Hall | ebaa5c5 | 2014-04-14 17:36:55 -0700 | [diff] [blame] | 209 | self.handle.expect(["closed",pexpect.EOF,pexpect.TIMEOUT]) |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 210 | else : |
Jon Hall | de47ebc | 2014-04-07 12:31:03 -0700 | [diff] [blame] | 211 | main.log.error("Connection failed to the host when trying to disconnect from RAMCloud component") |
admin | e72fefb | 2014-04-03 17:24:16 -0700 | [diff] [blame] | 212 | response = main.FALSE |
| 213 | return response |