blob: 2a575aeb444cd6dd3be18a2db5c58a15b6d81909 [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
22ZookeeperCliDriver is the basic driver which will handle the Zookeeper 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 ZookeeperCliDriver(CLI):
39 '''
adminaeedddd2013-08-02 15:14:15 -070040 ZookeeperCliDriver is the basic driver which will handle the Zookeeper'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(ZookeeperCliDriver, 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):
adminaeedddd2013-08-02 15:14:15 -070067 '''
68 This Function will start the Zookeeper
69 '''
adminbae64d82013-08-01 10:50:15 -070070 main.log.info( "Starting Zookeeper" )
71 self.handle.sendline("")
72 self.handle.expect("\$")
73 self.handle.sendline("~/zookeeper-3.4.5/bin/zkServer.sh start")
74 self.handle.expect("zkServer.sh start")
75 self.handle.expect("\$")
76 response = self.handle.before + self.handle.after
77 if re.search("STARTED", response):
78 main.log.info("Zookeeper Started ")
79 return main.TRUE
80 elif re.search("running", response):
81 main.log.warn("zookeeper ... already running")
82 else:
83 main.log.error("Failed to start Zookeeper"+ response)
84 return main.FALSE
85
86 def status(self):
adminaeedddd2013-08-02 15:14:15 -070087 '''
88 This Function will return the Status of the Zookeeper
89 '''
adminbae64d82013-08-01 10:50:15 -070090 time.sleep(5)
91 self.execute(cmd="\r",prompt="\$",timeout=10)
92 response = self.execute(cmd="~/zookeeper-3.4.5/bin/zkServer.sh status ",prompt="JMX",timeout=10)
93
94 self.execute(cmd="\r",prompt="\$",timeout=10)
95 return response
96
97 def stop(self):
adminaeedddd2013-08-02 15:14:15 -070098 '''
99 This Function will stop the Zookeeper if it is Running
100 '''
adminbae64d82013-08-01 10:50:15 -0700101 self.execute(cmd="\r",prompt="\$",timeout=10)
102 time.sleep(5)
103 response = self.execute(cmd="~/zookeeper-3.4.5/bin/zkServer.sh stop ",prompt="STOPPED",timeout=10)
104 self.execute(cmd="\r",prompt="\$",timeout=10)
105 if re.search("STOPPED",response):
106 main.log.info("Zookeeper Stopped")
107 return main.TRUE
108 else:
109 main.log.warn("No zookeeper to stop")
110 return main.FALSE
111
112 def disconnect(self):
adminaeedddd2013-08-02 15:14:15 -0700113 '''
114 Called at the end of the test to disconnect the ZK handle
115 '''
adminbae64d82013-08-01 10:50:15 -0700116 response = ''
117 if self.handle:
118 self.handle.sendline("exit")
119 self.handle.expect("closed")
120 else :
121 main.log.error("Connection failed to the host")
122 response = main.FALSE
123 return response
124
125 def isup(self):
adminaeedddd2013-08-02 15:14:15 -0700126 '''
127 Calls the zookeeper status and returns TRUE if it has an assigned Mode to it.
128 '''
adminbae64d82013-08-01 10:50:15 -0700129 self.execute(cmd="\n",prompt="\$",timeout=10)
130 response = self.execute(cmd="~/zookeeper-3.4.5/bin/zkServer.sh status ",prompt="Mode",timeout=10)
131 pattern = '(.*)Mode(.*)'
132 if re.search(pattern, response):
133 return main.TRUE
134 else:
135 return main.FALSE
136
137