diff options
author | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2019-01-24 01:59:13 +0000 |
---|---|---|
committer | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2019-01-24 01:59:13 +0000 |
commit | 3a6e953fe5b51c76bb6ebb0881eaf181267112ed (patch) | |
tree | 6c99885462d2b40b6d52dda5fc3e82c54091987d | |
parent | 528e8ed738567db883fcfe38f2924af29d0d033d (diff) | |
parent | 9be316419923997932c2f176b592de4d18210604 (diff) | |
download | buildstream-3a6e953fe5b51c76bb6ebb0881eaf181267112ed.tar.gz |
Merge branch 'tristan/insufficient-storage-error' into 'master'
Tristan/insufficient storage error
See merge request BuildStream/buildstream!1102
-rw-r--r-- | buildstream/_artifactcache.py | 20 | ||||
-rw-r--r-- | tests/artifactcache/cache_size.py | 28 | ||||
-rw-r--r-- | tests/artifactcache/expiry.py | 36 | ||||
-rw-r--r-- | tests/internals/utils.py | 34 |
4 files changed, 60 insertions, 58 deletions
diff --git a/buildstream/_artifactcache.py b/buildstream/_artifactcache.py index 9ccbebade..b1afdf377 100644 --- a/buildstream/_artifactcache.py +++ b/buildstream/_artifactcache.py @@ -882,16 +882,16 @@ class ArtifactCache(): 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" + - "\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)) + 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 0d12cda8c..11c8f6194 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 @@ -60,3 +62,29 @@ def test_cache_size_write(cli, tmpdir): with open(sizefile, "r") as f: size_data = f.read() size = int(size_data) + + +def test_quota_over_1024T(cli, tmpdir): + KiB = 1024 + MiB = (KiB * 1024) + GiB = (MiB * 1024) + TiB = (GiB * 1024) + + cli.configure({ + 'cache': { + 'quota': 2048 * TiB + } + }) + project = tmpdir.join("main") + os.makedirs(str(project)) + _yaml.dump({'name': 'main'}, str(project.join("project.conf"))) + + volume_space_patch = mock.patch( + "buildstream._artifactcache.ArtifactCache._get_volume_space_info_for", + autospec=True, + return_value=(1025 * TiB, 1025 * TiB) + ) + + with volume_space_patch: + result = cli.run(project, args=["build", "file.bst"]) + result.assert_main_error(ErrorDomain.ARTIFACT, 'insufficient-storage-for-quota') diff --git a/tests/artifactcache/expiry.py b/tests/artifactcache/expiry.py index 4c47ef75c..1292e50ea 100644 --- a/tests/artifactcache/expiry.py +++ b/tests/artifactcache/expiry.py @@ -304,20 +304,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), - ("7K", False), - ("70%", 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')) @@ -356,10 +364,10 @@ def test_invalid_cache_quota(cli, datafiles, tmpdir, quota, success): with volume_space_patch, cache_size_patch: res = cli.run(project=project, args=['workspace', 'list']) - if 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) diff --git a/tests/internals/utils.py b/tests/internals/utils.py deleted file mode 100644 index a34d3cda5..000000000 --- a/tests/internals/utils.py +++ /dev/null @@ -1,34 +0,0 @@ -import os -from unittest import mock - -from buildstream import _yaml - -from ..testutils.runcli import cli - - -KiB = 1024 -MiB = (KiB * 1024) -GiB = (MiB * 1024) -TiB = (GiB * 1024) - - -def test_parse_size_over_1024T(cli, tmpdir): - cli.configure({ - 'cache': { - 'quota': 2048 * TiB - } - }) - project = tmpdir.join("main") - os.makedirs(str(project)) - _yaml.dump({'name': 'main'}, str(project.join("project.conf"))) - - volume_space_patch = mock.patch( - "buildstream._artifactcache.ArtifactCache._get_volume_space_info_for", - autospec=True, - return_value=(1025 * TiB, 1025 * TiB) - ) - - with volume_space_patch: - result = cli.run(project, args=["build", "file.bst"]) - failure_msg = 'Your system does not have enough available space to support the cache quota specified.' - assert failure_msg in result.stderr |