fix: filter hostd volumes in Python to avoid building SQL from a string
Lint / Python (flake8) (push) Successful in 1m35s
Lint / Notify on failure (push) Skipped
Lint / Python (flake8) (pull_request) Successful in 1m30s
Lint / Notify on failure (pull_request) Skipped
Security / Python Security (bandit) (push) Successful in 1m33s
Test / Python Tests (pytest) (push) Successful in 1m46s
Security / Python Security (bandit) (pull_request) Successful in 1m9s
Test / Python Tests (pytest) (pull_request) Successful in 1m16s
Lint / Python (flake8) (push) Successful in 1m35s
Lint / Notify on failure (push) Skipped
Lint / Python (flake8) (pull_request) Successful in 1m30s
Lint / Notify on failure (pull_request) Skipped
Security / Python Security (bandit) (push) Successful in 1m33s
Test / Python Tests (pytest) (push) Successful in 1m46s
Security / Python Security (bandit) (pull_request) Successful in 1m9s
Test / Python Tests (pytest) (pull_request) Successful in 1m16s
Bandit 1.9.4 in CI flagged the query (B608). Select every volume with a static query and match the mountpoint in Python instead. Also stops a mount like /mnt/sia-other from matching /mnt/sia. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d8f707ade7
commit
99d4350f4d
2 files changed
+22
-11
No files matched your search
+15
-6
@@ -615,7 +615,7 @@ GIB = 1024 ** 3
|
||||
SIA_DF = "mp0 storj-pool:vm-141-disk-0 15.5T 14.8T 700.0G 95.5 /mnt/sia\n"
|
||||
|
||||
|
||||
def _run_lxc_check(monitor, df_rows, hostd_stdout='1|2', hostd_returncode=0, hostd_error=None):
|
||||
def _run_lxc_check(monitor, df_rows, hostd_stdout='/mnt/sia/d.dat|1|2\n', hostd_returncode=0, hostd_error=None):
|
||||
"""Run _check_lxc_storage against canned pct output; return (health, pct exec calls)."""
|
||||
exec_calls = []
|
||||
|
||||
@@ -639,7 +639,7 @@ def _run_lxc_check(monitor, df_rows, hostd_stdout='1|2', hostd_returncode=0, hos
|
||||
class TestManagedVolumes:
|
||||
def test_full_mount_with_low_hostd_usage_cuts_no_ticket(self, monitor):
|
||||
"""The mount reads 95.5% full but hostd only uses 3.4 of 15 TiB."""
|
||||
health, calls = _run_lxc_check(monitor, SIA_DF, hostd_stdout='895045|3932160\n')
|
||||
health, calls = _run_lxc_check(monitor, SIA_DF, hostd_stdout='/mnt/sia/hostd-data/data.dat|895045|3932160\n')
|
||||
assert health['status'] == 'OK'
|
||||
assert health['issues'] == []
|
||||
fs = health['containers'][0]['filesystems'][0]
|
||||
@@ -648,26 +648,27 @@ class TestManagedVolumes:
|
||||
assert 'mode=ro' in calls[0][5]
|
||||
|
||||
def test_warns_when_hostd_usage_crosses_warning(self, monitor):
|
||||
health, _ = _run_lxc_check(monitor, SIA_DF, hostd_stdout='3342336|3932160\n')
|
||||
health, _ = _run_lxc_check(monitor, SIA_DF, hostd_stdout='/mnt/sia/hostd-data/data.dat|3342336|3932160\n')
|
||||
assert health['status'] == 'WARNING'
|
||||
assert health['issues'] == ['LXC 141 high storage usage: 85.0% on /mnt/sia']
|
||||
|
||||
def test_critical_when_hostd_usage_crosses_critical(self, monitor):
|
||||
health, _ = _run_lxc_check(monitor, SIA_DF, hostd_stdout='3800000|3932160\n')
|
||||
health, _ = _run_lxc_check(monitor, SIA_DF, hostd_stdout='/mnt/sia/hostd-data/data.dat|3800000|3932160\n')
|
||||
assert health['status'] == 'CRITICAL'
|
||||
assert health['issues'] == ['LXC 141 critical storage usage: 96.6% on /mnt/sia']
|
||||
|
||||
def test_critical_when_filesystem_is_nearly_out_of_space(self, monitor):
|
||||
"""A real out-of-space risk must alert even with low hostd usage."""
|
||||
df = "mp0 storj-pool:vm-141-disk-0 15.5T 15.4T 10.0G 99.9 /mnt/sia\n"
|
||||
health, _ = _run_lxc_check(monitor, df, hostd_stdout='895045|3932160\n')
|
||||
health, _ = _run_lxc_check(monitor, df, hostd_stdout='/mnt/sia/hostd-data/data.dat|895045|3932160\n')
|
||||
assert health['status'] == 'CRITICAL'
|
||||
assert health['issues'] == ['LXC 141 critical storage usage: filesystem nearly out of space on /mnt/sia']
|
||||
|
||||
@pytest.mark.parametrize('kwargs', [
|
||||
{'hostd_returncode': 1, 'hostd_stdout': ''},
|
||||
{'hostd_stdout': 'garbage'},
|
||||
{'hostd_stdout': '0|0\n'},
|
||||
{'hostd_stdout': ''},
|
||||
{'hostd_stdout': '/mnt/other/data.dat|3800000|3932160\n'},
|
||||
{'hostd_error': subprocess.TimeoutExpired('pct', 30)},
|
||||
])
|
||||
def test_unreadable_hostd_usage_does_not_fall_back_to_df(self, monitor, kwargs):
|
||||
@@ -681,6 +682,14 @@ class TestManagedVolumes:
|
||||
assert health['status'] == 'CRITICAL'
|
||||
assert len(health['issues']) == 1
|
||||
|
||||
def test_sums_only_volumes_on_this_mount(self, monitor):
|
||||
stdout = ('/mnt/sia/a.dat|100|1000\n'
|
||||
'/mnt/sia/b.dat|800|1000\n'
|
||||
'/mnt/sia-other/c.dat|1000|1000\n')
|
||||
health, _ = _run_lxc_check(monitor, SIA_DF, hostd_stdout=stdout)
|
||||
assert health['containers'][0]['filesystems'][0]['usage_percent'] == pytest.approx(45.0)
|
||||
assert health['status'] == 'OK'
|
||||
|
||||
def test_other_mounts_still_use_df(self, monitor):
|
||||
"""The container's rootfs, and other containers, keep normal df alerting."""
|
||||
df = "rootfs sia-nvme:vm-141-disk-0 125.9G 115.0G 5.0G 91.3 /\n"
|
||||
|
||||
Reference in new issue
Block a user