From cd88c6d8532c304cc1b1b283324f92f9ed257657 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 3 Mar 2012 12:43:50 +0100 Subject: [PATCH] PBS: Send amount of free disk space to server. Also do not request new jobs when the free disk space is less than 2GB. --- python/pakfire/client/base.py | 4 ++-- python/pakfire/client/builder.py | 17 ++++++++++++++++- python/pakfire/system.py | 14 +++++++------- python/pakfire/transaction.py | 2 +- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/python/pakfire/client/base.py b/python/pakfire/client/base.py index 3ac4bef5f..9c2e12794 100644 --- a/python/pakfire/client/base.py +++ b/python/pakfire/client/base.py @@ -188,7 +188,7 @@ class PakfireUserClient(BuildMixin, PakfireClient): class PakfireBuilderClient(BuildMixin, PakfireClient): type = "builder" - def send_keepalive(self, overload=None): + def send_keepalive(self, overload=None, free_space=None): """ Sends a little keepalive to the server and updates the hardware information if the server @@ -199,7 +199,7 @@ class PakfireBuilderClient(BuildMixin, PakfireClient): # Collect the current loadavg and send it to the hub. loadavg = ", ".join(("%.2f" % round(l, 2) for l in os.getloadavg())) - needs_update = self.conn.send_keepalive(loadavg, overload) + needs_update = self.conn.send_keepalive(loadavg, overload, free_space) if needs_update: log.debug("The hub is requesting an update.") diff --git a/python/pakfire/client/builder.py b/python/pakfire/client/builder.py index 32dff2308..0292f81c4 100644 --- a/python/pakfire/client/builder.py +++ b/python/pakfire/client/builder.py @@ -155,10 +155,20 @@ class PakfireDaemon(object): # Return the number of processes. return len(self.processes) + @property + def free_space(self): + mp = system.get_mountpoint(BUILD_ROOT) + + return mp.space_left + def get_job(self): """ Get a build job from the hub. """ + if not self.free_space >= 2 * 1024**3: + log.warning(_("Less than 2GB of free space. Cannot request a new job.")) + return + log.info("Requesting a new job from the server...") # Get some information about this system. @@ -193,7 +203,12 @@ class PakfireDaemon(object): if time.time() - self._last_keepalive < 30: return - self.client.send_keepalive(overload=self.has_overload()) + free_space = self.free_space / 1024**2 + + self.client.send_keepalive( + overload=self.has_overload(), + free_space=free_space, + ) self._last_keepalive = time.time() def remove_finished_builders(self): diff --git a/python/pakfire/system.py b/python/pakfire/system.py index 8d99fb815..36d5da459 100644 --- a/python/pakfire/system.py +++ b/python/pakfire/system.py @@ -140,14 +140,15 @@ class System(object): return memory + def get_mountpoint(self, path): + return Mountpoint(path) + # Create an instance of this class to only keep it once in memory. system = System() class Mountpoints(object): - def __init__(self, pakfire, root="/"): - self.pakfire = pakfire - + def __init__(self, root="/"): self._mountpoints = [] # Scan for all mountpoints on the system. @@ -163,7 +164,7 @@ class Mountpoints(object): # If root is not equal to /, we are in a chroot and # our root must be a mountpoint to count files. if not root == "/": - mp = Mountpoint(self.pakfire, "/", root=root) + mp = Mountpoint("/", root=root) self._mountpoints.append(mp) f = open("/proc/mounts") @@ -184,7 +185,7 @@ class Mountpoints(object): else: mountpoint = os.path.join("/", mountpoint) - mp = Mountpoint(self.pakfire, mountpoint, root=root) + mp = Mountpoint(mountpoint, root=root) if not mp in self._mountpoints: self._mountpoints.append(mp) @@ -224,8 +225,7 @@ class Mountpoints(object): class Mountpoint(object): - def __init__(self, pakfire, path, root="/"): - self.pakfire = pakfire + def __init__(self, path, root="/"): self.path = path self.root = root diff --git a/python/pakfire/transaction.py b/python/pakfire/transaction.py index afb5000b6..f18f9453c 100644 --- a/python/pakfire/transaction.py +++ b/python/pakfire/transaction.py @@ -54,7 +54,7 @@ class TransactionCheck(object): self.filelist = self.load_filelist() # Get information about the mounted filesystems. - self.mountpoints = system.Mountpoints(self.pakfire, root=self.pakfire.path) + self.mountpoints = system.Mountpoints(self.pakfire.path) @property def error_files(self): -- 2.39.5