diff options
author | James Ennis <james.ennis@codethink.com> | 2018-11-08 11:32:59 +0000 |
---|---|---|
committer | Javier Jardón <jjardon@gnome.org> | 2018-11-08 17:54:18 +0000 |
commit | 09faf0029d02cd2792b007041e6e4a793cf6bd3c (patch) | |
tree | 2e2703047659c2c32a512940dab57cde0610a77f | |
parent | fe33e328fac88aeb94855d6ddf1d4d76c37415b6 (diff) | |
download | buildstream-09faf0029d02cd2792b007041e6e4a793cf6bd3c.tar.gz |
artifactcache.py: Fix misleading error message when using % cache quotajennis/quota_declaration_fix
Due to the changed Exception message, this patch also changes
the test_parse_size_over_1024T test in misc.py
-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 |