~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_upgrade.py

  • Committer: Andrew Bennetts
  • Date: 2010-03-11 04:33:41 UTC
  • mfrom: (4797.33.4 2.1)
  • mto: This revision was merged to the branch mainline in revision 5082.
  • Revision ID: andrew.bennetts@canonical.com-20100311043341-rzdik83fnactjsxs
Merge lp:bzr/2.1, including fixes for #496813, #526211, #526353.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Black box tests for the upgrade ui."""
18
 
import os
19
 
import stat
20
18
 
21
19
from bzrlib import (
22
20
    bzrdir,
23
 
    controldir,
24
 
    lockable_files,
25
 
    ui,
 
21
    repository,
26
22
    )
27
23
from bzrlib.tests import (
28
 
    features,
 
24
    TestCaseInTempDir,
29
25
    TestCaseWithTransport,
30
26
    )
31
27
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
32
 
from bzrlib.repofmt.knitpack_repo import RepositoryFormatKnitPack1
33
 
 
34
 
 
35
 
class OldBzrDir(bzrdir.BzrDirMeta1):
36
 
    """An test bzr dir implementation"""
37
 
 
38
 
    def needs_format_conversion(self, format):
39
 
        return not isinstance(format, self.__class__)
40
 
 
41
 
 
42
 
class ConvertOldTestToMeta(controldir.Converter):
43
 
    """A trivial converter, used for testing."""
44
 
 
45
 
    def convert(self, to_convert, pb):
46
 
        ui.ui_factory.note('starting upgrade from old test format to 2a')
47
 
        to_convert.control_transport.put_bytes(
48
 
            'branch-format',
49
 
            bzrdir.BzrDirMetaFormat1().get_format_string(),
50
 
            mode=to_convert._get_file_mode())
51
 
        return bzrdir.BzrDir.open(to_convert.user_url)
52
 
 
53
 
 
54
 
class OldBzrDirFormat(bzrdir.BzrDirMetaFormat1):
55
 
 
56
 
    _lock_class = lockable_files.TransportLock
57
 
 
58
 
    def get_converter(self, format=None):
59
 
        return ConvertOldTestToMeta()
60
 
 
61
 
    def get_format_string(self):
62
 
        return "Ancient Test Format"
63
 
 
64
 
    def _open(self, transport):
65
 
        return OldBzrDir(transport, self)
 
28
from bzrlib.transport import get_transport
 
29
from bzrlib.repofmt.knitrepo import (
 
30
    RepositoryFormatKnit1,
 
31
    )
66
32
 
67
33
 
68
34
class TestWithUpgradableBranches(TestCaseWithTransport):
69
35
 
70
36
    def setUp(self):
71
37
        super(TestWithUpgradableBranches, self).setUp()
 
38
        self.addCleanup(bzrdir.BzrDirFormat._set_default_format,
 
39
                        bzrdir.BzrDirFormat.get_default_format())
72
40
 
73
41
    def make_current_format_branch_and_checkout(self):
74
42
        current_tree = self.make_branch_and_tree('current_format_branch',
76
44
        current_tree.branch.create_checkout(
77
45
            self.get_url('current_format_checkout'), lightweight=True)
78
46
 
 
47
    def make_format_5_branch(self):
 
48
        # setup a format 5 branch we can upgrade from.
 
49
        self.make_branch_and_tree('format_5_branch',
 
50
                                  format=bzrdir.BzrDirFormat5())
 
51
 
 
52
    def make_metadir_weave_branch(self):
 
53
        self.make_branch_and_tree('metadir_weave_branch', format='metaweave')
 
54
 
79
55
    def test_readonly_url_error(self):
80
 
        self.make_branch_and_tree("old_format_branch", format="knit")
 
56
        self.make_format_5_branch()
81
57
        (out, err) = self.run_bzr(
82
 
            ['upgrade', self.get_readonly_url("old_format_branch")], retcode=3)
83
 
        err_msg = 'Upgrade URL cannot work with readonly URLs.'
84
 
        self.assertEqualDiff('conversion error: %s\nbzr: ERROR: %s\n'
85
 
                             % (err_msg, err_msg),
86
 
                             err)
 
58
            ['upgrade', self.get_readonly_url('format_5_branch')], retcode=3)
 
