blob: 0b43d322c8e1daca81b9adc03dcff613af519b93 [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 '''
40 CassandraCliDriver is the basic driver which will handle the Cassandra's 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(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 :
58 self.start()
59 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):
67 ''' This Function will start the Cassandra'''
68 main.log.info( "Starting Cassandra" )
69 self.handle.sendline("")
70 self.handle.expect("\$")
71 self.handle.sendline("~/ONOS/start-cassandra.sh start")
72 self.handle.expect("start-cassandra.sh start")
73 self.handle.expect("\$")
74 response = self.handle.before + self.handle.after
75 time.sleep(5)
76 if re.search("Starting\scassandra(.*)", response):
77 main.log.info("Cassandra Started ")
78 return main.TRUE
79 else:
80 main.log.error("Failed to start Cassandra"+ response)
81 return main.FALSE
82
83 def status(self):
84 '''This Function will return the Status of the Cassandra '''
85 time.sleep(5)
86 self.execute(cmd="\r",prompt="\$",timeout=10)
87 response = self.execute(cmd="~/ONOS/start-cassandra.sh status ",prompt="\d+\sinstance\sof\scassandra\srunning(.*)",timeout=10)
88
89
90 self.execute(cmd="\r",prompt="\$",timeout=10)
91 return response
92
93 if re.search("0\sinstance\sof\scassandra\srunning(.*)") :
94 main.log.info("Cassandra not running")
95 return main.TRUE
96 elif re.search("1\sinstance\sof\scassandra\srunning(.*)"):
97 main.log.warn("Cassandra Running")
98 return main.TRUE
99
100 def stop(self):
101 '''This Function will stop the Cassandra if it is Running'''
102 self.execute(cmd="\r",prompt="\$",timeout=10)
103 time.sleep(5)
104 response = self.execute(cmd="~/ONOS/start-cassandra.sh stop ",prompt="Killed\sexisting\sprosess(.*)",timeout=10)
105 self.execute(cmd="\r",prompt="\$",timeout=10)
106 if re.search("Killed\sexisting\sprosess(.*)",response):
107 main.log.info("Cassandra Stopped")
108 return main.TRUE
109 else:
110 main.log.warn("Cassndra is not Running")
111 return main.FALSE
112
113 def disconnect(self):
114
115 response = ''
116 if self.handle:
117 self.handle.sendline("exit")
118 self.handle.expect("closed")
119 else :
120 main.log.error("Connection failed to the host")
121 response = main.FALSE
122 return response
123
124 def isup(self):
125 tries = 5
126 main.log.info("trying %i times" % tries )
127 for i in range(tries):
128 self.execute(cmd="\r",prompt="\$",timeout=10)
129 self.handle.sendline("")
130 self.handle.expect("\$")
131 self.handle.sendline("~/ONOS/start-cassandra.sh status")
132 self.handle.expect("sh status")
133 self.handle.expect("\$")
134 result = self.handle.before + self.handle.after
135 pattern = '(.*)Up(.*)Normal(.*)\n(.*)Up(.*)Normal(.*)\n(.*)Up(.*)Normal(.*)\n(.*)Up(.*)Normal(.*)'
136 if re.search(pattern, result):
137 return main.TRUE
138 return main.FALSE