32
31
class drizzleServer():
33
32
""" represents a drizzle server, its possessions
34
33
(datadir, ports, etc), and methods for controlling
36
TODO: create a base server class that contains
37
standard methods from which we can inherit
38
Currently there are definitely methods / attr
39
43
def __init__(self, name, server_manager, server_options
61
65
self.valgrind_time_buffer = 10
63
self.valgrind_time_buffer = 0
67
self.valgrind_time_buffer = 1
64
68
self.cmd_prefix = self.system_manager.cmd_prefix
65
69
self.logging = self.system_manager.logging
66
70
self.no_secure_file_priv = self.server_manager.no_secure_file_priv
148
152
value = vars(self)[key]
149
153
self.logging.info("%s: %s" %(key.upper(), value))
151
def start(self, expect_fail):
152
""" Start the server, using the options in option_list
153
as well as self.standard_options
155
if expect_fail = 1, we know the server shouldn't
155
def get_start_cmd(self):
156
""" Return the command string that will start up the server
157
as desired / intended
160
self.logging.verbose("Starting server: %s.%s" %(self.owner, self.name))
161
start_cmd = "%s %s %s --mysql-protocol.port=%d --mysql-protocol.connect-timeout=60 --mysql-unix-socket-protocol.path=%s --pid-file=%s --drizzle-protocol.port=%d --datadir=%s --tmpdir=%s --innodb.data-file-path=ibdata1:20M:autoextend --sort-buffer-size=256K --max-heap-table-size=1M %s %s > %s 2>&1 & " % ( self.cmd_prefix
161
return "%s %s %s --mysql-protocol.port=%d --mysql-protocol.connect-timeout=60 --mysql-unix-socket-protocol.path=%s --pid-file=%s --drizzle-protocol.port=%d --datadir=%s --tmpdir=%s --innodb.data-file-path=ibdata1:20M:autoextend --sort-buffer-size=256K --max-heap-table-size=1M %s %s > %s 2>&1 & " % ( self.cmd_prefix
162
162
, self.server_path
163
163
, self.process_server_options()
164
164
, self.master_port
171
171
, self.user_string
175
self.logging.debug("Starting server with:")
176
self.logging.debug("%s" %(start_cmd))
177
# we signal we tried to start as an attempt
178
# to catch the case where a server is just
179
# starting up and the user ctrl-c's
180
# we don't know the server is running (still starting up)
181
# so we give it a few minutes
183
server_retcode = os.system(start_cmd)
175
def get_stop_cmd(self):
176
""" Return the command that will shut us down """
186
timeout = self.server_start_timeout
187
while not self.ping(quiet= True) and timer != timeout:
190
# We make sure the server is running and return False if not
191
if timer == timeout and not self.ping(quiet= True):
192
self.logging.error(( "Server failed to start within %d seconds. This could be a problem with the test machine or the server itself" %(timeout)))
195
if server_retcode == 0:
196
self.status = 1 # we are running
198
if server_retcode != 0 and not expect_fail and self.debug:
199
self.logging.debug("Server startup command: %s failed with error code %d" %( start_cmd
201
elif server_retcode == 0 and expect_fail:
202
# catch a startup that should have failed and report
203
self.logging.error("Server startup command :%s expected to fail, but succeeded" %(start_cmd))
205
return server_retcode ^ expect_fail
208
""" Stop the server """
210
self.logging.verbose("Stopping server %s.%s" %(self.owner, self.name))
211
stop_cmd = "%s --user=root --port=%d --shutdown " %(self.drizzle_client_path, self.master_port)
213
self.logging.debug("%s" %(stop_cmd))
214
retcode, output = self.system_manager.execute_cmd(stop_cmd)
216
self.logging.error("Problem shutting down server:")
217
self.logging.error("%s : %s" %(retcode, output))
219
self.status = 0 # indicate we are shutdown
178
return "%s --user=root --port=%d --shutdown " %(self.drizzle_client_path, self.master_port)
222
def ping(self, quiet= False):
223
"""Pings the server. Returns True if server is up and running, False otherwise."""
224
ping_cmd= "%s --ping --port=%d --user=root" % (self.drizzle_client_path, self.master_port)
226
self.logging.info("Pinging Drizzled server on port %d" % self.master_port)
227
(retcode, output)= self.system_manager.execute_cmd(ping_cmd, must_pass = 0)
181
def get_ping_cmd(self):
182
"""Return the command string that will
183
ping / check if the server is alive
187
return "%s --ping --port=%d --user=root" % (self.drizzle_client_path, self.master_port)
230
189
def process_server_options(self):
231
190
"""Consume the list of options we have been passed.