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

« back to all changes in this revision

Viewing changes to percona_tests/xtrabackup_main/tar4ibd_symlink_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-file-per-table']]
 
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 test_ib_stream(self):
 
47
            """Tests for tar4ibd + symlinks (bug #387587)"""
 
48
            innobackupex = test_executor.system_manager.innobackupex_path
 
49
            xtrabackup = test_executor.system_manager.xtrabackup_path
 
50
            master_server = servers[0] # assumption that this is 'master'
 
51
            backup_path = os.path.join(master_server.vardir, '_xtrabackup')
 
52
            tar_file_path = os.path.join(backup_path,'out.tar')
 
53
            output_path = os.path.join(master_server.vardir, 'innobackupex.out')
 
54
            exec_path = os.path.dirname(innobackupex)
 
55
 
 
56
            # populate our server with a test bed
 
57
            test_cmd = "./gentest.pl --gendata=conf/percona/percona.zz"
 
58
            retcode, output = self.execute_randgen(test_cmd, test_executor, master_server)
 
59
 
 
60
            # Move some of our .ibd files and make symlinks
 
61
            shutil.move( os.path.join(master_server.datadir,'test/CC.ibd')
 
62
                        , master_server.vardir)
 
63
            os.symlink(os.path.join(master_server.vardir,'CC.ibd')
 
64
                      ,os.path.join(master_server.datadir,'test/CC.ibd'))
 
65
 
 
66
            shutil.move( os.path.join(master_server.datadir,'test/BB.ibd')
 
67
                        , master_server.vardir)
 
68
            os.symlink(os.path.join(master_server.vardir,'BB.ibd')
 
69
                      ,os.path.join(master_server.vardir,'BB_link.ibd'))
 
70
            os.symlink(os.path.join(master_server.vardir,'BB_link.ibd')
 
71
                      ,os.path.join(master_server.datadir,'test/BB.ibd'))
 
72
 
 
73
            # take a backup
 
74
            try:
 
75
                os.mkdir(backup_path)
 
76
            except OSError: 
 
77
                pass
 
78
            cmd = [ innobackupex
 
79
                  , "--defaults-file=%s" %master_server.cnf_file
 
80
                  , "--stream=tar"
 
81
                  , "--user=root"
 
82
                  , "--port=%d" %master_server.master_port
 
83
                  , "--host=127.0.0.1"
 
84
                  , "--no-timestamp"
 
85
                  , "--ibbackup=%s" %xtrabackup
 
86
                  , "%s > %s" %(backup_path,tar_file_path)
 
87
                  ]
 
88
            cmd = " ".join(cmd)
 
89
            retcode, output = self.execute_cmd(cmd, output_path, exec_path, True)
 
90
            self.assertTrue(retcode==0,output)
 
91
 
 
92
            # stop the server
 
93
            master_server.stop()
 
94
 
 
95
            # extract our backup tarball
 
96
            cmd = "tar -ivxf %s" %tar_file_path
 
97
            retcode, output = self.execute_cmd(cmd, output_path, backup_path, True)
 
98
            self.assertEqual(retcode,0,output) 
 
99
            # Check for Bug 723318 - seems quicker than separate test case
 
100
            self.assertTrue('xtrabackup_binary' in os.listdir(backup_path)
 
101
                           , msg = "Bug723318:  xtrabackup_binary not included in tar archive when streaming")
 
102
 
 
103
            # do prepare on backup
 
104
            cmd = [ innobackupex
 
105
                  , "--apply-log"
 
106
                  , "--no-timestamp"
 
107
                  , "--use-memory=500M"
 
108
                  , "--ibbackup=%s" %xtrabackup
 
109
                  , backup_path
 
110
                  ]
 
111
            cmd = " ".join(cmd)
 
112
            retcode, output = self.execute_cmd(cmd, output_path, exec_path, True)
 
113
            self.assertEqual(retcode,0,output)
 
114
 
 
115
            # remove old datadir
 
116
            shutil.rmtree(master_server.datadir)
 
117
            os.mkdir(master_server.datadir)
 
118
 
 
119
            # Remove our symlinks
 
120
            os.remove(os.path.join(master_server.vardir,'CC.ibd'))
 
121
            os.remove(os.path.join(master_server.vardir,'BB.ibd'))
 
122
            os.remove(os.path.join(master_server.vardir,'BB_link.ibd'))
 
123
        
 
124
            # restore from backup
 
125
            cmd = [ innobackupex
 
126
                  , "--defaults-file=%s" %master_server.cnf_file
 
127
                  , "--copy-back"
 
128
                  , "--ibbackup=%s" %(xtrabackup)
 
129
                  , backup_path
 
130
                  ]
 
131
            cmd = " ".join(cmd)
 
132
            retcode, output = self.execute_cmd(cmd, output_path, exec_path, True)
 
133
            self.assertEqual(retcode,0, output)
 
134
 
 
135
            # restart server (and ensure it doesn't crash)
 
136
            master_server.start()
 
137
            self.assertEqual(master_server.status,1, 'Server failed restart from restored datadir...')
 
138
            
 
139
            # Check the server is ok
 
140
            query = "SELECT COUNT(*) FROM test.BB"
 
141
            expected_output = ((10L,),) 
 
142
            retcode, output = self.execute_query(query, master_server)
 
143
            self.assertEqual(output, expected_output, msg = "%s || %s" %(output, expected_output))
 
144
 
 
145
            query = "SELECT COUNT(*) FROM test.CC"
 
146
            expected_output = ((100L,),) 
 
147
            retcode, output = self.execute_query(query, master_server)
 
148
            self.assertEqual(output, expected_output, msg = "%s || %s" %(output, expected_output))
 
149
 
 
150
              
 
151
    def tearDown(self):
 
152
            server_manager.reset_servers(test_executor.name)
 
153