~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/translations/tests/test_translationtemplatesbuildbehavior.py

[r=allenap, bac, gmb, julian-edwards, wallyworld][bug=905853, 905855,
 906079] In buildmaster,
 always shift into a read-write database transaction access mode before
 updating PackageBuild statuses. Shift into read-write transactions in
 appropriate places in TranslationTemplatesBuildBehavior. Ensure that all
 lp.buildmaster tests to which it is relevant are running with
 BuilddManagerTestFixture.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2010 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
"""Unit tests for TranslationTemplatesBuildBehavior."""
20
20
    IBuildFarmJobBehavior,
21
21
    )
22
22
from lp.buildmaster.interfaces.buildqueue import IBuildQueueSet
 
23
from lp.buildmaster.testing import BuilddManagerTestFixture
23
24
from lp.buildmaster.tests.mock_slaves import (
24
25
    SlaveTestHelpers,
25
26
    WaitingSlave,
73
74
        Anything that might communicate with build slaves and such
74
75
        (which we can't really do here) is mocked up.
75
76
        """
76
 
        specific_job = self.factory.makeTranslationTemplatesBuildJob(
77
 
            branch=branch)
78
 
        behavior = IBuildFarmJobBehavior(specific_job)
79
 
        slave = WaitingSlave()
80
 
        behavior._builder = removeSecurityProxy(self.factory.makeBuilder())
81
 
        behavior._builder.setSlaveForTesting(slave)
82
 
        if use_fake_chroot:
83
 
            lf = self.factory.makeLibraryFileAlias()
84
 
            self.layer.txn.commit()
85
 
            behavior._getChroot = lambda: lf
86
 
        return behavior
 
77
        with BuilddManagerTestFixture.extraSetUp():
 
78
            specific_job = self.factory.makeTranslationTemplatesBuildJob(
 
79
                branch=branch)
 
80
            behavior = IBuildFarmJobBehavior(specific_job)
 
81
            slave = WaitingSlave()
 
82
            behavior._builder = removeSecurityProxy(
 
83
                self.factory.makeBuilder())
 
84
            behavior._builder.setSlaveForTesting(slave)
 
85
            if use_fake_chroot:
 
86
                lf = self.factory.makeLibraryFileAlias()
 
87
                self.layer.txn.commit()
 
88
                behavior._getChroot = lambda: lf
 
89
            return behavior
87
90
 
88
91
    def makeProductSeriesWithBranchForTranslation(self):
89
 
        productseries = self.factory.makeProductSeries()
90
 
        branch = self.factory.makeProductBranch(
91
 
            productseries.product)
92
 
        productseries.branch = branch
93
 
        productseries.translations_autoimport_mode = (
94
 
            TranslationsBranchImportMode.IMPORT_TEMPLATES)
95
 
        return productseries
 
92
        with BuilddManagerTestFixture.extraSetUp():
 
93
            productseries = self.factory.makeProductSeries()
 
94
            branch = self.factory.makeProductBranch(
 
95
                productseries.product)
 
96
            productseries.branch = branch
 
97
            productseries.translations_autoimport_mode = (
 
98
                TranslationsBranchImportMode.IMPORT_TEMPLATES)
 
99
            return productseries
96
100
 
97
101
 
98
102
class TestTranslationTemplatesBuildBehavior(
105
109
    def setUp(self):
106
110
        super(TestTranslationTemplatesBuildBehavior, self).setUp()
107
111
        self.slave_helper = self.useFixture(SlaveTestHelpers())
 
112
        self.useFixture(BuilddManagerTestFixture())
108
113
 
109
114
    def _becomeBuilddMaster(self):
110
115
        """Log into the database as the buildd master."""
145
150
        # _getChroot produces the current chroot for the current Ubuntu
146
151
        # release, on the nominated architecture for
147
152
        # architecture-independent builds.
148
 
        ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
149
 
        current_ubuntu = ubuntu.currentseries
150
 
        distroarchseries = current_ubuntu.nominatedarchindep
151
 
 
152
 
        # Set an arbitrary chroot file.
153
 
        fake_chroot_file = getUtility(ILibraryFileAliasSet)[1]
154
 
        distroarchseries.addOrUpdateChroot(fake_chroot_file)
 
153
        with BuilddManagerTestFixture.extraSetUp():
 
154
            ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
 
155
            current_ubuntu = ubuntu.currentseries
 
156
            distroarchseries = current_ubuntu.nominatedarchindep
 
157
            # Set an arbitrary chroot file.
 
158
            fake_chroot_file = getUtility(ILibraryFileAliasSet)[1]
 
159
            distroarchseries.addOrUpdateChroot(fake_chroot_file)
155
160
 
156
161
        behavior = self.makeBehavior(use_fake_chroot=False)
157
162
        chroot = behavior._getChroot()
180
185
 
181
186
    def test_updateBuild_WAITING_OK(self):
182
187
        # Hopefully, a build will succeed and produce a tarball.
183
 
        behavior = self.makeBehavior()
184
 
        behavior._uploadTarball = FakeMethod()
185
 
        queue_item = FakeBuildQueue(behavior)
186
 
        builder = behavior._builder
 
188
        with BuilddManagerTestFixture.extraSetUp():
 
189
            behavior = self.makeBehavior()
 
190
            behavior._uploadTarball = FakeMethod()
 
191
            queue_item = FakeBuildQueue(behavior)
 
192
            builder = behavior._builder
187
193
 
188
194
        d = behavior.dispatchBuildToSlave(queue_item, logging)
189
195
 
221
227
 
222
228
    def test_updateBuild_WAITING_failed(self):
223
229
        # Builds may also fail (and produce no tarball).
224
 
        behavior = self.makeBehavior()
225
 
        behavior._uploadTarball = FakeMethod()
226
 
        queue_item = FakeBuildQueue(behavior)
227
 
        builder = behavior._builder
 
230
        with BuilddManagerTestFixture.extraSetUp():
 
231
            behavior = self.makeBehavior()
 
232
            behavior._uploadTarball = FakeMethod()
 
233
            queue_item = FakeBuildQueue(behavior)
 
234
            builder = behavior._builder
 
235
 
228
236
        d = behavior.dispatchBuildToSlave(queue_item, logging)
229
237
 
230
238
        def got_dispatch((status, info)):
264
272
    def test_updateBuild_WAITING_notarball(self):
265
273
        # Even if the build status is "OK," absence of a tarball will
266
274
        # not faze the Behavior class.
267
 
        behavior = self.makeBehavior()
268
 
        behavior._uploadTarball = FakeMethod()
269
 
        queue_item = FakeBuildQueue(behavior)
270
 
        builder = behavior._builder
 
275
        with BuilddManagerTestFixture.extraSetUp():
 
276
            behavior = self.makeBehavior()
 
277
            behavior._uploadTarball = FakeMethod()
 
278
            queue_item = FakeBuildQueue(behavior)
 
279
            builder = behavior._builder
 
280
 
271
281
        d = behavior.dispatchBuildToSlave(queue_item, logging)
272
282
 
273
283
        def got_dispatch((status, info)):
301
311
        return d
302
312
 
303
313
    def test_updateBuild_WAITING_uploads(self):
304
 
        productseries = self.makeProductSeriesWithBranchForTranslation()
305
 
        branch = productseries.branch
306
 
        behavior = self.makeBehavior(branch=branch)
307
 
        queue_item = FakeBuildQueue(behavior)
308
 
        builder = behavior._builder
 
314
        with BuilddManagerTestFixture.extraSetUp():
 
315
            productseries = self.makeProductSeriesWithBranchForTranslation()
 
316
            branch = productseries.branch
 
317
            behavior = self.makeBehavior(branch=branch)
 
318
            queue_item = FakeBuildQueue(behavior)
 
319
            builder = behavior._builder
309
320
 
310
321
        d = behavior.dispatchBuildToSlave(queue_item, logging)
311
322