\
privconn = (testConnPtr)dom->conn->privateData; \
do { \
- if ((privdom = virDomainFindByName(&privconn->domains, \
- (dom)->name)) == NULL) { \
- testError((dom)->conn, (dom), NULL, VIR_ERR_INVALID_ARG, \
- __FUNCTION__); \
+ if ((privdom = virDomainFindByName(&privconn->domains, \
+ (dom)->name)) == NULL) { \
+ testError((dom)->conn, VIR_ERR_INVALID_ARG, __FUNCTION__); \
return (ret); \
} \
} while (0)
do { \
if ((privnet = virNetworkFindByName(&privconn->networks, \
(net)->name)) == NULL) { \
- testError((net)->conn, NULL, (net), VIR_ERR_INVALID_ARG, \
- __FUNCTION__); \
+ testError((net)->conn, VIR_ERR_INVALID_ARG, __FUNCTION__); \
return (ret); \
} \
} while (0)
privconn = (testConnPtr)conn->privateData;
-#define testError(conn, dom, net, code, fmt...) \
- __virReportErrorHelper(conn, VIR_FROM_TEST, code, __FILE__, \
+#define testError(conn, code, fmt...) \
+ __virReportErrorHelper(conn, VIR_FROM_TEST, code, __FILE__, \
__FUNCTION__, __LINE__, fmt)
static virCapsPtr
return caps;
no_memory:
- testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
+ testError(conn, VIR_ERR_NO_MEMORY, NULL);
virCapabilitiesFree(caps);
return NULL;
}
virNetworkObjPtr netobj = NULL;
if (VIR_ALLOC(privconn) < 0) {
- testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "testConn");
+ testError(conn, VIR_ERR_NO_MEMORY, "testConn");
return VIR_DRV_OPEN_ERROR;
}
conn->privateData = privconn;
if (gettimeofday(&tv, NULL) < 0) {
- testError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("getting time of day"));
+ testError(NULL, VIR_ERR_INTERNAL_ERROR, _("getting time of day"));
goto error;
}
virDomainObjPtr dom;
testConnPtr privconn;
if (VIR_ALLOC(privconn) < 0) {
- testError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "testConn");
+ testError(NULL, VIR_ERR_NO_MEMORY, "testConn");
return VIR_DRV_OPEN_ERROR;
}
conn->privateData = privconn;
goto error;
if ((fd = open(file, O_RDONLY)) < 0) {
- testError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("loading host definition file"));
+ testError(NULL, VIR_ERR_INTERNAL_ERROR, _("loading host definition file"));
goto error;
}
if (!(xml = xmlReadFd(fd, file, NULL,
XML_PARSE_NOENT | XML_PARSE_NONET |
XML_PARSE_NOERROR | XML_PARSE_NOWARNING))) {
- testError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("host"));
+ testError(NULL, VIR_ERR_INTERNAL_ERROR, _("host"));
goto error;
}
close(fd);
root = xmlDocGetRootElement(xml);
if ((root == NULL) || (!xmlStrEqual(root->name, BAD_CAST "node"))) {
- testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node"));
+ testError(NULL, VIR_ERR_XML_ERROR, _("node"));
goto error;
}
ctxt = xmlXPathNewContext(xml);
if (ctxt == NULL) {
- testError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("creating xpath context"));
+ testError(NULL, VIR_ERR_INTERNAL_ERROR, _("creating xpath context"));
goto error;
}
if (ret == 0) {
nodeInfo->nodes = l;
} else if (ret == -2) {
- testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node cpu numa nodes"));
+ testError(NULL, VIR_ERR_XML_ERROR, _("node cpu numa nodes"));
goto error;
}
if (ret == 0) {
nodeInfo->sockets = l;
} else if (ret == -2) {
- testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node cpu sockets"));
+ testError(NULL, VIR_ERR_XML_ERROR, _("node cpu sockets"));
goto error;
}
if (ret == 0) {
nodeInfo->cores = l;
} else if (ret == -2) {
- testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node cpu cores"));
+ testError(NULL, VIR_ERR_XML_ERROR, _("node cpu cores"));
goto error;
}
if (ret == 0) {
nodeInfo->threads = l;
} else if (ret == -2) {
- testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node cpu threads"));
+ testError(NULL, VIR_ERR_XML_ERROR, _("node cpu threads"));
goto error;
}
nodeInfo->cpus = l;
}
} else if (ret == -2) {
- testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node active cpu"));
+ testError(NULL, VIR_ERR_XML_ERROR, _("node active cpu"));
goto error;
}
ret = virXPathLong(conn, "string(/node/cpu/mhz[1])", ctxt, &l);
if (ret == 0) {
nodeInfo->mhz = l;
} else if (ret == -2) {
- testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node cpu mhz"));
+ testError(NULL, VIR_ERR_XML_ERROR, _("node cpu mhz"));
goto error;
}
if (ret == 0) {
nodeInfo->memory = l;
} else if (ret == -2) {
- testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node memory"));
+ testError(NULL, VIR_ERR_XML_ERROR, _("node memory"));
goto error;
}
ret = virXPathNodeSet(conn, "/node/domain", ctxt, &domains);
if (ret < 0) {
- testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node domain list"));
+ testError(NULL, VIR_ERR_XML_ERROR, _("node domain list"));
goto error;
}
char *absFile = testBuildFilename(file, relFile);
VIR_FREE(relFile);
if (!absFile) {
- testError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("resolving domain filename"));
+ testError(NULL, VIR_ERR_INTERNAL_ERROR, _("resolving domain filename"));
goto error;
}
def = virDomainDefParseFile(conn, privconn->caps, absFile);
ret = virXPathNodeSet(conn, "/node/network", ctxt, &networks);
if (ret < 0) {
- testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node network list"));
+ testError(NULL, VIR_ERR_XML_ERROR, _("node network list"));
goto error;
}
for (i = 0 ; i < ret ; i++) {
char *absFile = testBuildFilename(file, relFile);
VIR_FREE(relFile);
if (!absFile) {
- testError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("resolving network filename"));
+ testError(NULL, VIR_ERR_INTERNAL_ERROR, _("resolving network filename"));
goto error;
}
if (!uri->path
|| uri->path[0] == '\0'
|| (uri->path[0] == '/' && uri->path[1] == '\0')) {
- testError (NULL, NULL, NULL, VIR_ERR_INVALID_ARG,
+ testError (NULL, VIR_ERR_INVALID_ARG,
_("testOpen: supply a path or use test:///default"));
return VIR_DRV_OPEN_ERROR;
}
r = gethostname (hostname, HOST_NAME_MAX+1);
if (r == -1) {
- testError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR, "%s",
+ testError (conn, VIR_ERR_SYSTEM_ERROR, "%s",
strerror (errno));
return NULL;
}
str = strdup (hostname);
if (str == NULL) {
- testError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR, "%s",
+ testError (conn, VIR_ERR_SYSTEM_ERROR, "%s",
strerror (errno));
return NULL;
}
GET_CONNECTION(conn);
if (asprintf (&uri, "test://%s", privconn->path) == -1) {
- testError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR, "%s",
+ testError (conn, VIR_ERR_SYSTEM_ERROR, "%s",
strerror (errno));
return NULL;
}
GET_CONNECTION(conn);
if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL) {
- testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
+ testError(conn, VIR_ERR_NO_MEMORY, NULL);
return NULL;
}
GET_CONNECTION(conn);
if ((dom = virDomainFindByID(&privconn->domains, id)) == NULL) {
- testError (conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL);
+ testError (conn, VIR_ERR_NO_DOMAIN, NULL);
return NULL;
}
GET_CONNECTION(conn);
if ((dom = virDomainFindByUUID(&privconn->domains, uuid)) == NULL) {
- testError (conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL);
+ testError (conn, VIR_ERR_NO_DOMAIN, NULL);
return NULL;
}
GET_CONNECTION(conn);
if ((dom = virDomainFindByName(&privconn->domains, name)) == NULL) {
- testError (conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL);
+ testError (conn, VIR_ERR_NO_DOMAIN, NULL);
return NULL;
}
GET_DOMAIN(domain, -1);
if (privdom->state != VIR_DOMAIN_PAUSED) {
- testError(domain->conn, domain, NULL,
- VIR_ERR_INTERNAL_ERROR, _("domain not paused"));
+ testError(domain->conn,
+ VIR_ERR_INTERNAL_ERROR, _("domain '%s' not paused"),
+ domain->name);
return -1;
}
if (privdom->state == VIR_DOMAIN_SHUTOFF ||
privdom->state == VIR_DOMAIN_PAUSED) {
- testError(domain->conn, domain, NULL,
- VIR_ERR_INTERNAL_ERROR, _("domain not running"));
+ testError(domain->conn,
+ VIR_ERR_INTERNAL_ERROR, _("domain '%s' not running"),
+ domain->name);
return -1;
}
GET_DOMAIN(domain, -1);
if (privdom->state == VIR_DOMAIN_SHUTOFF) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR, "domain not running");
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
+ _("domain '%s' not running"), domain->name);
return -1;
}
GET_DOMAIN(domain, -1);
if (gettimeofday(&tv, NULL) < 0) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR, _("getting time of day"));
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
+ _("getting time of day"));
return (-1);
}
xml = testDomainDumpXML(domain, 0);
if (xml == NULL) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot allocate space for metadata"));
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
+ _("saving domain '%s' failed to allocate space for metadata: %s"),
+ domain->name, strerror(errno));
return (-1);
}
if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot save domain"));
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
+ _("saving domain '%s' to '%s': open failed: %s"),
+ domain->name, path, strerror(errno));
return (-1);
}
len = strlen(xml);
if (safewrite(fd, TEST_SAVE_MAGIC, sizeof(TEST_SAVE_MAGIC)) < 0) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot write header"));
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
+ _("saving domain '%s' to '%s': write failed: %s"),
+ domain->name, path, strerror(errno));
close(fd);
return (-1);
}
if (safewrite(fd, (char*)&len, sizeof(len)) < 0) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot write metadata length"));
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
+ _("saving domain '%s' to '%s': write failed: %s"),
+ domain->name, path, strerror(errno));
close(fd);
return (-1);
}
if (safewrite(fd, xml, len) < 0) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot write metadata"));
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
+ _("saving domain '%s' to '%s': write failed: %s"),
+ domain->name, path, strerror(errno));
VIR_FREE(xml);
close(fd);
return (-1);
}
VIR_FREE(xml);
if (close(fd) < 0) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot save domain data"));
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
+ _("saving domain '%s' to '%s': write failed: %s"),
+ domain->name, path, strerror(errno));
close(fd);
return (-1);
}
GET_CONNECTION(conn);
if ((fd = open(path, O_RDONLY)) < 0) {
- testError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(conn, VIR_ERR_INTERNAL_ERROR,
_("cannot read domain image"));
return (-1);
}
if (read(fd, magic, sizeof(magic)) != sizeof(magic)) {
- testError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(conn, VIR_ERR_INTERNAL_ERROR,
_("incomplete save header"));
close(fd);
return (-1);
}
if (memcmp(magic, TEST_SAVE_MAGIC, sizeof(magic))) {
- testError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(conn, VIR_ERR_INTERNAL_ERROR,
_("mismatched header magic"));
close(fd);
return (-1);
}
if (read(fd, (char*)&len, sizeof(len)) != sizeof(len)) {
- testError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(conn, VIR_ERR_INTERNAL_ERROR,
_("failed to read metadata length"));
close(fd);
return (-1);
}
if (len < 1 || len > 8192) {
- testError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(conn, VIR_ERR_INTERNAL_ERROR,
_("length of metadata out of range"));
close(fd);
return (-1);
}
if (VIR_ALLOC_N(xml, len+1) < 0) {
- testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "xml");
+ testError(conn, VIR_ERR_NO_MEMORY, "xml");
close(fd);
return (-1);
}
if (read(fd, xml, len) != len) {
- testError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(conn, VIR_ERR_INTERNAL_ERROR,
_("incomplete metdata"));
close(fd);
return (-1);
GET_DOMAIN(domain, -1);
if ((fd = open(to, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot save domain core"));
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
+ _("domain '%s' coredump: failed to open %s: %s"),
+ domain->name, to, strerror (errno));
return (-1);
}
if (safewrite(fd, TEST_SAVE_MAGIC, sizeof(TEST_SAVE_MAGIC)) < 0) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot write header"));
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
+ _("domain '%s' coredump: failed to write header to %s: %s"),
+ domain->name, to, strerror (errno));
close(fd);
return (-1);
}
if (close(fd) < 0) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot save domain data"));
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
+ _("domain '%s' coredump: write failed: %s: %s"),
+ domain->name, to, strerror (errno));
close(fd);
return (-1);
}
static char *testGetOSType(virDomainPtr dom) {
char *ret = strdup("linux");
if (!ret)
- testError(dom->conn, dom, NULL, VIR_ERR_NO_MEMORY, NULL);
+ testError(dom->conn, VIR_ERR_NO_MEMORY, NULL);
return ret;
}
GET_DOMAIN(domain, -1);
if (memory > privdom->def->maxmem) {
- testError(domain->conn, domain, NULL,
+ testError(domain->conn,
VIR_ERR_INVALID_ARG, __FUNCTION__);
return (-1);
}
/* We allow more cpus in guest than host */
if (nrCpus > 32) {
- testError(domain->conn, domain, NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
+ testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
return (-1);
}
return n;
no_memory:
- testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
+ testError(conn, VIR_ERR_NO_MEMORY, NULL);
for (n = 0 ; n < maxnames ; n++)
VIR_FREE(names[n]);
return -1;
GET_CONNECTION(conn);
if (startCell > privconn->numCells) {
- testError(conn, NULL, NULL, VIR_ERR_INVALID_ARG,
+ testError(conn, VIR_ERR_INVALID_ARG,
_("Range exceeds available cells"));
return -1;
}
GET_DOMAIN(domain, -1);
if (privdom->state != VIR_DOMAIN_SHUTOFF) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Domain is already running"));
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
+ _("Domain '%s' is already running"), domain->name);
return (-1);
}
GET_DOMAIN(domain, -1);
if (privdom->state != VIR_DOMAIN_SHUTOFF) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Domain is still running"));
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
+ _("Domain '%s' is still running"), domain->name);
return (-1);
}
*nparams = 1;
type = strdup("fair");
if (!type) {
- testError(domain->conn, domain, NULL, VIR_ERR_NO_MEMORY, "schedular");
+ testError(domain->conn, VIR_ERR_NO_MEMORY, "schedular");
return (NULL);
}
return type;
{
GET_DOMAIN(domain, -1);
if (*nparams != 1) {
- testError(domain->conn, domain, NULL, VIR_ERR_INVALID_ARG, "nparams");
+ testError(domain->conn, VIR_ERR_INVALID_ARG, "nparams");
return (-1);
}
strcpy(params[0].field, "weight");
{
GET_DOMAIN(domain, -1);
if (nparams != 1) {
- testError(domain->conn, domain, NULL, VIR_ERR_INVALID_ARG, "nparams");
+ testError(domain->conn, VIR_ERR_INVALID_ARG, "nparams");
return (-1);
}
if (STRNEQ(params[0].field, "weight")) {
- testError(domain->conn, domain, NULL, VIR_ERR_INVALID_ARG, "field");
+ testError(domain->conn, VIR_ERR_INVALID_ARG, "field");
return (-1);
}
if (params[0].type != VIR_DOMAIN_SCHED_FIELD_UINT) {
- testError(domain->conn, domain, NULL, VIR_ERR_INVALID_ARG, "type");
+ testError(domain->conn, VIR_ERR_INVALID_ARG, "type");
return (-1);
}
/* XXX */
GET_CONNECTION(conn);
if ((net = virNetworkFindByUUID(&privconn->networks, uuid)) == NULL) {
- testError (conn, NULL, NULL, VIR_ERR_NO_NETWORK, NULL);
+ testError (conn, VIR_ERR_NO_NETWORK, NULL);
return NULL;
}
GET_CONNECTION(conn);
if ((net = virNetworkFindByName(&privconn->networks, name)) == NULL) {
- testError (conn, NULL, NULL, VIR_ERR_NO_NETWORK, NULL);
+ testError (conn, VIR_ERR_NO_NETWORK, NULL);
return NULL;
}
return n;
no_memory:
- testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
+ testError(conn, VIR_ERR_NO_MEMORY, NULL);
for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]);
return (-1);
return n;
no_memory:
- testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
+ testError(conn, VIR_ERR_NO_MEMORY, NULL);
for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]);
return (-1);
GET_NETWORK(network, -1);
if (virNetworkIsActive(privnet)) {
- testError(network->conn, NULL, network, VIR_ERR_INTERNAL_ERROR,
- _("Network is still running"));
+ testError(network->conn, VIR_ERR_INTERNAL_ERROR,
+ _("Network '%s' is still running"), network->name);
return (-1);
}
GET_NETWORK(network, -1);
if (virNetworkIsActive(privnet)) {
- testError(network->conn, NULL, network, VIR_ERR_INTERNAL_ERROR,
- _("Network is already running"));
+ testError(network->conn, VIR_ERR_INTERNAL_ERROR,
+ _("Network '%s' is already running"), network->name);
return (-1);
}
GET_NETWORK(network, NULL);
if (privnet->def->bridge &&
!(bridge = strdup(privnet->def->bridge))) {
- testError(network->conn, NULL, network, VIR_ERR_NO_MEMORY, "network");
+ testError(network->conn, VIR_ERR_NO_MEMORY, "network");
return NULL;
}
return bridge;