mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
tests: Tests for the xen-xl parser
Add disk and spice config tests for the xen_xl config parser Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Jim Fehlig <jfehlig@suse.com>
This commit is contained in:
parent
4689cdf779
commit
4ed5fb9193
@ -138,6 +138,7 @@ EXTRA_DIST = \
|
||||
vmx2xmldata \
|
||||
xencapsdata \
|
||||
xmconfigdata \
|
||||
xlconfigdata \
|
||||
xml2sexprdata \
|
||||
xml2vmxdata \
|
||||
vmwareverdata \
|
||||
@ -227,6 +228,11 @@ if WITH_XEN
|
||||
test_programs += xml2sexprtest sexpr2xmltest \
|
||||
xmconfigtest xencapstest statstest reconnect
|
||||
endif WITH_XEN
|
||||
|
||||
if WITH_LIBXL
|
||||
test_programs += xlconfigtest
|
||||
endif WITH_LIBXL
|
||||
|
||||
if WITH_QEMU
|
||||
test_programs += qemuxml2argvtest qemuxml2xmltest qemuxmlnstest \
|
||||
qemuargv2xmltest qemuhelptest domainsnapshotxml2xmltest \
|
||||
@ -477,6 +483,11 @@ sexpr2xmltest_SOURCES = \
|
||||
testutils.c testutils.h
|
||||
sexpr2xmltest_LDADD = $(xen_LDADDS)
|
||||
|
||||
xlconfigtest_SOURCES = \
|
||||
xlconfigtest.c testutilsxen.c testutilsxen.h \
|
||||
testutils.c testutils.h
|
||||
xlconfigtest_LDADD =$(xen_LDADDS)
|
||||
|
||||
xmconfigtest_SOURCES = \
|
||||
xmconfigtest.c testutilsxen.c testutilsxen.h \
|
||||
testutils.c testutils.h
|
||||
|
@ -69,3 +69,53 @@ virCapsPtr testXenCapsInit(void)
|
||||
virObjectUnref(caps);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
virCapsPtr
|
||||
testXLInitCaps(void)
|
||||
{
|
||||
virCapsPtr caps;
|
||||
virCapsGuestPtr guest;
|
||||
virCapsGuestMachinePtr *machines;
|
||||
int nmachines;
|
||||
static const char *const x86_machines[] = {
|
||||
"xenfv"
|
||||
};
|
||||
static const char *const xen_machines[] = {
|
||||
"xenpv"
|
||||
};
|
||||
|
||||
if ((caps = virCapabilitiesNew(virArchFromHost(),
|
||||
false, false)) == NULL)
|
||||
return NULL;
|
||||
nmachines = ARRAY_CARDINALITY(x86_machines);
|
||||
if ((machines = virCapabilitiesAllocMachines(x86_machines, nmachines)) == NULL)
|
||||
goto cleanup;
|
||||
if ((guest = virCapabilitiesAddGuest(caps, "hvm", VIR_ARCH_X86_64,
|
||||
"/usr/lib/xen/bin/qemu-dm", NULL,
|
||||
nmachines, machines)) == NULL)
|
||||
goto cleanup;
|
||||
machines = NULL;
|
||||
if (virCapabilitiesAddGuestDomain(guest, "xen", NULL,
|
||||
NULL, 0, NULL) == NULL)
|
||||
goto cleanup;
|
||||
nmachines = ARRAY_CARDINALITY(xen_machines);
|
||||
if ((machines = virCapabilitiesAllocMachines(xen_machines, nmachines)) == NULL)
|
||||
goto cleanup;
|
||||
|
||||
if ((guest = virCapabilitiesAddGuest(caps, "xen", VIR_ARCH_X86_64,
|
||||
"/usr/lib/xen/bin/qemu-dm", NULL,
|
||||
nmachines, machines)) == NULL)
|
||||
goto cleanup;
|
||||
machines = NULL;
|
||||
|
||||
if (virCapabilitiesAddGuestDomain(guest, "xen", NULL,
|
||||
NULL, 0, NULL) == NULL)
|
||||
goto cleanup;
|
||||
return caps;
|
||||
|
||||
cleanup:
|
||||
virCapabilitiesFreeMachines(machines, nmachines);
|
||||
virObjectUnref(caps);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1,3 +1,10 @@
|
||||
#include "capabilities.h"
|
||||
#ifndef _TESTUTILSXEN_H_
|
||||
# define _TESTUTILSXEN_H_
|
||||
|
||||
# include "capabilities.h"
|
||||
|
||||
virCapsPtr testXenCapsInit(void);
|
||||
|
||||
virCapsPtr testXLInitCaps(void);
|
||||
|
||||
#endif /* _TESTUTILSXEN_H_ */
|
||||
|
26
tests/xlconfigdata/test-new-disk.cfg
Normal file
26
tests/xlconfigdata/test-new-disk.cfg
Normal file
@ -0,0 +1,26 @@
|
||||
name = "XenGuest2"
|
||||
uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809"
|
||||
maxmem = 579
|
||||
memory = 394
|
||||
vcpus = 1
|
||||
builder = "hvm"
|
||||
kernel = "/usr/lib/xen/boot/hvmloader"
|
||||
boot = "d"
|
||||
pae = 1
|
||||
acpi = 1
|
||||
apic = 1
|
||||
hap = 0
|
||||
viridian = 0
|
||||
localtime = 0
|
||||
on_poweroff = "destroy"
|
||||
on_reboot = "restart"
|
||||
on_crash = "restart"
|
||||
device_model = "/usr/lib/xen/bin/qemu-dm"
|
||||
sdl = 0
|
||||
vnc = 1
|
||||
vncunused = 1
|
||||
vnclisten = "127.0.0.1"
|
||||
vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ]
|
||||
parallel = "none"
|
||||
serial = "none"
|
||||
disk = [ "/dev/HostVG/XenGuest2,raw,hda,w,backendtype=phy", "/var/lib/libvirt/images/XenGuest2-home,qcow2,hdb,w,backendtype=qdisk", "/root/boot.iso,raw,hdc,r,backendtype=qdisk,devtype=cdrom" ]
|
51
tests/xlconfigdata/test-new-disk.xml
Normal file
51
tests/xlconfigdata/test-new-disk.xml
Normal file
@ -0,0 +1,51 @@
|
||||
<domain type='xen'>
|
||||
<name>XenGuest2</name>
|
||||
<uuid>c7a5fdb2-cdaf-9455-926a-d65c16db1809</uuid>
|
||||
<memory unit='KiB'>592896</memory>
|
||||
<currentMemory unit='KiB'>403456</currentMemory>
|
||||
<vcpu placement='static'>1</vcpu>
|
||||
<os>
|
||||
<type arch='x86_64' machine='xenfv'>hvm</type>
|
||||
<loader type='rom'>/usr/lib/xen/boot/hvmloader</loader>
|
||||
<boot dev='cdrom'/>
|
||||
</os>
|
||||
<features>
|
||||
<acpi/>
|
||||
<apic/>
|
||||
<pae/>
|
||||
</features>
|
||||
<clock offset='utc' adjustment='reset'/>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>restart</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/lib/xen/bin/qemu-dm</emulator>
|
||||
<disk type='block' device='disk'>
|
||||
<driver name='phy' type='raw'/>
|
||||
<source dev='/dev/HostVG/XenGuest2'/>
|
||||
<target dev='hda' bus='ide'/>
|
||||
</disk>
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='qcow2'/>
|
||||
<source file='/var/lib/libvirt/images/XenGuest2-home'/>
|
||||
<target dev='hdb' bus='ide'/>
|
||||
</disk>
|
||||
<disk type='file' device='cdrom'>
|
||||
<driver name='qemu' type='raw'/>
|
||||
<source file='/root/boot.iso'/>
|
||||
<target dev='hdc' bus='ide'/>
|
||||
<readonly/>
|
||||
</disk>
|
||||
<interface type='bridge'>
|
||||
<mac address='00:16:3e:66:92:9c'/>
|
||||
<source bridge='xenbr1'/>
|
||||
<script path='vif-bridge'/>
|
||||
<model type='e1000'/>
|
||||
</interface>
|
||||
<input type='mouse' bus='ps2'/>
|
||||
<input type='keyboard' bus='ps2'/>
|
||||
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
|
||||
<listen type='address' address='127.0.0.1'/>
|
||||
</graphics>
|
||||
</devices>
|
||||
</domain>
|
31
tests/xlconfigdata/test-spice.cfg
Normal file
31
tests/xlconfigdata/test-spice.cfg
Normal file
@ -0,0 +1,31 @@
|
||||
name = "XenGuest2"
|
||||
uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809"
|
||||
maxmem = 579
|
||||
memory = 394
|
||||
vcpus = 1
|
||||
builder = "hvm"
|
||||
kernel = "/usr/lib/xen/boot/hvmloader"
|
||||
boot = "d"
|
||||
pae = 1
|
||||
acpi = 1
|
||||
apic = 1
|
||||
hap = 0
|
||||
viridian = 0
|
||||
localtime = 0
|
||||
on_poweroff = "destroy"
|
||||
on_reboot = "restart"
|
||||
on_crash = "restart"
|
||||
device_model = "/usr/lib/xen/bin/qemu-dm"
|
||||
vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ]
|
||||
parallel = "none"
|
||||
serial = "none"
|
||||
disk = [ "/dev/HostVG/XenGuest2,raw,hda,w,backendtype=phy", "/root/boot.iso,raw,hdc,r,backendtype=qdisk,devtype=cdrom" ]
|
||||
sdl = 0
|
||||
vnc = 0
|
||||
spice = 1
|
||||
spiceport = 590
|
||||
spicetls_port = 500
|
||||
spicedisable_ticketing = 1
|
||||
spicepasswd = "thebeast"
|
||||
spicehost = "127.0.0.1"
|
||||
spiceagent_mouse = 0
|
46
tests/xlconfigdata/test-spice.xml
Normal file
46
tests/xlconfigdata/test-spice.xml
Normal file
@ -0,0 +1,46 @@
|
||||
<domain type='xen'>
|
||||
<name>XenGuest2</name>
|
||||
<uuid>c7a5fdb2-cdaf-9455-926a-d65c16db1809</uuid>
|
||||
<memory unit='KiB'>592896</memory>
|
||||
<currentMemory unit='KiB'>403456</currentMemory>
|
||||
<vcpu placement='static'>1</vcpu>
|
||||
<os>
|
||||
<type arch='x86_64' machine='xenfv'>hvm</type>
|
||||
<loader type='rom'>/usr/lib/xen/boot/hvmloader</loader>
|
||||
<boot dev='cdrom'/>
|
||||
</os>
|
||||
<features>
|
||||
<acpi/>
|
||||
<apic/>
|
||||
<pae/>
|
||||
</features>
|
||||
<clock offset='utc' adjustment='reset'/>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>restart</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/lib/xen/bin/qemu-dm</emulator>
|
||||
<disk type='block' device='disk'>
|
||||
<driver name='phy' type='raw'/>
|
||||
<source dev='/dev/HostVG/XenGuest2'/>
|
||||
<target dev='hda' bus='ide'/>
|
||||
</disk>
|
||||
<disk type='file' device='cdrom'>
|
||||
<driver name='qemu' type='raw'/>
|
||||
<source file='/root/boot.iso'/>
|
||||
<target dev='hdc' bus='ide'/>
|
||||
<readonly/>
|
||||
</disk>
|
||||
<interface type='bridge'>
|
||||
<mac address='00:16:3e:66:92:9c'/>
|
||||
<source bridge='xenbr1'/>
|
||||
<script path='vif-bridge'/>
|
||||
<model type='e1000'/>
|
||||
</interface>
|
||||
<input type='mouse' bus='ps2'/>
|
||||
<input type='keyboard' bus='ps2'/>
|
||||
<graphics type='spice' port='590' tlsPort='500' autoport='no' listen='127.0.0.1' passwd='thebeast'>
|
||||
<listen type='address' address='127.0.0.1'/>
|
||||
</graphics>
|
||||
</devices>
|
||||
</domain>
|
225
tests/xlconfigtest.c
Normal file
225
tests/xlconfigtest.c
Normal file
@ -0,0 +1,225 @@
|
||||
/*
|
||||
* xlconfigtest.c: Test backend for xl_internal config file handling
|
||||
*
|
||||
* Copyright (C) 2007, 2010-2011, 2014 Red Hat, Inc.
|
||||
* Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Author: Daniel P. Berrange <berrange@redhat.com>
|
||||
* Author: Kiarie Kahurani <davidkiarie4@gmail.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "datatypes.h"
|
||||
#include "xenconfig/xen_xl.h"
|
||||
#include "viralloc.h"
|
||||
#include "virstring.h"
|
||||
#include "testutils.h"
|
||||
#include "testutilsxen.h"
|
||||
#include "xen/xen_driver.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||
|
||||
static virCapsPtr caps;
|
||||
static virDomainXMLOptionPtr xmlopt;
|
||||
/*
|
||||
* parses the xml, creates a domain def and compare with equivalent xm config
|
||||
*/
|
||||
static int
|
||||
testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
|
||||
{
|
||||
char *xmlData = NULL;
|
||||
char *xmcfgData = NULL;
|
||||
char *gotxmcfgData = NULL;
|
||||
virConfPtr conf = NULL;
|
||||
virConnectPtr conn = NULL;
|
||||
int wrote = 4096;
|
||||
int ret = -1;
|
||||
virDomainDefPtr def = NULL;
|
||||
|
||||
if (VIR_ALLOC_N(gotxmcfgData, wrote) < 0)
|
||||
goto fail;
|
||||
|
||||
conn = virGetConnect();
|
||||
if (!conn) goto fail;
|
||||
|
||||
if (virtTestLoadFile(xml, &xmlData) < 0)
|
||||
goto fail;
|
||||
|
||||
if (virtTestLoadFile(xmcfg, &xmcfgData) < 0)
|
||||
goto fail;
|
||||
|
||||
if (!(def = virDomainDefParseString(xmlData, caps, xmlopt,
|
||||
1 << VIR_DOMAIN_VIRT_XEN,
|
||||
VIR_DOMAIN_XML_INACTIVE)))
|
||||
goto fail;
|
||||
|
||||
if (!virDomainDefCheckABIStability(def, def)) {
|
||||
fprintf(stderr, "ABI stability check failed on %s", xml);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!(conf = xenFormatXL(def, conn, xendConfigVersion)))
|
||||
goto fail;
|
||||
|
||||
if (virConfWriteMem(gotxmcfgData, &wrote, conf) < 0)
|
||||
goto fail;
|
||||
gotxmcfgData[wrote] = '\0';
|
||||
|
||||
if (STRNEQ(xmcfgData, gotxmcfgData)) {
|
||||
virtTestDifference(stderr, xmcfgData, gotxmcfgData);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
VIR_FREE(xmlData);
|
||||
VIR_FREE(xmcfgData);
|
||||
VIR_FREE(gotxmcfgData);
|
||||
if (conf)
|
||||
virConfFree(conf);
|
||||
virDomainDefFree(def);
|
||||
virObjectUnref(conn);
|
||||
|
||||
return ret;
|
||||
}
|
||||
/*
|
||||
* parses the xl config, develops domain def and compares with equivalent xm config
|
||||
*/
|
||||
static int
|
||||
testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion)
|
||||
{
|
||||
char *xmlData = NULL;
|
||||
char *xmcfgData = NULL;
|
||||
char *gotxml = NULL;
|
||||
virConfPtr conf = NULL;
|
||||
int ret = -1;
|
||||
virConnectPtr conn;
|
||||
virDomainDefPtr def = NULL;
|
||||
|
||||
conn = virGetConnect();
|
||||
if (!conn) goto fail;
|
||||
|
||||
if (virtTestLoadFile(xml, &xmlData) < 0)
|
||||
goto fail;
|
||||
|
||||
if (virtTestLoadFile(xmcfg, &xmcfgData) < 0)
|
||||
goto fail;
|
||||
|
||||
if (!(conf = virConfReadMem(xmcfgData, strlen(xmcfgData), 0)))
|
||||
goto fail;
|
||||
|
||||
if (!(def = xenParseXL(conf, caps, xendConfigVersion)))
|
||||
goto fail;
|
||||
|
||||
if (!(gotxml = virDomainDefFormat(def, VIR_DOMAIN_XML_INACTIVE |
|
||||
VIR_DOMAIN_XML_SECURE)))
|
||||
goto fail;
|
||||
|
||||
if (STRNEQ(xmlData, gotxml)) {
|
||||
virtTestDifference(stderr, xmlData, gotxml);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
if (conf)
|
||||
virConfFree(conf);
|
||||
VIR_FREE(xmlData);
|
||||
VIR_FREE(xmcfgData);
|
||||
VIR_FREE(gotxml);
|
||||
virDomainDefFree(def);
|
||||
virObjectUnref(conn);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
struct testInfo {
|
||||
const char *name;
|
||||
int version;
|
||||
int mode;
|
||||
};
|
||||
|
||||
static int
|
||||
testCompareHelper(const void *data)
|
||||
{
|
||||
int result = -1;
|
||||
const struct testInfo *info = data;
|
||||
char *xml = NULL;
|
||||
char *cfg = NULL;
|
||||
|
||||
if (virAsprintf(&xml, "%s/xlconfigdata/test-%s.xml",
|
||||
abs_srcdir, info->name) < 0 ||
|
||||
virAsprintf(&cfg, "%s/xlconfigdata/test-%s.cfg",
|
||||
abs_srcdir, info->name) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (info->mode == 0)
|
||||
result = testCompareParseXML(cfg, xml, info->version);
|
||||
else
|
||||
result = testCompareFormatXML(cfg, xml, info->version);
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(xml);
|
||||
VIR_FREE(cfg);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
mymain(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (!(caps = testXLInitCaps()))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (!(xmlopt = xenDomainXMLConfInit()))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
#define DO_TEST(name, version) \
|
||||
do { \
|
||||
struct testInfo info0 = { name, version, 0 }; \
|
||||
struct testInfo info1 = { name, version, 1 }; \
|
||||
if (virtTestRun("Xen XM-2-XML Parse " name, \
|
||||
testCompareHelper, &info0) < 0) \
|
||||
ret = -1; \
|
||||
if (virtTestRun("Xen XM-2-XML Format " name, \
|
||||
testCompareHelper, &info1) < 0) \
|
||||
ret = -1; \
|
||||
} while (0)
|
||||
|
||||
DO_TEST("new-disk", 3);
|
||||
DO_TEST("spice", 3);
|
||||
|
||||
virObjectUnref(caps);
|
||||
virObjectUnref(xmlopt);
|
||||
|
||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
||||
VIRT_TEST_MAIN(mymain)
|
Loading…
Reference in New Issue
Block a user