mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
VMware: Make version parsing testable and add tests
This splits up the version parsing code into a callable API like QEMU help/version string parsing so that we can test it as we need to add additional patterns for newer versions/products.
This commit is contained in:
parent
e7a1ce9d07
commit
7457cbe871
1
.gitignore
vendored
1
.gitignore
vendored
@ -217,6 +217,7 @@
|
|||||||
/tests/virsystemdtest
|
/tests/virsystemdtest
|
||||||
/tests/virtimetest
|
/tests/virtimetest
|
||||||
/tests/viruritest
|
/tests/viruritest
|
||||||
|
/tests/vmwarevertest
|
||||||
/tests/vmx2xmltest
|
/tests/vmx2xmltest
|
||||||
/tests/xencapstest
|
/tests/xencapstest
|
||||||
/tests/xmconfigtest
|
/tests/xmconfigtest
|
||||||
|
@ -1768,6 +1768,12 @@ else ! WITH_VMX
|
|||||||
SYM_FILES += $(srcdir)/libvirt_vmx.syms
|
SYM_FILES += $(srcdir)/libvirt_vmx.syms
|
||||||
endif ! WITH_VMX
|
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
|
if WITH_XENXS
|
||||||
USED_SYM_FILES += $(srcdir)/libvirt_xenxs.syms
|
USED_SYM_FILES += $(srcdir)/libvirt_xenxs.syms
|
||||||
else ! WITH_XENXS
|
else ! WITH_XENXS
|
||||||
|
12
src/libvirt_vmware.syms
Normal file
12
src/libvirt_vmware.syms
Normal file
@ -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:
|
@ -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
|
int
|
||||||
vmwareExtractVersion(struct vmware_driver *driver)
|
vmwareExtractVersion(struct vmware_driver *driver)
|
||||||
{
|
{
|
||||||
unsigned long version = 0;
|
unsigned long version = 0;
|
||||||
char *tmp;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virCommandPtr cmd;
|
virCommandPtr cmd;
|
||||||
char * outbuf = NULL;
|
char * outbuf = NULL;
|
||||||
const char * bin = (driver->type == VMWARE_DRIVER_PLAYER) ?
|
const char * bin = (driver->type == VMWARE_DRIVER_PLAYER) ?
|
||||||
"vmplayer" : "vmware";
|
"vmplayer" : "vmware";
|
||||||
const char * pattern = (driver->type == VMWARE_DRIVER_PLAYER) ?
|
|
||||||
"VMware Player " : "VMware Workstation ";
|
|
||||||
|
|
||||||
cmd = virCommandNewArgList(bin, "-v", NULL);
|
cmd = virCommandNewArgList(bin, "-v", NULL);
|
||||||
virCommandSetOutputBuffer(cmd, &outbuf);
|
virCommandSetOutputBuffer(cmd, &outbuf);
|
||||||
@ -237,19 +268,9 @@ vmwareExtractVersion(struct vmware_driver *driver)
|
|||||||
if (virCommandRun(cmd, NULL) < 0)
|
if (virCommandRun(cmd, NULL) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((tmp = STRSKIP(outbuf, pattern)) == NULL) {
|
if (vmwareParseVersionStr(driver->type, outbuf, &version) < 0)
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("failed to parse %s version"), bin);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (virParseVersionString(tmp, &version, false) < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("version parsing error"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
driver->version = version;
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
@ -66,6 +66,8 @@ void vmwareSetSentinal(const char **prog, const char *key);
|
|||||||
|
|
||||||
int vmwareExtractVersion(struct vmware_driver *driver);
|
int vmwareExtractVersion(struct vmware_driver *driver);
|
||||||
|
|
||||||
|
int vmwareParseVersionStr(int type, const char *buf, unsigned long *version);
|
||||||
|
|
||||||
int vmwareDomainConfigDisplay(vmwareDomainPtr domain, virDomainDefPtr vmdef);
|
int vmwareDomainConfigDisplay(vmwareDomainPtr domain, virDomainDefPtr vmdef);
|
||||||
|
|
||||||
int vmwareParsePath(char *path, char **directory, char **filename);
|
int vmwareParsePath(char *path, char **directory, char **filename);
|
||||||
|
@ -107,6 +107,7 @@ EXTRA_DIST = \
|
|||||||
xmconfigdata \
|
xmconfigdata \
|
||||||
xml2sexprdata \
|
xml2sexprdata \
|
||||||
xml2vmxdata \
|
xml2vmxdata \
|
||||||
|
vmwareverdata \
|
||||||
.valgrind.supp
|
.valgrind.supp
|
||||||
|
|
||||||
test_helpers = commandhelper ssh test_conf
|
test_helpers = commandhelper ssh test_conf
|
||||||
@ -188,6 +189,10 @@ if WITH_VMX
|
|||||||
test_programs += vmx2xmltest xml2vmxtest
|
test_programs += vmx2xmltest xml2vmxtest
|
||||||
endif WITH_VMX
|
endif WITH_VMX
|
||||||
|
|
||||||
|
if WITH_VMWARE
|
||||||
|
test_programs += vmwarevertest
|
||||||
|
endif WITH_VMWARE
|
||||||
|
|
||||||
if WITH_CIL
|
if WITH_CIL
|
||||||
test_programs += object-locking
|
test_programs += object-locking
|
||||||
endif WITH_CIL
|
endif WITH_CIL
|
||||||
@ -507,6 +512,15 @@ else ! WITH_VMX
|
|||||||
EXTRA_DIST += vmx2xmltest.c xml2vmxtest.c
|
EXTRA_DIST += vmx2xmltest.c xml2vmxtest.c
|
||||||
endif ! WITH_VMX
|
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_SOURCES = \
|
||||||
networkxml2xmltest.c \
|
networkxml2xmltest.c \
|
||||||
testutils.c testutils.h
|
testutils.c testutils.h
|
||||||
|
1
tests/vmwareverdata/workstation-7.0.0.txt
Normal file
1
tests/vmwareverdata/workstation-7.0.0.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
VMware Workstation 7.0.0 build-203739 Release
|
105
tests/vmwarevertest.c
Normal file
105
tests/vmwarevertest.c
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013. Doug Goldstein <cardoe@cardoe.com>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#include "testutils.h"
|
||||||
|
|
||||||
|
#ifdef WITH_VMWARE
|
||||||
|
|
||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
|
||||||
|
# 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 */
|
Loading…
Reference in New Issue
Block a user