blob: 6a961ee5288f4df64d1ff200246469c623be61f1 [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -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
22CassandraCliDriver is the basic driver which will handle the Cassandra 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 CassandraCliDriver(CLI):
39 '''
adminaeedddd2013-08-02 15:14:15 -070040 CassandraCliDriver is the basic driver which will handle the Cassandra's functions
adminbae64d82013-08-01 10:50:15 -070041 '''
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(CassandraCliDriver, 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 :
admine0ae8202013-08-28 11:51:43 -070058 #self.start()
adminbae64d82013-08-01 10:50:15 -070059 return main.TRUE
60 else :
61 main.log.error("Connection failed to the host "+self.user_name+"@"+self.ip_address)
62 main.log.error("Failed to connect to the Onos system")
63 return main.FALSE
64
65
66 def start(self):
adminaeedddd2013-08-02 15:14:15 -070067 '''
68 This Function will start the Cassandra
69 '''
adminbae64d82013-08-01 10:50:15 -070070 main.log.info( "Starting Cassandra" )
71 self.handle.sendline("")
72 self.handle.expect("\$")
73 self.handle.sendline("~/ONOS/start-cassandra.sh start")
74 self.handle.expect("start-cassandra.sh start")
75 self.handle.expect("\$")
76 response = self.handle.before + self.handle.after
77 time.sleep(5)
78 if re.search("Starting\scassandra(.*)", response):
79 main.log.info("Cassandra Started ")
80 return main.TRUE
81 else:
82 main.log.error("Failed to start Cassandra"+ response)
83 return main.FALSE
84
85 def status(self):
adminaeedddd2013-08-02 15:14:15 -070086 '''
87 This Function will return the Status of the Cassandra
88 '''
adminbae64d82013-08-01 10:50:15 -070089 time.sleep(5)
90 self.execute(cmd="\r",prompt="\$",timeout=10)
91 response = self.execute(cmd="~/ONOS/start-cassandra.sh status ",prompt="\d+\sinstance\sof\scassandra\srunning(.*)",timeout=10)
92
93
94 self.execute(cmd="\r",prompt="\$",timeout=10)
95 return response
96
97 if re.search("0\sinstance\sof\scassandra\srunning(.*)") :
98 main.log.info("Cassandra not running")
99 return main.TRUE
100 elif re.search("1\sinstance\sof\scassandra\srunning(.*)"):
101 main.log.warn("Cassandra Running")
102 return main.TRUE
103
104 def stop(self):
adminaeedddd2013-08-02 15:14:15 -0700105 '''
106 This Function will stop the Cassandra if it is Running
107 '''
adminbae64d82013-08-01 10:50:15 -0700108 self.execute(cmd="\r",prompt="\$",timeout=10)
109 time.sleep(5)
110 response = self.execute(cmd="~/ONOS/start-cassandra.sh stop ",prompt="Killed\sexisting\sprosess(.*)",timeout=10)
111 self.execute(cmd="\r",prompt="\$",timeout=10)
112 if re.search("Killed\sexisting\sprosess(.*)",response):
113 main.log.info("Cassandra Stopped")
114 return main.TRUE
115 else:
116 main.log.warn("Cassndra is not Running")
117 return main.FALSE
118
119 def disconnect(self):
adminaeedddd2013-08-02 15:14:15 -0700120 '''
121 Called at the end of the test to disconnect the ssh handle.
122 '''
adminbae64d82013-08-01 10:50:15 -0700123 response = ''
124 if self.handle:
125 self.handle.sendline("exit")
126 self.handle.expect("closed")
127 else :
128 main.log.error("Connection failed to the host")
129 response = main.FALSE
130 return response
131
132 def isup(self):
adminaeedddd2013-08-02 15:14:15 -0700133 '''
134 A more complete status check of cassandra.
135 Tries 5 times to call start-cassandra.sh status
136 returns TRUE if it sees four occurances of both Up, and Normal
137 '''
adminbae64d82013-08-01 10:50:15 -0700138 tries = 5
139 main.log.info("trying %i times" % tries )
140 for i in range(tries):
141 self.execute(cmd="\r",prompt="\$",timeout=10)
142 self.handle.sendline("")
143 self.handle.expect("\$")
144 self.handle.sendline("~/ONOS/start-cassandra.sh status")
145 self.handle.expect("sh status")
146 self.handle.expect("\$")
147 result = self.handle.before + self.handle.after
148 pattern = '(.*)Up(.*)Normal(.*)\n(.*)Up(.*)Normal(.*)\n(.*)Up(.*)Normal(.*)\n(.*)Up(.*)Normal(.*)'
149 if re.search(pattern, result):
150 return main.TRUE
151 return main.FALSE