运维:固定虚拟PCI设备并补充过夜观察与电源策略
This commit is contained in:
1 parent
6f2ff67300
commit
65f92df8b7
42 files changed
+1705
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
import shlex
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
spec = importlib.util.spec_from_file_location("fixed_pci", Path(__file__).parents[1] / "set-fixed-pci.py")
|
||||
policy = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(policy)
|
||||
|
||||
|
||||
class FixedPciPolicyTests(unittest.TestCase):
|
||||
def test_keeps_gpu_identity_and_quoted_arguments(self):
|
||||
old = '-set device.hostpci0.x-pci-sub-vendor-id=0x1558 -set device.hostpci0.x-pci-sub-device-id=0x6557 -name "desktop test"'
|
||||
updated = policy.fixed_args(old)
|
||||
self.assertEqual(shlex.split(updated)[:len(shlex.split(old))], shlex.split(old))
|
||||
self.assertTrue(updated.startswith(old))
|
||||
self.assertEqual(policy.fixed_args(updated), updated)
|
||||
self.assertFalse(any("usb" in token.lower() for token in shlex.split(updated)))
|
||||
|
||||
def test_conflicting_explicit_hotplug_setting_requires_review(self):
|
||||
with self.assertRaisesRegex(ValueError, "Conflicting"):
|
||||
policy.fixed_args('-global pcie-root-port.hotplug=on')
|
||||
|
||||
def test_online_vm_cannot_be_changed(self):
|
||||
with patch.object(policy, "command", return_value="status: running") as call:
|
||||
with self.assertRaisesRegex(RuntimeError, "normally shut down"):
|
||||
policy.require_stopped(100)
|
||||
call.assert_called_once_with(["qm", "status", "100"])
|
||||
|
||||
def test_stopped_vm_can_proceed(self):
|
||||
with patch.object(policy, "command", return_value="status: stopped"):
|
||||
policy.require_stopped(100)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user