~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin
  • Date: 2011-04-15 21:22:57 UTC
  • mto: This revision was merged to the branch mainline in revision 5797.
  • Revision ID: gzlist@googlemail.com-20110415212257-jgtovwwp4be7egd9
Add release notes

Show diffs side-by-side

added added

removed removed

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