This minor patch:* Introduces a VIR_FROM_TEST class of errors and makes errors generated by test come from that class.
* Provides a reasonable error message if the user forgets to supply a path. Also stops the driver from trying to open ("/"). Example:
$ src/virsh -c test:/// capabilities
libvir: Test error : invalid argument in testOpen: supply a
path or use test:///default
lt-virsh: error: failed to connect to the hypervisor
* Arranges that Xen-unified appears last in the list of drivers, because
qemu and test have well-defined URI syntaxes so can be checked first.
'make check' passes all tests with this patch. Rich. -- Emerging Technologies, Red Hat http://et.redhat.com/~rjones/ 64 Baker Street, London, W1U 7DF Mobile: +44 7866 314 421 Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Directors: Michael Cunningham (USA), Charlie Peters (USA) and David Owens (Ireland)
Index: src/libvirt.c
===================================================================
RCS file: /data/cvs/libvirt/src/libvirt.c,v
retrieving revision 1.67
diff -u -r1.67 libvirt.c
--- src/libvirt.c 12 Apr 2007 14:18:39 -0000 1.67
+++ src/libvirt.c 18 Apr 2007 09:29:14 -0000
@@ -64,15 +64,15 @@
* Note that the order is important: the first ones have a higher
* priority when calling virConnectOpen.
*/
-#ifdef WITH_XEN
- if (xenUnifiedRegister () == -1) return -1;
-#endif
#ifdef WITH_TEST
if (testRegister() == -1) return -1;
#endif
#ifdef WITH_QEMU
if (qemuRegister() == -1) return -1;
#endif
+#ifdef WITH_XEN
+ if (xenUnifiedRegister () == -1) return -1;
+#endif
return(0);
}
Index: src/test.c
===================================================================
RCS file: /data/cvs/libvirt/src/test.c,v
retrieving revision 1.27
diff -u -r1.27 test.c
--- src/test.c 6 Apr 2007 15:34:09 -0000 1.27
+++ src/test.c 18 Apr 2007 09:29:15 -0000
@@ -213,7 +213,7 @@
return;
errmsg = __virErrorMsg(error, info);
- __virRaiseError(con, dom, NULL, VIR_FROM_XEN, error, VIR_ERR_ERROR,
+ __virRaiseError(con, dom, NULL, VIR_FROM_TEST, error, VIR_ERR_ERROR,
errmsg, info, NULL, 0, 0, errmsg, info, 0);
}
@@ -722,13 +722,19 @@
return VIR_DRV_OPEN_DECLINED;
}
- if (!uri->scheme ||
- strcmp(uri->scheme, "test") ||
- !uri->path) {
+ if (!uri->scheme || strcmp(uri->scheme, "test") != 0) {
xmlFreeURI(uri);
return VIR_DRV_OPEN_DECLINED;
}
+ /* From this point on, the connection is for us. */
+ if (!uri->path
+ || uri->path[0] == '\0'
+ || (uri->path[0] == '/' && uri->path[1] == '\0')) {
+ testError (conn, NULL, VIR_ERR_INVALID_ARG,
+ _("testOpen: supply a path or use test:///default"));
+ return VIR_DRV_OPEN_ERROR;
+ }
if ((connid = getNextConnection()) < 0) {
testError(NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("too many connections"));
@@ -738,12 +744,12 @@
/* Allocate per-connection private data. */
priv = conn->privateData = malloc (sizeof (struct _testPrivate));
if (!priv) {
- testError(NULL, NULL, VIR_ERR_NO_MEMORY, "allocating private data");
+ testError(conn, NULL, VIR_ERR_NO_MEMORY, _("allocating private data"));
return VIR_DRV_OPEN_ERROR;
}
priv->handle = -1;
- if (!strcmp(uri->path, "/default")) {
+ if (strcmp(uri->path, "/default") == 0) {
ret = testOpenDefault(conn,
connid);
} else {
Index: src/virterror.c
===================================================================
RCS file: /data/cvs/libvirt/src/virterror.c,v
retrieving revision 1.23
diff -u -r1.23 virterror.c
--- src/virterror.c 15 Mar 2007 17:24:57 -0000 1.23
+++ src/virterror.c 18 Apr 2007 09:29:16 -0000
@@ -274,6 +274,9 @@
case VIR_FROM_NET:
dom = "Network ";
break;
+ case VIR_FROM_TEST:
+ dom = "Test ";
+ break;
}
if ((err->dom != NULL) && (err->code != VIR_ERR_INVALID_DOMAIN)) {
domain = err->dom->name;
Index: tests/.cvsignore
===================================================================
RCS file: /data/cvs/libvirt/tests/.cvsignore,v
retrieving revision 1.7
diff -u -r1.7 .cvsignore
--- tests/.cvsignore 23 Feb 2007 17:15:42 -0000 1.7
+++ tests/.cvsignore 18 Apr 2007 09:29:16 -0000
@@ -9,6 +9,7 @@
conftest
reconnect
xmconfigtest
+xencapstest
*.gcda
*.gcno
Attachment:
smime.p7s
Description: S/MIME Cryptographic Signature