orphan disk search update

This commit is contained in:
David Schroeder
2026-09-22 22:17:39 -05:00
parent 431eee5b72
commit cce22283d5
4 changed files with 45 additions and 7 deletions
+21
View File
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import contextlib
import csv
import importlib.util
import io
from pathlib import Path
@@ -88,6 +89,26 @@ class ReportTests(unittest.TestCase):
with self.assertRaises(FileExistsError):
disks.export_csv(path, [], [])
def test_disk_sizes_in_display_and_csv(self):
for index, (size, expected) in enumerate([
(4 * 1024 ** 2, '4.00 MiB'),
(100 * 1024 ** 3, '100.00 GiB'),
(2 * 1024 ** 4, '2.00 TiB'),
(0, '0.00 B'), (None, 'Unknown')]):
with self.subTest(size=size):
row = dict(zip(disks.FIELDS, ['a', 'local', 'local:vm-100-disk-1',
size, 'Unused disk', 'app-server (VM 100)']))
output = io.StringIO()
with contextlib.redirect_stdout(output):
disks.render([row], [], [])
self.assertIn('Disk size: ' + expected, output.getvalue())
path = self.root / f'sizes-{index}.csv'
disks.export_csv(path, [row], [])
with path.open(newline='') as handle:
exported = next(csv.DictReader(handle))
self.assertEqual(exported['disk_size'], expected)
self.assertEqual(exported['size_bytes'], '' if size is None else str(size))
def test_offline_node_and_config_change(self):
def get(path, *options):
if path == '/nodes':