diff options
author | bst-marge-bot <marge-bot@buildstream.build> | 2019-04-15 08:45:34 +0000 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-04-15 08:45:34 +0000 |
commit | 4aafa38e0d3c73b2fb2663984ce170e7d7ed8e95 (patch) | |
tree | cc946f5b1d045d719d6cbbc886f3b288ad378e97 /tests/artifactcache/expiry.py | |
parent | b3817226286a0c60b7ca955686b767bc40fb1051 (diff) | |
parent | 2db11763d50b2295ab49b44c5ed0adee38ad67fe (diff) | |
download | buildstream-4aafa38e0d3c73b2fb2663984ce170e7d7ed8e95.tar.gz |
Merge branch 'tristan/platform-cache-quota-1.2' into 'bst-1.2'
Cache quote related backports
See merge request BuildStream/buildstream!1288
Diffstat (limited to 'tests/artifactcache/expiry.py')
-rw-r--r-- | tests/artifactcache/expiry.py | 65 |
1 files changed, 52 insertions, 13 deletions
diff --git a/tests/artifactcache/expiry.py b/tests/artifactcache/expiry.py index f8b928cbf..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')) @@ -303,11 +314,39 @@ def test_invalid_cache_quota(cli, datafiles, tmpdir, quota, success): } }) - res = cli.run(project=project, args=['workspace', 'list']) - if success: + # We patch how we get space information + # Ideally we would instead create a FUSE device on which we control + # everything. + # If the value is a percentage, we fix the current values to take into + # account the block size, since this is important in how we compute the size + + if quota.endswith("%"): # We set the used space at 60% of total space + stats = os.statvfs(".") + free_space = 0.6 * stats.f_bsize * stats.f_blocks + total_space = stats.f_bsize * stats.f_blocks + else: + free_space = 6000 + total_space = 10000 + + volume_space_patch = mock.patch( + "buildstream._artifactcache.ArtifactCache._get_cache_volume_size", + autospec=True, + return_value=(total_space, free_space), + ) + + cache_size_patch = mock.patch( + "buildstream._artifactcache.ArtifactCache.get_cache_size", + autospec=True, + return_value=0, + ) + + with volume_space_patch, cache_size_patch: + res = cli.run(project=project, args=['workspace', 'list']) + + 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) |