def test_cancelling_a_build(self):
        # When scanning an in-progress build, if its state is CANCELLING
        # then the build should be aborted, and eventually stopped and moved
        # to the CANCELLED state if it does not abort by itself.

        # Set up a mock building slave.
        slave = BuildingSlave()

        # Set the sample data builder building with the slave from above.
        builder = getUtility(IBuilderSet)[BOB_THE_BUILDER_NAME]
        login('*****@*****.**')
        builder.builderok = True
        # For now, we can only cancel virtual builds.
        builder.virtualized = True
        builder.vm_host = "fake_vm_host"
        self.patch(BuilderSlave, 'makeBuilderSlave', FakeMethod(slave))
        transaction.commit()
        login(ANONYMOUS)
        buildqueue = builder.currentjob
        behavior = IBuildFarmJobBehavior(buildqueue.specific_job)
        slave.build_id = behavior.getBuildCookie()
        self.assertBuildingJob(buildqueue, builder)

        # Now set the build to CANCELLING.
        build = getUtility(IBinaryPackageBuildSet).getByQueueEntry(buildqueue)
        build.updateStatus(BuildStatus.CANCELLING)

        # Run 'scan' and check its results.
        switch_dbuser(config.builddmaster.dbuser)
        clock = task.Clock()
        scanner = self._getScanner(clock=clock)
        yield scanner.scan()

        # An abort request should be sent.
        self.assertEqual(1, slave.call_log.count("abort"))
        self.assertEqual(BuildStatus.CANCELLING, build.status)

        # Advance time a little.  Nothing much should happen.
        clock.advance(1)
        yield scanner.scan()
        self.assertEqual(1, slave.call_log.count("abort"))
        self.assertEqual(BuildStatus.CANCELLING, build.status)

        # Advance past the timeout.  The build state should be cancelled and
        # we should have also called the resume() method on the slave that
        # resets the virtual machine.
        clock.advance(SlaveScanner.CANCEL_TIMEOUT)
        yield scanner.scan()
        self.assertEqual(1, slave.call_log.count("abort"))
        self.assertEqual(1, slave.call_log.count("resume"))
        self.assertEqual(BuildStatus.CANCELLED, build.status)
    def test_cancelling_a_build(self):
        # When scanning an in-progress build, if its state is CANCELLING
        # then the build should be aborted, and eventually stopped and moved
        # to the CANCELLED state if it does not abort by itself.

        # Set up a mock building slave.
        slave = BuildingSlave()

        # Set the sample data builder building with the slave from above.
        builder = getUtility(IBuilderSet)[BOB_THE_BUILDER_NAME]
        login('*****@*****.**')
        builder.builderok = True
        # For now, we can only cancel virtual builds.
        builder.virtualized = True
        builder.vm_host = "fake_vm_host"
        self.patch(BuilderSlave, 'makeBuilderSlave', FakeMethod(slave))
        transaction.commit()
        login(ANONYMOUS)
        buildqueue = builder.currentjob
        behavior = IBuildFarmJobBehavior(buildqueue.specific_job)
        slave.build_id = behavior.getBuildCookie()
        self.assertBuildingJob(buildqueue, builder)

        # Now set the build to CANCELLING.
        build = getUtility(IBinaryPackageBuildSet).getByQueueEntry(buildqueue)
        build.updateStatus(BuildStatus.CANCELLING)

        # Run 'scan' and check its results.
        switch_dbuser(config.builddmaster.dbuser)
        clock = task.Clock()
        scanner = self._getScanner(clock=clock)
        yield scanner.scan()

        # An abort request should be sent.
        self.assertEqual(1, slave.call_log.count("abort"))
        self.assertEqual(BuildStatus.CANCELLING, build.status)

        # Advance time a little.  Nothing much should happen.
        clock.advance(1)
        yield scanner.scan()
        self.assertEqual(1, slave.call_log.count("abort"))
        self.assertEqual(BuildStatus.CANCELLING, build.status)

        # Advance past the timeout.  The build state should be cancelled and
        # we should have also called the resume() method on the slave that
        # resets the virtual machine.
        clock.advance(SlaveScanner.CANCEL_TIMEOUT)
        yield scanner.scan()
        self.assertEqual(1, slave.call_log.count("abort"))
        self.assertEqual(1, slave.call_log.count("resume"))
        self.assertEqual(BuildStatus.CANCELLED, build.status)
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.behavior = IBuildFarmJobBehavior(
            self.build.buildqueue_record.specific_job)

    def test_getUploadDirLeafCookie_parseable(self):
        # getUploadDirLeaf should return a directory name
        # that is parseable by the upload processor.
        upload_leaf = self.behavior.getUploadDirLeaf(
            self.behavior.getBuildCookie())
        (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))
Example #4
0
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.behavior = IBuildFarmJobBehavior(
            self.build.buildqueue_record.specific_job)

    def test_getUploadDirLeafCookie_parseable(self):
        # getUploadDirLeaf should return a directory name
        # that is parseable by the upload processor.
        upload_leaf = self.behavior.getUploadDirLeaf(
            self.behavior.getBuildCookie())
        (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))