launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #15032
[Merge] lp:~wgrant/launchpad/ttb-refactor-create into lp:launchpad
William Grant has proposed merging lp:~wgrant/launchpad/ttb-refactor-create into lp:launchpad.
Commit message:
TranslationTemplatesBuild.create now makes the underlying BuildFarmJob itself.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~wgrant/launchpad/ttb-refactor-create/+merge/145305
Encapsulate TranslationTemplatesBuild BuildFarmJob creation in TTB.create() like the other BFJ implementations.
--
https://code.launchpad.net/~wgrant/launchpad/ttb-refactor-create/+merge/145305
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/ttb-refactor-create into lp:launchpad.
=== modified file 'lib/lp/soyuz/browser/tests/test_builder_views.py'
--- lib/lp/soyuz/browser/tests/test_builder_views.py 2013-01-23 06:54:49 +0000
+++ lib/lp/soyuz/browser/tests/test_builder_views.py 2013-01-29 04:51:22 +0000
@@ -87,12 +87,8 @@
layer = LaunchpadFunctionalLayer
def createTranslationTemplateBuild(self):
- build_farm_job_source = getUtility(IBuildFarmJobSource)
- build_farm_job = build_farm_job_source.new(
- BuildFarmJobType.TRANSLATIONTEMPLATESBUILD)
- source = getUtility(ITranslationTemplatesBuildSource)
branch = self.factory.makeBranch()
- return source.create(build_farm_job, branch)
+ return getUtility(ITranslationTemplatesBuildSource).create(branch)
def createSourcePackageRecipeBuild(self):
sprb = self.factory.makeSourcePackageRecipeBuild()
@@ -172,12 +168,8 @@
def createTranslationTemplateBuildWithBuilder(self, builder=None):
if builder is None:
builder = self.factory.makeBuilder()
- build_farm_job_source = getUtility(IBuildFarmJobSource)
- build_farm_job = build_farm_job_source.new(
- BuildFarmJobType.TRANSLATIONTEMPLATESBUILD)
- source = getUtility(ITranslationTemplatesBuildSource)
branch = self.factory.makeBranch()
- build = source.create(build_farm_job, branch)
+ build = getUtility(ITranslationTemplatesBuildSource).create(branch)
self.markAsBuilt(build, builder)
return build
=== modified file 'lib/lp/translations/browser/tests/test_translationtemplatesbuild.py'
--- lib/lp/translations/browser/tests/test_translationtemplatesbuild.py 2013-01-23 10:16:18 +0000
+++ lib/lp/translations/browser/tests/test_translationtemplatesbuild.py 2013-01-29 04:51:22 +0000
@@ -11,11 +11,7 @@
from zope.component import getUtility
from zope.security.proxy import removeSecurityProxy
-from lp.buildmaster.enums import (
- BuildFarmJobType,
- BuildStatus,
- )
-from lp.buildmaster.interfaces.buildfarmjob import IBuildFarmJobSource
+from lp.buildmaster.enums import BuildStatus
from lp.services.webapp.servers import LaunchpadTestRequest
from lp.testing import TestCaseWithFactory
from lp.testing.layers import DatabaseFunctionalLayer
@@ -43,10 +39,7 @@
"""Create a `TranslationTemplatesBuild`."""
if branch is None:
branch = self.factory.makeBranch()
- job = getUtility(IBuildFarmJobSource).new(
- BuildFarmJobType.TRANSLATIONTEMPLATESBUILD)
- return getUtility(ITranslationTemplatesBuildSource).create(
- job, branch)
+ return getUtility(ITranslationTemplatesBuildSource).create(branch)
def _makeView(self, build=None):
"""Create a view for testing."""
=== modified file 'lib/lp/translations/model/translationtemplatesbuild.py'
--- lib/lp/translations/model/translationtemplatesbuild.py 2013-01-04 12:21:05 +0000
+++ lib/lp/translations/model/translationtemplatesbuild.py 2013-01-29 04:51:22 +0000
@@ -13,11 +13,15 @@
Reference,
Storm,
)
+from zope.component import getUtility
from zope.interface import (
classProvides,
implements,
)
+from lp.app.interfaces.launchpad import ILaunchpadCelebrities
+from lp.buildmaster.enums import BuildFarmJobType
+from lp.buildmaster.interfaces.buildfarmjob import IBuildFarmJobSource
from lp.buildmaster.model.buildfarmjob import (
BuildFarmJobDerived,
BuildFarmJobMixin,
@@ -88,8 +92,21 @@
return store
@classmethod
- def create(cls, build_farm_job, branch):
+ def _getBuildArch(cls):
+ """Returns an `IProcessor` to queue a translation build for."""
+ ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
+ # A round-about way of hard-coding i386.
+ return ubuntu.currentseries.nominatedarchindep.default_processor
+
+ @classmethod
+ def create(cls, branch):
"""See `ITranslationTemplatesBuildSource`."""
+ # XXX Danilo Segan bug=580429: we hard-code processor to the Ubuntu
+ # default processor architecture. This stops the buildfarm from
+ # accidentally dispatching the jobs to private builders.
+ build_farm_job = getUtility(IBuildFarmJobSource).new(
+ BuildFarmJobType.TRANSLATIONTEMPLATESBUILD,
+ processor=cls._getBuildArch())
build = TranslationTemplatesBuild(build_farm_job, branch)
store = cls._getStore()
store.add(build)
=== modified file 'lib/lp/translations/model/translationtemplatesbuildjob.py'
--- lib/lp/translations/model/translationtemplatesbuildjob.py 2013-01-22 06:42:23 +0000
+++ lib/lp/translations/model/translationtemplatesbuildjob.py 2013-01-29 04:51:22 +0000
@@ -19,10 +19,8 @@
)
from zope.security.proxy import removeSecurityProxy
-from lp.app.interfaces.launchpad import ILaunchpadCelebrities
from lp.buildmaster.enums import BuildFarmJobType
from lp.buildmaster.interfaces.buildfarmbranchjob import IBuildFarmBranchJob
-from lp.buildmaster.interfaces.buildfarmjob import IBuildFarmJobSource
from lp.buildmaster.interfaces.buildqueue import IBuildQueueSet
from lp.buildmaster.model.buildfarmjob import BuildFarmJobOld
from lp.buildmaster.model.buildqueue import BuildQueue
@@ -143,18 +141,10 @@
def create(cls, branch, testing=False):
"""See `ITranslationTemplatesBuildJobSource`."""
logger = logging.getLogger('translation-templates-build')
- # XXX Danilo Segan bug=580429: we hard-code processor to the Ubuntu
- # default processor architecture. This stops the buildfarm from
- # accidentally dispatching the jobs to private builders.
- processor = cls._getBuildArch()
- build_farm_job = getUtility(IBuildFarmJobSource).new(
- BuildFarmJobType.TRANSLATIONTEMPLATESBUILD, processor=processor)
build = getUtility(ITranslationTemplatesBuildSource).create(
- build_farm_job, branch)
- logger.debug(
- "Made BuildFarmJob %s, TranslationTemplatesBuild %s.",
- build_farm_job.id, build.id)
+ branch)
+ logger.debug("Made TranslationTemplatesBuild %s.", build.id)
specific_job = build.makeJob()
if testing:
@@ -166,7 +156,7 @@
build_queue_entry = BuildQueue(
estimated_duration=duration_estimate,
job_type=BuildFarmJobType.TRANSLATIONTEMPLATESBUILD,
- job=specific_job.job, processor=processor)
+ job=specific_job.job, processor=build.processor)
IMasterStore(BuildQueue).add(build_queue_entry)
logger.debug("Made BuildQueue %s.", build_queue_entry.id)
@@ -174,13 +164,6 @@
return specific_job
@classmethod
- def _getBuildArch(cls):
- """Returns an `IProcessor` to queue a translation build for."""
- ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
- # A round-about way of hard-coding i386.
- return ubuntu.currentseries.nominatedarchindep.default_processor
-
- @classmethod
def scheduleTranslationTemplatesBuild(cls, branch):
"""See `ITranslationTemplatesBuildJobSource`."""
logger = logging.getLogger('translation-templates-build')
=== modified file 'lib/lp/translations/tests/test_translationtemplatesbuild.py'
--- lib/lp/translations/tests/test_translationtemplatesbuild.py 2013-01-07 07:53:54 +0000
+++ lib/lp/translations/tests/test_translationtemplatesbuild.py 2013-01-29 04:51:22 +0000
@@ -9,11 +9,7 @@
from zope.component import getUtility
from zope.interface.verify import verifyObject
-from lp.buildmaster.enums import BuildFarmJobType
-from lp.buildmaster.interfaces.buildfarmjob import (
- IBuildFarmJob,
- IBuildFarmJobSource,
- )
+from lp.buildmaster.interfaces.buildfarmjob import IBuildFarmJob
from lp.services.config import config
from lp.testing import TestCaseWithFactory
from lp.testing.dbuser import switch_dbuser
@@ -34,21 +30,12 @@
layer = LaunchpadZopelessLayer
- def _makeBuildFarmJob(self):
- """Create a `BuildFarmJob` for testing."""
- source = getUtility(IBuildFarmJobSource)
- return source.new(BuildFarmJobType.TRANSLATIONTEMPLATESBUILD)
-
def test_baseline(self):
- source = getUtility(ITranslationTemplatesBuildSource)
branch = self.factory.makeBranch()
- build_farm_job = self._makeBuildFarmJob()
-
- build = source.create(build_farm_job, branch)
+ build = getUtility(ITranslationTemplatesBuildSource).create(branch)
self.assertTrue(verifyObject(ITranslationTemplatesBuild, build))
self.assertTrue(verifyObject(IBuildFarmJob, build))
- self.assertEqual(build_farm_job, build.build_farm_job)
self.assertEqual(branch, build.branch)
def test_permissions(self):
@@ -56,23 +43,19 @@
# the database privileges it needs for that.
branch = self.factory.makeBranch()
switch_dbuser(config.branchscanner.dbuser)
- utility = getUtility(ITranslationTemplatesBuildSource)
- build_farm_job = self._makeBuildFarmJob()
- utility.create(build_farm_job, branch)
+ build = getUtility(ITranslationTemplatesBuildSource).create(branch)
# Writing the new objects to the database violates no access
# restrictions.
- Store.of(build_farm_job).flush()
+ Store.of(build).flush()
def test_created_by_buildjobsource(self):
# ITranslationTemplatesBuildJobSource.create also creates a
# TranslationTemplatesBuild. This utility will become obsolete
# later.
- jobset = getUtility(ITranslationTemplatesBuildJobSource)
source = getUtility(ITranslationTemplatesBuildSource)
branch = self.factory.makeBranch()
-
- jobset.create(branch)
+ source.create(branch)
builds = list(source.findByBranch(branch))
self.assertEqual(1, len(builds))
@@ -80,50 +63,45 @@
def test_findByBranch(self):
source = getUtility(ITranslationTemplatesBuildSource)
- build_farm_job = self._makeBuildFarmJob()
branch = self.factory.makeBranch()
self.assertContentEqual([], source.findByBranch(branch))
- build = source.create(build_farm_job, branch)
+ build = source.create(branch)
by_branch = list(source.findByBranch(branch))
self.assertEqual([build], by_branch)
def test_get(self):
source = getUtility(ITranslationTemplatesBuildSource)
- build_farm_job = self._makeBuildFarmJob()
branch = self.factory.makeBranch()
- build = source.create(build_farm_job, branch)
+ build = source.create(branch)
self.assertEqual(build, source.getByID(build.id))
def test_get_returns_none_if_not_found(self):
source = getUtility(ITranslationTemplatesBuildSource)
- build_farm_job = self._makeBuildFarmJob()
branch = self.factory.makeBranch()
- build = source.create(build_farm_job, branch)
+ build = source.create(branch)
self.assertIs(None, source.getByID(build.id + 999))
def test_getByBuildFarmJob(self):
source = getUtility(ITranslationTemplatesBuildSource)
- build_farm_job = self._makeBuildFarmJob()
branch = self.factory.makeBranch()
- build = source.create(build_farm_job, branch)
+ build = source.create(branch)
- self.assertEqual(build, source.getByBuildFarmJob(build_farm_job))
+ self.assertEqual(build, source.getByBuildFarmJob(build.build_farm_job))
def test_getByBuildFarmJobs(self):
source = getUtility(ITranslationTemplatesBuildSource)
build_farm_jobs = []
builds = []
for i in xrange(10):
- build_farm_job = self._makeBuildFarmJob()
branch = self.factory.makeBranch()
- build = source.create(build_farm_job, branch)
- build_farm_jobs.append(build_farm_job)
+ build = source.create(branch)
builds.append(build)
+ build_farm_jobs.append(build.build_farm_job)
self.assertContentEqual(
builds,
@@ -131,11 +109,10 @@
def test_getByBuildFarmJob_returns_none_if_not_found(self):
source = getUtility(ITranslationTemplatesBuildSource)
- build_farm_job = self._makeBuildFarmJob()
branch = self.factory.makeBranch()
- source.create(build_farm_job, branch)
+ source.create(branch)
- another_job = self._makeBuildFarmJob()
+ another_job = self.factory.makeBinaryPackageBuild().build_farm_job
self.assertIs(
None,
source.getByBuildFarmJob(another_job))