/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2009-07-27 06:28:35 UTC
  • mto: This revision was merged to the branch mainline in revision 4587.
  • Revision ID: mbp@sourcefrog.net-20090727062835-o66p8it658tq1sma
Add CountedLock.get_physical_lock_status

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
 
18
19
import os
19
 
import stat
20
20
 
21
 
from breezy import (
22
 
    bzr,
23
 
    controldir,
24
 
    lockable_files,
 
21
from bzrlib import (
 
22
    bzrdir,
 
23
    repository,
25
24
    ui,
26
 
    urlutils,
27
 
    )
28
 
from breezy.bzr import (
29
 
    bzrdir,
30
 
    )
31
 
from breezy.tests import (
32
 
    features,
 
25
    )
 
26
from bzrlib.tests import (
 
27
    TestCaseInTempDir,
33
28
    TestCaseWithTransport,
34
 
    )
35
 
from breezy.tests.test_sftp_transport import TestCaseWithSFTPServer
36
 
from breezy.bzr.knitpack_repo import RepositoryFormatKnitPack1
37
 
 
38
 
 
39
 
class OldBzrDir(bzrdir.BzrDirMeta1):
40
 
    """An test brz dir implementation"""
41
 
 
42
 
    def needs_format_conversion(self, format):
43
 
        return not isinstance(format, self.__class__)
44
 
 
45
 
 
46
 
class ConvertOldTestToMeta(controldir.Converter):
47
 
    """A trivial converter, used for testing."""
48
 
 
49
 
    def convert(self, to_convert, pb):
50
 
        ui.ui_factory.note('starting upgrade from old test format to 2a')
51
 
        to_convert.control_transport.put_bytes(
52
 
            'branch-format',
53
 
            bzrdir.BzrDirMetaFormat1().get_format_string(),
54
 
            mode=to_convert._get_file_mode())
55
 
        return controldir.ControlDir.open(to_convert.user_url)
56
 
 
57
 
 
58
 
class OldBzrDirFormat(bzrdir.BzrDirMetaFormat1):
59
 
 
60
 
    _lock_class = lockable_files.TransportLock
61
 
 
62
 
    def get_converter(self, format=None):
63
 
        return ConvertOldTestToMeta()
64
 
 
65
 
    @classmethod
66
 
    def get_format_string(cls):
67
 
        return b"Ancient Test Format"
68
 
 
69
 
    def _open(self, transport):
70
 
        return OldBzrDir(transport, self)
 
29
    TestUIFactory,
 
30
    )
 
31
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
 
32
from bzrlib.transport import get_transport
 
33
from bzrlib.repofmt.knitrepo import (
 
34
    RepositoryFormatKnit1,
 
35
    )
71
36
 
72
37
 
73
38
class TestWithUpgradableBranches(TestCaseWithTransport):
74
39
 
75
40
    def setUp(self):
76
41
        super(TestWithUpgradableBranches, self).setUp()
77
 
 
78
 
    def make_current_format_branch_and_checkout(self):
 
42
        self.old_format = bzrdir.BzrDirFormat.get_default_format()
 
43
        self.old_ui_factory = ui.ui_factory
 
44
        self.addCleanup(self.restoreDefaults)
 
45
 
 
46
        ui.ui_factory = TestUIFactory()
 
47
        # setup a format 5 branch we can upgrade from.
 
48
        self.make_branch_and_tree('format_5_branch',
 
49
                                  format=bzrdir.BzrDirFormat5())
 
50
 
79
51
        current_tree = self.make_branch_and_tree('current_format_branch',
80
52
                                                 format='default')
 
53
        self.make_branch_and_tree('metadir_weave_branch', format='metaweave')
81
54
        current_tree.branch.create_checkout(
82
55
            self.get_url('current_format_checkout'), lightweight=True)
83
56
 
 
57
    def restoreDefaults(self):
 
58
        ui.ui_factory = self.old_ui_factory
 
59
        bzrdir.BzrDirFormat._set_default_format(self.old_format)
 
60
 
84
61
    def test_readonly_url_error(self):
85
 
        self.make_branch_and_tree("old_format_branch", format="knit")
86
62
        (out, err) = self.run_bzr(
87
 
            ['upgrade', self.get_readonly_url("old_format_branch")], retcode=3)
88
 
        err_msg = 'Upgrade URL cannot work with readonly URLs.'
89
 
        self.assertEqualDiff('conversion error: %s\nbrz: ERROR: %s\n'
90
 
                             % (err_msg, err_msg),
91
 
                             err)
 
63
            ['upgrade', self.get_readonly_url('format_5_branch')], retcode=3)
 
64
        self.assertEqual(out, "")
 
