~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2012-02-14 17:22:37 UTC
  • mfrom: (6466 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120214172237-7dv7er3n4uy8d5m4
Merge trunk

Show diffs side-by-side

added added

removed removed

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