James Ennis pushed to branch jennis/quota_declaration_fix at BuildStream / buildstream
Commits:
- 
2d9f6f9a
by James Ennis at 2018-11-08T12:41:42Z
2 changed files:
Changes:
| ... | ... | @@ -937,15 +937,22 @@ class ArtifactCache(): | 
| 937 | 937 |                              "Invalid cache quota ({}): ".format(utils._pretty_size(cache_quota)) +
 | 
| 938 | 938 |                              "BuildStream requires a minimum cache quota of 2G.")
 | 
| 939 | 939 |          elif cache_quota > cache_size + available_space:  # Check maximum
 | 
| 940 | +            if '%' in self.context.config_cache_quota:
 | |
| 941 | +                available = (available_space / (stat.f_blocks * stat.f_bsize)) * 100
 | |
| 942 | +                available = '{}% of total disk space'.format(round(available, 1))
 | |
| 943 | +            else:
 | |
| 944 | +                available = utils._pretty_size(available_space)
 | |
| 945 | + | |
| 940 | 946 |              raise LoadError(LoadErrorReason.INVALID_DATA,
 | 
| 941 | 947 |                              ("Your system does not have enough available " +
 | 
| 942 | 948 |                               "space to support the cache quota specified.\n" +
 | 
| 943 | -                             "You currently have:\n" +
 | |
| 944 | -                             "- {used} of cache in use at {local_cache_path}\n" +
 | |
| 945 | -                             "- {available} of available system storage").format(
 | |
| 946 | -                                 used=utils._pretty_size(cache_size),
 | |
| 947 | -                                 local_cache_path=self.context.artifactdir,
 | |
| 948 | -                                 available=utils._pretty_size(available_space)))
 | |
| 949 | +                             "\nYou have specified a quota of {quota} total disk space.\n" +
 | |
| 950 | +                             "- The filesystem containing {local_cache_path} only " +
 | |
| 951 | +                             "has: {available_size} available.")
 | |
| 952 | +                            .format(
 | |
| 953 | +                                quota=self.context.config_cache_quota,
 | |
| 954 | +                                local_cache_path=self.context.artifactdir,
 | |
| 955 | +                                available_size=available))
 | |
| 949 | 956 |  | 
| 950 | 957 |          # Place a slight headroom (2e9 (2GB) on the cache_quota) into
 | 
| 951 | 958 |          # cache_quota to try and avoid exceptions.
 | 
| ... | ... | @@ -27,4 +27,5 @@ def test_parse_size_over_1024T(cli, tmpdir): | 
| 27 | 27 |      patched_statvfs = mock_os.mock_statvfs(f_bavail=bavail, f_bsize=BLOCK_SIZE)
 | 
| 28 | 28 |      with mock_os.monkey_patch("statvfs", patched_statvfs):
 | 
| 29 | 29 |          result = cli.run(project, args=["build", "file.bst"])
 | 
| 30 | -        assert "1025T of available system storage" in result.stderr | |
| 30 | +        failure_msg = 'Your system does not have enough available space to support the cache quota specified.'
 | |
| 31 | +        assert failure_msg in result.stderr | 