65
        self.assertEqual(err, "bzr: ERROR: Upgrade URL cannot work with readonly URLs.\n")
92
66
 
93
67
    def test_upgrade_up_to_date(self):
94
 
        self.make_current_format_branch_and_checkout()
95
68
        # when up to date we should get a message to that effect
96
 
        burl = self.get_transport('current_format_branch').local_abspath(".")
97
 
        (out, err) = self.run_bzr('upgrade current_format_branch', retcode=0)
98
 
        self.assertEqual(
99
 
            'Upgrading branch %s/ ...\n'
100
 
            'The branch format %s is already at the most recent format.\n'
101
 
            % (burl, 'Meta directory format 1'),
102
 
            out)
 
69
        (out, err) = self.run_bzr('upgrade current_format_branch', retcode=3)
 
70
        self.assertEqual("", out)
 
71
        self.assertEqualDiff("bzr: ERROR: The branch format Meta "
 
72
                             "directory format 1 is already at the most "
 
73
                             "recent format.\n", err)
103
74
 
104
75
    def test_upgrade_up_to_date_checkout_warns_branch_left_alone(self):
105
 
        self.make_current_format_branch_and_checkout()
106
76
        # when upgrading a checkout, the branch location and a suggestion
107
77
        # to upgrade it should be emitted even if the checkout is up to
108
78
        # date
109
 
        burl = self.get_transport('current_format_branch').local_abspath(".")
110
 
        curl = self.get_transport('current_format_checkout').local_abspath(".")
111
 
        (out, err) = self.run_bzr('upgrade current_format_checkout', retcode=0)
112
 
        self.assertEqual(
113
 
            'Upgrading branch %s/ ...\nThis is a checkout.'
114
 
            ' The branch (%s/) needs to be upgraded separately.\n'
115
 
            'The branch format %s is already at the most recent format.\n'
116
 
            % (curl, burl, 'Meta directory format 1'),
117
 
            out)
 
79
        (out, err) = self.run_bzr('upgrade current_format_checkout', retcode=3)
 
80
        self.assertEqual("This is a checkout. The branch (%s) needs to be "
 
81
                         "upgraded separately.\n"
 
82
                         % get_transport(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)
118
87
 
119
88
    def test_upgrade_checkout(self):
120
89
        # upgrading a checkout should work
125
94
        # anonymous branch
126
95
        pass
127
96
 
128
 
    def test_upgrade_branch_in_repo(self):
 
97
    def test_ugrade_branch_in_repo(self):
129
98
        # upgrading a branch in a repo should warn about not upgrading the repo
130
99
        pass
131
100
 
132
 
    def test_upgrade_control_dir(self):
133
 
        old_format = OldBzrDirFormat()
134
 
        self.addCleanup(bzr.BzrProber.formats.remove,
135
 
                        old_format.get_format_string())
136
 
        bzr.BzrProber.formats.register(old_format.get_format_string(),
137
 
                                       old_format)
138
 
        self.addCleanup(controldir.ControlDirFormat._set_default_format,
139
 
                        controldir.ControlDirFormat.get_default_format())
140
 
 
141
 
        # setup an old format branch we can upgrade from.
142
 
        path = 'old_format_branch'
143
 
        self.make_branch_and_tree(path, format=old_format)
144
 
        transport = self.get_transport(path)
145
 
        url = transport.base
146
 
        display_url = transport.local_abspath('.')
 
101
    def test_upgrade_explicit_metaformat(self):
 
102
        # users can force an upgrade to metadir format.
 
103
        url = get_transport(self.get_url('format_5_branch')).base
147
104
        # check --format takes effect
148
 
        controldir.ControlDirFormat._set_default_format(old_format)
149
 
        backup_dir = 'backup.bzr.~1~'
 
105
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
150
106
        (out, err) = self.run_bzr(
151
 
            ['upgrade', '--format=2a', url])
152
 
        self.assertEqualDiff("""Upgrading branch %s/ ...
153
 
starting upgrade of %s/
154
 
making backup of %s/.bzr
155
 
  to %s/%s
156
 
starting upgrade from old test format to 2a
 
107
            ['upgrade', '--format=metaweave', url])
 
108
        self.assertEqualDiff("""starting upgrade of %s
 
109
making backup of %s.bzr
 
110
  to %sbackup.bzr
 
111
starting upgrade from format 5 to 6
 
112
adding prefixes to weaves
 
113
adding prefixes to revision-store
 
114
starting upgrade from format 6 to metadir
157
115
finished
158
 
""" % (display_url, display_url, display_url, display_url, backup_dir), out)
 
116
""" % (url, url, url), out)
159
117
        self.assertEqualDiff("", err)
160
118
        self.assertTrue(isinstance(
161
 
            controldir.ControlDir.open(self.get_url(path))._format,
 
119
            bzrdir.BzrDir.open(self.get_url('format_5_branch'))._format,
162
120
            bzrdir.BzrDirMetaFormat1))
163
121
 
164
122
    def test_upgrade_explicit_knit(self):
165
 
        # users can force an upgrade to knit format from a metadir pack 0.92
166
 
        # branch to a 2a branch.
167
 
        self.make_branch_and_tree('branch', format='knit')
168
 
        transport = self.get_transport('branch')
169
 
        url = transport.base
170
 
        display_url = transport.local_abspath('.')
 
123
        # users can force an upgrade to knit format from a metadir weave
 
124
        # branch
 
125
        url = get_transport(self.get_url('metadir_weave_branch')).base
171
126
        # check --format takes effect
172
 
        backup_dir = 'backup.bzr.~1~'
 
127
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
173
128
        (out, err) = self.run_bzr(
174
 
            ['upgrade', '--format=pack-0.92', url])
175
 
        self.assertEqualDiff("""Upgrading branch %s/ ...
176
 
starting upgrade of %s/
177
 
making backup of %s/.bzr
178
 
  to %s/%s
 
129
            ['upgrade', '--format=knit', url])
 
130
        self.assertEqualDiff("""starting upgrade of %s
 
131
making backup of %s.bzr
 
132
  to %sbackup.bzr
179
133
starting repository conversion
180
134
repository converted
181
135
finished
182
 
""" % (display_url, display_url, display_url, display_url, backup_dir),
183
 
            out)
 
136
""" % (url, url, url), out)
184
137
        self.assertEqualDiff("", err)
185
 
        converted_dir = controldir.ControlDir.open(self.get_url('branch'))
 
138
        converted_dir = bzrdir.BzrDir.open(self.get_url('metadir_weave_branch'))
186
139
        self.assertTrue(isinstance(converted_dir._format,
187
140
                                   bzrdir.BzrDirMetaFormat1))
188
141
        self.assertTrue(isinstance(converted_dir.open_repository()._format,
189
 
                                   RepositoryFormatKnitPack1))
 
142
                                   RepositoryFormatKnit1))
