← Back to team overview

launchpad-reviewers team mailing list archive

lp:~allenap/launchpad/translation-templates-build-behaviour-ro-crash-bug-905855 into lp:launchpad

 

Gavin Panella has proposed merging lp:~allenap/launchpad/translation-templates-build-behaviour-ro-crash-bug-905855 into lp:launchpad with lp:~allenap/launchpad/handle-status-ro-crash-bug-905853 as a prerequisite.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #905855 in Launchpad itself: "TranslationTemplatesBuildBehaviour.updateBuild_WAITING writes in a read-only transaction"
  https://bugs.launchpad.net/launchpad/+bug/905855

For more details, see:
https://code.launchpad.net/~allenap/launchpad/translation-templates-build-behaviour-ro-crash-bug-905855/+merge/86425

This gets TestTranslationTemplatesBuildBehavior to use
BuilddManagerTestFixture introduced in the dependency branch. Doing
this broke a lot, and the rest of the branch is work to get things
working again.

-- 
https://code.launchpad.net/~allenap/launchpad/translation-templates-build-behaviour-ro-crash-bug-905855/+merge/86425
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/launchpad/translation-templates-build-behaviour-ro-crash-bug-905855 into lp:launchpad.
=== modified file 'lib/lp/translations/model/translationtemplatesbuildbehavior.py'
--- lib/lp/translations/model/translationtemplatesbuildbehavior.py	2011-12-20 16:21:02 +0000
+++ lib/lp/translations/model/translationtemplatesbuildbehavior.py	2011-12-20 16:21:02 +0000
@@ -62,8 +62,12 @@
 
             filemap = {}
 
-            return self._builder.slave.build(
-                cookie, self.build_type, chroot_sha1, filemap, args)
+            with DatabaseTransactionPolicy(read_only=False):
+                d = self._builder.slave.build(
+                    cookie, self.build_type, chroot_sha1, filemap, args)
+                transaction.commit()
+
+            return d
         return d.addCallback(got_cache_file)
 
     def _getChroot(self):
@@ -176,7 +180,9 @@
             # dangerous.
             if filename is None:
                 logger.error("Build produced no tarball.")
-                self.setBuildStatus(BuildStatus.FULLYBUILT)
+                with DatabaseTransactionPolicy(read_only=False):
+                    self.setBuildStatus(BuildStatus.FULLYBUILT)
+                    transaction.commit()
                 return
 
             tarball_file = open(filename)
@@ -186,17 +192,24 @@
                     logger.error("Build produced empty tarball.")
                 else:
                     logger.debug("Uploading translation templates tarball.")
-                    self._uploadTarball(
-                        queue_item.specific_job.branch, tarball, logger)
+                    with DatabaseTransactionPolicy(read_only=False):
+                        self._uploadTarball(
+                            queue_item.specific_job.branch, tarball, logger)
+                        transaction.commit()
                     logger.debug("Upload complete.")
             finally:
-                self.setBuildStatus(BuildStatus.FULLYBUILT)
+                transaction.abort()
+                with DatabaseTransactionPolicy(read_only=False):
+                    self.setBuildStatus(BuildStatus.FULLYBUILT)
+                    transaction.commit()
                 tarball_file.close()
                 os.remove(filename)
 
         def build_info_stored(ignored):
             if build_status == 'OK':
-                self.setBuildStatus(BuildStatus.UPLOADING)
+                with DatabaseTransactionPolicy(read_only=False):
+                    self.setBuildStatus(BuildStatus.UPLOADING)
+                    transaction.commit()
                 logger.debug("Processing successful templates build.")
                 filemap = slave_status.get('filemap')
                 d = self._readTarball(queue_item, filemap, logger)
@@ -204,7 +217,10 @@
                 d.addCallback(clean_slave)
                 return d
 
-            self.setBuildStatus(BuildStatus.FAILEDTOBUILD)
+            with DatabaseTransactionPolicy(read_only=False):
+                self.setBuildStatus(BuildStatus.FAILEDTOBUILD)
+                transaction.commit()
+
             return clean_slave(None)
 
         d = self.storeBuildInfo(self, queue_item, build_status)

=== modified file 'lib/lp/translations/tests/test_translationtemplatesbuildbehavior.py'
--- lib/lp/translations/tests/test_translationtemplatesbuildbehavior.py	2011-12-19 23:38:16 +0000
+++ lib/lp/translations/tests/test_translationtemplatesbuildbehavior.py	2011-12-20 16:21:02 +0000
@@ -1,4 +1,4 @@
-# Copyright 2010 Canonical Ltd.  This software is licensed under the
+# Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Unit tests for TranslationTemplatesBuildBehavior."""
@@ -24,6 +24,7 @@
     IBuildFarmJobBehavior,
     )
 from lp.buildmaster.interfaces.buildqueue import IBuildQueueSet
