def test_verifySuccessfulBuild_allows_modifiable_suite(self):
     # verifySuccessfulBuild allows uploading to a suite that the archive
     # says is modifiable.
     build = self.makeBuild()
     behaviour = IBuildFarmJobBehaviour(
         build.buildqueue_record.specific_build)
     behaviour.verifySuccessfulBuild()
 def test_dont_dispatch_release_builds(self):
     archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
     builder = self.factory.makeBuilder()
     distroseries = self.factory.makeDistroSeries(
         status=SeriesStatus.CURRENT, distribution=archive.distribution)
     distro_arch_series = self.factory.makeDistroArchSeries(
         distroseries=distroseries)
     build = self.factory.makeBinaryPackageBuild(
         builder=builder,
         archive=archive,
         distroarchseries=distro_arch_series,
         pocket=PackagePublishingPocket.RELEASE)
     lf = self.factory.makeLibraryFileAlias()
     transaction.commit()
     build.distro_arch_series.addOrUpdateChroot(lf)
     behaviour = IBuildFarmJobBehaviour(build)
     behaviour.setBuilder(builder, None)
     e = self.assertRaises(AssertionError, behaviour.verifyBuildRequest,
                           BufferLogger())
     expected_message = (
         "%s (%s) can not be built for pocket %s: invalid pocket due "
         "to the series status of %s." %
         (build.title, build.id, build.pocket.name,
          build.distro_series.name))
     self.assertEqual(expected_message, str(e))
 def makeJob(self,
             archive=None,
             pocket=PackagePublishingPocket.RELEASE,
             with_builder=False,
             **kwargs):
     """Create a sample `ILiveFSBuildBehaviour`."""
     if archive is None:
         distribution = self.factory.makeDistribution(name="distro")
     else:
         distribution = archive.distribution
     distroseries = self.factory.makeDistroSeries(distribution=distribution,
                                                  name="unstable")
     processor = getUtility(IProcessorSet).getByName("386")
     distroarchseries = self.factory.makeDistroArchSeries(
         distroseries=distroseries,
         architecturetag="i386",
         processor=processor)
     build = self.factory.makeLiveFSBuild(archive=archive,
                                          distroarchseries=distroarchseries,
                                          pocket=pocket,
                                          name="test-livefs",
                                          **kwargs)
     job = IBuildFarmJobBehaviour(build)
     if with_builder:
         builder = MockBuilder()
         builder.processor = processor
         job.setBuilder(builder, None)
     return job