59
        self.assertEqual(out, "")
 
60
        self.assertEqual(err, "bzr: ERROR: Upgrade URL cannot work with readonly URLs.\n")
87
61
 
88
62
    def test_upgrade_up_to_date(self):
89
63
        self.make_current_format_branch_and_checkout()
90
64
        # when up to date we should get a message to that effect
91
65
        (out, err) = self.run_bzr('upgrade current_format_branch', retcode=3)
92
 
        err_msg = ('The branch format %s is already at the most recent format.'
93
 
                   % ('Meta directory format 1'))
94
 
        self.assertEqualDiff('conversion error: %s\nbzr: ERROR: %s\n'
95
 
                             % (err_msg, err_msg),
96
 
                             err)
 
66
        self.assertEqual("", out)
 
67
        self.assertEqualDiff("bzr: ERROR: The branch format Meta "
 
68
                             "directory format 1 is already at the most "
 
69
                             "recent format.\n", err)
97
70
 
98
71
    def test_upgrade_up_to_date_checkout_warns_branch_left_alone(self):
99
72
        self.make_current_format_branch_and_checkout()
100
73
        # when upgrading a checkout, the branch location and a suggestion
101
74
        # to upgrade it should be emitted even if the checkout is up to
102
75
        # date
103
 
        burl = self.get_transport('current_format_branch').base
104
 
        curl = self.get_transport('current_format_checkout').base
105
76
        (out, err) = self.run_bzr('upgrade current_format_checkout', retcode=3)
106
 
        self.assertEqual(
107
 
            'Upgrading branch %s ...\nThis is a checkout.'
108
 
            ' The branch (%s) needs to be upgraded separately.\n'
109
 
            % (curl, burl),
110
 
            out)
111
 
        msg = 'The branch format %s is already at the most recent format.' % (
112
 
            'Meta directory format 1')
113
 
        self.assertEqualDiff('conversion error: %s\nbzr: ERROR: %s\n'
114
 
                             % (msg, msg),
115
 
                             err)
 
77
        self.assertEqual("This is a checkout. The branch (%s) needs to be "
 
78
                         "upgraded separately.\n"
 
79
                         % get_transport(self.get_url('current_format_branch')).base,
 
80
                         out)
 
81
        self.assertEqualDiff("bzr: ERROR: The branch format Meta "
 
82
                             "directory format 1 is already at the most "
 
83
                             "recent format.\n", err)
116
84
 
117
85
    def test_upgrade_checkout(self):
118
86
        # upgrading a checkout should work
123
91
        # anonymous branch
124
92
        pass
125
93
 
126
 
    def test_upgrade_branch_in_repo(self):
 
94
    def test_ugrade_branch_in_repo(self):
127
95
        # upgrading a branch in a repo should warn about not upgrading the repo
128
96
        pass
129
97
 
130
 
    def test_upgrade_control_dir(self):
131
 
        old_format = OldBzrDirFormat()
132
 
        self.addCleanup(bzrdir.BzrProber.formats.remove,
133
 
            old_format.get_format_string())
134
 
        bzrdir.BzrProber.formats.register(old_format.get_format_string(),
135
 
            old_format)
136
 
        self.addCleanup(controldir.ControlDirFormat._set_default_format,
137
 
                        controldir.ControlDirFormat.get_default_format())
138
 
 
139
 
        # setup an old format branch we can upgrade from.
140
 
        path = 'old_format_branch'
141
 
        self.make_branch_and_tree(path, format=old_format)
142
 
        url = self.get_transport(path).base
 
98
    def test_upgrade_explicit_metaformat(self):
 
99
        # users can force an upgrade to metadir format.
 
100
        self.make_format_5_branch()
 
101
        url = get_transport(self.get_url('format_5_branch')).base
143
102
        # check --format takes effect
144
 
        controldir.ControlDirFormat._set_default_format(old_format)
 
103
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
145
104
        backup_dir = 'backup.bzr.~1~'
146
105
        (out, err) = self.run_bzr(
147
 
            ['upgrade', '--format=2a', url])