190
143
 
191
144
    def test_upgrade_repo(self):
192
 
        self.run_bzr('init-shared-repository --format=pack-0.92 repo')
193
 
        self.run_bzr('upgrade --format=2a repo')
194
 
 
195
 
    def assertLegalOption(self, option_str):
196
 
        # Confirm that an option is legal. (Lower level tests are
197
 
        # expected to validate the actual functionality.)
198
 
        self.run_bzr('init --format=pack-0.92 branch-foo')
199
 
        self.run_bzr('upgrade --format=2a branch-foo %s' % (option_str,))
200
 
 
201
 
    def assertBranchFormat(self, dir, format):
202
 
        branch = controldir.ControlDir.open_tree_or_branch(self.get_url(dir))[
203
 
            1]
204
 
        branch_format = branch._format
205
 
        meta_format = controldir.format_registry.make_controldir(format)
206
 
        expected_format = meta_format.get_branch_format()
207
 
        self.assertEqual(expected_format, branch_format)
208
 
 
209
 
    def test_upgrade_clean_supported(self):
210
 
        self.assertLegalOption('--clean')
211
 
        self.assertBranchFormat('branch-foo', '2a')
212
 
        backup_bzr_dir = os.path.join("branch-foo", "backup.bzr.~1~")
213
 
        self.assertFalse(os.path.exists(backup_bzr_dir))
214
 
 
215
 
    def test_upgrade_dry_run_supported(self):
216
 
        self.assertLegalOption('--dry-run')
217
 
        self.assertBranchFormat('branch-foo', 'pack-0.92')
218
 
 
219
 
    def test_upgrade_permission_check(self):
220
 
        """'backup.bzr' should retain permissions of .bzr. Bug #262450"""
221
 
        self.requireFeature(features.posix_permissions_feature)
222
 
        old_perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
223
 
        backup_dir = 'backup.bzr.~1~'
224
 
        self.run_bzr('init --format=1.6')
225
 
        os.chmod('.bzr', old_perms)
226
 
        self.run_bzr('upgrade')
227
 
        new_perms = os.stat(backup_dir).st_mode & 0o777
228
 
        self.assertTrue(new_perms == old_perms)
229
 
 
230
 
    def test_upgrade_with_existing_backup_dir(self):
231
 
        self.make_branch_and_tree("old_format_branch", format="knit")
232
 
        t = self.get_transport("old_format_branch")
