~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/lib/server_mgmt/drizzled.py

  • Committer: Andrew Hutchings
  • Date: 2011-02-02 12:51:57 UTC
  • mto: (2157.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2158.
  • Revision ID: andrew@linuxjedi.co.uk-20110202125157-r6thh7ox4g9l90ec
Make transaction_message_threshold a read-only global variable instead of a per-session variable
Make replication_dictionary column lengths use transation_message_threshold

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/env python
 
1
#! /usr/bin/python
2
2
# -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3
3
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
4
#
27
27
 
28
28
# imports
29
29
import os
 
30
import time
30
31
 
31
32
class drizzleServer():
32
33
    """ represents a drizzle server, its possessions
33
34
        (datadir, ports, etc), and methods for controlling
34
35
        and querying it
35
36
 
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
 
              which are general
40
 
 
41
37
    """
42
38
 
43
 
    def __init__( self
44
 
                , name
45
 
                , server_manager
46
 
                , default_storage_engine
47
 
                , server_options
48
 
                , requester
49
 
                , workdir_root):
 
39
    def __init__(self, name, server_manager, server_options
 
40
                , requester, workdir_root):
50
41
        self.skip_keys = [ 'server_manager'
51
42
                         , 'system_manager'
52
43
                         , 'dirset'
60
51
        self.initial_run = 1
61
52
        self.owner = requester
62
53
        self.server_options = server_options
63
 
        self.default_storage_engine = default_storage_engine
64
54
        self.server_manager = server_manager
65
55
        # We register with server_manager asap
66
56
        self.server_manager.log_server(self, requester)
67
57
 
68
58
        self.system_manager = self.server_manager.system_manager
69
59
        self.valgrind = self.system_manager.valgrind
70
 
        self.gdb = self.system_manager.gdb
71
60
        if self.valgrind:
72
61
            self.valgrind_time_buffer = 10
73
62
        else:
74
 
            self.valgrind_time_buffer = 1
 
63
            self.valgrind_time_buffer = 0
75
64
        self.cmd_prefix = self.system_manager.cmd_prefix
76
65
        self.logging = self.system_manager.logging
77
66
        self.no_secure_file_priv = self.server_manager.no_secure_file_priv
91
80
        self.drizzle_tcp_port = self.port_block[1]
92
81
        self.mc_port = self.port_block[2]
93
82
        self.pbms_port = self.port_block[3]
94
 
        self.rabbitmq_node_port = self.port_block[4]
 
83
        self.rabbit_mq_node_port = self.port_block[4]
95
84
        
96
85
 
97
86
        # Generate our working directories
150
139
                        , 'drizzle_tcp_port'
151
140
                        , 'mc_port'
152
141
                        , 'pbms_port'
153
 
                        , 'rabbitmq_node_port'
 
142
                        , 'rabbit_mq_node_port'
154
143
                        , 'vardir'
155
144
                        , 'status'
156
145
                        ]
159
148
          value = vars(self)[key] 
160
149
          self.logging.info("%s: %s" %(key.upper(), value))
161
150
 
162
 
    def get_start_cmd(self):
163
 
        """ Return the command string that will start up the server 
164
 
            as desired / intended
165
 
 
 
151
    def start(self, expect_fail):
 
152
        """ Start the server, using the options in option_list
 
153
            as well as self.standard_options
 
154
            
 
155
            if expect_fail = 1, we know the server shouldn't 
 
156
            start up
 
157
 
166
158
        """
167
 
 
168
 
        server_args = [ self.process_server_options()
169
 
                      , "--mysql-protocol.port=%d" %(self.master_port)
170
 
                      , "--mysql-protocol.connect-timeout=60"
171
 
                      , "--innodb.data-file-path=ibdata1:20M:autoextend"
172
 
                      , "--sort-buffer-size=256K"
173
 
                      , "--max-heap-table-size=1M"
174
 
                      , "--mysql-unix-socket-protocol.path=%s" %(self.socket_file)
175
 
                      , "--pid-file=%s" %(self.pid_file)
176
 
                      , "--drizzle-protocol.port=%d" %(self.drizzle_tcp_port)
177
 
                      , "--default-storage-engine=%s" %(self.default_storage_engine)
178
 
                      , "--datadir=%s" %(self.datadir)
179
 
                      , "--tmpdir=%s" %(self.tmpdir)
180
 
                      , self.secure_file_string
181
 
                      , self.user_string
182
 
                      ]
183
 
 
184
 
        if self.gdb:
185
 
            server_args.append('--gdb')
186
 
            return self.system_manager.handle_gdb_reqs(self, server_args)
 
159
        if self.verbose:
 
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
 
162
                                               , self.server_path
 
163
                                               , self.process_server_options()
 
164
                                               , self.master_port
 
165
                                               , self.socket_file
 
166
                                               , self.pid_file
 
167
                                               , self.drizzle_tcp_port
 
168
                                               , self.datadir
 
169
                                               , self.tmpdir
 
170
                                               , self.secure_file_string
 
171
                                               , self.user_string 
 
172
                                               , self.error_log
 
173
                                               )
 
174
        if self.debug:
 
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
 
182
        self.tried_start = 1
 
183
        server_retcode = os.system(start_cmd)
 
184
        
 
185
        timer = 0
 
186
        timeout = self.server_start_timeout
 
187
        while not self.ping(quiet= True) and timer != timeout:
 
188
            time.sleep(1)
 
189
            timer= timer + 1
 
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)))
 
193
                server_retcode = 1
 
194
     
 
195
        if server_retcode == 0:
 
196
            self.status = 1 # we are running
 
197
 
 
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
 
200
                                                                                  , server_retcode))
 
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))
 
204
        self.tried_start = 0 
 
205
        return server_retcode ^ expect_fail
 
206
 
 
207
    def stop(self):
 
208
        """ Stop the server """
 
209
        if self.verbose:
 
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)
 
212
        if self.debug:
 
213
            self.logging.debug("%s" %(stop_cmd))
 
214
        retcode, output = self.system_manager.execute_cmd(stop_cmd)
 
215
        if retcode:
 
216
            self.logging.error("Problem shutting down server:")
 
217
            self.logging.error("%s : %s" %(retcode, output))
187
218
        else:
188
 
            return "%s %s %s & " % ( self.cmd_prefix
189
 
                                   , self.server_path
190
 
                                   , " ".join(server_args)
191
 
                                   )
192
 
 
193
 
 
194
 
    def get_stop_cmd(self):
195
 
        """ Return the command that will shut us down """
196
 
        
197
 
        return "%s --user=root --port=%d --shutdown " %(self.drizzle_client_path, self.master_port)
 
219
            self.status = 0 # indicate we are shutdown
198
220
           
199
221
 
200
 
    def get_ping_cmd(self):
201
 
        """Return the command string that will 
202
 
           ping / check if the server is alive 
203
 
 
204
 
        """
205
 
 
206
 
        return "%s --ping --port=%d --user=root" % (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)
 
225
        if not quiet:
 
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)
 
228
        return retcode == 0
207
229
 
208
230
    def process_server_options(self):
209
231
        """Consume the list of options we have been passed.