[libvirt] [PATCH] openvz: Add simple test for openvzReadNetworkConf
by Matthias Bolte
Convert openvzLocateConfFile to a replaceable callback to allow
testing the config file parsing without rewriting the whole OpenVZ
config parsing to a more testable structure.
Also ignore the openvzutilstest binary.
---
src/openvz/openvz_conf.c | 28 +++++++++++----
src/openvz/openvz_conf.h | 6 +++
tests/.gitignore | 1 +
tests/openvzutilstest.c | 78 ++++++++++++++++++++++++++++++++++++++++++++
tests/openvzutilstest.conf | 1 +
5 files changed, 106 insertions(+), 8 deletions(-)
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 6e32242..bba4e6f 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -60,6 +60,9 @@ static char *openvzLocateConfDir(void);
static int openvzGetVPSUUID(int vpsid, char *uuidstr, size_t len);
static int openvzLocateConfFile(int vpsid, char **conffile, const char *ext);
static int openvzAssignUUIDs(void);
+static int openvzLocateConfFileDefault(int vpsid, char **conffile, const char *ext);
+
+openvzLocateConfFileFunc openvzLocateConfFileCallback = openvzLocateConfFileDefault;
int
strtoI(const char *str)
@@ -171,7 +174,7 @@ no_memory:
}
-static int
+int
openvzReadNetworkConf(virDomainDefPtr def,
int veid) {
int ret;
@@ -473,6 +476,8 @@ int openvzLoadDomains(struct openvz_driver *driver) {
if (VIR_ALLOC(dom->def) < 0)
goto no_memory;
+ dom->def->virtType = VIR_DOMAIN_VIRT_OPENVZ;
+
if (STREQ(status, "stopped")) {
virDomainObjSetState(dom, VIR_DOMAIN_SHUTOFF,
VIR_DOMAIN_SHUTOFF_UNKNOWN);
@@ -793,12 +798,9 @@ cleanup:
return ret;
}
-/* Locate config file of container
-* return -1 - error
-* 0 - OK
-*/
+
static int
-openvzLocateConfFile(int vpsid, char **conffile, const char *ext)
+openvzLocateConfFileDefault(int vpsid, char **conffile, const char *ext)
{
char * confdir;
int ret = 0;
@@ -817,8 +819,18 @@ openvzLocateConfFile(int vpsid, char **conffile, const char *ext)
return ret;
}
-static char
-*openvzLocateConfDir(void)
+/* Locate config file of container
+ * return -1 - error
+ * 0 - OK
+ */
+static int
+openvzLocateConfFile(int vpsid, char **conffile, const char *ext)
+{
+ return openvzLocateConfFileCallback(vpsid, conffile, ext);
+}
+
+static char *
+openvzLocateConfDir(void)
{
const char *conf_dir_list[] = {"/etc/vz/conf", "/usr/local/etc/conf", NULL};
int i=0;
diff --git a/src/openvz/openvz_conf.h b/src/openvz/openvz_conf.h
index d5a57a6..182ebae 100644
--- a/src/openvz/openvz_conf.h
+++ b/src/openvz/openvz_conf.h
@@ -53,6 +53,11 @@ struct openvz_driver {
int version;
};
+typedef int (*openvzLocateConfFileFunc)(int vpsid, char **conffile, const char *ext);
+
+/* this allows the testsuite to replace the conf file locator function */
+extern openvzLocateConfFileFunc openvzLocateConfFileCallback;
+
int openvz_readline(int fd, char *ptr, int maxlen);
int openvzExtractVersion(struct openvz_driver *driver);
int openvzReadVPSConfigParam(int vpsid, const char *param, char **value);
@@ -66,5 +71,6 @@ int strtoI(const char *str);
int openvzSetDefinedUUID(int vpsid, unsigned char *uuid);
unsigned int openvzGetNodeCPUs(void);
int openvzGetVEID(const char *name);
+int openvzReadNetworkConf(virDomainDefPtr def, int veid);
#endif /* OPENVZ_CONF_H */
diff --git a/tests/.gitignore b/tests/.gitignore
index e3906f0..749b5b9 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -16,6 +16,7 @@ object-locking
object-locking-files.txt
object-locking.cmi
object-locking.cmx
+openvzutilstest
qemuargv2xmltest
qemuhelptest
qemuxml2argvtest
diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c
index fe6a2ea..567131a 100644
--- a/tests/openvzutilstest.c
+++ b/tests/openvzutilstest.c
@@ -12,6 +12,13 @@
# include "util.h"
# include "openvz/openvz_conf.h"
+static int
+testLocateConfFile(int vpsid ATTRIBUTE_UNUSED, char **conffile,
+ const char *ext ATTRIBUTE_UNUSED)
+{
+ return virAsprintf(conffile, "%s/openvzutilstest.conf", abs_srcdir);
+}
+
struct testConfigParam {
const char *param;
const char *value;
@@ -62,10 +69,80 @@ cleanup:
}
static int
+testReadNetworkConf(const void *data ATTRIBUTE_UNUSED)
+{
+ int result = -1;
+ virDomainDefPtr def = NULL;
+ char *actual = NULL;
+ virErrorPtr err = NULL;
+ const char *expected =
+ "<domain type='openvz'>\n"
+ " <uuid>00000000-0000-0000-0000-000000000000</uuid>\n"
+ " <memory>0</memory>\n"
+ " <currentMemory>0</currentMemory>\n"
+ " <vcpu>0</vcpu>\n"
+ " <os>\n"
+ " <type>exe</type>\n"
+ " <init>/sbin/init</init>\n"
+ " </os>\n"
+ " <clock offset='utc'/>\n"
+ " <on_poweroff>destroy</on_poweroff>\n"
+ " <on_reboot>destroy</on_reboot>\n"
+ " <on_crash>destroy</on_crash>\n"
+ " <devices>\n"
+ " <interface type='ethernet'>\n"
+ " <mac address='00:00:00:00:00:00'/>\n"
+ " <ip address='194.44.18.88'/>\n"
+ " </interface>\n"
+ " <interface type='bridge'>\n"
+ " <mac address='00:18:51:c1:05:ee'/>\n"
+ " <target dev='veth105.10'/>\n"
+ " </interface>\n"
+ " </devices>\n"
+ "</domain>\n";
+
+ if (VIR_ALLOC(def) < 0 ||
+ !(def->os.type = strdup("exe")) ||
+ !(def->os.init = strdup("/sbin/init")))
+ goto cleanup;
+
+ def->virtType = VIR_DOMAIN_VIRT_OPENVZ;
+
+ if (openvzReadNetworkConf(def, 1) < 0) {
+ err = virGetLastError();
+ fprintf(stderr, "ERROR: %s\n", err != NULL ? err->message : "<unknown>");
+ goto cleanup;
+ }
+
+ actual = virDomainDefFormat(def, VIR_DOMAIN_XML_INACTIVE);
+
+ if (actual == NULL) {
+ err = virGetLastError();
+ fprintf(stderr, "ERROR: %s\n", err != NULL ? err->message : "<unknown>");
+ goto cleanup;
+ }
+
+ if (STRNEQ(expected, actual)) {
+ virtTestDifference(stderr, expected, actual);
+ goto cleanup;
+ }
+
+ result = 0;
+
+cleanup:
+ VIR_FREE(actual);
+ virDomainDefFree(def);
+
+ return result;
+}
+
+static int
mymain(void)
{
int result = 0;
+ openvzLocateConfFileCallback = testLocateConfFile;
+
# define DO_TEST(_name) \
do { \
if (virtTestRun("OpenVZ "#_name, 1, test##_name, \
@@ -75,6 +152,7 @@ mymain(void)
} while (0)
DO_TEST(ReadConfigParam);
+ DO_TEST(ReadNetworkConf);
return result == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
diff --git a/tests/openvzutilstest.conf b/tests/openvzutilstest.conf
index a1b93b7..c5d048c 100644
--- a/tests/openvzutilstest.conf
+++ b/tests/openvzutilstest.conf
@@ -39,3 +39,4 @@ QUOTATIME=""
DISK_QUOTA=no
OSTEMPLATE="rhel-5-lystor"
IP_ADDRESS="194.44.18.88"
+NETIF="ifname=eth10,mac=00:18:51:C1:05:EE,host_ifname=veth105.10,host_mac=00:18:51:8F:D9:F3
--
1.7.0.4
13 years, 5 months
[libvirt] [PATCH] openvz: Set virtType to openvz in openvzLoadDomains
by Matthias Bolte
Otherwise virsh dumpxml will report <domain type='qemu'> instead
of the expected <domain type='openvz'>.
---
I pushed this one as Eric already ACK'ed it as part of another patch [1]
where I accientially included it and Jean-Baptiste confirmed that the
problem exists [2].
[1] https://www.redhat.com/archives/libvir-list/2011-May/msg01886.html
[2] https://www.redhat.com/archives/libvir-list/2011-May/msg01887.html
src/openvz/openvz_conf.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 7c76e6b..9ce92dc 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -473,6 +473,8 @@ int openvzLoadDomains(struct openvz_driver *driver) {
if (VIR_ALLOC(dom->def) < 0)
goto no_memory;
+ dom->def->virtType = VIR_DOMAIN_VIRT_OPENVZ;
+
if (STREQ(status, "stopped")) {
virDomainObjSetState(dom, VIR_DOMAIN_SHUTOFF,
VIR_DOMAIN_SHUTOFF_UNKNOWN);
--
1.7.0.4
13 years, 5 months
[libvirt] virsh version problem with remote connection
by Matthias Bolte
virsh version does basically this
hvType = virConnectGetType(...)
virGetVersion(..., hvType, ...)
[...]
Assuming a remote connection virConnectGetType calls the remote driver
that returns the type of the underlying driver on the server side, for
example QEMU. Then virGetVersion compares hvType to a set of strings
that depend on configure options and returns LIBVIR_VERSION_NUMBER in
most cases. Now this fails in case libvirt on the client side is just
compiled with the remote driver enabled and the server side has the
actual driver such as the QEMU driver. It just happens to work when
the actual driver is compiled in on client and server side. But that's
not the case here.
freebsd# ./tools/virsh -c qemu+tcp://192.168.178.22/system version
Compiled against library: libvir 0.9.2
error: failed to get the library version
error: this function is not supported by the connection driver: virGetVersion
This is not FreeBSD specific, happens on Windows as well due to the
similar drivers configuration. The problem is that virConnectGetType
returns QEMU, but virGetVersion on the client side only accepts Remote
as hvType due to all other drivers being disabled on the client side.
I'm not sure how to fix this properly, does anyone have some idea?
Matthias
13 years, 5 months
[libvirt] [PATCH] util: Fix incorrect error in PCI functions.
by Osier Yang
Substitute VIR_ERR_NO_SUPPORT with VIR_ERR_INTERNAL_ERROR. Error
like following is not what user want to see.
error : pciDeviceIsAssignable:1487 : this function is not supported
by the connection driver: Device 0000:07:10.0 is behind a switch
lacking ACS and cannot be assigned
---
src/util/pci.c | 20 ++++++++++----------
1 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/util/pci.c b/src/util/pci.c
index 9cc7b20..8baa3d8 100644
--- a/src/util/pci.c
+++ b/src/util/pci.c
@@ -614,7 +614,7 @@ pciTrySecondaryBusReset(pciDevice *dev,
* are not in use by the host or other guests.
*/
if ((conflict = pciBusContainsActiveDevices(dev, inactiveDevs))) {
- pciReportError(VIR_ERR_NO_SUPPORT,
+ pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Active %s devices on bus with %s, not doing bus reset"),
conflict->name, dev->name);
return -1;
@@ -624,7 +624,7 @@ pciTrySecondaryBusReset(pciDevice *dev,
if (pciGetParentDevice(dev, &parent) < 0)
return -1;
if (!parent) {
- pciReportError(VIR_ERR_NO_SUPPORT,
+ pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to find parent device for %s"),
dev->name);
return -1;
@@ -637,7 +637,7 @@ pciTrySecondaryBusReset(pciDevice *dev,
* are multiple devices/functions
*/
if (pciRead(dev, 0, config_space, PCI_CONF_LEN) < 0) {
- pciReportError(VIR_ERR_NO_SUPPORT,
+ pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to read PCI config space for %s"),
dev->name);
goto out;
@@ -657,7 +657,7 @@ pciTrySecondaryBusReset(pciDevice *dev,
usleep(200 * 1000); /* sleep 200ms */
if (pciWrite(dev, 0, config_space, PCI_CONF_LEN) < 0) {
- pciReportError(VIR_ERR_NO_SUPPORT,
+ pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to restore PCI config space for %s"),
dev->name);
goto out;
@@ -683,7 +683,7 @@ pciTryPowerManagementReset(pciDevice *dev)
/* Save and restore the device's config space. */
if (pciRead(dev, 0, &config_space[0], PCI_CONF_LEN) < 0) {
- pciReportError(VIR_ERR_NO_SUPPORT,
+ pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to read PCI config space for %s"),
dev->name);
return -1;
@@ -703,7 +703,7 @@ pciTryPowerManagementReset(pciDevice *dev)
usleep(10 * 1000); /* sleep 10ms */
if (pciWrite(dev, 0, &config_space[0], PCI_CONF_LEN) < 0) {
- pciReportError(VIR_ERR_NO_SUPPORT,
+ pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to restore PCI config space for %s"),
dev->name);
return -1;
@@ -770,7 +770,7 @@ pciResetDevice(pciDevice *dev,
if (ret < 0) {
virErrorPtr err = virGetLastError();
- pciReportError(VIR_ERR_NO_SUPPORT,
+ pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to reset PCI device %s: %s"),
dev->name,
err ? err->message : _("no FLR, PM reset or bus reset available"));
@@ -1324,7 +1324,7 @@ pciGetDevice(unsigned domain,
product = pciReadDeviceID(dev, "device");
if (!vendor || !product) {
- pciReportError(VIR_ERR_NO_SUPPORT,
+ pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to read product/vendor ID for %s"),
dev->name);
VIR_FREE(product);
@@ -1588,7 +1588,7 @@ pciDeviceIsBehindSwitchLackingACS(pciDevice *dev)
if (dev->bus == 0)
return 0;
else {
- pciReportError(VIR_ERR_NO_SUPPORT,
+ pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to find parent device for %s"),
dev->name);
return -1;
@@ -1643,7 +1643,7 @@ int pciDeviceIsAssignable(pciDevice *dev,
VIR_DEBUG("%s %s: strict ACS check disabled; device assignment allowed",
dev->id, dev->name);
} else {
- pciReportError(VIR_ERR_NO_SUPPORT,
+ pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Device %s is behind a switch lacking ACS and "
"cannot be assigned"),
dev->name);
--
1.7.4
13 years, 5 months