~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/buildmaster/model/builder.py

[rs=buildbot-poller] automatic merge from stable. Revisions: 14373,
        14374, 14375, 14376 included.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import os
19
19
import socket
20
20
import tempfile
21
 
import transaction
22
21
import xmlrpclib
23
22
 
24
23
from lazr.restful.utils import safe_hasattr
34
33
    Count,
35
34
    Sum,
36
35
    )
 
36
import transaction
37
37
from twisted.internet import (
38
38
    defer,
39
39
    reactor as default_reactor,
78
78
from lp.registry.interfaces.person import validate_public_person
79
79
from lp.services.job.interfaces.job import JobStatus
80
80
from lp.services.job.model.job import Job
81
 
from lp.services.propertycache import cachedproperty
 
81
from lp.services.propertycache import (
 
82
    cachedproperty,
 
83
    get_property_cache,
 
84
    )
 
85
from lp.services.twistedsupport import cancel_on_timeout
82
86
from lp.services.twistedsupport.processmonitor import ProcessWithTimeout
83
 
from lp.services.twistedsupport import cancel_on_timeout
84
87
# XXX Michael Nelson 2010-01-13 bug=491330
85
88
# These dependencies on soyuz will be removed when getBuildRecords()
86
89
# is moved.
526
529
 
527
530
        return d.addCallback(got_resume_ok).addErrback(got_resume_bad)
528
531
 
 
532
    _testing_slave = None
 
533
 
529
534
    @cachedproperty
530
535
    def slave(self):
531
536
        """See IBuilder."""
532
 
        # A cached attribute is used to allow tests to replace
533
 
        # the slave object, which is usually an XMLRPC client, with a
534
 
        # stub object that removes the need to actually create a buildd
535
 
        # slave in various states - which can be hard to create.
 
537
        # When testing it's possible to substitute the slave object, which is
 
538
        # usually an XMLRPC client, with a stub object that removes the need
 
539
        # to actually create a buildd slave in various states - which can be
 
540
        # hard to create. We cannot use the property cache because it is
 
541
        # cleared on transaction boundaries, hence the low tech approach.
 
542
        if self._testing_slave is not None:
 
543
            return self._testing_slave
536
544
        return BuilderSlave.makeBuilderSlave(self.url, self.vm_host)
537
545
 
538
546
    def setSlaveForTesting(self, proxy):
539
547
        """See IBuilder."""
540
 
        self.slave = proxy
 
548
        self._testing_slave = proxy
 
549
        del get_property_cache(self).slave
541
550
 
542
551
    def startBuild(self, build_queue_item, logger):
543
552
        """See IBuilder."""