~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2010-08-18 07:25:22 UTC
  • mto: This revision was merged to the branch mainline in revision 5383.
  • Revision ID: mbp@sourcefrog.net-20100818072522-uk3gsazoia3l3s0a
Start adding 'what's new in 2.3'

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2010 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
20
20
 
21
21
from bzrlib import (
22
22
    bzrdir,
23
 
    controldir,
24
 
    lockable_files,
25
 
    ui,
 
23
    repository,
 
24
    transport,
26
25
    )
27
26
from bzrlib.tests import (
28
27
    features,
 
28
    TestCaseInTempDir,
29
29
    TestCaseWithTransport,
30
30
    )
31
31
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)
 
32
from bzrlib.repofmt.knitrepo import (
 
33
    RepositoryFormatKnit1,
 
34
    )
66
35
 
67
36
 
68
37
class TestWithUpgradableBranches(TestCaseWithTransport):
69
38
 
70
39
    def setUp(self):
71
40
        super(TestWithUpgradableBranches, self).setUp()
 
41
        self.addCleanup(bzrdir.BzrDirFormat._set_default_format,
 
42
                        bzrdir.BzrDirFormat.get_default_format())
72
43
 
73
44
    def make_current_format_branch_and_checkout(self):
74
45
        current_tree = self.make_branch_and_tree('current_format_branch',
76
47
        current_tree.branch.create_checkout(
77
48
            self.get_url('current_format_checkout'), lightweight=True)
78
49
 
 
50
    def make_format_5_branch(self):
 
51
        # setup a format 5 branch we can upgrade from.
 
52
        self.make_branch_and_tree('format_5_branch',
 
53
                                  format=bzrdir.BzrDirFormat5())
 
54
 
 
55
    def make_metadir_weave_branch(self):
 
56
        self.make_branch_and_tree('metadir_weave_branch', format='metaweave')
 
57
 
79
58
    def test_readonly_url_error(self):
80
 
        self.make_branch_and_tree("old_format_branch", format="knit")
 
59
        self.make_format_5_branch()
81
60
        (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)
 
61
            ['upgrade', self.get_readonly_url('format_5_branch')], retcode=3)
 
62
        self.assertEqual(out, "")
 
63
        self.assertEqual(err, "bzr: ERROR: Upgrade URL cannot work with readonly URLs.\n")
87
64
 
88
65
    def test_upgrade_up_to_date(self):
89
66
        self.make_current_format_branch_and_checkout()
90
67
        # when up to date we should get a message to that effect
91
68
        (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)
 
69
        self.assertEqual("", out)
 
70
        self.assertEqualDiff("bzr: ERROR: The branch format Meta "
 
71
                             "directory format 1 is already at the most "
 
72
                             "recent format.\n", err)
97
73
 
98
74
    def test_upgrade_up_to_date_checkout_warns_branch_left_alone(self):
99
75
        self.make_current_format_branch_and_checkout()
100
76
        # when upgrading a checkout, the branch location and a suggestion
101
77
        # to upgrade it should be emitted even if the checkout is up to
102
78
        # date
103
 
        burl = self.get_transport('current_format_branch').base
104
 
        curl = self.get_transport('current_format_checkout').base
105
79
        (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)
 
80
        self.assertEqual("This is a checkout. The branch (%s) needs to be "
 
81
                         "upgraded separately.\n"
 
82
                         % transport.get_transport(
 
83
                self.get_url('current_format_branch')).base,
 
84
                         out)
 
85
        self.assertEqualDiff("bzr: ERROR: The branch format Meta "
 
86
                             "directory format 1 is already at the most "
 
87
                             "recent format.\n", err)
116
88
 
117
89
    def test_upgrade_checkout(self):
118
90
        # upgrading a checkout should work
123
95
        # anonymous branch
124
96
        pass
125
97
 
126
 
    def test_upgrade_branch_in_repo(self):
 
98
    def test_ugrade_branch_in_repo(self):
127
99
        # upgrading a branch in a repo should warn about not upgrading the repo
128
100
        pass
129
101
 
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
 
102
    def test_upgrade_explicit_metaformat(self):
 
103
        # users can force an upgrade to metadir format.
 
104
        self.make_format_5_branch()
 
105
        url = transport.get_transport(self.get_url('format_5_branch')).base
143
106
        # check --format takes effect
144
 
        controldir.ControlDirFormat._set_default_format(old_format)
 
107
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
145
108
        backup_dir = 'backup.bzr.~1~'
146
109
        (out, err) = self.run_bzr(
147
 
            ['upgrade', '--format=2a', url])
148
 
        self.assertEqualDiff("""Upgrading branch %s ...
149
 
starting upgrade of %s
 
110
            ['upgrade', '--format=metaweave', url])
 
111
        self.assertEqualDiff("""starting upgrade of %s
150
112
making backup of %s.bzr
151
113
  to %s%s
152
 
starting upgrade from old test format to 2a
 
114
starting upgrade from format 5 to 6
 
115
adding prefixes to weaves
 
116
adding prefixes to revision-store
 
117
starting upgrade from format 6 to metadir
153
118
finished
154
 
""" % (url, url, url, url, backup_dir), out)
 
119
""" % (url, url, url, backup_dir), out)
155
120
        self.assertEqualDiff("", err)
