~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Lee Bieber
  • Date: 2011-02-05 05:56:29 UTC
  • mfrom: (2145.1.3 build)
  • Revision ID: kalebral@gmail.com-20110205055629-iud8evvqwmozo61v
Merge Andrew - 702575: Need to document bug #622472
Merge Andrew - 702878: "Show table status" needs an overhaul  
Merge Lee - 712123: Remove warnings from unittests
Merge Patrick - 711273: dbqp not running rabbitmq tests, plus clean up server management

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/python
 
1
#! /usr/bin/env 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
31
30
 
32
31
class drizzleServer():
33
32
    """ represents a drizzle server, its possessions
34
33
        (datadir, ports, etc), and methods for controlling
35
34
        and querying it
36
35
 
 
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
 
37
41
    """
38
42
 
39
43
    def __init__(self, name, server_manager, server_options
60
64
        if self.valgrind:
61
65
            self.valgrind_time_buffer = 10
62
66
        else:
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
80
84
        self.drizzle_tcp_port = self.port_block[1]
81
85
        self.mc_port = self.port_block[2]
82
86
        self.pbms_port = self.port_block[3]
83
 
        self.rabbit_mq_node_port = self.port_block[4]
 
87
        self.rabbitmq_node_port = self.port_block[4]
84
88
        
85
89
 
86
90
        # Generate our working directories
139
143
                        , 'drizzle_tcp_port'
140
144
                        , 'mc_port'
141
145
                        , 'pbms_port'
142
 
                        , 'rabbit_mq_node_port'
 
146
                        , 'rabbitmq_node_port'
143
147
                        , 'vardir'
144
148
                        , 'status'
145
149
                        ]
148
152
          value = vars(self)[key] 
149
153
          self.logging.info("%s: %s" %(key.upper(), value))
150
154
 
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
 
 
 
155
    def get_start_cmd(self):
 
156
        """ Return the command string that will start up the server 
 
157
            as desired / intended
 
158
 
158
159
        """
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
 
160
      
 
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 
172
172
                                               , self.error_log
173
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)
 
174
 
 
175
    def get_stop_cmd(self):
 
176
        """ Return the command that will shut us down """
184
177
        
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))
218
 
        else:
219
 
            self.status = 0 # indicate we are shutdown
 
178
        return "%s --user=root --port=%d --shutdown " %(self.drizzle_client_path, self.master_port)
220
179
           
221
180
 
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
 
181
    def get_ping_cmd(self):
 
182
        """Return the command string that will 
 
183
           ping / check if the server is alive 
 
184
 
 
185
        """
 
186
 
 
187
        return "%s --ping --port=%d --user=root" % (self.drizzle_client_path, self.master_port)
229
188
 
230
189
    def process_server_options(self):
231
190
        """Consume the list of options we have been passed.