mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
tests: Enable and fix test-add-libvirt-dom test.
Commit96158d42f5enabled the previously private guestfs_add_libvirt_dom API. It also tried to enable the existing test for this API, but failed to do that correctly. Also the test was broken. Fix all of this. This fixes commit96158d42f5.
This commit is contained in:
@@ -96,6 +96,7 @@ vc-list-files
|
||||
warnings
|
||||
xalloc
|
||||
xalloc-die
|
||||
xgetcwd
|
||||
xstrtol
|
||||
xstrtoll
|
||||
xvasprintf
|
||||
|
||||
1
m4/.gitignore
vendored
1
m4/.gitignore
vendored
@@ -180,6 +180,7 @@
|
||||
/readlink.m4
|
||||
/read.m4
|
||||
/realloc.m4
|
||||
/rewinddir.m4
|
||||
/rmdir.m4
|
||||
/safe-read.m4
|
||||
/safe-write.m4
|
||||
|
||||
@@ -67,11 +67,10 @@ check_PROGRAMS += test-just-header-cxx
|
||||
TESTS += test-just-header-cxx
|
||||
endif
|
||||
|
||||
# The API behind this test is not baked yet.
|
||||
#if HAVE_LIBVIRT
|
||||
#check_PROGRAMS += test-add-libvirt-dom
|
||||
#TESTS += test-add-libvirt-dom
|
||||
#endif
|
||||
if HAVE_LIBVIRT
|
||||
check_PROGRAMS += test-add-libvirt-dom
|
||||
TESTS += test-add-libvirt-dom
|
||||
endif
|
||||
EXTRA_DIST += test-add-libvirt-dom.c
|
||||
|
||||
TESTS_ENVIRONMENT = \
|
||||
@@ -243,7 +242,9 @@ test_event_string_LDADD = \
|
||||
if HAVE_LIBVIRT
|
||||
test_add_libvirt_dom_SOURCES = test-add-libvirt-dom.c
|
||||
test_add_libvirt_dom_CPPFLAGS = \
|
||||
-I$(top_srcdir)/src -I$(top_builddir)/src -I$(top_srcdir)/gnulib/lib
|
||||
-I$(top_srcdir)/src -I$(top_builddir)/src \
|
||||
-I$(top_srcdir)/gnulib/lib \
|
||||
-I$(top_builddir)/gnulib/lib
|
||||
test_add_libvirt_dom_CFLAGS = \
|
||||
$(LIBVIRT_CFLAGS) \
|
||||
$(WARN_CFLAGS) $(WERROR_CFLAGS)
|
||||
|
||||
@@ -23,11 +23,11 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "xgetcwd.h"
|
||||
|
||||
#include <libvirt/libvirt.h>
|
||||
#include <libvirt/virterror.h>
|
||||
|
||||
#include "xgetcwd.h"
|
||||
|
||||
#include "guestfs.h"
|
||||
#include "guestfs-internal-frontend.h"
|
||||
|
||||
@@ -73,13 +73,29 @@ main (int argc, char *argv[])
|
||||
virDomainPtr dom;
|
||||
virErrorPtr err;
|
||||
int r;
|
||||
const char *test_xml;
|
||||
char *backend;
|
||||
char *cwd;
|
||||
FILE *fp;
|
||||
char libvirt_uri[1024];
|
||||
|
||||
cwd = xgetcwd ();
|
||||
|
||||
/* Create the guestfs handle. */
|
||||
g = guestfs_create ();
|
||||
if (g == NULL) {
|
||||
fprintf (stderr, "failed to create handle\n");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
backend = guestfs_get_backend (g);
|
||||
if (STREQ (backend, "uml")) {
|
||||
printf ("%s: test skipped because UML backend does not support qcow2\n",
|
||||
argv[0]);
|
||||
free (backend);
|
||||
exit (77);
|
||||
}
|
||||
free (backend);
|
||||
|
||||
/* Create the libvirt XML and test images in the current
|
||||
* directory.
|
||||
*/
|
||||
@@ -91,41 +107,26 @@ main (int argc, char *argv[])
|
||||
make_test_xml (fp, cwd);
|
||||
fclose (fp);
|
||||
|
||||
fp = fopen ("test-add-libvirt-dom-1.img", "w");
|
||||
if (fp == NULL) {
|
||||
perror ("test-add-libvirt-dom-1.img");
|
||||
if (guestfs_disk_create (g, "test-add-libvirt-dom-1.img", "raw",
|
||||
1024*1024, -1) == -1)
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
fclose (fp);
|
||||
|
||||
fp = fopen ("test-add-libvirt-dom-2.img", "w");
|
||||
if (fp == NULL) {
|
||||
perror ("test-add-libvirt-dom-2.img");
|
||||
if (guestfs_disk_create (g, "test-add-libvirt-dom-2.img", "raw",
|
||||
1024*1024, -1) == -1)
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
fclose (fp);
|
||||
|
||||
fp = fopen ("test-add-libvirt-dom-3.img", "w");
|
||||
if (fp == NULL) {
|
||||
perror ("test-add-libvirt-dom-3.img");
|
||||
if (guestfs_disk_create (g, "test-add-libvirt-dom-3.img", "qcow2",
|
||||
1024*1024, -1) == -1)
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
fclose (fp);
|
||||
|
||||
/* Create the guestfs handle. */
|
||||
g = guestfs_create ();
|
||||
if (g == NULL) {
|
||||
fprintf (stderr, "failed to create handle\n");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Create the libvirt connection. */
|
||||
snprintf (libvirt_uri, sizeof libvirt_uri, "test://%s/test-add-libvirt-dom.xml", cwd);
|
||||
conn = virConnectOpenReadOnly (libvirt_uri);
|
||||
if (!conn) {
|
||||
err = virGetLastError ();
|
||||
fprintf (stderr, "could not connect to libvirt (code %d, domain %d): %s\n",
|
||||
err->code, err->domain, err->message);
|
||||
fprintf (stderr,
|
||||
"%s: could not connect to libvirt (code %d, domain %d): %s\n",
|
||||
argv[0], err->code, err->domain, err->message);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -133,7 +134,8 @@ main (int argc, char *argv[])
|
||||
if (!dom) {
|
||||
err = virGetLastError ();
|
||||
fprintf (stderr,
|
||||
"no libvirt domain called '%s': %s\n", "guest", err->message);
|
||||
"%s: no libvirt domain called '%s': %s\n",
|
||||
argv[0], "guest", err->message);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -143,6 +145,13 @@ main (int argc, char *argv[])
|
||||
if (r == -1)
|
||||
exit (EXIT_FAILURE);
|
||||
|
||||
if (r != 3) {
|
||||
fprintf (stderr,
|
||||
"%s: incorrect number of disks added (%d, expected 3)\n",
|
||||
argv[0], r);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
guestfs_close (g);
|
||||
|
||||
unlink ("test-add-libvirt-dom.xml");
|
||||
|
||||
Reference in New Issue
Block a user