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

« back to all changes in this revision

Viewing changes to percona_tests/xtrabackup_main/bug810269_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 shutil
 
24
import tarfile
 
25
 
 
26
from lib.util.mysqlBaseTestCase import mysqlBaseTestCase
 
27
 
 
28
server_requirements = [["--innodb_strict_mode --innodb_file_per_table --innodb_file_format=Barracuda"]]
 
29
servers = []
 
30
server_manager = None
 
31
test_executor = None
 
32
# we explicitly use the --no-timestamp option
 
33
# here.  We will be using a generic / vanilla backup dir
 
34
backup_path = None
 
35
 
 
36
class basicTest(mysqlBaseTestCase):
 
37
 
 
38
    def setUp(self):
 
39
        master_server = servers[0] # assumption that this is 'master'
 
40
        backup_path = os.path.join(master_server.vardir, '_xtrabackup')
 
41
        # remove backup paths
 
42
        for del_path in [backup_path]:
 
43
            if os.path.exists(del_path):
 
44
                shutil.rmtree(del_path)
 
45
 
 
46
    def load_table(self, table_name, row_count, server):
 
47
        queries = []
 
48
        for i in range(row_count):
 
49
            queries.append("INSERT INTO %s VALUES (%d, %d)" %(table_name,i, row_count))
 
50
        retcode, result = self.execute_queries(queries, server)
 
51
        self.assertEqual(retcode, 0, msg=result)
 
52
 
 
53
    def test_ib_stream(self):
 
54
            """ Bug #665210: tar4ibd does not support innodb row_format=compressed
 
55
                Bug #810269: tar4ibd does not check for doublewrite buffer pages
 
56
            """
 
57
 
 
58
            innobackupex = test_executor.system_manager.innobackupex_path
 
59
            xtrabackup = test_executor.system_manager.xtrabackup_path
 
60
            master_server = servers[0] # assumption that this is 'master'
 
61
            backup_path = os.path.join(master_server.vardir, '_xtrabackup')
 
62
            tar_file_path = os.path.join(backup_path,'out.tar')
 
63
            output_path = os.path.join(master_server.vardir, 'innobackupex.out')
 
64
            exec_path = os.path.dirname(innobackupex)
 
65
            table_name = "t1"
 
66
 
 
67
            # populate our server with a test bed
 
68
            queries = ["DROP TABLE IF EXISTS %s" %(table_name)
 
69
                      ,("CREATE TABLE %s "
 
70
                        "(`a` int(11) DEFAULT NULL, "
 
71
                        "`number` int(11) DEFAULT NULL) "
 
72
                        " ENGINE=InnoDB DEFAULT CHARSET=latin1"
 
73
                        %(table_name)
 
74
                       )
 
75
                       # compress tables 
 
76
                      ,("ALTER TABLE %s ENGINE=InnoDB "
 
77
                        "ROW_FORMAT=compressed KEY_BLOCK_SIZE=4"
 
78
                        %(table_name)
 
79
                       )
 
80
                      ]
 
81
            retcode, result = self.execute_queries(queries, master_server)
 
82
            self.assertEqual(retcode, 0, msg = result) 
 
83
            row_count = 10000
 
84
            self.load_table(table_name, row_count, master_server)
 
85
 
 
86
            # get a checksum that we'll compare against post-restore
 
87
            query = "CHECKSUM TABLE %s" %table_name
 
88
            retcode, orig_checksum = self.execute_query(query, master_server)
 
89
            self.assertEqual(retcode, 0, orig_checksum)
 
90
     
 
91
            # take a backup
 
92
            try:
 
93
                os.mkdir(backup_path)
 
94
            except OSError: 
 
95
                pass
 
96
            cmd = [ innobackupex
 
97
                  , "--defaults-file=%s" %master_server.cnf_file
 
98
                  , "--stream=tar"
 
99
                  , "--user=root"
 
100
                  , "--port=%d" %master_server.master_port
 
101
                  , "--host=127.0.0.1"
 
102
                  , "--no-timestamp"
 
103
                  , "--ibbackup=%s" %xtrabackup
 
104
                  , "%s > %s" %(backup_path,tar_file_path)
 
105
                  ]
 
106
            cmd = " ".join(cmd)
 
107
            retcode, output = self.execute_cmd(cmd, output_path, exec_path, True)
 
108
            self.assertTrue(retcode==0,output)
 
109
 
 
110
            # stop the server
 
111
            master_server.stop()
 
112
 
 
113
            # extract our backup tarball
 
114
            cmd = "tar -ivxf %s" %tar_file_path
 
115
            retcode, output = self.execute_cmd(cmd, output_path, backup_path, True)
 
116
            self.assertEqual(retcode,0,output) 
 
117
            # Check for Bug 723318 - seems quicker than separate test case
 
118
            self.assertTrue('xtrabackup_binary' in os.listdir(backup_path)
 
119
                           , msg = "Bug723318:  xtrabackup_binary not included in tar archive when streaming")
 
120
 
 
121
            # do prepare on backup
 
122
            cmd = [ innobackupex
 
123
                  , "--apply-log"
 
124
                  , "--no-timestamp"
 
125
                  , "--use-memory=500M"
 
126
                  , "--ibbackup=%s" %xtrabackup
 
127
                  , backup_path
 
128
                  ]
 
129
            cmd = " ".join(cmd)
 
130
            retcode, output = self.execute_cmd(cmd, output_path, exec_path, True)
 
131
            self.assertEqual(retcode,0,output)
 
132
 
 
133
            # remove old datadir
 
134
            shutil.rmtree(master_server.datadir)
 
135
            os.mkdir(master_server.datadir)
 
136
        
 
137
            # restore from backup
 
138
            cmd = [ innobackupex
 
139
                  , "--defaults-file=%s" %master_server.cnf_file
 
140
                  , "--copy-back"
 
141
                  , "--ibbackup=%s" %(xtrabackup)
 
142
                  , backup_path
 
143
                  ]
 
144
            cmd = " ".join(cmd)
 
145
            retcode, output = self.execute_cmd(cmd, output_path, exec_path, True)
 
146
            self.assertEqual(retcode,0, output)
 
147
 
 
148
            # restart server (and ensure it doesn't crash)
 
149
            master_server.start()
 
150
            self.assertEqual(master_server.status,1, 'Server failed restart from restored datadir...')
 
151
            
 
152
            # Check the server is ok
 
153
            # get a checksum that we'll compare against pre-restore
 
154
            query = "CHECKSUM TABLE %s" %table_name
 
155
            retcode, restored_checksum = self.execute_query(query, master_server)
 
156
            self.assertEqual(retcode, 0, restored_checksum)
 
157
            self.assertEqual(orig_checksum, restored_checksum, "%s || %s" %(orig_checksum, restored_checksum))
 
158
 
 
159
              
 
160
    def tearDown(self):
 
161
            server_manager.reset_servers(test_executor.name)
 
162