+from lp.buildmaster.testing import BuilddManagerTestFixture
 from lp.buildmaster.tests.mock_slaves import (
     SlaveTestHelpers,
     WaitingSlave,
@@ -73,26 +74,29 @@
         Anything that might communicate with build slaves and such
         (which we can't really do here) is mocked up.
         """
-        specific_job = self.factory.makeTranslationTemplatesBuildJob(
-            branch=branch)
-        behavior = IBuildFarmJobBehavior(specific_job)
-        slave = WaitingSlave()
-        behavior._builder = removeSecurityProxy(self.factory.makeBuilder())
-        behavior._builder.setSlaveForTesting(slave)
-        if use_fake_chroot:
-            lf = self.factory.makeLibraryFileAlias()
-            self.layer.txn.commit()
-            behavior._getChroot = lambda: lf
-        return behavior
+        with BuilddManagerTestFixture.extraSetUp():
+            specific_job = self.factory.makeTranslationTemplatesBuildJob(
+                branch=branch)
+            behavior = IBuildFarmJobBehavior(specific_job)
+            slave = WaitingSlave()
+            behavior._builder = removeSecurityProxy(
+                self.factory.makeBuilder())
+            behavior._builder.setSlaveForTesting(slave)
+            if use_fake_chroot:
+                lf = self.factory.makeLibraryFileAlias()
+                self.layer.txn.commit()
+                behavior._getChroot = lambda: lf
+            return behavior
 
     def makeProductSeriesWithBranchForTranslation(self):
-        productseries = self.factory.makeProductSeries()
-        branch = self.factory.makeProductBranch(
-            productseries.product)
-        productseries.branch = branch
-        productseries.translations_autoimport_mode = (
-            TranslationsBranchImportMode.IMPORT_TEMPLATES)
-        return productseries
+        with BuilddManagerTestFixture.extraSetUp():
+            productseries = self.factory.makeProductSeries()
+            branch = self.factory.makeProductBranch(
+                productseries.product)
+            productseries.branch = branch
+            productseries.translations_autoimport_mode = (
+                TranslationsBranchImportMode.IMPORT_TEMPLATES)
+            return productseries
 
 
 class TestTranslationTemplatesBuildBehavior(
@@ -105,6 +109,7 @@
     def setUp(self):
         super(TestTranslationTemplatesBuildBehavior, self).setUp()
         self.slave_helper = self.useFixture(SlaveTestHelpers())
+        self.useFixture(BuilddManagerTestFixture())
 
     def _becomeBuilddMaster(self):
         """Log into the database as the buildd master."""
@@ -145,13 +150,13 @@
         # _getChroot produces the current chroot for the current Ubuntu
         # release, on the nominated architecture for
         # architecture-independent builds.
-        ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
-        current_ubuntu = ubuntu.currentseries
-        distroarchseries = current_ubuntu.nominatedarchindep
-
-        # Set an arbitrary chroot file.
-        fake_chroot_file = getUtility(ILibraryFileAliasSet)[1]
-        distroarchseries.addOrUpdateChroot(fake_chroot_file)
+        with BuilddManagerTestFixture.extraSetUp():
+            ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
+            current_ubuntu = ubuntu.currentseries
+            distroarchseries = current_ubuntu.nominatedarchindep
+            # Set an arbitrary chroot file.
+            fake_chroot_file = getUtility(ILibraryFileAliasSet)[1]
+            distroarchseries.addOrUpdateChroot(fake_chroot_file)
 
         behavior = self.makeBehavior(use_fake_chroot=False)
         chroot = behavior._getChroot()
@@ -180,10 +185,11 @@
 
     def test_updateBuild_WAITING_OK(self):
         # Hopefully, a build will succeed and produce a tarball.
-        behavior = self.makeBehavior()
-        behavior._uploadTarball = FakeMethod()
-        queue_item = FakeBuildQueue(behavior)
-        builder = behavior._builder
+        with BuilddManagerTestFixture.extraSetUp():
+            behavior = self.makeBehavior()
+            behavior._uploadTarball = FakeMethod()
+            queue_item = FakeBuildQueue(behavior)
+            builder = behavior._builder
 
         d = behavior.dispatchBuildToSlave(queue_item, logging)
 
@@ -221,10 +227,12 @@
 
     def test_updateBuild_WAITING_failed(self):
         # Builds may also fail (and produce no tarball).
-        behavior = self.makeBehavior()
-        behavior._uploadTarball = FakeMethod()
-        queue_item = FakeBuildQueue(behavior)
-        builder = behavior._builder
+        with BuilddManagerTestFixture.extraSetUp():
+            behavior = self.makeBehavior()
+            behavior._uploadTarball = FakeMethod()
+            queue_item = FakeBuildQueue(behavior)
+            builder = behavior._builder
+
         d = behavior.dispatchBuildToSlave(queue_item, logging)
 
         def got_dispatch((status, info)):
@@ -264,10 +272,12 @@
     def test_updateBuild_WAITING_notarball(self):
         # Even if the build status is "OK," absence of a tarball will
         # not faze the Behavior class.
-        behavior = self.makeBehavior()
-        behavior._uploadTarball = FakeMethod()
-        queue_item = FakeBuildQueue(behavior)
-        builder = behavior._builder
+        with BuilddManagerTestFixture.extraSetUp():
+            behavior = self.makeBehavior()
+            behavior._uploadTarball = FakeMethod()
+            queue_item = FakeBuildQueue(behavior)
+            builder = behavior._builder
+
         d = behavior.dispatchBuildToSlave(queue_item, logging)
 
         def got_dispatch((status, info)):
@@ -301,11 +311,12 @@
         return d
 
     def test_updateBuild_WAITING_uploads(self):
-        productseries = self.makeProductSeriesWithBranchForTranslation()
-        branch = productseries.branch
-        behavior = self.makeBehavior(branch=branch)
-        queue_item = FakeBuildQueue(behavior)
-        builder = behavior._builder
+        with BuilddManagerTestFixture.extraSetUp():
+            productseries = self.makeProductSeriesWithBranchForTranslation()
+            branch = productseries.branch
+            behavior = self.makeBehavior(branch=branch)
+            queue_item = FakeBuildQueue(behavior)
+            builder = behavior._builder
 
         d = behavior.dispatchBuildToSlave(queue_item, logging)