From 2dbaea0587d55351d7e1a278beccef6e8f761e19 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 14 Apr 2012 15:54:46 +0200 Subject: [PATCH] Send configured host key to hub. --- python/pakfire/cli.py | 7 +------ python/pakfire/client/base.py | 5 +++++ python/pakfire/client/builder.py | 20 +++++++++++++------- python/pakfire/client/transport.py | 14 +++++++++----- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/python/pakfire/cli.py b/python/pakfire/cli.py index 31d5b6d8b..05a8c6edf 100644 --- a/python/pakfire/cli.py +++ b/python/pakfire/cli.py @@ -1141,12 +1141,7 @@ class CliDaemon(Cli): conf = config.ConfigDaemon() # Create daemon instance. - d = pakfire.client.PakfireDaemon( - server = conf.get("daemon", "server"), - hostname = conf.get("daemon", "hostname"), - secret = conf.get("daemon", "secret"), - ) - + d = pakfire.client.PakfireDaemon() try: d.run() diff --git a/python/pakfire/client/base.py b/python/pakfire/client/base.py index ab9ecd974..dc08f674c 100644 --- a/python/pakfire/client/base.py +++ b/python/pakfire/client/base.py @@ -213,6 +213,8 @@ class PakfireBuilderClient(BuildMixin, PakfireClient): def send_update(self): log.info("Sending host information update to hub...") + config = pakfire.config.ConfigDaemon() + self.conn.send_update( # Supported architectures. system.supported_arches, @@ -226,4 +228,7 @@ class PakfireBuilderClient(BuildMixin, PakfireClient): # Send the currently running version of Pakfire. PAKFIRE_VERSION, + + # Send the host key. + config.get("signatures", "host_key", None), ) diff --git a/python/pakfire/client/builder.py b/python/pakfire/client/builder.py index 35820e409..4bdaf45e9 100644 --- a/python/pakfire/client/builder.py +++ b/python/pakfire/client/builder.py @@ -48,7 +48,13 @@ class PakfireDaemon(object): The PakfireDaemon class that creates a a new process per build job and also handles the keepalive/abort stuff. """ - def __init__(self, server, hostname, secret): + def __init__(self): + self.config = pakfire.config.ConfigDaemon() + + server = self.config.get("daemon", "server") + hostname = self.config.get("daemon", "hostname") + secret = self.config.get("daemon", "secret") + self.client = base.PakfireBuilderClient(server, hostname, secret) self.conn = self.client.conn @@ -207,12 +213,12 @@ class PakfireDaemon(object): if time.time() - self._last_keepalive < 30: return - free_space = self.free_space / 1024**2 + kwargs = { + "overload" : self.has_overload(), + "free_space" : self.free_space / 1024**2, + } - self.client.send_keepalive( - overload=self.has_overload(), - free_space=free_space, - ) + self.client.send_keepalive(**kwargs) self._last_keepalive = time.time() def remove_finished_builders(self): @@ -405,7 +411,7 @@ class ClientBuilder(object): raise DownloadError, "Hash check did not succeed." # Build configuration. - config = pakfire.config.Config(files=["general.conf"]) + config = pakfire.config.ConfigDaemon() # Parse the configuration received from the build service. config.parse(self.build_config) diff --git a/python/pakfire/client/transport.py b/python/pakfire/client/transport.py index c5036ce99..4fb8a8f27 100644 --- a/python/pakfire/client/transport.py +++ b/python/pakfire/client/transport.py @@ -31,6 +31,9 @@ log = logging.getLogger("pakfire.client") from pakfire.constants import * from pakfire.i18n import _ +# Set the default socket timeout to 30 seconds. +socket.setdefaulttimeout(30) + class XMLRPCMixin: user_agent = "pakfire/%s" % PAKFIRE_VERSION @@ -46,16 +49,17 @@ class XMLRPCMixin: ret = xmlrpclib.Transport.single_request(self, *args, **kwargs) # Catch errors related to the connection. Just try again. - except (socket.error, ssl.SSLError): - pass + except (socket.error, ssl.SSLError), e: + log.warning("Exception: %s: %s" % (e.__class__.__name__, e)) # Presumably, the server closed the connection before sending anything. except httplib.BadStatusLine: - pass + # Try again immediately. + continue # The XML reponse could not be parsed. - except xmlrpclib.ResponseError: - pass + except xmlrpclib.ResponseError, e: + log.warning("Exception: %s: %s" % (e.__class__.__name__, e)) except xmlrpclib.ProtocolError, e: if e.errcode == 403: -- 2.39.5