~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: 2011-07-06 09:22:00 UTC
  • mfrom: (6008 +trunk)
  • mto: (6012.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6013.
  • Revision ID: v.ladeuil+lp@free.fr-20110706092200-7iai2mwzc0sqdsvf
MergingĀ inĀ 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,
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
 
        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
79
    def test_readonly_url_error(self):
59
 
        path = self.make_format_5_branch()
 
80
        self.make_branch_and_tree("old_format_branch", format="knit")
60
81
        (out, err) = self.run_bzr(
61
 
            ['upgrade', self.get_readonly_url(path)], retcode=3)
 
82
            ['upgrade', self.get_readonly_url("old_format_branch")], retcode=3)
62
83
        err_msg = 'Upgrade URL cannot work with readonly URLs.'
63
84
        self.assertEqualDiff('conversion error: %s\nbzr: ERROR: %s\n'
64
85
                             % (err_msg, err_msg),
106
127
        # upgrading a branch in a repo should warn about not upgrading the repo
107
128
        pass
108
129
 
109
 
    def test_upgrade_explicit_metaformat(self):
110
 
        # users can force an upgrade to metadir format.
111
 
        path = self.make_format_5_branch()
 
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)
112
142
        url = self.get_transport(path).base
113
143
        # check --format takes effect
114
 
        controldir.ControlDirFormat._set_default_format(bzrdir.BzrDirFormat5())
 
144
        controldir.ControlDirFormat._set_default_format(old_format)
115
145
        backup_dir = 'backup.bzr.~1~'
116
146
        (out, err) = self.run_bzr(
117
 
            ['upgrade', '--format=metaweave', url])
 
147
            ['upgrade', '--format=2a', url])
118
148
        self.assertEqualDiff("""Upgrading branch %s ...
119
149
starting upgrade of %s
120
150
making backup of %s.bzr
121
151
  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
 
152
starting upgrade from old test format to 2a
126
153
finished
127
154
""" % (url, url, url, url, backup_dir), out)
128
155
        self.assertEqualDiff("", err)
131
158
            bzrdir.BzrDirMetaFormat1))
132
159
 
133
160
    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
 
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
138
165
        # check --format takes effect
139
 
        controldir.ControlDirFormat._set_default_format(bzrdir.BzrDirFormat5())
140
166
        backup_dir = 'backup.bzr.~1~'
141
167
        (out, err) = self.run_bzr(
142
 
            ['upgrade', '--format=knit', url])
 
168
            ['upgrade', '--format=pack-0.92', url])
143
169
        self.assertEqualDiff("""Upgrading branch %s ...
144
170
starting upgrade of %s
145
171
making backup of %s.bzr
150
176
""" % (url, url, url, url, backup_dir),
151
177
                             out)
152
178
        self.assertEqualDiff("", err)
153
 
        converted_dir = bzrdir.BzrDir.open(self.get_url('metadir_weave_branch'))
 
179
        converted_dir = bzrdir.BzrDir.open(self.get_url('branch'))
154
180
        self.assertTrue(isinstance(converted_dir._format,
155
181
                                   bzrdir.BzrDirMetaFormat1))
156
182
        self.assertTrue(isinstance(converted_dir.open_repository()._format,
157
 
                                   RepositoryFormatKnit1))
 
183
                                   RepositoryFormatKnitPack1))
158
184
 
159
185
    def test_upgrade_repo(self):
160
 
        self.run_bzr('init-repository --format=metaweave repo')
161
 
        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')
162
188
 
163
189
    def assertLegalOption(self, option_str):
164
190
        # Confirm that an option is legal. (Lower level tests are
195
221
        self.assertTrue(new_perms == old_perms)
196
222
 
197
223
    def test_upgrade_with_existing_backup_dir(self):
198
 
        path = self.make_format_5_branch()
199
 
        t = self.get_transport(path)
 
224
        self.make_branch_and_tree("old_format_branch", format="knit")
 
225
        t = self.get_transport("old_format_branch")
200
226
        url = t.base
201
 
        controldir.ControlDirFormat._set_default_format(bzrdir.BzrDirFormat5())
202
227
        backup_dir1 = 'backup.bzr.~1~'
203
228
        backup_dir2 = 'backup.bzr.~2~'
204
229
        # explicitly create backup_dir1. bzr should create the .~2~ directory
205
230
        # as backup
206
231
        t.mkdir(backup_dir1)
207
232
        (out, err) = self.run_bzr(
208
 
            ['upgrade', '--format=metaweave', url])
 
233
            ['upgrade', '--format=2a', url])
209
234
        self.assertEqualDiff("""Upgrading branch %s ...
210
235
starting upgrade of %s
211
236
making backup of %s.bzr
212
237
  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
 
238
starting repository conversion
 
239
repository converted
217
240
finished
218
241
""" % (url, url, url, url, backup_dir2), out)
219
242
        self.assertEqualDiff("", err)
220
243
        self.assertTrue(isinstance(
221
 
            bzrdir.BzrDir.open(self.get_url(path))._format,
 
244
            bzrdir.BzrDir.open(self.get_url("old_format_branch"))._format,
222
245
            bzrdir.BzrDirMetaFormat1))
223
246
        self.assertTrue(t.has(backup_dir2))
224
247
 
 
248
 
225
249
class SFTPTests(TestCaseWithSFTPServer):
226
250
    """Tests for upgrade over sftp."""
227
251
 
228
252
    def test_upgrade_url(self):
229
 
        self.run_bzr('init --format=weave')
 
253
        self.run_bzr('init --format=pack-0.92')
230
254
        t = self.get_transport()
231
255
        url = t.base
232
 
        out, err = self.run_bzr(['upgrade', '--format=knit', url])
 
256
        out, err = self.run_bzr(['upgrade', '--format=2a', url])
233
257
        backup_dir = 'backup.bzr.~1~'
234
258
        self.assertEqualDiff("""Upgrading branch %s ...
235
259
starting upgrade of %s
236
260
making backup of %s.bzr
237
261
  to %s%s
238
 
starting upgrade from format 6 to metadir
239
262
starting repository conversion
240
263
repository converted
241
264
finished