diff --git a/.gitignore b/.gitignore index d70d0dd0a5a88d0defdc1e88cee75a987acac7ee..edd5d26180c178690e40573f6c7e223363f416a7 100644 --- a/.gitignore +++ b/.gitignore @@ -217,6 +217,7 @@ /tests/virsystemdtest /tests/virtimetest /tests/viruritest +/tests/vmwarevertest /tests/vmx2xmltest /tests/xencapstest /tests/xmconfigtest diff --git a/src/Makefile.am b/src/Makefile.am index 1388c5fdb5b9519028774646367679f7db327bf0..4375ef7835ced02e03cfd78caa65a1ee8f42531e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1768,6 +1768,12 @@ else ! WITH_VMX SYM_FILES += $(srcdir)/libvirt_vmx.syms endif ! WITH_VMX +if WITH_VMWARE +USED_SYM_FILES += $(srcdir)/libvirt_vmware.syms +else ! WITH_VMWARE +SYM_FILES += $(srcdir)/libvirt_vmware.syms +endif ! WITH_VMWARE + if WITH_XENXS USED_SYM_FILES += $(srcdir)/libvirt_xenxs.syms else ! WITH_XENXS diff --git a/src/libvirt_vmware.syms b/src/libvirt_vmware.syms new file mode 100644 index 0000000000000000000000000000000000000000..c64a7d5ee065d12e8b1cdd32eacc74e3cfaf9b4e --- /dev/null +++ b/src/libvirt_vmware.syms @@ -0,0 +1,12 @@ +# +# These symbols are dependent upon --with-vmware via WITH_VMWARE. +# + +# vmware/vmware_conf.h +vmwareDriverTypeFromString; +vmwareParseVersionStr; + +# Let emacs know we want case-insensitive sorting +# Local Variables: +# sort-fold-case: t +# End: diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index b33bddc11c36d8bff4284272319e4b96b9f68c5a..261a4f6e5d2676c02ad151e93211a5f171e514ec 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -218,18 +218,49 @@ vmwareSetSentinal(const char **prog, const char *key) } } +int +vmwareParseVersionStr(int type, const char *verbuf, unsigned long *version) +{ + const char *pattern; + const char *tmp; + + switch (type) { + case VMWARE_DRIVER_PLAYER: + pattern = "VMware Player "; + break; + case VMWARE_DRIVER_WORKSTATION: + pattern = "VMware Workstation "; + break; + default: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid driver type: %d"), type); + return -1; + } + + if ((tmp = STRSKIP(verbuf, pattern)) == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse %sversion"), pattern); + return -1; + } + + if (virParseVersionString(tmp, version, false) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("version parsing error")); + return -1; + } + + return 0; +} + int vmwareExtractVersion(struct vmware_driver *driver) { unsigned long version = 0; - char *tmp; int ret = -1; virCommandPtr cmd; char * outbuf = NULL; const char * bin = (driver->type == VMWARE_DRIVER_PLAYER) ? "vmplayer" : "vmware"; - const char * pattern = (driver->type == VMWARE_DRIVER_PLAYER) ? - "VMware Player " : "VMware Workstation "; cmd = virCommandNewArgList(bin, "-v", NULL); virCommandSetOutputBuffer(cmd, &outbuf); @@ -237,19 +268,9 @@ vmwareExtractVersion(struct vmware_driver *driver) if (virCommandRun(cmd, NULL) < 0) goto cleanup; - if ((tmp = STRSKIP(outbuf, pattern)) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to parse %s version"), bin); + if (vmwareParseVersionStr(driver->type, outbuf, &version) < 0) goto cleanup; - } - - if (virParseVersionString(tmp, &version, false) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("version parsing error")); - goto cleanup; - } - driver->version = version; ret = 0; cleanup: diff --git a/src/vmware/vmware_conf.h b/src/vmware/vmware_conf.h index 4b99d8e449eff0398906d67d8e4d08aeec4f083d..a4fd8550ab60c7f6de2500347a4ea96e718d0551 100644 --- a/src/vmware/vmware_conf.h +++ b/src/vmware/vmware_conf.h @@ -66,6 +66,8 @@ void vmwareSetSentinal(const char **prog, const char *key); int vmwareExtractVersion(struct vmware_driver *driver); +int vmwareParseVersionStr(int type, const char *buf, unsigned long *version); + int vmwareDomainConfigDisplay(vmwareDomainPtr domain, virDomainDefPtr vmdef); int vmwareParsePath(char *path, char **directory, char **filename); diff --git a/tests/Makefile.am b/tests/Makefile.am index b1d6dab4c09c7b6a87387923f1ffc8f4c181dc64..fe3681031ef8880835e836d12519a29882e72831 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -107,6 +107,7 @@ EXTRA_DIST = \ xmconfigdata \ xml2sexprdata \ xml2vmxdata \ + vmwareverdata \ .valgrind.supp test_helpers = commandhelper ssh test_conf @@ -188,6 +189,10 @@ if WITH_VMX test_programs += vmx2xmltest xml2vmxtest endif WITH_VMX +if WITH_VMWARE +test_programs += vmwarevertest +endif WITH_VMWARE + if WITH_CIL test_programs += object-locking endif WITH_CIL @@ -507,6 +512,15 @@ else ! WITH_VMX EXTRA_DIST += vmx2xmltest.c xml2vmxtest.c endif ! WITH_VMX +if WITH_VMWARE +vmwarevertest_SOURCES = \ + vmwarevertest.c \ + testutils.c testutils.h +vmwarevertest_LDADD = $(LDADDS) +else ! WITH_VMWARE +EXTRA_DIST += vmwarevertest.c +endif ! WITH_VMWARE + networkxml2xmltest_SOURCES = \ networkxml2xmltest.c \ testutils.c testutils.h diff --git a/tests/vmwareverdata/workstation-7.0.0.txt b/tests/vmwareverdata/workstation-7.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..207b71c10aba4bac63717f744670cfc543cc89b6 --- /dev/null +++ b/tests/vmwareverdata/workstation-7.0.0.txt @@ -0,0 +1 @@ +VMware Workstation 7.0.0 build-203739 Release diff --git a/tests/vmwarevertest.c b/tests/vmwarevertest.c new file mode 100644 index 0000000000000000000000000000000000000000..f5ccb06fb994b500f143b7d6b53fb9c7818cd0aa --- /dev/null +++ b/tests/vmwarevertest.c @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2013. Doug Goldstein + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "testutils.h" + +#ifdef WITH_VMWARE + +# include +# include + +# include "vmware/vmware_conf.h" + +//# define VIR_FROM_THIS VIR_FROM_NONE + +struct testInfo { + const char *vmware_type; + const char *name; + unsigned long version; +}; + +static int +testVerStrParse(const void *data) +{ + const struct testInfo *info = data; + int ret = -1; + char *path = NULL; + char *databuf = NULL; + unsigned long version; + int vmware_type; + + if (virAsprintf(&path, "%s/vmwareverdata/%s.txt", abs_srcdir, + info->name) < 0) + return -1; + + if (virtTestLoadFile(path, &databuf) < 0) + goto cleanup; + + if ((vmware_type = vmwareDriverTypeFromString(info->vmware_type)) < 0) + goto cleanup; + + if (vmwareParseVersionStr(vmware_type, databuf, &version) < 0) + goto cleanup; + + if (version != info->version) { + fprintf(stderr, "%s: parsed versions do not match: got %lu, " + "expected %lu\n", info->name, version, info->version); + goto cleanup; + } + + ret = 0; + +cleanup: + VIR_FREE(path); + VIR_FREE(databuf); + return ret; +} + +static int +mymain(void) +{ + int ret = 0; + +# define DO_TEST(vmware_type, name, version) \ + do { \ + struct testInfo info = { \ + vmware_type, name, version \ + }; \ + if (virtTestRun("VMware Version String Parsing " name, \ + 1, testVerStrParse, &info) < 0) \ + ret = -1; \ + } while (0) + + DO_TEST("ws", "workstation-7.0.0", 7000000); + + return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +VIRT_TEST_MAIN(mymain) + +#else + +int +main(void) +{ + return EXIT_AM_SKIP; +} + +#endif /* WITH_VMWARE */