예제 #4
0
 def test_verifyBuildRequest_bad_pocket(self):
     # verifyBuildRequest will raise if a bad pocket is proposed.
     build = self.factory.makeSourcePackageRecipeBuild(
         pocket=PackagePublishingPocket.SECURITY)
     job = IBuildFarmJobBehaviour(build)
     job.setBuilder(MockBuilder("bob-de-bouwer"), OkSlave())
     e = self.assertRaises(
         AssertionError, job.verifyBuildRequest, BufferLogger())
     self.assertIn('invalid pocket due to the series status of', str(e))
 def test_verifyBuildRequest_no_chroot(self):
     # Don't dispatch a build when the DAS has no chroot.
     archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
     builder = self.factory.makeBuilder()
     build = self.factory.makeBinaryPackageBuild(builder=builder,
                                                 archive=archive)
     behaviour = IBuildFarmJobBehaviour(build)
     behaviour.setBuilder(builder, None)
     e = self.assertRaises(CannotBuild, behaviour.verifyBuildRequest,
                           BufferLogger())
     self.assertIn("Missing CHROOT", str(e))
 def test_arch_indep(self):
     # BinaryPackageBuild.arch_indep is passed through to the slave.
     builder = self.factory.makeBuilder()
     build = self.factory.makeBinaryPackageBuild(arch_indep=False)
     behaviour = IBuildFarmJobBehaviour(build)
     behaviour.setBuilder(builder, None)
     extra_args = yield behaviour.extraBuildArgs()
     self.assertFalse(extra_args['arch_indep'])
     build = self.factory.makeBinaryPackageBuild(arch_indep=True)
     behaviour = IBuildFarmJobBehaviour(build)
     behaviour.setBuilder(builder, None)
     extra_args = yield behaviour.extraBuildArgs()
     self.assertTrue(extra_args['arch_indep'])
    def makeBehaviour(self, branch=None, use_fake_chroot=True, **kwargs):
        """Create a TranslationTemplatesBuildBehaviour.

        Anything that might communicate with build slaves and such
        (which we can't really do here) is mocked up.
        """
        build = self.factory.makeTranslationTemplatesBuild(branch=branch)
        behaviour = IBuildFarmJobBehaviour(build)
        slave = WaitingSlave(**kwargs)
        behaviour.setBuilder(self.factory.makeBuilder(), slave)
        if use_fake_chroot:
            behaviour.distro_arch_series.addOrUpdateChroot(
                self.factory.makeLibraryFileAlias(db_only=True))
            self.layer.txn.commit()
        return behaviour
    def test_log_file_collection(self):
        self.build.updateStatus(BuildStatus.FULLYBUILT)
        old_tmps = sorted(os.listdir('/tmp'))

        slave = WaitingSlave('BuildStatus.OK')

        def got_log(logfile_lfa_id):
            # Grabbing logs should not leave new files in /tmp (bug #172798)
            logfile_lfa = getUtility(ILibraryFileAliasSet)[logfile_lfa_id]
            new_tmps = sorted(os.listdir('/tmp'))
            self.assertEqual(old_tmps, new_tmps)

            # The new librarian file is stored compressed with a .gz
            # extension and text/plain file type for easy viewing in
            # browsers, as it decompresses and displays the file inline.
            self.assertTrue(
                logfile_lfa.filename.endswith('_FULLYBUILT.txt.gz'))
            self.assertEqual('text/plain', logfile_lfa.mimetype)
            self.layer.txn.commit()

            # LibrarianFileAlias does not implement tell() or seek(), which
            # are required by gzip.open(), so we need to read the file out
            # of the librarian first.
            fd, fname = tempfile.mkstemp()
            self.addCleanup(os.remove, fname)
            tmp = os.fdopen(fd, 'wb')
            tmp.write(logfile_lfa.read())
            tmp.close()
            uncompressed_file = gzip.open(fname).read()

            # Now make a temp filename that getFile() can write to.
            fd, tmp_orig_file_name = tempfile.mkstemp()
            self.addCleanup(os.remove, tmp_orig_file_name)

            # Check that the original file from the slave matches the
            # uncompressed file in the librarian.
            def got_orig_log(ignored):
                orig_file_content = open(tmp_orig_file_name).read()
                self.assertEqual(orig_file_content, uncompressed_file)

            d = removeSecurityProxy(slave).getFile('buildlog',
                                                   tmp_orig_file_name)
            return d.addCallback(got_orig_log)

        behaviour = IBuildFarmJobBehaviour(self.build)
        behaviour.setBuilder(self.builder, slave)
        d = behaviour.getLogFromSlave(self.build.buildqueue_record)
        return d.addCallback(got_log)
