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

« back to all changes in this revision

Viewing changes to tests/kewpie/lib/util/sqlbench_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_sqlbench(test_cmd, test_executor, servers):
26
 
    """ Execute the commandline and return the result.
27
 
        We use subprocess as we can pass os.environ dicts and whatnot 
28
 
 
29
 
    """
30
 
    
31
 
    bot = test_executor
32
 
    sqlbench_outfile = os.path.join(bot.logdir,'sqlbench.out')
33
 
    sqlbench_output = open(sqlbench_outfile,'w')
34
 
    bot.logging.info("Executing sqlbench:  %s" %(test_cmd))
35
 
    bot.logging.info("This may take some time...")
36
 
    sqlbench_subproc = subprocess.Popen( test_cmd
37
 
                                       , shell=True
38
 
                                       , cwd=os.path.join(bot.system_manager.testdir, 'sql-bench')
39
 
                                       , env=bot.working_environment
40
 
                                       , stdout = sqlbench_output
41
 
                                       , stderr = subprocess.STDOUT
42
 
                                       )
43
 
    sqlbench_subproc.wait()
44
 
    retcode = sqlbench_subproc.returncode     
45
 
 
46
 
    sqlbench_output.close()
47
 
    sqlbench_file = open(sqlbench_outfile,'r')
48
 
    output = ''.join(sqlbench_file.readlines())
49
 
    sqlbench_file.close()
50
 
 
51
 
    bot.current_test_retcode = retcode
52
 
    bot.current_test_output = output
53
 
    test_status = process_sqlbench_output(bot)
54
 
    return test_status, retcode, output
55
 
 
56
 
def process_sqlbench_output(bot):
57
 
        
58
 
    # Check for 'Failed' in sql-bench output
59
 
    # The tests don't die on a failed test and
60
 
    # require some checking of the output file
61
 
    error_flag = False
62
 
    for inline in bot.current_test_output:
63
 
        if 'Failed' in inline:
64
 
            error_flag= True
65
 
            logging.info(inline.strip())
66
 
    if bot.current_test_retcode == 0 and not error_flag:
67
 
        return 'pass'
68
 
    else:
69
 
        return 'fail'
70