This is part of the effort to minimize use of virDomainDiskSourceParse.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
tests/qemublocktest.c | 130 ++++++++++++++++++++----------------------
1 file changed, 61 insertions(+), 69 deletions(-)
diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
index 96c70e381a..48cec2869b 100644
--- a/tests/qemublocktest.c
+++ b/tests/qemublocktest.c
@@ -34,15 +34,10 @@
VIR_LOG_INIT("tests.storagetest");
-struct testBackingXMLjsonXMLdata {
- int type;
- const char *xml;
-};
-
static int
testBackingXMLjsonXML(const void *args)
{
- const struct testBackingXMLjsonXMLdata *data = args;
+ const char *xmlstr = args;
VIR_AUTOPTR(xmlDoc) xml = NULL;
VIR_AUTOPTR(xmlXPathContext) ctxt = NULL;
VIR_AUTOCLEAN(virBuffer) buf = VIR_BUFFER_INITIALIZER;
@@ -57,12 +52,13 @@ testBackingXMLjsonXML(const void *args)
if (!(xmlsrc = virStorageSourceNew()))
return -1;
- xmlsrc->type = data->type;
-
- if (!(xml = virXMLParseStringCtxt(data->xml, "(test storage source
XML)", &ctxt)))
+ if (!(xml = virXMLParseStringCtxt(xmlstr, "(test storage source XML)",
&ctxt)))
return -1;
- if (virDomainDiskSourceParse(ctxt->node, ctxt, xmlsrc, 0, NULL) < 0) {
+ if (!(xmlsrc = virDomainStorageSourceParseFull("string(./@type)",
+ "string(./@format)",
+ ".", NULL, false,
+ ctxt, 0, NULL))) {
fprintf(stderr, "failed to parse disk source xml\n");
return -1;
}
@@ -86,17 +82,19 @@ testBackingXMLjsonXML(const void *args)
return -1;
}
- if (virDomainDiskSourceFormat(&buf, jsonsrc, 0, 0, true, false, false, NULL) <
0 ||
+ jsonsrc->format = VIR_STORAGE_FILE_RAW;
+
+ if (virDomainStorageSourceFormatFull(&buf, jsonsrc, "source", false,
false, NULL) < 0 ||
!(actualxml = virBufferContentAndReset(&buf))) {
fprintf(stderr, "failed to format disk source xml\n");
return -1;
}
- if (STRNEQ(actualxml, data->xml)) {
+ if (STRNEQ(actualxml, xmlstr)) {
fprintf(stderr, "\n expected storage source xml:\n'%s'\n"
"actual storage source xml:\n%s\n"
"intermediate json:\n%s\n",
- data->xml, actualxml, protocolwrapper);
+ xmlstr, actualxml, protocolwrapper);
return -1;
}
@@ -317,7 +315,6 @@ mymain(void)
{
int ret = 0;
virQEMUDriver driver;
- struct testBackingXMLjsonXMLdata xmljsonxmldata;
struct testQemuDiskXMLToJSONData diskxmljsondata;
char *capslatest_x86_64 = NULL;
virQEMUCapsPtr caps_x86_64 = NULL;
@@ -341,70 +338,65 @@ mymain(void)
virTestCounterReset("qemu storage source xml->json->xml ");
-# define TEST_JSON_FORMAT(tpe, xmlstr) \
+# define TEST_JSON_FORMAT(xmlstr) \
do { \
- xmljsonxmldata.type = tpe; \
- xmljsonxmldata.xml = xmlstr; \
if (virTestRun(virTestCounterNext(), testBackingXMLjsonXML, \
- &xmljsonxmldata) < 0) \
+ xmlstr) < 0) \
ret = -1; \
} while (0)
-# define TEST_JSON_FORMAT_NET(xmlstr) \
- TEST_JSON_FORMAT(VIR_STORAGE_TYPE_NETWORK, xmlstr)
-
- TEST_JSON_FORMAT(VIR_STORAGE_TYPE_FILE, "<source
file='/path/to/file'/>\n");
+ TEST_JSON_FORMAT("<source type='file' format='raw'
file='/path/to/file'/>\n");
/* type VIR_STORAGE_TYPE_BLOCK is not tested since it parses back to 'file'
*/
/* type VIR_STORAGE_TYPE_DIR it is a 'format' driver in qemu */
- TEST_JSON_FORMAT_NET("<source protocol='http'
name=''>\n"
- " <host name='example.com'
port='80'/>\n"
- "</source>\n");
- TEST_JSON_FORMAT_NET("<source protocol='http'
name='file'>\n"
- " <host name='example.com'
port='80'/>\n"
- "</source>\n");
- TEST_JSON_FORMAT_NET("<source protocol='https'
name='file'>\n"
- " <host name='example.com'
port='432'/>\n"
- "</source>\n");
- TEST_JSON_FORMAT_NET("<source protocol='gluster'
name='vol/file'>\n"
- " <host name='example.com'
port='24007'/>\n"
- "</source>\n");
- TEST_JSON_FORMAT_NET("<source protocol='gluster'
name='testvol/img.qcow2'>\n"
- " <host name='example.com'
port='1234'/>\n"
- " <host transport='unix'
socket='/path/socket'/>\n"
- " <host name='example.com'
port='24007'/>\n"
- "</source>\n");
- TEST_JSON_FORMAT_NET("<source protocol='nbd'>\n"
- " <host transport='unix'
socket='/path/to/socket'/>\n"
- "</source>\n");
- TEST_JSON_FORMAT_NET("<source protocol='nbd'
name='blah'>\n"
- " <host name='example.org'
port='6000'/>\n"
- "</source>\n");
- TEST_JSON_FORMAT_NET("<source protocol='nbd'>\n"
- " <host name='example.org'
port='6000'/>\n"
- "</source>\n");
- TEST_JSON_FORMAT_NET("<source protocol='ssh'
name='blah'>\n"
- " <host name='example.org'
port='6000'/>\n"
- "</source>\n");
- TEST_JSON_FORMAT_NET("<source protocol='rbd'
name='libvirt/test'>\n"
- " <host name='example.com'
port='1234'/>\n"
- " <host name='example2.com'/>\n"
- " <snapshot name='snapshotname'/>\n"
- " <config file='/path/to/conf'/>\n"
- "</source>\n");
- TEST_JSON_FORMAT_NET("<source protocol='iscsi'
name='iqn.2016-12.com.virttest:emulated-iscsi-noauth.target/0'>\n"
- " <host name='test.org'
port='3260'/>\n"
- "</source>\n");
- TEST_JSON_FORMAT_NET("<source protocol='iscsi'
name='iqn.2016-12.com.virttest:emulated-iscsi-noauth.target/6'>\n"
- " <host name='test.org'
port='1234'/>\n"
- "</source>\n");
- TEST_JSON_FORMAT_NET("<source protocol='sheepdog'
name='test'>\n"
- " <host name='example.com'
port='321'/>\n"
- "</source>\n");
- TEST_JSON_FORMAT_NET("<source protocol='vxhs'
name='c6718f6b-0401-441d-a8c3-1f0064d75ee0'>\n"
- " <host name='example.com'
port='9999'/>\n"
- "</source>\n");
+ TEST_JSON_FORMAT("<source type='network' format='raw'
protocol='http' name=''>\n"
+ " <host name='example.com'
port='80'/>\n"
+ "</source>\n");
+ TEST_JSON_FORMAT("<source type='network' format='raw'
protocol='http' name='file'>\n"
+ " <host name='example.com'
port='80'/>\n"
+ "</source>\n");
+ TEST_JSON_FORMAT("<source type='network' format='raw'
protocol='https' name='file'>\n"
+ " <host name='example.com'
port='432'/>\n"
+ "</source>\n");
+ TEST_JSON_FORMAT("<source type='network' format='raw'
protocol='gluster' name='vol/file'>\n"
+ " <host name='example.com'
port='24007'/>\n"
+ "</source>\n");
+ TEST_JSON_FORMAT("<source type='network' format='raw'
protocol='gluster' name='testvol/img.qcow2'>\n"
+ " <host name='example.com'
port='1234'/>\n"
+ " <host transport='unix'
socket='/path/socket'/>\n"
+ " <host name='example.com'
port='24007'/>\n"
+ "</source>\n");
+ TEST_JSON_FORMAT("<source type='network' format='raw'
protocol='nbd'>\n"
+ " <host transport='unix'
socket='/path/to/socket'/>\n"
+ "</source>\n");
+ TEST_JSON_FORMAT("<source type='network' format='raw'
protocol='nbd' name='blah'>\n"
+ " <host name='example.org'
port='6000'/>\n"
+ "</source>\n");
+ TEST_JSON_FORMAT("<source type='network' format='raw'
protocol='nbd'>\n"
+ " <host name='example.org'
port='6000'/>\n"
+ "</source>\n");
+ TEST_JSON_FORMAT("<source type='network' format='raw'
protocol='ssh' name='blah'>\n"
+ " <host name='example.org'
port='6000'/>\n"
+ "</source>\n");
+ TEST_JSON_FORMAT("<source type='network' format='raw'
protocol='rbd' name='libvirt/test'>\n"
+ " <host name='example.com'
port='1234'/>\n"
+ " <host name='example2.com'/>\n"
+ " <snapshot name='snapshotname'/>\n"
+ " <config file='/path/to/conf'/>\n"
+ "</source>\n");
+ TEST_JSON_FORMAT("<source type='network' format='raw'
protocol='iscsi'
name='iqn.2016-12.com.virttest:emulated-iscsi-noauth.target/0'>\n"
+ " <host name='test.org'
port='3260'/>\n"
+ "</source>\n");
+ TEST_JSON_FORMAT("<source type='network' format='raw'
protocol='iscsi'
name='iqn.2016-12.com.virttest:emulated-iscsi-noauth.target/6'>\n"
+ " <host name='test.org'
port='1234'/>\n"
+ "</source>\n");
+ TEST_JSON_FORMAT("<source type='network' format='raw'
protocol='sheepdog' name='test'>\n"
+ " <host name='example.com'
port='321'/>\n"
+ "</source>\n");
+ TEST_JSON_FORMAT("<source type='network' format='raw'
protocol='vxhs' name='c6718f6b-0401-441d-a8c3-1f0064d75ee0'>\n"
+ " <host name='example.com'
port='9999'/>\n"
+ "</source>\n");
# define TEST_DISK_TO_JSON_FULL(nme, fl) \
do { \
--
2.20.1