51
51
self.server_base_name = 's'
52
52
self.no_secure_file_priv = variables['nosecurefilepriv']
53
53
self.system_manager = system_manager
54
self.code_manager = system_manager.code_manager
55
self.env_manager = system_manager.env_manager
54
56
self.logging = system_manager.logging
55
57
self.gdb = self.system_manager.gdb
56
self.code_tree = system_manager.code_tree
57
58
self.default_storage_engine = variables['defaultengine']
59
self.default_server_type = variables['defaultservertype']
58
60
self.user_server_opts = variables['drizzledoptions']
61
self.ld_lib_paths = system_manager.ld_lib_paths
62
63
self.mutex = thread.allocate_lock()
63
64
self.timer_increment = .5
65
self.libeatmydata = variables['libeatmydata']
66
self.libeatmydata_path = variables['libeatmydatapath']
65
68
self.logging.info("Using default-storage-engine: %s" %(self.default_storage_engine))
68
self.logging.debug_class(self)
70
self.logging.debug_class(self)
70
72
def request_servers( self, requester, workdir, cnf_path, server_requirements
71
73
, working_environ, expect_fail = 0):
103
def allocate_server(self, requester, server_options, workdir):
105
def allocate_server( self, requester, server_options
106
, workdir, server_type=None, server_version=None):
104
107
""" Intialize an appropriate server object.
105
108
Start up occurs elsewhere
111
# use default server type unless specifically requested to do otherwise
113
server_type = self.default_server_type
109
115
# Get a name for our server
110
116
server_name = self.get_server_name(requester)
112
118
# initialize our new server_object
113
if self.code_tree.type == 'Drizzle':
114
from lib.server_mgmt.drizzled import drizzleServer as server_type
119
# get the right codeTree type from the code manager
120
code_tree = self.code_manager.get_tree(server_type, server_version)
122
# import the correct server type object
123
if server_type == 'drizzle':
124
from lib.server_mgmt.drizzled import drizzleServer as server_type
125
elif server_type == 'mysql':
126
from lib.server_mgmt.mysqld import mysqlServer as server_type
115
128
new_server = server_type( server_name
117
131
, self.default_storage_engine
163
# take care of any environment updates we need to do
164
self.handle_environment_reqs(server, working_environ)
148
self.logging.verbose("Starting server: %s.%s" %(server.owner, server.name))
166
self.logging.verbose("Starting server: %s.%s" %(server.owner, server.name))
149
167
start_cmd = server.get_start_cmd()
151
self.logging.debug("Starting server with:")
152
self.logging.debug("%s" %(start_cmd))
168
self.logging.debug("Starting server with:")
169
self.logging.debug("%s" %(start_cmd))
153
170
# we signal we tried to start as an attempt
154
171
# to catch the case where a server is just
155
172
# starting up and the user ctrl-c's
340
356
We should have the proper number of servers at this point
360
# A dictionary that holds various tricks
361
# we can do with our test servers
362
special_processing_reqs = {}
343
364
current_servers = self.servers[requester]
345
# We have a config reader so we can do
346
# special per-server magic for setting up more
347
# complex scenario-based testing (eg we use a certain datadir)
349
config_reader = RawConfigParser()
350
config_reader.read(cnf_path)
353
# A list that holds tuples of src,tgt pairs
354
# for using a pre-loaded-datadirs on a test server
355
datadir_requests = []
357
366
for index,server in enumerate(current_servers):
358
desired_server_options = server_requirements[index]
359
# We add in any user-supplied options here
360
desired_server_options = desired_server_options + self.user_server_opts
362
367
# We handle a reset in case we need it:
363
368
if server.need_reset:
364
369
self.reset_server(server)
365
370
server.need_reset = False
367
# Do our checking for config-specific madness we need to do
368
if config_reader and config_reader.has_section(server.name):
369
# mark server for restart in case it hasn't yet
370
# this method is a bit hackish - need better method later
371
if '--restart' not in desired_server_options:
372
desired_server_options.append('--restart')
373
# We handle various scenarios
374
server_config_data = config_reader.items(server.name)
375
for cnf_option, data in server_config_data:
376
if cnf_option == 'load-datadir':
378
datadir_requests.append((datadir_path,server))
372
desired_server_options = server_requirements[index]
374
# do any special config processing - this can alter
375
# how we view our servers
377
self.handle_server_config_file( cnf_path
379
, special_processing_reqs
380
, desired_server_options
380
383
if self.compare_options( server.server_options
381
384
, desired_server_options):
384
387
# We need to reset what is running and change the server
386
389
desired_server_options = self.filter_server_options(desired_server_options)
387
390
self.reset_server(server)
388
391
self.update_server_options(server, desired_server_options)
389
self.load_datadirs(datadir_requests)
393
self.handle_special_server_requests(special_processing_reqs)
395
def handle_server_config_file( self
398
, special_processing_reqs
399
, desired_server_options
401
# We have a config reader so we can do
402
# special per-server magic for setting up more
403
# complex scenario-based testing (eg we use a certain datadir)
404
config_reader = RawConfigParser()
405
config_reader.read(cnf_path)
407
# Do our checking for config-specific madness we need to do
408
if config_reader and config_reader.has_section(server.name):
409
# mark server for restart in case it hasn't yet
410
# this method is a bit hackish - need better method later
411
if '--restart' not in desired_server_options:
412
desired_server_options.append('--restart')
413
# We handle various scenarios
414
server_config_data = config_reader.items(server.name)
415
for cnf_option, data in server_config_data:
416
if cnf_option == 'load-datadir':
418
request_key = 'datadir_requests'
419
if request_key not in special_processing_reqs:
420
special_processing_reqs[request_key] = []
421
special_processing_reqs[request_key].append((datadir_path,server))
423
def handle_special_server_requests(self, request_dictionary):
424
""" We run through our set of special requests and do
425
the appropriate voodoo
428
for key, item in request_dictionary.items():
429
if key == 'datadir_requests':
430
self.load_datadirs(item)
394
432
def filter_server_options(self, server_options):
395
433
""" Remove a list of options we don't want passed to the server
502
539
if server.failed_test:
503
540
self.reset_server(server)
542
def handle_environment_reqs(self, server, working_environ):
543
""" We update the working_environ as we need to
544
before starting the server.
546
This includes things like libeatmydata, ld_preloads, etc
549
environment_reqs = {}
551
if self.libeatmydata:
552
# We want to use libeatmydata to disable fsyncs
553
# this speeds up test execution, but we only want
554
# it to happen for the servers' environments
556
environment_reqs.update({'LD_PRELOAD':self.libeatmydata_path})
559
ld_lib_paths = self.env_manager.join_env_var_values(server.code_tree.ld_lib_paths)
560
environment_reqs.update({'LD_LIBRARY_PATH' : self.env_manager.append_env_var( 'LD_LIBRARY_PATH'
565
, 'DYLD_LIBRARY_PATH' : self.env_manager.append_env_var( 'DYLD_LIBRARY_PATH'
572
self.env_manager.update_environment_vars(environment_reqs)