~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to tests/lib/sys_mgmt/codeTree.py

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! /usr/bin/env python
2
 
# -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
# -*- mode: python; indent-tabs-mode: nil; -*-
3
3
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
4
#
5
 
# Copyright (C) 2010 Patrick Crews
 
5
# Copyright (C) 2010, 2011 Patrick Crews
6
6
#
7
7
# This program is free software; you can redistribute it and/or modify
8
8
# it under the terms of the GNU General Public License as published by
29
29
"""
30
30
# imports
31
31
import os
 
32
import sys
32
33
 
33
34
 
34
35
class codeTree:
58
59
        self.skip_keys = ['ld_lib_paths']
59
60
        self.debug = variables['debug']
60
61
        self.verbose = variables['verbose']
61
 
        self.basedir = self.system_manager.find_path([os.path.abspath(variables['basedir'])])
 
62
        self.basedir = self.system_manager.find_path([os.path.abspath(variables['basedir'][0])])
62
63
        self.source_dist = os.path.isdir(os.path.join(self.basedir, 'drizzled'))
63
64
        self.builddir = self.system_manager.find_path([os.path.abspath(self.basedir)])
64
65
        self.top_builddir = variables['topbuilddir']
67
68
                                     , os.path.join(self.basedir, 'client')
68
69
                                     , os.path.join(self.basedir, 'bin')])
69
70
        self.srcdir = self.system_manager.find_path([self.basedir])
70
 
        self.suite_paths = [ os.path.join(self.basedir,'plugin')
71
 
                           , os.path.join(self.testdir,'suite')
72
 
                           ]
73
 
 
74
 
 
75
 
        self.drizzleadmin = self.system_manager.find_path([os.path.join(self.clientbindir,
76
 
                                                     'drizzleadmin')])
 
71
        self.suite_paths = variables['suitepaths']
 
72
 
77
73
 
78
74
        self.drizzle_client = self.system_manager.find_path([os.path.join(self.clientbindir,
79
75
                                                     'drizzle')])
109
105
        self.server_compile_os = None
110
106
        self.server_platform = None
111
107
        self.server_compile_comment = None
112
 
        self.type = 'Drizzle'
 
108
        self.type = 'drizzle'
113
109
 
114
110
        self.process_server_version()
115
111
        self.ld_lib_paths = self.get_ld_lib_paths()
116
112
         
117
113
        self.report()
118
114
 
119
 
        if self.debug:
120
 
            self.logging.debug_class(self)
 
115
        self.logging.debug_class(self)
121
116
 
122
117
    def report(self):
123
118
        self.logging.info("Using Drizzle source tree:")
147
142
    def get_ld_lib_paths(self):
148
143
        """ Return a list of paths we want added to LD_LIB variables
149
144
 
150
 
            These are processed later by the system manager, but we want to 
 
145
            These are processed later at the server_manager level, but we want to 
151
146
            specify them here (for a drizzle source tree) and now
152
147
  
153
148
        """
154
149
        ld_lib_paths = []
155
150
        if self.source_dist:
156
151
            ld_lib_paths = [ os.path.join(self.basedir,"libdrizzleclient/.libs/")
 
152
                           #, os.path.join(self.basedir,"libdrizzle-2.0/libdrizzle.libs")
157
153
                           , os.path.join(self.basedir,"libdrizzle/.libs")
 
154
                           , os.path.join(self.basedir,"libdrizzle-2.0/libdrizzle/.libs")
 
155
                           , os.path.join(self.basedir,"libdrizzle-1.0/libdrizzle/.libs")
158
156
                           , os.path.join(self.basedir,"mysys/.libs/")
159
157
                           , os.path.join(self.basedir,"mystrings/.libs/")
160
158
                           , os.path.join(self.basedir,"drizzled/.libs/")
164
162
            ld_lib_paths = [ os.path.join(self.basedir,"lib")]
165
163
        return ld_lib_paths
166
164
 
 
165
class mysqlTree(codeTree):
 
166
    """ What a MySQL code tree should look like to the test-runner
 
