~drizzle-trunk/drizzle/development

2194.2.1 by patrick crews
Integrated randgen with dbqp. We now have mode=randgen and a set of randgen test suites (very basic now). Output = same as dtr : ) We also have mode=cleanup to kill any servers we have started. Docs updates too. Gendata utility allows us to populate test servers
1
#! /usr/bin/env python
2235.5.2 by Stewart Smith
dbqp source (and all its libs) should use emacs python mode, not emacs C mode
2
# -*- mode: python; indent-tabs-mode: nil; -*-
2194.2.1 by patrick crews
Integrated randgen with dbqp. We now have mode=randgen and a set of randgen test suites (very basic now). Output = same as dtr : ) We also have mode=cleanup to kill any servers we have started. Docs updates too. Gendata utility allows us to populate test servers
3
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
#
5
# Copyright (C) 2010,2011 Patrick Crews
6
#
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
11
#
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
21
22
""" server.py:  generic server object used by the server
23
    manager.  This contains the generic methods for all 
24
    servers.  Specific types (Drizzle, MySQL, etc) should
25
    inherit from this guy
26
27
"""
28
29
# imports
30
import os
31
32
class Server(object):
33
    """ the server class from which other servers
34
        will inherit - contains generic methods
35
        certain methods will be overridden by more
36
        specific ones
37
38
    """
39
40
    def __init__(self
41
                , name
42
                , server_manager
2337.1.12 by patrick crews
Additional work on allowing dbqp to handle multiple server types / versions (even simultaneously)
43
                , code_tree
2194.2.1 by patrick crews
Integrated randgen with dbqp. We now have mode=randgen and a set of randgen test suites (very basic now). Output = same as dtr : ) We also have mode=cleanup to kill any servers we have started. Docs updates too. Gendata utility allows us to populate test servers
44
                , default_storage_engine
45
                , server_options
46
                , requester
47
                , workdir_root):
48
        self.skip_keys = [ 'server_manager'
49
                         , 'system_manager'
50
                         , 'dirset'
51
                         , 'preferred_base_port'
52
                         , 'no_secure_file_priv'
53
                         , 'secure_file_string'
54
                         , 'port_block'
55
                         ]
56
        self.debug = server_manager.debug
57
        self.verbose = server_manager.verbose
58
        self.initial_run = 1
59
        self.owner = requester
60
        self.server_options = server_options
61
        self.default_storage_engine = default_storage_engine
62
        self.server_manager = server_manager
63
        # We register with server_manager asap
64
        self.server_manager.log_server(self, requester)
65
66
        self.system_manager = self.server_manager.system_manager
2337.1.12 by patrick crews
Additional work on allowing dbqp to handle multiple server types / versions (even simultaneously)
67
        self.code_tree = code_tree
2194.2.1 by patrick crews
Integrated randgen with dbqp. We now have mode=randgen and a set of randgen test suites (very basic now). Output = same as dtr : ) We also have mode=cleanup to kill any servers we have started. Docs updates too. Gendata utility allows us to populate test servers
68
        self.valgrind = self.system_manager.valgrind
69
        self.gdb = self.system_manager.gdb
70
        if self.valgrind:
71
            self.valgrind_time_buffer = 10
72
        else:
73
            self.valgrind_time_buffer = 1
74
        self.cmd_prefix = self.system_manager.cmd_prefix
75
        self.logging = self.system_manager.logging
76
        self.no_secure_file_priv = self.server_manager.no_secure_file_priv
77
        self.name = name
78
        self.status = 0 # stopped, 1 = running
79
        self.tried_start = 0
80
        self.failed_test = 0 # was the last test a failure?  our state is suspect
81
        self.server_start_timeout = 60 * self.valgrind_time_buffer
2246.5.1 by patrick crews
Tweaked randgen tests so that we now have crash tests for inno_rpl_log and slave plugin! : )
82
        self.pid = None
2313.1.1 by patrick crews
Updates to server management to deal with dbqp bug
83
        self.need_reset = False
2194.2.1 by patrick crews
Integrated randgen with dbqp. We now have mode=randgen and a set of randgen test suites (very basic now). Output = same as dtr : ) We also have mode=cleanup to kill any servers we have started. Docs updates too. Gendata utility allows us to populate test servers
84
85
    def initialize_databases(self):
86
        """ Call schemawriter to make db.opt files """
87
        databases = [ 'test'
88
                    , 'mysql'
89
                    ]
