~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: pcrews
  • Date: 2011-05-24 17:36:24 UTC
  • mfrom: (1099.4.232 drizzle)
  • Revision ID: pcrews@lucid32-20110524173624-mwr1bvq6fa1r01ao
Updated translations + 2011.05.18 tarball tag

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
# -*- mode: python; indent-tabs-mode: nil; -*-
 
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
 
43
                , default_storage_engine
 
44
                , server_options
 
45
                , requester
 
46
                , workdir_root):
 
47
        self.skip_keys = [ 'server_manager'
 
48
                         , 'system_manager'
 
49
                         , 'dirset'
 
50
                         , 'preferred_base_port'
 
51
                         , 'no_secure_file_priv'
 
52
                         , 'secure_file_string'
 
53
                         , 'port_block'
 
54
                         ]
 
55
        self.debug = server_manager.debug
 
56
        self.verbose = server_manager.verbose
 
57
        self.initial_run = 1
 
58
        self.owner = requester
 
59
        self.server_options = server_options
 
60
        self.default_storage_engine = default_storage_engine
 
61
        self.server_manager = server_manager
 
62
        # We register with server_manager asap
 
63
        self.server_manager.log_server(self, requester)
 
64
 
 
65
        self.system_manager = self.server_manager.system_manager
 
66
        self.valgrind = self.system_manager.valgrind
 
67
        self.gdb = self.system_manager.gdb
 
68
        if self.valgrind:
 
69
            self.valgrind_time_buffer = 10
 
70
        else:
 
71
            self.valgrind_time_buffer = 1
 
72
        self.cmd_prefix = self.system_manager.cmd_prefix
 
73
        self.logging = self.system_manager.logging
 
74
        self.no_secure_file_priv = self.server_manager.no_secure_file_priv
 
75
        self.name = name
 
76
        self.status = 0 # stopped, 1 = running
 
77
        self.tried_start = 0
 
78
        self.failed_test = 0 # was the last test a failure?  our state is suspect
 
79
        self.server_start_timeout = 60 * self.valgrind_time_buffer
 
80
        self.pid = None
 
81
 
 
82
    def initialize_databases(self):
 
83
        """ Call schemawriter to make db.opt files """
 
84
        databases = [ 'test'
 
85
                    , 'mysql'
 
86
                    ]
 
87
        for database in databases:
 
88
            db_path = os.path.join(self.datadir,'local',database,'db.opt')
 
89
            cmd = "%s %s %s" %(self.schemawriter, database, db_path)
 
90
            self.system_manager.execute_cmd(cmd)
 
91
 
 
92
    def process_server_options(self):
 
93
        """Consume the list of options we have been passed.
 
94
           Return a string with them joined
 
95
 
 
96
        """
 
97
        
 
98
        return " ".join(self.server_options)
 
99
 
 
100
    def take_db_snapshot(self):
 
101
        """ Take a snapshot of our vardir for quick restores """
 
102
       
 
103
        self.logging.info("Taking clean db snapshot...")
 
104
        if os.path.exists(self.snapshot_path):
 
105
            # We need to remove an existing path as python shutil
 
106
            # doesn't want an existing target
 
107
            self.system_manager.remove_dir(self.snapshot_path)
 
108
        self.system_manager.copy_dir(self.datadir, self.snapshot_path)
 
109
 
 
110
    def restore_snapshot(self):
 
111
        """ Restore from a stored snapshot """
 
112
        
 
113
        if self.verbose:
 
114
            self.logging.verbose("Restoring from db snapshot")
 
115
        if not os.path.exists(self.snapshot_path):
 
116
            self.logging.error("Could not find snapshot: %s" %(self.snapshot_path))
 
117
        self.system_manager.remove_dir(self.datadir)
 
118
        self.system_manager.copy_dir(self.snapshot_path, self.datadir)
 
119
 
 
120
    def is_started(self):
 
121
        """ Is the server running?  Particulars are server-dependent """
 
122
 
 
123
        return
 
124
 
 
125
    def get_start_cmd(self):
 
126
        """ Return the command the server_manager can use to start me """
 
127
 
 
128
        return "Allakazam!"
 
129
 
 
130
    def get_stop_cmd(self):
 
131
        """ Return the command the server_manager can use to stop me """
 
132
 
 
133
        return "Whoa, Nelly!"
 
134
 
 
135
    def get_ping_cmd(self):
 
136
        """ Return the command that can be used to 'ping' me 
 
137
            Very similar to is_started, but different
 
138
 
 
139
            Determining if a server is still running (ping)
 
140
            may differ from the method used to determine
 
141
            server startup
 
142
 
 
143
        """
 
144
   
 
145
        return "Hello?"
 
146
 
 
147
    def cleanup(self):
 
148
        """ Cleanup - just free ports for now..."""
 
149
        self.system_manager.port_manager.free_ports(self.port_block)
 
150
 
 
151
    def set_server_options(self, server_options):
 
152
        """ We update our server_options to the new set """
 
153
        self.server_options = server_options
 
154
 
 
155
    def reset(self):
 
156
        """ Voodoo to reset ourselves """
 
157
        self.failed_test = 0