예제 #9
0
    def findAndStartJob(cls, vitals, builder, slave):
        """Find a job to run and send it to the buildd slave.

        :return: A Deferred whose value is the `IBuildQueue` instance
            found or None if no job was found.
        """
        logger = cls._getSlaveScannerLogger()
        # XXX This method should be removed in favour of two separately
        # called methods that find and dispatch the job.  It will
        # require a lot of test fixing.
        candidate = builder.acquireBuildCandidate()
        if candidate is None:
            logger.debug("No build candidates available for builder.")
            defer.returnValue(None)

        new_behaviour = cls.getBuildBehaviour(candidate, builder, slave)
        needed_bfjb = type(
            removeSecurityProxy(
                IBuildFarmJobBehaviour(candidate.specific_build)))
        if not zope_isinstance(new_behaviour, needed_bfjb):
            raise AssertionError(
                "Inappropriate IBuildFarmJobBehaviour: %r is not a %r" %
                (new_behaviour, needed_bfjb))
        yield cls._startBuild(candidate, vitals, builder, slave, new_behaviour,
                              logger)
        defer.returnValue(candidate)
 def test_verifySuccessfulBuild_denies_unmodifiable_suite(self):
     # verifySuccessfulBuild refuses to upload to a suite that the
     # archive says is unmodifiable.
     build = self.makeUnmodifiableBuild()
     behaviour = IBuildFarmJobBehaviour(
         build.buildqueue_record.specific_build)
     self.assertRaises(AssertionError, behaviour.verifySuccessfulBuild)
 def test_dont_dispatch_security_builds(self):
     archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
     builder = self.factory.makeBuilder()
     build = self.factory.makeBinaryPackageBuild(
         builder=builder,
         archive=archive,
         pocket=PackagePublishingPocket.SECURITY)
     lf = self.factory.makeLibraryFileAlias()
     transaction.commit()
     build.distro_arch_series.addOrUpdateChroot(lf)
     behaviour = IBuildFarmJobBehaviour(build)
     behaviour.setBuilder(builder, None)
     e = self.assertRaises(AssertionError, behaviour.verifyBuildRequest,
                           BufferLogger())
     self.assertEqual(
         'Soyuz is not yet capable of building SECURITY uploads.', str(e))
 def test_verifyBuildRequest(self):
     # Don't allow a virtual build on a non-virtual builder.
     archive = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
     builder = self.factory.makeBuilder(virtualized=False)
     build = self.factory.makeBinaryPackageBuild(
         builder=builder,
         archive=archive,
         pocket=PackagePublishingPocket.RELEASE)
     lf = self.factory.makeLibraryFileAlias()
     transaction.commit()
     build.distro_arch_series.addOrUpdateChroot(lf)
     behaviour = IBuildFarmJobBehaviour(build)
     behaviour.setBuilder(builder, None)
     e = self.assertRaises(AssertionError, behaviour.verifyBuildRequest,
                           BufferLogger())
     self.assertEqual(
         'Attempt to build virtual archive on a non-virtual builder.',
         str(e))