90
        for database in databases:
91
            db_path = os.path.join(self.datadir,'local',database,'db.opt')
92
            cmd = "%s %s %s" %(self.schemawriter, database, db_path)
93
            self.system_manager.execute_cmd(cmd)
94
95
    def process_server_options(self):
96
        """Consume the list of options we have been passed.
97
           Return a string with them joined
98
99
        """
100
        
101
        return " ".join(self.server_options)
102
103
    def take_db_snapshot(self):
104
        """ Take a snapshot of our vardir for quick restores """
105
       
106
        self.logging.info("Taking clean db snapshot...")
107
        if os.path.exists(self.snapshot_path):
108
            # We need to remove an existing path as python shutil
109
            # doesn't want an existing target
110
            self.system_manager.remove_dir(self.snapshot_path)
111
        self.system_manager.copy_dir(self.datadir, self.snapshot_path)
112
113
    def restore_snapshot(self):
114
        """ Restore from a stored snapshot """
115
        
2337.1.5 by patrick crews
Additonal code cleanup
116
        self.logging.verbose("Restoring from db snapshot")
2194.2.1 by patrick crews
Integrated randgen with dbqp. We now have mode=randgen and a set of randgen test suites (very basic now). Output = same as dtr : ) We also have mode=cleanup to kill any servers we have started. Docs updates too. Gendata utility allows us to populate test servers
117
        if not os.path.exists(self.snapshot_path):
118
            self.logging.error("Could not find snapshot: %s" %(self.snapshot_path))
119
        self.system_manager.remove_dir(self.datadir)
120
        self.system_manager.copy_dir(self.snapshot_path, self.datadir)
121
122
    def is_started(self):
123
        """ Is the server running?  Particulars are server-dependent """
124
2337.1.14 by patrick crews
Believed to be last tweaks needed to have different code trees / basedirs in a single dbqp run. Now to code for new servers : )
125
        return "You need to implement is_started"
2194.2.1 by patrick crews
Integrated randgen with dbqp. We now have mode=randgen and a set of randgen test suites (very basic now). Output = same as dtr : ) We also have mode=cleanup to kill any servers we have started. Docs updates too. Gendata utility allows us to populate test servers
126
127
    def get_start_cmd(self):
128
        """ Return the command the server_manager can use to start me """
129
2337.1.14 by patrick crews
Believed to be last tweaks needed to have different code trees / basedirs in a single dbqp run. Now to code for new servers : )
130
        return "You need to implement get_start_cmd"
2194.2.1 by patrick crews
Integrated randgen with dbqp. We now have mode=randgen and a set of randgen test suites (very basic now). Output = same as dtr : ) We also have mode=cleanup to kill any servers we have started. Docs updates too. Gendata utility allows us to populate test servers
131
132
    def get_stop_cmd(self):
133
        """ Return the command the server_manager can use to stop me """
134
2337.1.14 by patrick crews
Believed to be last tweaks needed to have different code trees / basedirs in a single dbqp run. Now to code for new servers : )
135
        return "You need to implement get_stop_cmd"
2194.2.1 by patrick crews
Integrated randgen with dbqp. We now have mode=randgen and a set of randgen test suites (very basic now). Output = same as dtr : ) We also have mode=cleanup to kill any servers we have started. Docs updates too. Gendata utility allows us to populate test servers
136
137
    def get_ping_cmd(self):
138
        """ Return the command that can be used to 'ping' me 
139
            Very similar to is_started, but different
140
141
            Determining if a server is still running (ping)
142
            may differ from the method used to determine
143
            server startup
144
145
        """
146
   
2337.1.14 by patrick crews
Believed to be last tweaks needed to have different code trees / basedirs in a single dbqp run. Now to code for new servers : )
147
        return "You need to implement get_ping_cmd"
2194.2.1 by patrick crews
Integrated randgen with dbqp. We now have mode=randgen and a set of randgen test suites (very basic now). Output = same as dtr : ) We also have mode=cleanup to kill any servers we have started. Docs updates too. Gendata utility allows us to populate test servers
148
149
    def cleanup(self):
150
        """ Cleanup - just free ports for now..."""
151
        self.system_manager.port_manager.free_ports(self.port_block)
152
153
    def set_server_options(self, server_options):
154
        """ We update our server_options to the new set """
155
        self.server_options = server_options
156
157
    def reset(self):
158
        """ Voodoo to reset ourselves """
159
        self.failed_test = 0