summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2019-01-19 10:41:57 -0500
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2019-04-14 16:54:30 +0900
commit0f181c88700ef1dcb0f4ee278fde9026654e6bef (patch)
tree81a51cb8ee53b4b24ceeeb1b4c1229e0b4a2aba0
parent66dfaa11a71936d91532bf1715ff383ad178162c (diff)
downloadbuildstream-0f181c88700ef1dcb0f4ee278fde9026654e6bef.tar.gz
_artifactcache.py: Raise ArtifactError() when quota size exceeds disk space.
This is not an error related to loading data, like a parse error in the quota specification is, but a problem raised by the artifact cache - this allows us to assert more specific machine readable errors in test cases (instead of checking the string in stderr, which this patch also fixes). This also removes a typo from the error message in the said error. * tests/artifactcache/cache_size.py Updated test case to expect the artifact error, which consequently changes the test case to properly assert a machine readable error instead of asserting text in the stderr (which is the real, secret motivation behind this patch). * tests/artifactcache/expiry.py: Reworked test_invalid_cache_quota() Now expect the artifact error for the tests which check configurations which create caches too large to fit on the disk.
-rw-r--r--buildstream/_artifactcache/artifactcache.py25
-rw-r--r--tests/artifactcache/cache_size.py2
-rw-r--r--tests/artifactcache/expiry.py33
3 files changed, 40 insertions, 20 deletions
diff --git a/buildstream/_artifactcache/artifactcache.py b/buildstream/_artifactcache/artifactcache.py
index 53f7708d6..bc2150c1b 100644
--- a/buildstream/_artifactcache/artifactcache.py
+++ b/buildstream/_artifactcache/artifactcache.py
@@ -699,15 +699,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
- 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)))
+ if '%' in self.context.config_cache_quota:
+ available = (available_space / total_size) * 100
+ available = '{}% of total disk space'.format(round(available, 1))
+ else:
+ available = utils._pretty_size(available_space)
+
+ raise ArtifactError("Your system does not have enough available " +
+ "space to support the cache quota specified.",
+ detail=("You 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),
+ reason='insufficient-storage-for-quota')
# Place a slight headroom (2e9 (2GB) on the cache_quota) into
# cache_quota to try and avoid exceptions.
diff --git a/tests/artifactcache/cache_size.py b/tests/artifactcache/cache_size.py
index 8e47f9fb6..63ab9ad07 100644
--- a/tests/artifactcache/cache_size.py
+++ b/tests/artifactcache/cache_size.py
@@ -1,8 +1,10 @@
import os
import pytest
+from unittest import mock
from buildstream import _yaml
from buildstream._artifactcache import CACHE_SIZE_FILE
+from buildstream._exceptions import ErrorDomain
from tests.testutils import cli, create_element_size
diff --git a/tests/artifactcache/expiry.py b/tests/artifactcache/expiry.py
index 68a1c87cd..ce8e6c9e8 100644
--- a/tests/artifactcache/expiry.py
+++ b/tests/artifactcache/expiry.py
@@ -1,6 +1,7 @@
import os
import pytest
+from unittest import mock
from buildstream import _yaml
from buildstream._exceptions import ErrorDomain, LoadErrorReason
@@ -282,18 +283,28 @@ def test_never_delete_required_track(cli, datafiles, tmpdir):
# Ensure that only valid cache quotas make it through the loading
# process.
-@pytest.mark.parametrize("quota,success", [
- ("1", True),
- ("1K", True),
- ("50%", True),
- ("infinity", True),
- ("0", True),
- ("-1", False),
- ("pony", False),
- ("200%", False)
+#
+# This test virtualizes the condition to assume a storage volume
+# has 10K total disk space, and 6K of it is already in use (not
+# including any space used by the artifact cache).
+#
+@pytest.mark.parametrize("quota,err_domain,err_reason", [
+ # Valid configurations
+ ("1", 'success', None),
+ ("1K", 'success', None),
+ ("50%", 'success', None),
+ ("infinity", 'success', None),
+ ("0", 'success', None),
+ # Invalid configurations
+ ("-1", ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA),
+ ("pony", ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA),
+ ("200%", ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA),
+ # Not enough space for these caches
+ ("7K", ErrorDomain.ARTIFACT, 'insufficient-storage-for-quota'),
+ ("70%", ErrorDomain.ARTIFACT, 'insufficient-storage-for-quota')
])
@pytest.mark.datafiles(DATA_DIR)
-def test_invalid_cache_quota(cli, datafiles, tmpdir, quota, success):
+def test_invalid_cache_quota(cli, datafiles, tmpdir, quota, err_domain, err_reason):
project = os.path.join(datafiles.dirname, datafiles.basename)
os.makedirs(os.path.join(project, 'elements'))
@@ -335,7 +346,7 @@ def test_invalid_cache_quota(cli, datafiles, tmpdir, quota, success):
if err_domain == 'success':
res.assert_success()
else:
- res.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
+ res.assert_main_error(err_domain, err_reason)
@pytest.mark.datafiles(DATA_DIR)