233
 
        url = t.base
234
 
        display_url = t.local_abspath('.')
235
 
        backup_dir1 = 'backup.bzr.~1~'
236
 
        backup_dir2 = 'backup.bzr.~2~'
237
 
        # explicitly create backup_dir1. brz should create the .~2~ directory
238
 
        # as backup
239
 
        t.mkdir(backup_dir1)
240
 
        (out, err) = self.run_bzr(
241
 
            ['upgrade', '--format=2a', url])
242
 
        self.assertEqualDiff("""Upgrading branch %s/ ...
243
 
starting upgrade of %s/
244
 
making backup of %s/.bzr
245
 
  to %s/%s
246
 
starting repository conversion
247
 
repository converted
248
 
finished
249
 
""" % (display_url, display_url, display_url, display_url, backup_dir2), out)
250
 
        self.assertEqualDiff("", err)
251
 
        self.assertTrue(isinstance(
252
 
            controldir.ControlDir.open(
253
 
                self.get_url("old_format_branch"))._format,
254
 
            bzrdir.BzrDirMetaFormat1))
255
 
        self.assertTrue(t.has(backup_dir2))
 
145
        self.run_bzr('init-repository --format=metaweave repo')
 
146
        self.run_bzr('upgrade --format=knit repo')
256
147
 
257
148
 
258
149
class SFTPTests(TestCaseWithSFTPServer):
259
150
    """Tests for upgrade over sftp."""
260
151
 
 
152
    def setUp(self):
 
153
        super(SFTPTests, self).setUp()
 
154
        self.old_ui_factory = ui.ui_factory
 
155
        self.addCleanup(self.restoreDefaults)
 
156
 
 
157
        ui.ui_factory = TestUIFactory()
 
158
 
 
159
    def restoreDefaults(self):
 
160
        ui.ui_factory = self.old_ui_factory
 
161
 
261
162
    def test_upgrade_url(self):
262
 
        self.run_bzr('init --format=pack-0.92')
263
 
        t = self.get_transport()
 
163
        self.run_bzr('init --format=weave')
 
164
        t = get_transport(self.get_url())
264
165
        url = t.base
265
 
        display_url = urlutils.unescape_for_display(url,
266
 
                                                    'utf-8')
267
 
        out, err = self.run_bzr(['upgrade', '--format=2a', url])
268
 
        backup_dir = 'backup.bzr.~1~'
269
 
        self.assertEqualDiff("""Upgrading branch %s ...
270
 
starting upgrade of %s
 
166
        out, err = self.run_bzr(['upgrade', '--format=knit', url])
 
167
        self.assertEqualDiff("""starting upgrade of %s
271
168
making backup of %s.bzr
272
 
  to %s%s
 
169
  to %sbackup.bzr
 
170
starting upgrade from format 6 to metadir
273
171
starting repository conversion
274
172
repository converted
275
173
finished
276
 
""" % (display_url, display_url, display_url, display_url, backup_dir), out)
 
174
""" % (url, url, url), out)
277
175
        self.assertEqual('', err)
278
176
 
279
177
 
280
 
class UpgradeRecommendedTests(TestCaseWithTransport):
 
178
class UpgradeRecommendedTests(TestCaseInTempDir):
281
179
 
282
180
    def test_recommend_upgrade_wt4(self):
283
181
        # using a deprecated format gives a warning
284
 
        self.run_bzr('init --format=knit a')
 
182
        self.run_bzr('init --knit a')
285
183
        out, err = self.run_bzr('status a')
286
 
        self.assertContainsRe(err, 'brz upgrade .*[/\\\\]a')
 
184
        self.assertContainsRe(err, 'bzr upgrade .*[/\\\\]a')
287
185
 
288
186
    def test_no_upgrade_recommendation_from_bzrdir(self):
289
187
        # we should only get a recommendation to upgrade when we're accessing
290
188
        # the actual workingtree, not when we only open a bzrdir that contains
291
189
        # an old workngtree
292
 
        self.run_bzr('init --format=knit a')
 
190
        self.run_bzr('init --knit a')
293
191
        out, err = self.run_bzr('revno a')
294
192
        if err.find('upgrade') > -1:
295
193
            self.fail("message shouldn't suggest upgrade:\n%s" % err)
296
 
 
297
 
    def test_upgrade_shared_repo(self):
298
 
        repo = self.make_repository('repo', format='2a', shared=True)
299
 
        branch = self.make_branch_and_tree('repo/branch', format="pack-0.92")
300
 
        self.get_transport('repo/branch/.bzr/repository').delete_tree('.')
301
 
        out, err = self.run_bzr(['upgrade'], working_dir='repo/branch')