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

« back to all changes in this revision

Viewing changes to percona_tests/xtrabackup_main/bug817132_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 sys
 
24
import time
 
25
import shutil
 
26
 
 
27
from lib.util.mysqlBaseTestCase import mysqlBaseTestCase
 
28
 
 
29
server_requirements = [[]]
 
30
servers = []
 
31
server_manager = None
 
32
test_executor = None
 
33
# we explicitly use the --no-timestamp option
 
34
# here.  We will be using a generic / vanilla backup dir
 
35
backup_path = None
 
36
 
 
37
class basicTest(mysqlBaseTestCase):
 
38
        
 
39
    def setUp(self):
 
40
        master_server = servers[0] # assumption that this is 'master'
 
41
        backup_path = os.path.join(master_server.vardir, '_xtrabackup')
 
42
        # remove backup path
 
43
        if os.path.exists(backup_path):
 
44
            shutil.rmtree(backup_path)
 
45
 
 
46
    def test_bug817132(self):
 
47
        """ --copy-back without explicit --ibbackup specification defaults to 'xtrabackup'. """
 
48
        self.servers = servers
 
49
        logging = test_executor.logging
 
50
        if servers[0].type not in ['mysql','percona']:
 
51
            return
 
52
        else:
 
53
            innobackupex = test_executor.system_manager.innobackupex_path
 
54
            xtrabackup = test_executor.system_manager.xtrabackup_path
 
55
            master_server = servers[0] # assumption that this is 'master'
 
56
            backup_path = os.path.join(master_server.vardir, '_xtrabackup')
 
57
            output_path = os.path.join(master_server.vardir, 'innobackupex.out')
 
58
            exec_path = os.path.dirname(innobackupex)
 
59
 
 
60
            # populate our server with a test bed
 
61
            test_cmd = "./gentest.pl --gendata=conf/percona/percona.zz"
 
62
            retcode, output = self.execute_randgen(test_cmd, test_executor, master_server)
 
63
     
 
64
            # take a backup
 
65
            cmd = [ innobackupex
 
66
                  , "--defaults-file=%s" %master_server.cnf_file
 
67
                  , "--parallel=8"
 
68
                  , "--user=root"
 
69
                  , "--port=%d" %master_server.master_port
 
70
                  , "--host=127.0.0.1"
 
71
                  , "--no-timestamp"
 
72
                  , "--ibbackup=%s" %xtrabackup
 
73
                  , backup_path
 
74
                  ]
 
75
            cmd = " ".join(cmd)
 
76
            retcode, output = self.execute_cmd(cmd, output_path, exec_path, True)
 
77
            self.assertTrue(retcode==0,output)
 
78
 
 
79
            # stop the server
 
80
            master_server.stop()
 
81
 
 
82
            # do prepare on backup
 
83
            cmd = [ innobackupex
 
84
                  , "--apply-log"
 
85
                  , "--no-timestamp"
 
86
                  , "--use-memory=500M"
 
87
                  , "--ibbackup=%s" %xtrabackup
 
88
                  , backup_path
 
89
                  ]
 
90
            cmd = " ".join(cmd)
 
91
            retcode, output = self.execute_cmd(cmd, output_path, exec_path, True)
 
92
            self.assertTrue(retcode==0,output)
 
93
 
 
94
            # remove old datadir
 
95
            shutil.rmtree(master_server.datadir)
 
96
            os.mkdir(master_server.datadir)
 
97
 
 
98
            # We add xtrabackup to PATH
 
99
            tmp_path = os.environ['PATH']
 
100
            tmp_path = "%s:%s" %(os.path.dirname(xtrabackup),tmp_path)
 
101
            os.environ['PATH'] = tmp_path
 
102
            
 
103
            # restore from backup
 
104
            cmd = [ innobackupex
 
105
                  , "--defaults-file=%s" %master_server.cnf_file
 
106
                  , "--copy-back"
 
107
                  # We don't use --ibbackup here
 
108
                  #, "--ibbackup=%s" %(xtrabackup)
 
109
                  , "--socket=%s" %master_server.socket_file
 
110
                  , backup_path
 
111
                  ]
 
112
            cmd = " ".join(cmd)
 
113
            retcode, output = self.execute_cmd(cmd, output_path, exec_path, True)
 
114
            self.assertEqual(retcode,0, output)
 
115
 
 
116
            # restart server (and ensure it doesn't crash)
 
117
            master_server.start()
 
118
            self.assertEqual(master_server.status,1, 'Server failed restart from restored datadir...')
 
119
            
 
120
            # Check the server is ok
 
121
            query = "SELECT COUNT(*) FROM test.DD"
 
122
            expected_output = ((100L,),) 
 
123
            retcode, output = self.execute_query(query, master_server)
 
124
            self.assertEqual(output, expected_output, msg = "%s || %s" %(output, expected_output))
 
125
 
 
126
              
 
127
    def tearDown(self):
 
128
            server_manager.reset_servers(test_executor.name)
 
129
 
 
130