diff options
-rw-r--r-- | buildstream/_artifactcache/artifactcache.py | 19 | ||||
-rw-r--r-- | tests/utils/misc.py | 3 |
2 files changed, 15 insertions, 7 deletions
diff --git a/buildstream/_artifactcache/artifactcache.py b/buildstream/_artifactcache/artifactcache.py index 06a2b84e0..b0324462c 100644 --- a/buildstream/_artifactcache/artifactcache.py +++ b/buildstream/_artifactcache/artifactcache.py @@ -937,15 +937,22 @@ class ArtifactCache(): "Invalid cache quota ({}): ".format(utils._pretty_size(cache_quota)) + "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 = '{}% of total disk space'.format(round(available, 1)) + else: + available = utils._pretty_size(available_space) + raise LoadError(LoadErrorReason.INVALID_DATA, ("Your system does not have enough available " + "space to support the cache quota specified.\n" + - "You currently have:\n" + - "- {used} of cache in use at {local_cache_path}\n" + - "- {available} of available system storage").format( - used=utils._pretty_size(cache_size), - local_cache_path=self.context.artifactdir, - available=utils._pretty_size(available_space))) + "\nYou have specified a quota of {quota} total disk space.\n" + + "- The filesystem containing {local_cache_path} only " + + "has: {available_size} available.") + .format( + quota=self.context.config_cache_quota, + local_cache_path=self.context.artifactdir, + available_size=available)) # Place a slight headroom (2e9 (2GB) on the cache_quota) into # cache_quota to try and avoid exceptions. diff --git a/tests/utils/misc.py b/tests/utils/misc.py index ae584e4d5..7df08aec5 100644 --- a/tests/utils/misc.py +++ b/tests/utils/misc.py @@ -27,4 +27,5 @@ def test_parse_size_over_1024T(cli, tmpdir): patched_statvfs = mock_os.mock_statvfs(f_bavail=bavail, f_bsize=BLOCK_SIZE) with mock_os.monkey_patch("statvfs", patched_statvfs): result = cli.run(project, args=["build", "file.bst"]) - assert "1025T of available system storage" in result.stderr + failure_msg = 'Your system does not have enough available space to support the cache quota specified.' + assert failure_msg in result.stderr |