~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/translations/model/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
"""An `IBuildFarmJobBehavior` for `TranslationTemplatesBuildJob`.
16
16
import tempfile
17
17
 
18
18
import pytz
 
19
import transaction
19
20
from twisted.internet import defer
20
21
from zope.component import getUtility
21
22
from zope.interface import implements
28
29
    )
29
30
from lp.buildmaster.model.buildfarmjobbehavior import BuildFarmJobBehaviorBase
30
31
from lp.registry.interfaces.productseries import IProductSeriesSet
 
32
from lp.services.database.transaction_policy import DatabaseTransactionPolicy
31
33
from lp.translations.interfaces.translationimportqueue import (
32
34
    ITranslationImportQueue,
33
35
    )
60
62
 
61
63
            filemap = {}
62
64
 
63
 
            return self._builder.slave.build(
64
 
                cookie, self.build_type, chroot_sha1, filemap, args)
 
65
            with DatabaseTransactionPolicy(read_only=False):
 
66
                d = self._builder.slave.build(
 
67
                    cookie, self.build_type, chroot_sha1, filemap, args)
 
68
                transaction.commit()
 
69
 
 
70
            return d
65
71
        return d.addCallback(got_cache_file)
66
72
 
67
73
    def _getChroot(self):
132
138
    def storeBuildInfo(build, queue_item, build_status):
133
139
        """See `IPackageBuild`."""
134
140
        def got_log(lfa_id):
135
 
            build.build.log = lfa_id
136
 
            build.build.builder = queue_item.builder
137
 
            build.build.date_started = queue_item.date_started
138
 
            # XXX cprov 20060615 bug=120584: Currently buildduration includes
139
 
            # the scanner latency, it should really be asking the slave for
140
 
            # the duration spent building locally.
141
 
            build.build.date_finished = datetime.datetime.now(pytz.UTC)
 
141
            transaction.commit()
 
142
            with DatabaseTransactionPolicy(read_only=False):
 
143
                build.build.log = lfa_id
 
144
                build.build.builder = queue_item.builder
 
145
                build.build.date_started = queue_item.date_started
 
146
                # XXX cprov 20060615 bug=120584: Currently buildduration
 
147
                # includes the scanner latency.  It should really be
 
148
                # asking the slave for the duration spent building locally.
 
149
                build.build.date_finished = datetime.datetime.now(pytz.UTC)
 
150
                transaction.commit()
142
151
 
143
152
        d = build.getLogFromSlave(build, queue_item)
144
153
        return d.addCallback(got_log)
171
180
            # dangerous.
172
181
            if filename is None:
173
182
                logger.error("Build produced no tarball.")
174
 
                self.setBuildStatus(BuildStatus.FULLYBUILT)
 
183
                with DatabaseTransactionPolicy(read_only=False):
 
184
                    self.setBuildStatus(BuildStatus.FULLYBUILT)
 
185
                    transaction.commit()
175
186
                return
176
187
 
177
188
            tarball_file = open(filename)
181
192
                    logger.error("Build produced empty tarball.")
182
193
                else:
183
194
                    logger.debug("Uploading translation templates tarball.")
184
 
                    self._uploadTarball(
185
 
                        queue_item.specific_job.branch, tarball, logger)
 
195
                    with DatabaseTransactionPolicy(read_only=False):
 
196
                        self._uploadTarball(
 
197
                            queue_item.specific_job.branch, tarball, logger)
 
198
                        transaction.commit()
186
199
                    logger.debug("Upload complete.")
187
200
            finally:
188
 
                self.setBuildStatus(BuildStatus.FULLYBUILT)
 
201
                with DatabaseTransactionPolicy(read_only=False):
 
202
                    self.setBuildStatus(BuildStatus.FULLYBUILT)
 
203
                    transaction.commit()
189
204
                tarball_file.close()
190
205
                os.remove(filename)
191
206
 
192
207
        def build_info_stored(ignored):
193
208
            if build_status == 'OK':
194
 
                self.setBuildStatus(BuildStatus.UPLOADING)
 
209
                with DatabaseTransactionPolicy(read_only=False):
 
210
                    self.setBuildStatus(BuildStatus.UPLOADING)
 
211
                    transaction.commit()
195
212
                logger.debug("Processing successful templates build.")
196
213
                filemap = slave_status.get('filemap')
197
214
                d = self._readTarball(queue_item, filemap, logger)
199
216
                d.addCallback(clean_slave)
200
217
                return d
201
218
 
202
 
            self.setBuildStatus(BuildStatus.FAILEDTOBUILD)
 
219
            with DatabaseTransactionPolicy(read_only=False):
 
220
                self.setBuildStatus(BuildStatus.FAILEDTOBUILD)
 
221
                transaction.commit()
 
222
 
203
223
            return clean_slave(None)
204
224
 
205
225
        d = self.storeBuildInfo(self, queue_item, build_status)