156
121
        self.assertTrue(isinstance(
157
 
            bzrdir.BzrDir.open(self.get_url(path))._format,
 
122
            bzrdir.BzrDir.open(self.get_url('format_5_branch'))._format,
158
123
            bzrdir.BzrDirMetaFormat1))
159
124
 
160
125
    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
 
126
        # users can force an upgrade to knit format from a metadir weave
 
127
        # branch
 
128
        self.make_metadir_weave_branch()
 
129
        url = transport.get_transport(self.get_url('metadir_weave_branch')).base
165
130
        # check --format takes effect
 
131
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
166
132
        backup_dir = 'backup.bzr.~1~'
167
133
        (out, err) = self.run_bzr(
168
 
            ['upgrade', '--format=pack-0.92', url])
169
 
        self.assertEqualDiff("""Upgrading branch %s ...
170
 
starting upgrade of %s
 
134
            ['upgrade', '--format=knit', url])
 
135
        self.assertEqualDiff("""starting upgrade of %s
171
136
making backup of %s.bzr
172
137
  to %s%s
173
138
starting repository conversion
174
139
repository converted
175
140
finished
176
 
""" % (url, url, url, url, backup_dir),
177
 
                             out)
 
141
""" % (url, url, url, backup_dir), out)
178
142
        self.assertEqualDiff("", err)
179
 
        converted_dir = bzrdir.BzrDir.open(self.get_url('branch'))
 
143
        converted_dir = bzrdir.BzrDir.open(self.get_url('metadir_weave_branch'))
180
144
        self.assertTrue(isinstance(converted_dir._format,
181
145
                                   bzrdir.BzrDirMetaFormat1))
182
146
        self.assertTrue(isinstance(converted_dir.open_repository()._format,
183
 
                                   RepositoryFormatKnitPack1))
 
147
                                   RepositoryFormatKnit1))
184
148
 
185
149
    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')
 
150
        self.run_bzr('init-repository --format=metaweave repo')
 
151
        self.run_bzr('upgrade --format=knit repo')
211
152
 
212
153
    def test_upgrade_permission_check(self):
213
154
        """'backup.bzr' should retain permissions of .bzr. Bug #262450"""
220
161
        new_perms = os.stat(backup_dir).st_mode & 0777
221
162
        self.assertTrue(new_perms == old_perms)
222
163
 
 
164
 
223
165
    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")
 
166
        self.make_format_5_branch()
 
167
        t = transport.get_transport(self.get_url('format_5_branch'))
226
168
        url = t.base
 
169
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
227
170
        backup_dir1 = 'backup.bzr.~1~'
228
171
        backup_dir2 = 'backup.bzr.~2~'
229
172
        # explicitly create backup_dir1. bzr should create the .~2~ directory
230
173
        # as backup
231
174
        t.mkdir(backup_dir1)
232
175
        (out, err) = self.run_bzr(
233
 
            ['upgrade', '--format=2a', url])
234
 
        self.assertEqualDiff("""Upgrading branch %s ...
235
 
starting upgrade of %s
 
176
            ['upgrade', '--format=metaweave', url])
 
177
        self.assertEqualDiff("""starting upgrade of %s
236
178
making backup of %s.bzr
237
179
  to %s%s
238
 
starting repository conversion
239
 
repository converted
 
180
starting upgrade from format 5 to 6
 
181
adding prefixes to weaves
 
182
adding prefixes to revision-store
 
183
starting upgrade from format 6 to metadir
240
184
finished
241
 
""" % (url, url, url, url, backup_dir2), out)
 
185
""" % (url, url, url, backup_dir2), out)
242
186
        self.assertEqualDiff("", err)
243
187
        self.assertTrue(isinstance(
244
 
            bzrdir.BzrDir.open(self.get_url("old_format_branch"))._format,
 
188
            bzrdir.BzrDir.open(self.get_url('format_5_branch'))._format,
245
189
            bzrdir.BzrDirMetaFormat1))
246
190
        self.assertTrue(t.has(backup_dir2))
247
191
 
248
 
 
249
192
class SFTPTests(TestCaseWithSFTPServer):
250
193
    """Tests for upgrade over sftp."""
251
194
 
252
195
    def test_upgrade_url(self):
253
 
        self.run_bzr('init --format=pack-0.92')
254
 
        t = self.get_transport()
 
196
        self.run_bzr('init --format=weave')
 
197
        t = transport.get_transport(self.get_url())
255
198
        url = t.base
256
 
        out, err = self.run_bzr(['upgrade', '--format=2a', url])
 
199
        out, err = self.run_bzr(['upgrade', '--format=knit', url])
257
200
        backup_dir = 'backup.bzr.~1~'
258
 
        self.assertEqualDiff("""Upgrading branch %s ...
259
 
starting upgrade of %s
 
201
        self.assertEqualDiff("""starting upgrade of %s
260
202
making backup of %s.bzr
261
203
  to %s%s
 
204
starting upgrade from format 6 to metadir
262
205
starting repository conversion
263
206
repository converted
264
207
finished
265
 
""" % (url, url, url, url,backup_dir), out)
 
208
""" % (url, url, url,backup_dir), out)
266
209
        self.assertEqual('', err)
267
210
 
268
211