167
    
 
168
    """
 
169
 
 
170
    def __init__(self, variables,system_manager):
 
171
        self.system_manager = system_manager
 
172
        self.logging = self.system_manager.logging
 
173
        self.skip_keys = ['ld_lib_paths']
 
174
        self.debug = variables['debug']
 
175
        self.verbose = variables['verbose']
 
176
        self.basedir = self.system_manager.find_path([os.path.abspath(variables['basedir'][0])])
 
177
        self.source_dist = os.path.isdir(os.path.join(self.basedir, 'mysqld'))
 
178
        self.builddir = self.system_manager.find_path([os.path.abspath(self.basedir)])
 
179
        self.top_builddir = variables['topbuilddir']
 
180
        self.testdir = self.system_manager.find_path([os.path.abspath(variables['testdir'])])
 
181
        self.clientbindir = self.system_manager.find_path([os.path.join(self.basedir, 'client_release')
 
182
                                                         , os.path.join(self.basedir, 'client_debug')
 
183
                                                         , os.path.join(self.basedir, 'client')
 
184
                                                         , os.path.join(self.basedir, 'bin')])
 
185
        self.charsetdir = self.system_manager.find_path([os.path.join(self.basedir, 'mysql/charsets')
 
186
                                                       , os.path.join(self.basedir, 'sql/share/charsets')
 
187
                                                       , os.path.join(self.basedir, 'share/charsets')])
 
188
        self.langdir = self.system_manager.find_path([os.path.join(self.basedir, 'share/mysql')
 
189
                                                    , os.path.join(self.basedir, 'sql/share')
 
190
                                                    , os.path.join(self.basedir, 'share')])
 
191
 
 
192
 
 
193
        self.srcdir = self.system_manager.find_path([self.basedir])
 
194
        self.suite_paths = variables['suitepaths']
 
195
 
 
196
        self.mysql_client = self.system_manager.find_path([os.path.join(self.clientbindir,
 
197
                                                           'mysql')])
 
198
 
 
199
        self.mysqldump = self.system_manager.find_path([os.path.join(self.clientbindir,
 
200
                                                        'mysqldump')])
 
201
 
 
202
        self.mysqlimport = self.system_manager.find_path([os.path.join(self.clientbindir,
 
203
                                                          'mysqlimport')])
 
204
 
 
205
        self.mysqladmin = self.system_manager.find_path([os.path.join(self.clientbindir,
 
206
                                                         'mysqladmin')])
 
207
 
 
208
        self.mysql_server = self.system_manager.find_path([ os.path.join(self.basedir, '/sql/mysqld-debug')
 
209
                                                          , os.path.join(self.basedir, '/libexec/mysqld-debug')
 
210
                                                          , os.path.join(self.basedir, '/sbin/mysqld-debug')
 
211
                                                          , os.path.join(self.basedir, '/bin/mysqld-debug')
 
212
                                                          , os.path.join(self.basedir, '/sql/mysqld')
 
213
                                                          , os.path.join(self.basedir, '/libexec/mysqld')
 
214
                                                          , os.path.join(self.basedir, '/sbin/mysqld')
 
215
                                                          , os.path.join(self.basedir, '/bin/mysqld')
 
216
                                                          , os.path.join(self.basedir, '/sql/mysqld-max-nt')
 
217
                                                          , os.path.join(self.basedir, '/libexec/mysqld-max-nt')
 
218
                                                          , os.path.join(self.basedir, '/sbin/mysqld-max-nt')
 
219
                                                          , os.path.join(self.basedir, '/bin/mysqld-max-nt')
 
220
                                                          , os.path.join(self.basedir, '/sql/mysqld-max')
 
221
                                                          , os.path.join(self.basedir, '/libexec/mysqld-max')
 
222
                                                          , os.path.join(self.basedir, '/sbin/mysqld-max')
 
223
                                                          , os.path.join(self.basedir, '/bin/mysqld-max')
 
224
                                                          , os.path.join(self.basedir, '/sql/mysqld-nt')
 
225
                                                          , os.path.join(self.basedir, '/libexec/mysqld-nt')
 
226
                                                          , os.path.join(self.basedir, '/sbin/mysqld-nt')
 
227
                                                          , os.path.join(self.basedir, '/bin/mysqld-nt')
 
228
                                                          ])
 
229
 
 
230
 
 
231
 
 
232
        self.mysqlslap = self.system_manager.find_path([os.path.join(self.clientbindir,
 
233
                                                     'mysqlslap')])
 
234
 
 
235
        self.mysqltest = self.system_manager.find_path([os.path.join(self.clientbindir,
 
236
                                                   'mysqltest')])
 
237
        self.server_version_string = None
 
238
        self.server_executable = None
 
239
        self.server_version = None
 
240
        self.server_compile_os = None
 
241
        self.server_platform = None
 
242
        self.server_compile_comment = None
 
243
        self.type = 'mysql'
 
244
        self.process_server_version()
 
245
        self.ld_lib_paths = self.get_ld_lib_paths()
 
246
        self.bootstrap_path = os.path.join( self.system_manager.workdir
 
247
                                          , 'mysql_bootstrap.sql' )
 
248
        self.generate_bootstrap()
 
249
         
 
250
        self.report()
 
251
 
 
252
        self.logging.debug_class(self)
 
253
 
 
254
    def report(self):
 
255
        self.logging.info("Using mysql source tree:")
 
256
        report_keys = ['basedir'
 
257
                      ,'clientbindir'
 
258
                      ,'testdir'
 
259
                      ,'server_version'
 
260
                      ,'server_compile_os'
 
261
                      ,'server_platform'
 
262
                      ,'server_comment']
 
263
        for key in report_keys:
 
264
            self.logging.info("%s: %s" %(key, vars(self)[key]))
 
265
        
 
266
    def process_server_version(self):
 
267
        """ Get the server version number from the found server executable """
 
268
        (retcode, self.server_version_string) = self.system_manager.execute_cmd(("%s --no-defaults --version" %(self.mysql_server)))
 
269
        # This is a bit bobo, but we're doing it, so nyah
 
270
        # TODO fix this : )
 
271
        self.server_executable, data_string = [data_item.strip() for data_item in self.server_version_string.split('Ver ')]
 
272
        self.server_version, data_string = [data_item.strip() for data_item in data_string.split('for ')]
 
273
        self.server_compile_os, data_string = [data_item.strip() for data_item in data_string.split(' on')]
 
274
        self.server_platform = data_string.split(' ')[0].strip()
 
275
        self.server_comment = data_string.replace(self.server_platform,'').strip()
 
276
 
 
277
    def get_ld_lib_paths(self):
 
278
        """ Return a list of paths we want added to LD_LIB variables
 
