orphan disk update
This commit is contained in:
@@ -109,6 +109,40 @@ class ReportTests(unittest.TestCase):
|
||||
self.assertEqual(exported['disk_size'], expected)
|
||||
self.assertEqual(exported['size_bytes'], '' if size is None else str(size))
|
||||
|
||||
def test_approximate_storage_sizes_match_proxmox_display(self):
|
||||
approximate = round(25.91 * 1024 ** 3)
|
||||
volumes = [
|
||||
{'volid': 'local:vm-100-disk-1', 'approximate-size': approximate},
|
||||
{'volid': 'local:vm-999-exact', 'size': 30 * 1024 ** 3, 'approximate-size': approximate},
|
||||
{'volid': 'local:vm-999-zero', 'size': 0, 'approximate-size': approximate},
|
||||
{'volid': 'local:vm-999-null', 'size': None, 'approximate-size': approximate},
|
||||
{'volid': 'local:vm-999-unknown'},
|
||||
]
|
||||
def get(path, *options):
|
||||
if path == '/nodes':
|
||||
return self.nodes
|
||||
if path == '/cluster/resources':
|
||||
return self.guests
|
||||
if path.endswith('/storage'):
|
||||
return [{'storage': 'local', 'content': 'images', 'active': 1}] if '/a/' in path else []
|
||||
return [dict(volume, content='images') for volume in volumes]
|
||||
with contextlib.redirect_stderr(io.StringIO()):
|
||||
rows, warnings, coverage = disks.scan(self.root, get)
|
||||
self.assertEqual(warnings, [])
|
||||
self.assertEqual([row['size_is_approximate'] for row in rows], [True, False, False, True, False])
|
||||
output = io.StringIO()
|
||||
with contextlib.redirect_stdout(output):
|
||||
disks.render(rows, warnings, coverage)
|
||||
self.assertIn('Disk size: ~25.91 GiB', output.getvalue())
|
||||
path = self.root / 'approximate.csv'
|
||||
disks.export_csv(path, rows, warnings)
|
||||
with path.open(newline='') as handle:
|
||||
exported = list(csv.DictReader(handle))
|
||||
self.assertEqual([row['disk_size'] for row in exported],
|
||||
['~25.91 GiB', '30.00 GiB', '0.00 B', '~25.91 GiB', 'Unknown'])
|
||||
self.assertEqual(exported[0]['size_bytes'], str(approximate))
|
||||
self.assertEqual(exported[0]['size_is_approximate'], 'True')
|
||||
|
||||
def test_offline_node_and_config_change(self):
|
||||
def get(path, *options):
|
||||
if path == '/nodes':
|
||||
|
||||
Reference in New Issue
Block a user