fix: tolerate QMP socket removal during status probes
This commit is contained in:
+4
-2
@@ -182,9 +182,11 @@ class Runtime:
|
|||||||
raise RuntimeError(f'Cannot verify VM identity: {exc}') from exc
|
raise RuntimeError(f'Cannot verify VM identity: {exc}') from exc
|
||||||
|
|
||||||
def _listening(self, path: Path) -> bool:
|
def _listening(self, path: Path) -> bool:
|
||||||
if not path.exists():
|
try:
|
||||||
|
mode = path.lstat().st_mode
|
||||||
|
except FileNotFoundError:
|
||||||
return False
|
return False
|
||||||
if not stat.S_ISSOCK(path.lstat().st_mode):
|
if not stat.S_ISSOCK(mode):
|
||||||
raise RuntimeError(f'Refusing non-socket runtime path: {path}')
|
raise RuntimeError(f'Refusing non-socket runtime path: {path}')
|
||||||
with socket.socket(socket.AF_UNIX) as probe:
|
with socket.socket(socket.AF_UNIX) as probe:
|
||||||
probe.settimeout(min(1, self.boot_timeout))
|
probe.settimeout(min(1, self.boot_timeout))
|
||||||
|
|||||||
@@ -105,6 +105,19 @@ class RuntimeTests(unittest.TestCase):
|
|||||||
self.assertNotIn('-vnc', argv)
|
self.assertNotIn('-vnc', argv)
|
||||||
self.assertNotIn('-virtfs', argv)
|
self.assertNotIn('-virtfs', argv)
|
||||||
|
|
||||||
|
def test_socket_removed_during_stat_is_safely_not_listening(self):
|
||||||
|
paths = self.runtime.paths('guest')
|
||||||
|
paths.qmp.parent.mkdir(parents=True)
|
||||||
|
with socket.socket(socket.AF_UNIX) as fixture:
|
||||||
|
fixture.bind(str(paths.qmp))
|
||||||
|
original_lstat = Path.lstat
|
||||||
|
def disappearing_socket(path):
|
||||||
|
if path == paths.qmp:
|
||||||
|
path.unlink(missing_ok=True)
|
||||||
|
return original_lstat(path)
|
||||||
|
with patch.object(Path, 'lstat', disappearing_socket):
|
||||||
|
self.assertFalse(self.runtime._listening(paths.qmp))
|
||||||
|
|
||||||
def test_argv_provides_audio_and_manual_usb_channels(self):
|
def test_argv_provides_audio_and_manual_usb_channels(self):
|
||||||
argv = build_qemu_argv(self.profile, self.runtime.paths('guest'))
|
argv = build_qemu_argv(self.profile, self.runtime.paths('guest'))
|
||||||
self.assertIn('spice,id=audio', argv)
|
self.assertIn('spice,id=audio', argv)
|
||||||
|
|||||||
Reference in New Issue
Block a user