148
 
        self.assertEqualDiff("""Upgrading branch %s ...
149
 
starting upgrade of %s
 
106
            ['upgrade', '--format=metaweave', url])
 
107
        self.assertEqualDiff("""starting upgrade of %s
150
108
making backup of %s.bzr
151
109
  to %s%s
152
 
starting upgrade from old test format to 2a
 
110
starting upgrade from format 5 to 6
 
111
adding prefixes to weaves
 
112
adding prefixes to revision-store
 
113
starting upgrade from format 6 to metadir
153
114
finished
154
 
""" % (url, url, url, url, backup_dir), out)
 
115
""" % (url, url, url, backup_dir), out)
155
116
        self.assertEqualDiff("", err)
156
117
        self.assertTrue(isinstance(
157
 
            bzrdir.BzrDir.open(self.get_url(path))._format,
 
118
            bzrdir.BzrDir.open(self.get_url('format_5_branch'))._format,
158
119
            bzrdir.BzrDirMetaFormat1))
159
120
 
160
121
    def test_upgrade_explicit_knit(self):
161
 
        # users can force an upgrade to knit format from a metadir pack 0.92
162
 
        # branch to a 2a branch.
163
 
        self.make_branch_and_tree('branch', format='knit')
164
 
        url = self.get_transport('branch').base
 
122
        # users can force an upgrade to knit format from a metadir weave
 
123
        # branch
 
124
        self.make_metadir_weave_branch()
 
125
        url = get_transport(self.get_url('metadir_weave_branch')).base
165
126
        # check --format takes effect
 
127
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
166
128
        backup_dir = 'backup.bzr.~1~'
167
129
        (out, err) = self.run_bzr(
168
 
            ['upgrade', '--format=pack-0.92', url])
169
 
        self.assertEqualDiff("""Upgrading branch %s ...
170
 
starting upgrade of %s
 
130
            ['upgrade', '--format=knit', url])
 
131
        self.assertEqualDiff("""starting upgrade of %s
171
132
making backup of %s.bzr
172
133
  to %s%s
173
134
starting repository conversion
174
135
repository converted
175
136
finished
176
 
""" % (url, url, url, url, backup_dir),
177
 
                             out)
 
137
""" % (url, url, url, backup_dir), out)
178
138
        self.assertEqualDiff("", err)
179
 
        converted_dir = bzrdir.BzrDir.open(self.get_url('branch'))
 
139
        converted_dir = bzrdir.BzrDir.open(self.get_url('metadir_weave_branch'))
180
140
        self.assertTrue(isinstance(converted_dir._format,
181
141
                                   bzrdir.BzrDirMetaFormat1))
182
142
        self.assertTrue(isinstance(converted_dir.open_repository()._format,
183
 
                                   RepositoryFormatKnitPack1))
 
143
                                   RepositoryFormatKnit1))
184
144
 
185
145
    def test_upgrade_repo(self):
186
 
        self.run_bzr('init-repository --format=pack-0.92 repo')
187
 
        self.run_bzr('upgrade --format=2a repo')
188
 
 
189
 
    def assertLegalOption(self, option_str):
190
 
        # Confirm that an option is legal. (Lower level tests are
191
 
        # expected to validate the actual functionality.)
192
 
        self.run_bzr('init --format=pack-0.92 branch-foo')
193
 
        self.run_bzr('upgrade --format=2a branch-foo %s' % (option_str,))
194
 
 
195
 
    def assertBranchFormat(self, dir, format):
196
 
        branch = bzrdir.BzrDir.open_tree_or_branch(self.get_url(dir))[1]
197
 
        branch_format = branch._format
198
 
        meta_format = bzrdir.format_registry.make_bzrdir(format)
199
 
        expected_format = meta_format.get_branch_format()
200
 
        self.assertEqual(expected_format, branch_format)
201
 
 
202
 
    def test_upgrade_clean_supported(self):
203
 
        self.assertLegalOption('--clean')
204
 
        self.assertBranchFormat('branch-foo', '2a')
205
 
        backup_bzr_dir = os.path.join("branch-foo", "backup.bzr.~1~")
206
 
        self.assertFalse(os.path.exists(backup_bzr_dir))
