From b39b1397ea6e6155b5e363d456196504093edd07 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Thu, 26 Feb 2015 15:28:07 +0100 Subject: [PATCH] domain_conf: Format without address correctly We have something like pvpanic device. However, in some cases it does not have any address assigned, in which case we produce this ugly XML (still valid though): /usr/bin/qemu ... Lets format "" instead. Signed-off-by: Michal Privoznik --- src/conf/domain_conf.c | 20 +++++++++---- .../qemuxml2argv-panic-no-address.args | 5 ++++ .../qemuxml2argv-panic-no-address.xml | 29 +++++++++++++++++++ tests/qemuxml2argvtest.c | 3 ++ tests/qemuxml2xmltest.c | 1 + 5 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-panic-no-address.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-panic-no-address.xml diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 01a3fbc3ab..cc8616b7c6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18840,13 +18840,21 @@ virDomainWatchdogDefFormat(virBufferPtr buf, static int virDomainPanicDefFormat(virBufferPtr buf, virDomainPanicDefPtr def) { - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); - if (virDomainDeviceInfoFormat(buf, &def->info, 0) < 0) - return -1; - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); + virBuffer childrenBuf = VIR_BUFFER_INITIALIZER; + int indent = virBufferGetIndent(buf, false); + virBufferAddLit(buf, "info, 0) < 0) + return -1; + if (virBufferUse(&childrenBuf)) { + virBufferAddLit(buf, ">\n"); + virBufferAddBuffer(buf, &childrenBuf); + virBufferAddLit(buf, "\n"); + } else { + virBufferAddLit(buf, "/>\n"); + } + virBufferFreeAndReset(&childrenBuf); return 0; } diff --git a/tests/qemuxml2argvdata/qemuxml2argv-panic-no-address.args b/tests/qemuxml2argvdata/qemuxml2argv-panic-no-address.args new file mode 100644 index 0000000000..3cbd688b20 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-panic-no-address.args @@ -0,0 +1,5 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \ +/usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults \ +-monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \ +-hda /dev/HostVG/QEMUGuest1 \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 -device pvpanic diff --git a/tests/qemuxml2argvdata/qemuxml2argv-panic-no-address.xml b/tests/qemuxml2argvdata/qemuxml2argv-panic-no-address.xml new file mode 100644 index 0000000000..79f8a1e150 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-panic-no-address.xml @@ -0,0 +1,29 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + +
+ + + + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 00fd044ffb..e2ad71344a 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1522,6 +1522,9 @@ mymain(void) DO_TEST("panic", QEMU_CAPS_DEVICE_PANIC, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); + DO_TEST("panic-no-address", QEMU_CAPS_DEVICE_PANIC, + QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); + DO_TEST("fips-enabled", QEMU_CAPS_ENABLE_FIPS); DO_TEST("shmem", QEMU_CAPS_PCIDEVICE, diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 2bec2b2d07..6608ccaf7d 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -401,6 +401,7 @@ mymain(void) DO_TEST("pcihole64-q35"); DO_TEST("panic"); + DO_TEST("panic-no-address"); DO_TEST_DIFFERENT("disk-backing-chains");