On a Wednesday in 2020, Peter Krempa wrote:
Migration cookie transports a lot of information but there are no
tests
for it.
The test supports both xml2xml testing and also testing of the
population of the migration cookie data from a domain object, although
that option is not very useful as many things are collected from running
qemu and thus can't be tested efficiently here.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
tests/meson.build | 1 +
.../basic-xml2xml-in.xml | 6 +
.../basic-xml2xml-out.xml | 9 +
.../modern-dom-out-dest.xml | 12 +
.../modern-dom-out-source.xml | 12 +
tests/qemumigrationcookiexmltest.c | 336 ++++++++++++++++++
6 files changed, 376 insertions(+)
create mode 100644 tests/qemumigrationcookiexmldata/basic-xml2xml-in.xml
create mode 100644 tests/qemumigrationcookiexmldata/basic-xml2xml-out.xml
create mode 100644 tests/qemumigrationcookiexmldata/modern-dom-out-dest.xml
create mode 100644 tests/qemumigrationcookiexmldata/modern-dom-out-source.xml
create mode 100644 tests/qemumigrationcookiexmltest.c
diff --git a/tests/meson.build b/tests/meson.build
index 818fce65f3..68a309ebfb 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -456,6 +456,7 @@ if conf.has('WITH_QEMU')
{ 'name': 'qemuxml2argvtest', 'link_with': [
test_qemu_driver_lib, test_utils_qemu_monitor_lib ], 'link_whole': [
test_utils_qemu_lib, test_file_wrapper_lib ] },
{ 'name': 'qemuxml2xmltest', 'link_with': [
test_qemu_driver_lib ], 'link_whole': [ test_utils_qemu_lib, test_file_wrapper_lib
] },
{ 'name': 'qemustatusxml2xmltest', 'link_with': [
test_qemu_driver_lib ], 'link_whole': [ test_utils_qemu_lib, test_file_wrapper_lib
] },
+ { 'name': 'qemumigrationcookiexmltest', 'link_with': [
test_qemu_driver_lib ], 'link_whole': [ test_utils_qemu_lib, test_file_wrapper_lib
] },
Same comment about ordering.
]
endif
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+static virQEMUDriver driver;
+
+static virBuffer testnamebuf = VIR_BUFFER_INITIALIZER;
+
+static const char *
+tn(const char *str, ...)
This name is not very descriptive.
How about testName?
+{
+ va_list ap;
+
+ virBufferFreeAndReset(&testnamebuf);
+ virBufferAdd(&testnamebuf, str, -1);
+
+ va_start(ap, str);
+ virBufferStrcatVArgs(&testnamebuf, ap);
+ va_end(ap);
+
+ return virBufferCurrentContent(&testnamebuf);
+}
+
+
+struct testQemuMigrationCookieData {
+ const char *name;
+ char *inStatus;
+ virDomainObjPtr vm;
+
+ unsigned int cookiePopulateFlags;
+ unsigned int cookieParseFlags;
+
+ qemuMigrationParty cookiePopulateParty;
+
+ char *xmlstr;
+ int xmlstrlen;
+ char *infile;
+ char *outfile;
+};
+
+
+static int
+testQemuMigrationCookiePopulate(const void *opaque)
+{
+ struct testQemuMigrationCookieData *data = (struct testQemuMigrationCookieData *)
opaque;
+ g_autoptr(qemuMigrationCookie) cookie = NULL;
+
+ if (!(cookie = qemuMigrationCookieNew(data->vm->def, NULL)))
+ return -1;
+
+ /* doctor the hostname and uuid, so that the output can be simply used for
+ * the xml2xmltest where the parser validates UUID match (yuck) */
Please drop the yuck.
+ g_free(cookie->localHostname);
+ cookie->localHostname = g_strdup("hostname2");
+
+ /* uuidgen --sha1 --namespace @dns --name "hostname2" */
+ if (virUUIDParse("8b3f4dc4-6a8e-5f9b-94a5-4c35babd8d95",
cookie->localHostuuid) < 0) {
+ VIR_TEST_DEBUG("\nfailed to parse fake UUID");
+ return -1;
+ }
+
+ /* allow re-run for checking both miration parties */
s/miration/migration/
+ g_clear_pointer(&data->xmlstr, g_free);
+
+ if (qemuMigrationCookieFormat(cookie,
+ &driver,
+ data->vm,
+ data->cookiePopulateParty,
+ &data->xmlstr,
+ &data->xmlstrlen,
+ data->cookiePopulateFlags) < 0) {
+ VIR_TEST_DEBUG("\n failed to populate and format qemu migration
cookie");
+ return -1;
+ }
+
+ if (virTestCompareToFile(data->xmlstr, data->outfile) < 0)
+ return -1;
+
+ return 0;
+}
+
+
Reviewed-by: Ján Tomko <jtomko(a)redhat.com>
Jano