container: Fix failure with defining a new VM

- We write to a file and immediately this file is consumed by the virsh command.
If the file is not flushed, the virsh command will see an empty file.

Tests:

- Without the change, virsh fails with an error message that the definition file
is empty. With the change, the failure goes away.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2026-08-17 16:38:44 -07:00 committed by James Valleroy
parent 80dceb12f4
commit d144dce428
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -1392,6 +1392,7 @@ class VM(Machine):
with tempfile.NamedTemporaryFile() as file_handle: with tempfile.NamedTemporaryFile() as file_handle:
file_handle.write(domain_xml.encode()) file_handle.write(domain_xml.encode())
file_handle.flush()
logger.info('Running `virsh define %s`', file_handle.name) logger.info('Running `virsh define %s`', file_handle.name)
self._virsh(['define', file_handle.name], self._virsh(['define', file_handle.name],
stdout=subprocess.DEVNULL) stdout=subprocess.DEVNULL)