backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / openvzutilstest.c
blob283ba03b21826e5e4ad59263a85c3830b6872d6e
1 #include <config.h>
3 #include "testutils.h"
5 #ifdef WITH_OPENVZ
7 # include <unistd.h>
9 # include "internal.h"
10 # include "viralloc.h"
11 # include "openvz/openvz_conf.h"
12 # include "virstring.h"
14 # define VIR_FROM_THIS VIR_FROM_OPENVZ
16 static int
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 {
24 const char *param;
25 const char *value;
26 int ret;
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 },
35 static int
36 testReadConfigParam(const void *data ATTRIBUTE_UNUSED)
38 int result = -1;
39 size_t i;
40 char *conf = NULL;
41 char *value = NULL;
43 if (virAsprintf(&conf, "%s/openvzutilstest.conf", abs_srcdir) < 0)
44 return -1;
46 for (i = 0; i < ARRAY_CARDINALITY(configParams); ++i) {
47 if (openvzReadConfigParam(conf, configParams[i].param,
48 &value) != configParams[i].ret) {
49 goto cleanup;
52 if (configParams[i].ret != 1)
53 continue;
55 if (STRNEQ(configParams[i].value, value)) {
56 virTestDifference(stderr, configParams[i].value, value);
57 goto cleanup;
61 result = 0;
63 cleanup:
64 VIR_FREE(conf);
65 VIR_FREE(value);
67 return result;
70 static int
71 testReadNetworkConf(const void *data ATTRIBUTE_UNUSED)
73 int result = -1;
74 virDomainDefPtr def = NULL;
75 char *actual = 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"
82 " <os>\n"
83 " <type>exe</type>\n"
84 " <init>/sbin/init</init>\n"
85 " </os>\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"
90 " <devices>\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"
94 " </interface>\n"
95 " <interface type='bridge'>\n"
96 " <mac address='00:18:51:c1:05:ee'/>\n"
97 " <target dev='veth105.10'/>\n"
98 " </interface>\n"
99 " </devices>\n"
100 "</domain>\n";
102 if (!(def = virDomainDefNew()) ||
103 VIR_STRDUP(def->os.init, "/sbin/init") < 0)
104 goto cleanup;
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());
111 goto cleanup;
114 actual = virDomainDefFormat(def, NULL, VIR_DOMAIN_DEF_FORMAT_INACTIVE);
116 if (actual == NULL) {
117 fprintf(stderr, "ERROR: %s\n", virGetLastErrorMessage());
118 goto cleanup;
121 if (STRNEQ(expected, actual)) {
122 virTestDifference(stderr, expected, actual);
123 goto cleanup;
126 result = 0;
128 cleanup:
129 VIR_FREE(actual);
130 virDomainDefFree(def);
132 return result;
135 static int
136 mymain(void)
138 int result = 0;
140 openvzLocateConfFile = testLocateConfFile;
142 # define DO_TEST(_name) \
143 do { \
144 if (virTestRun("OpenVZ "#_name, test##_name, \
145 NULL) < 0) { \
146 result = -1; \
148 } while (0)
150 DO_TEST(ReadConfigParam);
151 DO_TEST(ReadNetworkConf);
153 return result == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
156 VIR_TEST_MAIN(mymain)
158 #else
160 int main(void)
162 return EXIT_AM_SKIP;
165 #endif /* WITH_OPENVZ */