2011-05-26 17:45:41 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2013-04-16 13:41:44 +00:00
|
|
|
#include "testutils.h"
|
|
|
|
|
2011-05-26 17:45:41 +00:00
|
|
|
#ifdef WITH_OPENVZ
|
|
|
|
|
|
|
|
# include <stdio.h>
|
|
|
|
# include <string.h>
|
|
|
|
# include <unistd.h>
|
|
|
|
|
|
|
|
# include "internal.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
# include "viralloc.h"
|
2011-05-26 17:45:41 +00:00
|
|
|
# include "openvz/openvz_conf.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
# include "virstring.h"
|
2011-05-26 17:45:41 +00:00
|
|
|
|
2013-05-03 12:52:21 +00:00
|
|
|
# define VIR_FROM_THIS VIR_FROM_OPENVZ
|
|
|
|
|
2011-05-31 12:58:58 +00:00
|
|
|
static int
|
|
|
|
testLocateConfFile(int vpsid ATTRIBUTE_UNUSED, char **conffile,
|
|
|
|
const char *ext ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
return virAsprintf(conffile, "%s/openvzutilstest.conf", abs_srcdir);
|
|
|
|
}
|
|
|
|
|
2011-05-26 17:45:41 +00:00
|
|
|
struct testConfigParam {
|
|
|
|
const char *param;
|
|
|
|
const char *value;
|
|
|
|
int ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct testConfigParam configParams[] = {
|
|
|
|
{ "OSTEMPLATE", "rhel-5-lystor", 1 },
|
|
|
|
{ "IP_ADDRESS", "194.44.18.88", 1 },
|
|
|
|
{ "THIS_PARAM_IS_MISSING", NULL, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
testReadConfigParam(const void *data ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
int result = -1;
|
Convert 'int i' to 'size_t i' in tests/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2011-05-26 17:45:41 +00:00
|
|
|
char *conf = NULL;
|
|
|
|
char *value = NULL;
|
|
|
|
|
2014-11-13 14:20:43 +00:00
|
|
|
if (virAsprintf(&conf, "%s/openvzutilstest.conf", abs_srcdir) < 0)
|
2011-05-26 17:45:41 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_CARDINALITY(configParams); ++i) {
|
|
|
|
if (openvzReadConfigParam(conf, configParams[i].param,
|
|
|
|
&value) != configParams[i].ret) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:20:43 +00:00
|
|
|
if (configParams[i].ret != 1)
|
2011-05-26 17:45:41 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (STRNEQ(configParams[i].value, value)) {
|
|
|
|
virtTestDifference(stderr, configParams[i].value, value);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2011-05-26 17:45:41 +00:00
|
|
|
VIR_FREE(conf);
|
|
|
|
VIR_FREE(value);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-05-31 12:58:58 +00:00
|
|
|
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"
|
2012-02-23 00:48:38 +00:00
|
|
|
" <memory unit='KiB'>0</memory>\n"
|
|
|
|
" <currentMemory unit='KiB'>0</currentMemory>\n"
|
2012-05-08 16:04:36 +00:00
|
|
|
" <vcpu placement='static'>0</vcpu>\n"
|
2011-05-31 12:58:58 +00:00
|
|
|
" <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"
|
2014-07-22 09:09:48 +00:00
|
|
|
" <ip address='194.44.18.88' family='ipv4'/>\n"
|
2011-05-31 12:58:58 +00:00
|
|
|
" </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 ||
|
2013-05-03 12:52:21 +00:00
|
|
|
VIR_STRDUP(def->os.type, "exe") < 0 ||
|
|
|
|
VIR_STRDUP(def->os.init, "/sbin/init") < 0)
|
2011-05-31 12:58:58 +00:00
|
|
|
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;
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2011-05-31 12:58:58 +00:00
|
|
|
VIR_FREE(actual);
|
|
|
|
virDomainDefFree(def);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-05-26 17:45:41 +00:00
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
|
2011-05-31 12:58:58 +00:00
|
|
|
openvzLocateConfFile = testLocateConfFile;
|
|
|
|
|
2011-05-26 17:45:41 +00:00
|
|
|
# define DO_TEST(_name) \
|
|
|
|
do { \
|
2013-09-20 18:13:35 +00:00
|
|
|
if (virtTestRun("OpenVZ "#_name, test##_name, \
|
2011-05-26 17:45:41 +00:00
|
|
|
NULL) < 0) { \
|
|
|
|
result = -1; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
DO_TEST(ReadConfigParam);
|
2011-05-31 12:58:58 +00:00
|
|
|
DO_TEST(ReadNetworkConf);
|
2011-05-26 17:45:41 +00:00
|
|
|
|
|
|
|
return result == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIRT_TEST_MAIN(mymain)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
return EXIT_AM_SKIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* WITH_OPENVZ */
|