10 # include "viralloc.h"
11 # include "openvz/openvz_conf.h"
12 # include "virstring.h"
14 # define VIR_FROM_THIS VIR_FROM_OPENVZ
17 testLocateConfFile(int vpsid ATTRIBUTE_UNUSED
, char **conffile
,
18 const char *ext ATTRIBUTE_UNUSED
)
20 return virAsprintf(conffile
, "%s/openvzutilstest.conf", abs_srcdir
);
23 struct testConfigParam
{
29 static struct testConfigParam configParams
[] = {
30 { "OSTEMPLATE", "rhel-5-lystor", 1 },
31 { "IP_ADDRESS", "194.44.18.88", 1 },
32 { "THIS_PARAM_IS_MISSING", NULL
, 0 },
36 testReadConfigParam(const void *data ATTRIBUTE_UNUSED
)
43 if (virAsprintf(&conf
, "%s/openvzutilstest.conf", abs_srcdir
) < 0)
46 for (i
= 0; i
< ARRAY_CARDINALITY(configParams
); ++i
) {
47 if (openvzReadConfigParam(conf
, configParams
[i
].param
,
48 &value
) != configParams
[i
].ret
) {
52 if (configParams
[i
].ret
!= 1)
55 if (STRNEQ(configParams
[i
].value
, value
)) {
56 virTestDifference(stderr
, configParams
[i
].value
, value
);
71 testReadNetworkConf(const void *data ATTRIBUTE_UNUSED
)
74 virDomainDefPtr def
= NULL
;
76 const char *expected
=
77 "<domain type='openvz'>\n"
78 " <uuid>00000000-0000-0000-0000-000000000000</uuid>\n"
79 " <memory unit='KiB'>0</memory>\n"
80 " <currentMemory unit='KiB'>0</currentMemory>\n"
81 " <vcpu placement='static'>0</vcpu>\n"
84 " <init>/sbin/init</init>\n"
86 " <clock offset='utc'/>\n"
87 " <on_poweroff>destroy</on_poweroff>\n"
88 " <on_reboot>destroy</on_reboot>\n"
89 " <on_crash>destroy</on_crash>\n"
91 " <interface type='ethernet'>\n"
92 " <mac address='00:00:00:00:00:00'/>\n"
93 " <ip address='194.44.18.88' family='ipv4'/>\n"
95 " <interface type='bridge'>\n"
96 " <mac address='00:18:51:c1:05:ee'/>\n"
97 " <target dev='veth105.10'/>\n"
102 if (!(def
= virDomainDefNew()) ||
103 VIR_STRDUP(def
->os
.init
, "/sbin/init") < 0)
106 def
->virtType
= VIR_DOMAIN_VIRT_OPENVZ
;
107 def
->os
.type
= VIR_DOMAIN_OSTYPE_EXE
;
109 if (openvzReadNetworkConf(def
, 1) < 0) {
110 fprintf(stderr
, "ERROR: %s\n", virGetLastErrorMessage());
114 actual
= virDomainDefFormat(def
, NULL
, VIR_DOMAIN_DEF_FORMAT_INACTIVE
);
116 if (actual
== NULL
) {
117 fprintf(stderr
, "ERROR: %s\n", virGetLastErrorMessage());
121 if (STRNEQ(expected
, actual
)) {
122 virTestDifference(stderr
, expected
, actual
);
130 virDomainDefFree(def
);
140 openvzLocateConfFile
= testLocateConfFile
;
142 # define DO_TEST(_name) \
144 if (virTestRun("OpenVZ "#_name, test##_name, \
150 DO_TEST(ReadConfigParam
);
151 DO_TEST(ReadNetworkConf
);
153 return result
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;
156 VIR_TEST_MAIN(mymain
)
165 #endif /* WITH_OPENVZ */