~longbow/percona-pam-for-mysql/pamtest_py

« back to all changes in this revision

Viewing changes to percona_tests/xtrabackup_main/xb_log_overwrap_test.py

  • Committer: Patrick Crews
  • Date: 2012-01-05 02:48:07 UTC
  • Revision ID: gleebix@gmail.com-20120105024807-iob2emmrylinos8d
Ported the last of the xtrabackup tests...huzzah \o/

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 time
 
24
import shutil
 
25
import signal
 
26
import subprocess
 
27
 
 
28
from lib.util.mysqlBaseTestCase import mysqlBaseTestCase
 
29
 
 
30
server_requirements = [['--innodb_log_file_size=1M --innodb_thread_concurrency=1']]
 
31
servers = []
 
32
server_manager = None
 
33
test_executor = None
 
34
# we explicitly use the --no-timestamp option
 
35
# here.  We will be using a generic / vanilla backup dir
 
36
backup_path = None
 
37
 
 
38
class basicTest(mysqlBaseTestCase):
 
39
 
 
40
    def setUp(self):
 
41
        master_server = servers[0] # assumption that this is 'master'
 
42
        backup_path = os.path.join(master_server.vardir, 'full_backup')
 
43
        # remove backup paths
 
44
        for del_path in [backup_path]:
 
45
            if os.path.exists(del_path):
 
46
                shutil.rmtree(del_path)
 
47
 
 
48
    def test_xb_log_overwrap(self):
 
49
        self.servers = servers
 
50
        logging = test_executor.logging
 
51
        if servers[0].type not in ['mysql','percona']:
 
52
            return
 
53
        else:
 
54
            innobackupex = test_executor.system_manager.innobackupex_path
 
55
            xtrabackup = test_executor.system_manager.xtrabackup_path
 
56
            master_server = servers[0] # assumption that this is 'master'
 
57
            backup_path = os.path.join(master_server.vardir, 'full_backup')
 
58
            output_path = os.path.join(master_server.vardir, 'innobackupex.out')
 
59
            suspended_file = os.path.join(backup_path, 'xtrabackup_suspended')
 
60
            exec_path = os.path.dirname(innobackupex)
 
61
 
 
62
            # populate our server with a test bed
 
63
            test_cmd = "./gentest.pl --gendata=conf/percona/percona.zz"
 
64
            retcode, output = self.execute_randgen(test_cmd, test_executor, master_server)
 
65
        
 
66
            # take a backup
 
67
            cmd = [ xtrabackup
 
68
                  , "--defaults-file=%s" %master_server.cnf_file
 
69
                  , "--datadir=%s" %master_server.datadir
 
70
                  , "--backup"
 
71
                  , "--target-dir=%s" %backup_path
 
72
                  , "--suspend-at-end"
 
73
                  ]
 
74
            output_file = open(output_path,'w')
 
75
            xtrabackup_subproc = subprocess.Popen( cmd
 
76
                                                 , cwd=exec_path
 
77
                                                 , env=test_executor.working_environment
 
78
                                                 , stdout = output_file
 
79
                                                 , stderr = subprocess.STDOUT 
 
80
                                                 )
 
81
 
 
82
            # Wait for the xtrabackup_suspended file to be created
 
83
            timeout = 30
 
84
            decrement = 1
 
85
            while timeout and not os.path.exists(suspended_file):
 
86
                time.sleep(decrement)
 
87
                timeout -= decrement
 
88
            # Stop the xtrabackup process
 
89
            xtrabackup_subproc.send_signal(signal.SIGSTOP)
 
90
 
 
91
            # Create a large amount of log data
 
92
            for i in range(20):
 
93
                query = "CREATE TABLE tmp%d ENGINE=InnoDB SELECT * FROM DD" %i
 
94
                retcode, result = self.execute_query(query, master_server)
 
95
                self.assertEqual(retcode,0,msg = result)
 
96
            
 
97
            # Resume the xtrabackup process and remove the suspended file
 
98
            xtrabackup_subproc.send_signal(signal.SIGCONT)
 
99
            os.remove(suspended_file)
 
100
 
 
101
            xtrabackup_subproc.wait()
 
102
            output_file.close()
 
103
            output_file = open(output_path,'r')
 
104
            output = ''.join(output_file.readlines())
 
105
            output_file.close()
 
106
            expected_warning = "xtrabackup: error: it looks like InnoDB log has wrapped around before xtrabackup could process all records due to either log copying being too slow, or  log files being too small."
 
107
                    
 
108
            self.assertEqual(xtrabackup_subproc.returncode,1,msg=output)
 
109
            self.assertTrue(expected_warning in output, msg= output)
 
110
 
 
111