207
 
 
208
 
    def test_upgrade_dry_run_supported(self):
209
 
        self.assertLegalOption('--dry-run')
210
 
        self.assertBranchFormat('branch-foo', 'pack-0.92')
211
 
 
212
 
    def test_upgrade_permission_check(self):
213
 
        """'backup.bzr' should retain permissions of .bzr. Bug #262450"""
214
 
        self.requireFeature(features.posix_permissions_feature)
215
 
        old_perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
216
 
        backup_dir = 'backup.bzr.~1~'
217
 
        self.run_bzr('init --format=1.6')
218
 
        os.chmod('.bzr', old_perms)
219
 
        self.run_bzr('upgrade')
220
 
        new_perms = os.stat(backup_dir).st_mode & 0777
221
 
        self.assertTrue(new_perms == old_perms)
 
146
        self.run_bzr('init-repository --format=metaweave repo')
 
147
        self.run_bzr('upgrade --format=knit repo')
 
148
 
222
149
 
223
150
    def test_upgrade_with_existing_backup_dir(self):
224
 
        self.make_branch_and_tree("old_format_branch", format="knit")
225
 
        t = self.get_transport("old_format_branch")
226
 
        url = t.base
 
151
        self.make_format_5_branch()
 
152
        transport = get_transport(self.get_url('format_5_branch'))
 
153
        url = transport.base
 
154
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
227
155
        backup_dir1 = 'backup.bzr.~1~'
228
156
        backup_dir2 = 'backup.bzr.~2~'
229
157
        # explicitly create backup_dir1. bzr should create the .~2~ directory
230
158
        # as backup
231
 
        t.mkdir(backup_dir1)
 
159
        transport.mkdir(backup_dir1)
232
160
        (out, err) = self.run_bzr(
233
 
            ['upgrade', '--format=2a', url])
234
 
        self.assertEqualDiff("""Upgrading branch %s ...
235
 
starting upgrade of %s
 
161
            ['upgrade', '--format=metaweave', url])
 
162
        self.assertEqualDiff("""starting upgrade of %s
236
163
making backup of %s.bzr
237
164
  to %s%s
238
 
starting repository conversion
239
 
repository converted
 
165
starting upgrade from format 5 to 6
 
166
adding prefixes to weaves
 
167
adding prefixes to revision-store
 
168
starting upgrade from format 6 to metadir
240
169
finished
241
 
""" % (url, url, url, url, backup_dir2), out)
 
170
""" % (url, url, url, backup_dir2), out)
242
171
        self.assertEqualDiff("", err)
243
172
        self.assertTrue(isinstance(
244
 
            bzrdir.BzrDir.open(self.get_url("old_format_branch"))._format,
 
173
            bzrdir.BzrDir.open(self.get_url('format_5_branch'))._format,
245
174
            bzrdir.BzrDirMetaFormat1))
246
 
        self.assertTrue(t.has(backup_dir2))
247
 
 
 
175
        self.assertTrue(transport.has(backup_dir2))
248
176
 
249
177
class SFTPTests(TestCaseWithSFTPServer):
250
178
    """Tests for upgrade over sftp."""
251
179
 
252
180
    def test_upgrade_url(self):
253
 
        self.run_bzr('init --format=pack-0.92')
254
 
        t = self.get_transport()
 
181
        self.run_bzr('init --format=weave')
 
182
        t = get_transport(self.get_url())
255
183
        url = t.base
256
 
        out, err = self.run_bzr(['upgrade', '--format=2a', url])
 
184
        out, err = self.run_bzr(['upgrade', '--format=knit', url])
257
185
        backup_dir = 'backup.bzr.~1~'
258
 
        self.assertEqualDiff("""Upgrading branch %s ...
259
 
starting upgrade of %s
 
186
        self.assertEqualDiff("""starting upgrade of %s
260
187
making backup of %s.bzr
261
188
  to %s%s
 
189
starting upgrade from format 6 to metadir
262
190
starting repository conversion
263
191
repository converted
264
192
finished
265
 
""" % (url, url, url, url,backup_dir), out)
 
193
""" % (url, url, url,backup_dir), out)
266
194
        self.assertEqual('', err)
267
195
 
268
196