예제 #13
0
 def makeJob(self, recipe_registrant=None, recipe_owner=None,
             archive=None, git=False, with_builder=False):
     """Create a sample `ISourcePackageRecipeBuild`."""
     spn = self.factory.makeSourcePackageName("apackage")
     if archive is None:
         distro = self.factory.makeDistribution(name="distro")
     else:
         distro = archive.distribution
     distroseries = self.factory.makeDistroSeries(
         name="mydistro", distribution=distro)
     processor = getUtility(IProcessorSet).getByName('386')
     distroseries.nominatedarchindep = distroseries.newArch(
         'i386', processor, True, self.factory.makePerson())
     sourcepackage = self.factory.makeSourcePackage(spn, distroseries)
     if recipe_registrant is None:
         recipe_registrant = self.factory.makePerson(
             email="*****@*****.**",
             name="joe", displayname="Joe User")
     if recipe_owner is None:
         recipe_owner = recipe_registrant
     if git:
         [somebranch] = self.factory.makeGitRefs(
             owner=recipe_owner, name="pkg",
             target=self.factory.makeProduct("someapp"),
             paths=["refs/heads/packaging"])
     else:
         somebranch = self.factory.makeBranch(
             owner=recipe_owner, name="pkg",
             product=self.factory.makeProduct("someapp"))
     recipe = self.factory.makeSourcePackageRecipe(
         recipe_registrant, recipe_owner, distroseries, "recept",
         "Recipe description", branches=[somebranch])
     spb = self.factory.makeSourcePackageRecipeBuild(
         sourcepackage=sourcepackage, archive=archive,
         recipe=recipe, requester=recipe_owner, distroseries=distroseries)
     job = IBuildFarmJobBehaviour(spb)
     if with_builder:
         builder = MockBuilder()
         builder.processor = processor
         job.setBuilder(builder, None)
     return job
 def test_extraBuildArgs_archive_trusted_keys(self):
     # If the archive has a signing key, extraBuildArgs sends it.
     yield self.useFixture(InProcessKeyServerFixture()).start()
     archive = self.factory.makeArchive()
     builder = self.factory.makeBuilder()
     key_path = os.path.join(gpgkeysdir, "*****@*****.**")
     yield IArchiveSigningKey(archive).setSigningKey(key_path,
                                                     async_keyserver=True)
     build = self.factory.makeBinaryPackageBuild(archive=archive)
     self.factory.makeBinaryPackagePublishingHistory(
         distroarchseries=build.distro_arch_series,
         pocket=build.pocket,
         archive=archive,
         status=PackagePublishingStatus.PUBLISHED)
     behaviour = IBuildFarmJobBehaviour(build)
     behaviour.setBuilder(builder, None)
     args = yield behaviour.extraBuildArgs()
     self.assertThat(
         args["trusted_keys"],
         MatchesListwise([
             Base64KeyMatches("0D57E99656BEFB0897606EE9A022DD1F5001B46D"),
         ]))
 def makeJob(self,
             archive=None,
             pocket=PackagePublishingPocket.UPDATES,
             **kwargs):
     """Create a sample `ISnapBuildBehaviour`."""
     if archive is None:
         distribution = self.factory.makeDistribution(name="distro")
     else:
         distribution = archive.distribution
     distroseries = self.factory.makeDistroSeries(distribution=distribution,
                                                  name="unstable")
     processor = getUtility(IProcessorSet).getByName("386")
     distroarchseries = self.factory.makeDistroArchSeries(
         distroseries=distroseries,
         architecturetag="i386",
         processor=processor)
     build = self.factory.makeSnapBuild(archive=archive,
                                        distroarchseries=distroarchseries,
                                        pocket=pocket,
                                        name="test-snap",
                                        **kwargs)
     return IBuildFarmJobBehaviour(build)
class TestGetUploadMethodsMixin:
    """Tests for `IPackageBuild` that need objects from the rest of LP."""

    layer = LaunchpadZopelessLayer

    def makeBuild(self):
        """Allow classes to override the build with which the test runs."""
        raise NotImplemented

    def setUp(self):
        super(TestGetUploadMethodsMixin, self).setUp()
        self.build = self.makeBuild()
        self.behaviour = IBuildFarmJobBehaviour(
            self.build.buildqueue_record.specific_build)

    def test_getUploadDirLeafCookie_parseable(self):
        # getUploadDirLeaf should return a directory name
        # that is parseable by the upload processor.
        upload_leaf = self.behaviour.getUploadDirLeaf(self.build.build_cookie)
        (job_type, job_id) = parse_build_upload_leaf_name(upload_leaf)
        self.assertEqual((self.build.job_type.name, self.build.id),
                         (job_type, job_id))
 def test_adapts_ISnapBuild(self):
     # IBuildFarmJobBehaviour adapts an ISnapBuild.
     build = self.factory.makeSnapBuild()
     job = IBuildFarmJobBehaviour(build)
     self.assertProvides(job, IBuildFarmJobBehaviour)
예제 #18
0
 def getBuildBehaviour(queue_item, builder, slave):
     if queue_item is None:
         return None
     behaviour = IBuildFarmJobBehaviour(queue_item.specific_build)
     behaviour.setBuilder(builder, slave)
     return behaviour
 def setUp(self):
     super(TestGetUploadMethodsMixin, self).setUp()
     self.build = self.makeBuild()
     self.behaviour = IBuildFarmJobBehaviour(
         self.build.buildqueue_record.specific_build)
예제 #20
0
 def test_adapts_ISourcePackageRecipeBuild(self):
     # IBuildFarmJobBehaviour adapts a ISourcePackageRecipeBuild
     build = self.factory.makeSourcePackageRecipeBuild()
     job = IBuildFarmJobBehaviour(build)
     self.assertProvides(job, IBuildFarmJobBehaviour)