~ubuntu-branches/ubuntu/vivid/drizzle/vivid-proposed

« back to all changes in this revision

Viewing changes to tests/lib/util/randgen_methods.py

  • Committer: Package Import Robot
  • Author(s): Tobias Frost
  • Date: 2013-08-22 20:18:31 UTC
  • mto: (20.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20130822201831-gn3ozsh7o7wmc5tk
Tags: upstream-7.2.3
ImportĀ upstreamĀ versionĀ 7.2.3

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) 2011 Patrick Crews
 
6
#
 
7
#
 
8
# This program is free software; you can redistribute it and/or modify
 
9
# it under the terms of the GNU General Public License as published by
 
10
# the Free Software Foundation; either version 2 of the License, or
 
11
# (at your option) any later version.
 
12
#
 
13
# This program is distributed in the hope that it will be useful,
 
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
# GNU General Public License for more details.
 
17
#
 
18
# You should have received a copy of the GNU General Public License
 
19
# along with this program; if not, write to the Free Software
 
20
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
21
 
 
22
import os
 
23
import subprocess
 
24
 
 
25
def execute_randgen(test_cmd, test_executor, servers, schema='test'):
 
26
    randgen_outfile = os.path.join(test_executor.logdir,'randgen.out')
 
27
    randgen_output = open(randgen_outfile,'w')
 
28
    server_type = test_executor.master_server.type
 
29
    if server_type in ['percona','galera']:
 
30
        # it is mysql for dbd::perl purposes
 
31
        server_type = 'mysql'
 
32
    dsn = "--dsn=dbi:%s:host=127.0.0.1:port=%d:user=root:password="":database=%s" %( server_type
 
33
                                                                                     , servers[0].master_port
 
34
                                                                                     , schema)
 
35
    randgen_cmd = " ".join([test_cmd, dsn])
 
36
    randgen_subproc = subprocess.Popen( randgen_cmd
 
37
                                      , shell=True
 
38
                                      , cwd=test_executor.system_manager.randgen_path
 
39
                                      , env=test_executor.working_environment
 
40
                                      , stdout = randgen_output
 
41
                                      , stderr = subprocess.STDOUT
 
42
                                      )
 
43
    randgen_subproc.wait()
 
44
    retcode = randgen_subproc.returncode     
 
45
    randgen_output.close()
 
46
 
 
47
    randgen_file = open(randgen_outfile,'r')
 
48
    output = ''.join(randgen_file.readlines())
 
49
    randgen_file.close()
 
50
    if retcode == 0:
 
51
        if not test_executor.verbose:
 
52
            output = None
 
53
    return retcode, output
 
54
 
 
55