~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Olaf van der Spek
  • Date: 2011-07-04 19:11:47 UTC
  • mto: This revision was merged to the branch mainline in revision 2367.
  • Revision ID: olafvdspek@gmail.com-20110704191147-s99ojek811zi1fzj
RemoveĀ unusedĀ Name_resolution_context::error_reporter

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
        self.need_reset = False
 
82
 
 
83
    def initialize_databases(self):
 
84
        """ Call schemawriter to make db.opt files """
 
85
        databases = [ 'test'
 
86
                    , 'mysql'
 
87
                    ]
 
88
        for database in databases:
 
89
            db_path = os.path.join(self.datadir,'local',database,'db.opt')
 
90
            cmd = "%s %s %s" %(self.schemawriter, database, db_path)
 
91
            self.system_manager.execute_cmd(cmd)
 
92
 
 
93
    def process_server_options(self):
 
94
        """Consume the list of options we have been passed.
 
95
           Return a string with them joined
 
96
 
 
97
        """
 
98
        
 
99
        return " ".join(self.server_options)
 
100
 
 
101
    def take_db_snapshot(self):
 
102
        """ Take a snapshot of our vardir for quick restores """
 
103
       
 
104
        self.logging.info("Taking clean db snapshot...")
 
105
        if os.path.exists(self.snapshot_path):
 
106
            # We need to remove an existing path as python shutil
 
107
            # doesn't want an existing target
 
108
            self.system_manager.remove_dir(self.snapshot_path)
 
109
        self.system_manager.copy_dir(self.datadir, self.snapshot_path)
 
110
 
 
111
    def restore_snapshot(self):
 
112
        """ Restore from a stored snapshot """
 
113
        
 
114
        if self.verbose:
 
115
            self.logging.verbose("Restoring from db snapshot")
 
116
        if not os.path.exists(self.snapshot_path):
 
117
            self.logging.error("Could not find snapshot: %s" %(self.snapshot_path))
 
118
        self.system_manager.remove_dir(self.datadir)
 
119
        self.system_manager.copy_dir(self.snapshot_path, self.datadir)
 
120
 
 
121
    def is_started(self):
 
122
        """ Is the server running?  Particulars are server-dependent """
 
123
 
 
124
        return
 
125
 
 
126
    def get_start_cmd(self):
 
127
        """ Return the command the server_manager can use to start me """
 
128
 
 
129
        return "Allakazam!"
 
130
 
 
131
    def get_stop_cmd(self):
 
132
        """ Return the command the server_manager can use to stop me """
 
133
 
 
134
        return "Whoa, Nelly!"
 
135
 
 
136
    def get_ping_cmd(self):
 
137
        """ Return the command that can be used to 'ping' me 
 
138
            Very similar to is_started, but different
 
139
 
 
140
            Determining if a server is still running (ping)
 
141
            may differ from the method used to determine
 
142
            server startup
 
143
 
 
144
        """
 
145
   
 
146
        return "Hello?"
 
147
 
 
148
    def cleanup(self):
 
149
        """ Cleanup - just free ports for now..."""
 
150
        self.system_manager.port_manager.free_ports(self.port_block)
 
151
 
 
152
    def set_server_options(self, server_options):
 
153
        """ We update our server_options to the new set """
 
154
        self.server_options = server_options
 
155
 
 
156
    def reset(self):
 
157
        """ Voodoo to reset ourselves """
 
158
        self.failed_test = 0