summaryrefslogtreecommitdiff
path: root/buildstream/_artifactcache
diff options
context:
space:
mode:
authorBenjamin Schubert <bschubert15@bloomberg.net>2018-08-10 18:10:13 +0100
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2018-12-13 10:24:11 +0000
commitd03bf31619f739cb85ece06eb3e94a314441e097 (patch)
treed3c075924a0b20a2e1e2c1c75f4caac7f4cf19f5 /buildstream/_artifactcache
parentb65284410329b7f55a0d097b88d297480f9f7307 (diff)
downloadbuildstream-BenjaminSchubert/fix-quota-tests.tar.gz
Mock storage space checks for tests.BenjaminSchubert/fix-quota-tests
Fix #530 - Extract free space computation in a function for easier mocking - Mock space computation during cache quota tests - Mock cache size during cachque quota tests - Add two more tests when the configuration would require to much storage space
Diffstat (limited to 'buildstream/_artifactcache')
-rw-r--r--buildstream/_artifactcache/artifactcache.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/buildstream/_artifactcache/artifactcache.py b/buildstream/_artifactcache/artifactcache.py
index 7771851ae..b4b8df320 100644
--- a/buildstream/_artifactcache/artifactcache.py
+++ b/buildstream/_artifactcache/artifactcache.py
@@ -874,9 +874,7 @@ class ArtifactCache():
"\nValid values are, for example: 800M 10G 1T 50%\n"
.format(str(e))) from e
- stat = os.statvfs(artifactdir_volume)
- available_space = (stat.f_bsize * stat.f_bavail)
-
+ available_space, total_size = self._get_volume_space_info_for(artifactdir_volume)
cache_size = self.get_cache_size()
# Ensure system has enough storage for the cache_quota
@@ -893,7 +891,7 @@ class ArtifactCache():
"BuildStream requires a minimum cache quota of 2G.")
elif cache_quota > cache_size + available_space: # Check maximum
if '%' in self.context.config_cache_quota:
- available = (available_space / (stat.f_blocks * stat.f_bsize)) * 100
+ available = (available_space / total_size) * 100
available = '{}% of total disk space'.format(round(available, 1))
else:
available = utils._pretty_size(available_space)
@@ -919,6 +917,20 @@ class ArtifactCache():
self._cache_quota = cache_quota - headroom
self._cache_lower_threshold = self._cache_quota / 2
+ # _get_volume_space_info_for
+ #
+ # Get the available space and total space for the given volume
+ #
+ # Args:
+ # volume: volume for which to get the size
+ #
+ # Returns:
+ # A tuple containing first the availabe number of bytes on the requested
+ # volume, then the total number of bytes of the volume.
+ def _get_volume_space_info_for(self, volume):
+ stat = os.statvfs(volume)
+ return stat.f_bsize * stat.f_bavail, stat.f_bsize * stat.f_blocks
+
# _configured_remote_artifact_cache_specs():
#