279
 
 
280
            These are processed later at the server_manager level, but we want to 
 
281
            specify them here (for a mysql source tree) and now
 
282
  
 
283
        """
 
284
        ld_lib_paths = []
 
285
        if self.source_dist:
 
286
            ld_lib_paths = [ os.path.join(self.basedir,"libmysql/.libs/")
 
287
                           , os.path.join(self.basedir,"libmysql_r/.libs")
 
288
                           , os.path.join(self.basedir,"zlib/.libs")
 
289
                           ]
 
290
        else:
 
291
            ld_lib_paths = [ os.path.join(self.basedir,"lib")
 
292
                           , os.path.join(self.basedir,"lib/mysql")]
 
293
        return ld_lib_paths
 
294
 
 
295
    def generate_bootstrap(self):
 
296
        """ We do the voodoo that we need to in order to create the bootstrap
 
297
            file needed by MySQL
 
298
 
 
299
        """
 
300
        found_new_sql = False
 
301
        # determine if we have a proper area for our sql or if we
 
302
        # use the rigged method from 5.0 / 5.1
 
303
        # first we search various possible locations
 
304
        test_file = "mysql_system_tables.sql"
 
305
        for candidate_dir in [ "mysql"
 
306
                         , "sql/share"
 
307
                         , "share/mysql"
 
308
                                           , "share"
 
309
                         , "scripts"]:
 
310
            candidate_path = os.path.join(self.basedir, candidate_dir, test_file)
 
311
            if os.path.exists(candidate_path):
 
312
                bootstrap_file = open(self.bootstrap_path,'w')
 
313
                bootstrap_file.write("use mysql\n")
 
314
                for sql_file in [ 'mysql_system_tables.sql' #official mysql system tables
 
315
                                , 'mysql_system_tables_data.sql' #initial data for sys tables
 
316
                                , 'mysql_test_data_timezone.sql' # subset of full tz table data for testing
 
317
                                , 'fill_help_tables.sql' # fill help tables populated only w/ src dist(?)
 
318
                                ]:
 
319
                    sql_file_path = os.path.join(self.basedir,candidate_dir,sql_file)
 
320
                    sql_file_handle = open(sql_file_path,'r')
 
321
                    bootstrap_file.write(sql_file_handle.readlines())
 
322
                    sql_file_handle.close()
 
323
                found_new_sql = True
 
324
                break
 
325
        if not found_new_sql:
 
326
            # Install the system db's from init_db.sql
 
327
            # that is in early 5.1 and 5.0 versions of MySQL
 
328
            sql_file_path = os.path.join(self.basedir,'mysql-test/lib/init_db.sql')
 
329
            self.logging.info("Attempting to use bootstrap file - %s" %(sql_file_path))
 
330
            try:
 
331
                in_file = open(sql_file_path,'r')
 
332
                bootstrap_file = open(self.bootstrap_path,'w')
 
333
                bootstrap_file.write(in_file.readlines())
 
334
                in_file.close()
 
335
            except IOError:
 
336
                self.logging.error("Cannot find data for generating bootstrap file")
 
337
                self.logging.error("Cannot proceed without this, system exiting...")
 
338
                sys.exit(1)
 
339
        # Remove anonymous users
 
340
        bootstrap_file.write("DELETE FROM mysql.user where user= '';\n")
 
341
        # Create mtr database
 
342
        bootstrap_file.write("CREATE DATABASE mtr;\n")
 
343
        for sql_file in [ 'mtr_warnings.sql' # help tables + data for warning detection / suppression
 
344
                        , 'mtr_check.sql' # Procs for checking proper restore post-testcase
 
345
                        ]:
 
346
            sql_file_path = os.path.join(self.basedir,'mysql-test/include',sql_file)
 
347
            sql_file_handle = open(sql_file_path,'r')
 
348
            bootstrap_file.write(sql_file_handle.readlines())
 
349
            sql_file_handle.close()
 
350
        bootstrap_file.close()
 
351
        return
 
352
 
 
353
 
 
354
        
 
355
 
 
356
 
167
357