def test_deferred_is_not_cancelled(self): clock = Clock() d = cancel_on_timeout(defer.succeed("frobnicle"), 1, clock) clock.advance(2) def result(value): self.assertEqual(value, "frobnicle") self.assertEqual([], clock.getDelayedCalls()) return d.addCallback(result)
def _verifyMacaroon(self, macaroon, aliasid): """Verify an LFA-authorising macaroon with the authserver. This must be called in the reactor thread. :param macaroon: A `Macaroon`. :param aliasid: A `LibraryFileAlias` ID. :return: True if the authserver reports that `macaroon` authorises access to `aliasid`; False if it reports that it does not. :raises Fault: if the authserver request fails. """ try: yield cancel_on_timeout( self._authserver.callRemote("verifyMacaroon", macaroon.serialize(), "LibraryFileAlias", aliasid), config.librarian.authentication_timeout) defer.returnValue(True) except Fault as fault: if fault.faultCode == faults.Unauthorized.error_code: defer.returnValue(False) else: raise
def _with_timeout(self, d): return cancel_on_timeout(d, self.timeout, self.reactor)
def test_deferred_is_cancelled(self): clock = Clock() d = cancel_on_timeout(defer.Deferred(), 1, clock) clock.advance(2) return assert_fails_with(d, defer.CancelledError)
def extraBuildArgs(self, logger=None): """ Return the extra arguments required by the slave for the given build. """ build = self.build args = yield super(SnapBuildBehaviour, self).extraBuildArgs( logger=logger) if config.snappy.builder_proxy_host and build.snap.allow_internet: token = yield self._requestProxyToken() args["proxy_url"] = ( "http://{username}:{password}@{host}:{port}".format( username=token['username'], password=token['secret'], host=config.snappy.builder_proxy_host, port=config.snappy.builder_proxy_port)) args["revocation_endpoint"] = ( "{endpoint}/{token}".format( endpoint=config.snappy.builder_proxy_auth_api_endpoint, token=token['username'])) args["name"] = build.snap.store_name or build.snap.name # XXX cjwatson 2015-08-03: Allow tools_source to be overridden at # some more fine-grained level. args["archives"], args["trusted_keys"] = ( yield get_sources_list_for_building( build, build.distro_arch_series, None, tools_source=config.snappy.tools_source, tools_fingerprint=config.snappy.tools_fingerprint, logger=logger)) channels = build.channels or {} if "snapcraft" not in channels: channels["snapcraft"] = ( getFeatureFlag(SNAP_SNAPCRAFT_CHANNEL_FEATURE_FLAG) or "apt") if channels.get("snapcraft") != "apt": # We have to remove the security proxy that Zope applies to this # dict, since otherwise we'll be unable to serialise it to # XML-RPC. args["channels"] = removeSecurityProxy(channels) if build.snap.branch is not None: args["branch"] = build.snap.branch.bzr_identity elif build.snap.git_ref is not None: if build.snap.git_ref.repository_url is not None: args["git_repository"] = build.snap.git_ref.repository_url elif build.snap.git_repository.private: macaroon_raw = yield cancel_on_timeout( self._authserver.callRemote( "issueMacaroon", "snap-build", "SnapBuild", build.id), config.builddmaster.authentication_timeout) # XXX cjwatson 2019-03-07: This is ugly and needs # refactoring once we support more general HTTPS # authentication; see also comment in # GitRepository.git_https_url. split = urlsplit(build.snap.git_repository.getCodebrowseUrl()) netloc = ":%s@%s" % (macaroon_raw, split.hostname) if split.port: netloc += ":%s" % split.port args["git_repository"] = urlunsplit([ split.scheme, netloc, split.path, "", ""]) else: args["git_repository"] = ( build.snap.git_repository.git_https_url) # "git clone -b" doesn't accept full ref names. If this becomes # a problem then we could change launchpad-buildd to do "git # clone" followed by "git checkout" instead. if build.snap.git_path != u"HEAD": args["git_path"] = build.snap.git_ref.name else: raise CannotBuild( "Source branch/repository for ~%s/%s has been deleted." % (build.snap.owner.name, build.snap.name)) args["build_source_tarball"] = build.snap.build_source_tarball args["private"] = build.is_private build_request = build.build_request if build_request is not None: args["build_request_id"] = build_request.id # RFC3339 format for timestamp # (matching snapd, SAS and snapcraft representation) timestamp = format_as_rfc3339(build_request.date_requested) args["build_request_timestamp"] = timestamp defer.returnValue(args)
def _with_timeout(self, d, timeout=None): return cancel_on_timeout(d, timeout or self.timeout, self.reactor)