]>
Commit | Line | Data |
---|---|---|
9c61a6d6 CB |
1 | /* liblxcapi |
2 | * | |
3 | * Copyright © 2017 Christian Brauner <christian.brauner@ubuntu.com>. | |
4 | * Copyright © 2017 Canonical Ltd. | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2, as | |
8 | * published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along | |
16 | * with this program; if not, write to the Free Software Foundation, Inc., | |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 | */ | |
19 | #include <lxc/lxccontainer.h> | |
20 | ||
8c582655 | 21 | #include <errno.h> |
9c61a6d6 CB |
22 | #include <signal.h> |
23 | #include <stdio.h> | |
24 | #include <stdlib.h> | |
8c582655 | 25 | #include <string.h> |
9c61a6d6 CB |
26 | #include <sys/types.h> |
27 | #include <sys/wait.h> | |
8c582655 | 28 | #include <unistd.h> |
9c61a6d6 | 29 | |
77803ee7 | 30 | #include "confile_utils.h" |
9c61a6d6 CB |
31 | #include "lxc/state.h" |
32 | #include "lxctest.h" | |
33 | ||
ae4ad10d CB |
34 | static int set_get_compare_clear_save_load(struct lxc_container *c, |
35 | const char *key, const char *value, | |
36 | const char *config_file, | |
37 | bool compare) | |
9c61a6d6 CB |
38 | { |
39 | char retval[4096] = {0}; | |
40 | int ret; | |
41 | ||
42 | if (!c->set_config_item(c, key, value)) { | |
43 | lxc_error("failed to set config item \"%s\" to \"%s\"\n", key, | |
44 | value); | |
45 | return -1; | |
46 | } | |
47 | ||
48 | ret = c->get_config_item(c, key, retval, sizeof(retval)); | |
49 | if (ret < 0) { | |
50 | lxc_error("failed to get config item \"%s\"\n", key); | |
51 | return -1; | |
52 | } | |
53 | ||
ae4ad10d CB |
54 | if (compare) { |
55 | ret = strcmp(retval, value); | |
56 | if (ret != 0) { | |
57 | lxc_error( | |
58 | "expected value \"%s\" and retrieved value \"%s\" " | |
59 | "for config key \"%s\" do not match\n", | |
60 | value, retval, key); | |
61 | return -1; | |
62 | } | |
63 | } | |
64 | ||
9c61a6d6 CB |
65 | if (config_file) { |
66 | if (!c->save_config(c, config_file)) { | |
67 | lxc_error("%s\n", "failed to save config file"); | |
68 | return -1; | |
69 | } | |
70 | ||
71 | c->clear_config(c); | |
72 | c->lxc_conf = NULL; | |
73 | ||
74 | if (!c->load_config(c, config_file)) { | |
75 | lxc_error("%s\n", "failed to load config file"); | |
76 | return -1; | |
77 | } | |
78 | } | |
79 | ||
80 | if (!c->clear_config_item(c, key)) { | |
81 | lxc_error("failed to clear config item \"%s\"\n", key); | |
82 | return -1; | |
83 | } | |
84 | ||
8c582655 CB |
85 | c->clear_config(c); |
86 | c->lxc_conf = NULL; | |
9c61a6d6 | 87 | |
8c582655 CB |
88 | return 0; |
89 | } | |
9c61a6d6 | 90 | |
8c582655 CB |
91 | static int set_and_clear_complete_netdev(struct lxc_container *c) |
92 | { | |
01aebbc3 CB |
93 | if (!c->set_config_item(c, "lxc.net.1.type", "veth")) { |
94 | lxc_error("%s\n", "lxc.net.1.type"); | |
8c582655 CB |
95 | return -1; |
96 | } | |
97 | ||
01aebbc3 CB |
98 | if (!c->set_config_item(c, "lxc.net.1.ipv4", "10.0.2.3/24")) { |
99 | lxc_error("%s\n", "lxc.net.1.ipv4"); | |
8c582655 CB |
100 | return -1; |
101 | } | |
102 | ||
01aebbc3 CB |
103 | if (!c->set_config_item(c, "lxc.net.1.ipv4_gateway", "10.0.2.2")) { |
104 | lxc_error("%s\n", "lxc.net.1.ipv4"); | |
8c582655 CB |
105 | return -1; |
106 | } | |
107 | ||
01aebbc3 | 108 | if (!c->set_config_item(c, "lxc.net.1.ipv6", |
8c582655 | 109 | "2003:db8:1:0:214:1234:fe0b:3596/64")) { |
01aebbc3 | 110 | lxc_error("%s\n", "lxc.net.1.ipv6"); |
8c582655 CB |
111 | return -1; |
112 | } | |
113 | ||
01aebbc3 | 114 | if (!c->set_config_item(c, "lxc.net.1.ipv6_gateway", |
8c582655 | 115 | "2003:db8:1:0::1")) { |
01aebbc3 | 116 | lxc_error("%s\n", "lxc.net.1.ipv6"); |
8c582655 CB |
117 | return -1; |
118 | } | |
119 | ||
01aebbc3 CB |
120 | if (!c->set_config_item(c, "lxc.net.1.flags", "up")) { |
121 | lxc_error("%s\n", "lxc.net.1.flags"); | |
8c582655 CB |
122 | return -1; |
123 | } | |
124 | ||
01aebbc3 CB |
125 | if (!c->set_config_item(c, "lxc.net.1.link", "br0")) { |
126 | lxc_error("%s\n", "lxc.net.1.link"); | |
8c582655 CB |
127 | return -1; |
128 | } | |
129 | ||
01aebbc3 CB |
130 | if (!c->set_config_item(c, "lxc.net.1.veth.pair", "bla")) { |
131 | lxc_error("%s\n", "lxc.net.1.veth.pair"); | |
8c582655 CB |
132 | return -1; |
133 | } | |
134 | ||
01aebbc3 | 135 | if (!c->set_config_item(c, "lxc.net.1.hwaddr", |
8c582655 | 136 | "52:54:00:80:7a:5d")) { |
01aebbc3 | 137 | lxc_error("%s\n", "lxc.net.1.hwaddr"); |
8c582655 CB |
138 | return -1; |
139 | } | |
140 | ||
01aebbc3 CB |
141 | if (!c->set_config_item(c, "lxc.net.1.mtu", "2000")) { |
142 | lxc_error("%s\n", "lxc.net.1.mtu"); | |
8c582655 CB |
143 | return -1; |
144 | } | |
145 | ||
01aebbc3 CB |
146 | if (!c->clear_config_item(c, "lxc.net.1")) { |
147 | lxc_error("%s", "failed to clear \"lxc.net.1\"\n"); | |
8c582655 | 148 | return -1; |
9c61a6d6 CB |
149 | } |
150 | ||
151 | c->clear_config(c); | |
152 | c->lxc_conf = NULL; | |
153 | ||
154 | return 0; | |
155 | } | |
156 | ||
77803ee7 CB |
157 | int test_idmap_parser(void) |
158 | { | |
159 | size_t i; | |
160 | struct idmap_check { | |
161 | bool is_valid; | |
162 | const char *idmap; | |
163 | }; | |
164 | static struct idmap_check idmaps[] = { | |
8c582655 CB |
165 | /* valid idmaps */ |
166 | { true, "u 0 0 1" }, | |
167 | { true, "g 0 0 1" }, | |
168 | { true, "u 1 100001 999999999" }, | |
169 | { true, "g 1 100001 999999999" }, | |
170 | { true, "u 0 0 0" }, | |
171 | { true, "g 0 0 0" }, | |
172 | { true, "u 1000 165536 65536" }, | |
173 | { true, "g 999 999 1" }, | |
174 | { true, "u 0 5000 100000" }, | |
175 | { true, "g 577 789 5" }, | |
176 | { true, "u 65536 65536 1 " }, | |
177 | /* invalid idmaps */ | |
178 | { false, "1u 0 0 0" }, | |
179 | { false, "1g 0 0 0a" }, | |
180 | { false, "1 u 0 0 0" }, | |
181 | { false, "1g 0 0 0 1" }, | |
182 | { false, "1u a0 b0 c0 d1" }, | |
183 | { false, "1g 0 b0 0 d1" }, | |
184 | { false, "1u a0 0 c0 1" }, | |
185 | { false, "g -1 0 -10" }, | |
186 | { false, "a 1 0 10" }, | |
187 | { false, "u 1 1 0 10" }, | |
188 | { false, "g 1 0 10 z " }, | |
77803ee7 CB |
189 | }; |
190 | ||
191 | for (i = 0; i < sizeof(idmaps) / sizeof(struct idmap_check); i++) { | |
192 | unsigned long hostid, nsid, range; | |
193 | char type; | |
194 | int ret; | |
195 | ret = parse_idmaps(idmaps[i].idmap, &type, &nsid, &hostid, | |
196 | &range); | |
197 | if ((ret < 0 && idmaps[i].is_valid) || | |
198 | (ret == 0 && !idmaps[i].is_valid)) { | |
199 | lxc_error("failed to parse idmap \"%s\"\n", | |
200 | idmaps[i].idmap); | |
201 | return -1; | |
202 | } | |
203 | } | |
204 | ||
205 | return 0; | |
206 | } | |
207 | ||
8c582655 CB |
208 | static int set_get_compare_clear_save_load_network( |
209 | struct lxc_container *c, const char *key, const char *value, | |
210 | const char *config_file, bool compare, const char *network_type) | |
211 | { | |
212 | char retval[4096] = {0}; | |
213 | int ret; | |
214 | ||
01aebbc3 CB |
215 | if (!c->set_config_item(c, "lxc.net.0.type", network_type)) { |
216 | lxc_error("%s\n", "lxc.net.0.type"); | |
8c582655 CB |
217 | return -1; |
218 | } | |
219 | ||
220 | if (!c->set_config_item(c, key, value)) { | |
221 | lxc_error("failed to set config item \"%s\" to \"%s\"\n", key, | |
222 | value); | |
223 | return -1; | |
224 | } | |
225 | ||
226 | ret = c->get_config_item(c, key, retval, sizeof(retval)); | |
227 | if (ret < 0) { | |
228 | lxc_error("failed to get config item \"%s\"\n", key); | |
229 | return -1; | |
230 | } | |
231 | ||
232 | if (compare) { | |
233 | ret = strcmp(retval, value); | |
234 | if (ret != 0) { | |
235 | lxc_error( | |
236 | "expected value \"%s\" and retrieved value \"%s\" " | |
237 | "for config key \"%s\" do not match\n", | |
238 | value, retval, key); | |
239 | return -1; | |
240 | } | |
241 | } | |
242 | ||
243 | if (config_file) { | |
244 | if (!c->save_config(c, config_file)) { | |
245 | lxc_error("%s\n", "failed to save config file"); | |
246 | return -1; | |
247 | } | |
248 | ||
249 | c->clear_config(c); | |
250 | c->lxc_conf = NULL; | |
251 | ||
252 | if (!c->load_config(c, config_file)) { | |
253 | lxc_error("%s\n", "failed to load config file"); | |
254 | return -1; | |
255 | } | |
256 | } | |
257 | ||
258 | if (!c->clear_config_item(c, key)) { | |
259 | lxc_error("failed to clear config item \"%s\"\n", key); | |
260 | return -1; | |
261 | } | |
262 | ||
01aebbc3 CB |
263 | if (!c->clear_config_item(c, "lxc.net.0.type")) { |
264 | lxc_error("%s\n", "lxc.net.0.type"); | |
8c582655 CB |
265 | return -1; |
266 | } | |
267 | ||
268 | c->clear_config(c); | |
269 | c->lxc_conf = NULL; | |
270 | ||
271 | return 0; | |
272 | } | |
273 | ||
9c61a6d6 CB |
274 | int main(int argc, char *argv[]) |
275 | { | |
276 | struct lxc_container *c; | |
277 | int fd = -1; | |
278 | int ret = EXIT_FAILURE; | |
279 | char tmpf[] = "lxc-parse-config-file-XXXXXX"; | |
280 | char retval[4096] = {0}; | |
281 | ||
8c582655 | 282 | c = lxc_container_new(tmpf, NULL); |
9c61a6d6 CB |
283 | if (!c) { |
284 | lxc_error("%s\n", "failed to create new container"); | |
285 | exit(EXIT_FAILURE); | |
286 | } | |
287 | ||
288 | fd = mkstemp(tmpf); | |
289 | if (fd < 0) { | |
290 | lxc_error("%s\n", "Could not create temporary file"); | |
8c582655 | 291 | exit(ret); |
9c61a6d6 CB |
292 | } |
293 | close(fd); | |
294 | ||
8c582655 | 295 | |
9c61a6d6 | 296 | /* lxc.arch */ |
8c582655 CB |
297 | if (set_get_compare_clear_save_load(c, "lxc.arch", "x86_64", tmpf, |
298 | true) < 0) { | |
9c61a6d6 CB |
299 | lxc_error("%s\n", "lxc.arch"); |
300 | goto non_test_error; | |
301 | } | |
302 | ||
303 | /* lxc.pts */ | |
8c582655 CB |
304 | if (set_get_compare_clear_save_load(c, "lxc.pts", "1000", tmpf, true) < |
305 | 0) { | |
9c61a6d6 CB |
306 | lxc_error("%s\n", "lxc.pts"); |
307 | goto non_test_error; | |
308 | } | |
309 | ||
310 | /* lxc.tty */ | |
8c582655 CB |
311 | if (set_get_compare_clear_save_load(c, "lxc.tty", "4", tmpf, true) < |
312 | 0) { | |
9c61a6d6 CB |
313 | lxc_error("%s\n", "lxc.tty"); |
314 | goto non_test_error; | |
315 | } | |
316 | ||
317 | /* lxc.devttydir */ | |
8c582655 CB |
318 | if (set_get_compare_clear_save_load(c, "lxc.devttydir", "not-dev", tmpf, |
319 | true) < 0) { | |
9c61a6d6 CB |
320 | lxc_error("%s\n", "lxc.devttydir"); |
321 | goto non_test_error; | |
322 | } | |
323 | ||
953fe44f CB |
324 | /* REMOVE IN LXC 3.0 |
325 | legacy security keys | |
326 | */ | |
8c582655 CB |
327 | if (set_get_compare_clear_save_load(c, "lxc.aa_profile", "unconfined", |
328 | tmpf, true) < 0) { | |
9c61a6d6 CB |
329 | lxc_error("%s\n", "lxc.aa_profile"); |
330 | goto non_test_error; | |
331 | } | |
332 | ||
953fe44f CB |
333 | /* REMOVE IN LXC 3.0 |
334 | legacy security keys | |
335 | */ | |
8c582655 CB |
336 | if (set_get_compare_clear_save_load(c, "lxc.aa_allow_incomplete", "1", |
337 | tmpf, true) < 0) { | |
9c61a6d6 CB |
338 | lxc_error("%s\n", "lxc.aa_allow_incomplete"); |
339 | goto non_test_error; | |
340 | } | |
341 | ||
953fe44f CB |
342 | /* REMOVE IN LXC 3.0 |
343 | legacy security keys | |
344 | */ | |
345 | if (set_get_compare_clear_save_load(c, "lxc.se_context", "system_u:system_r:lxc_t:s0:c22", | |
346 | tmpf, true) < 0) { | |
347 | lxc_error("%s\n", "lxc.apparmor.se_context"); | |
348 | goto non_test_error; | |
349 | } | |
350 | ||
351 | /* lxc.apparmor.profile */ | |
352 | if (set_get_compare_clear_save_load(c, "lxc.apparmor.profile", "unconfined", | |
353 | tmpf, true) < 0) { | |
354 | lxc_error("%s\n", "lxc.apparmor.profile"); | |
355 | goto non_test_error; | |
356 | } | |
357 | ||
358 | /* lxc.apparmor.allow_incomplete */ | |
359 | if (set_get_compare_clear_save_load(c, "lxc.apparmor.allow_incomplete", "1", | |
360 | tmpf, true) < 0) { | |
361 | lxc_error("%s\n", "lxc.apparmor.allow_incomplete"); | |
362 | goto non_test_error; | |
363 | } | |
364 | ||
365 | /* lxc.selinux.context */ | |
366 | if (set_get_compare_clear_save_load(c, "lxc.selinux.context", "system_u:system_r:lxc_t:s0:c22", | |
367 | tmpf, true) < 0) { | |
368 | lxc_error("%s\n", "lxc.apparmor.selinux.context"); | |
369 | goto non_test_error; | |
370 | } | |
371 | ||
9c61a6d6 | 372 | /* lxc.cgroup.cpuset.cpus */ |
8c582655 CB |
373 | if (set_get_compare_clear_save_load(c, "lxc.cgroup.cpuset.cpus", |
374 | "1-100", tmpf, false) < 0) { | |
9c61a6d6 CB |
375 | lxc_error("%s\n", "lxc.cgroup.cpuset.cpus"); |
376 | goto non_test_error; | |
377 | } | |
378 | ||
379 | /* lxc.cgroup */ | |
380 | if (!c->set_config_item(c, "lxc.cgroup.cpuset.cpus", "1-100")) { | |
381 | lxc_error("%s\n", "failed to set config item " | |
382 | "\"lxc.cgroup.cpuset.cpus\" to \"1-100\""); | |
383 | return -1; | |
384 | } | |
385 | ||
386 | if (!c->set_config_item(c, "lxc.cgroup.memory.limit_in_bytes", | |
387 | "123456789")) { | |
388 | lxc_error( | |
389 | "%s\n", | |
390 | "failed to set config item " | |
391 | "\"lxc.cgroup.memory.limit_in_bytes\" to \"123456789\""); | |
392 | return -1; | |
393 | } | |
394 | ||
395 | if (!c->get_config_item(c, "lxc.cgroup", retval, sizeof(retval))) { | |
396 | lxc_error("%s\n", "failed to get config item \"lxc.cgroup\""); | |
397 | return -1; | |
398 | } | |
399 | ||
400 | c->clear_config(c); | |
401 | c->lxc_conf = NULL; | |
402 | ||
403 | /* lxc.id_map | |
404 | * We can't really save the config here since save_config() wants to | |
405 | * chown the container's directory but we haven't created an on-disk | |
406 | * container. So let's test set-get-clear. | |
407 | */ | |
8c582655 CB |
408 | if (set_get_compare_clear_save_load( |
409 | c, "lxc.id_map", "u 0 100000 1000000000", NULL, false) < 0) { | |
9c61a6d6 CB |
410 | lxc_error("%s\n", "lxc.id_map"); |
411 | goto non_test_error; | |
412 | } | |
413 | ||
414 | if (!c->set_config_item(c, "lxc.id_map", "u 1 100000 10000000")) { | |
415 | lxc_error("%s\n", "failed to set config item " | |
416 | "\"lxc.id_map\" to \"u 1 100000 10000000\""); | |
417 | return -1; | |
418 | } | |
419 | ||
420 | if (!c->set_config_item(c, "lxc.id_map", "g 1 100000 10000000")) { | |
421 | lxc_error("%s\n", "failed to set config item " | |
422 | "\"lxc.id_map\" to \"g 1 100000 10000000\""); | |
423 | return -1; | |
424 | } | |
425 | ||
426 | if (!c->get_config_item(c, "lxc.id_map", retval, sizeof(retval))) { | |
427 | lxc_error("%s\n", "failed to get config item \"lxc.cgroup\""); | |
428 | return -1; | |
429 | } | |
430 | ||
431 | c->clear_config(c); | |
432 | c->lxc_conf = NULL; | |
433 | ||
46cc906d | 434 | /* REMOVE IN LXC 3.0 |
435 | legacy lxc.loglevel key | |
436 | */ | |
8c582655 CB |
437 | if (set_get_compare_clear_save_load(c, "lxc.loglevel", "DEBUG", tmpf, |
438 | true) < 0) { | |
9c61a6d6 CB |
439 | lxc_error("%s\n", "lxc.loglevel"); |
440 | goto non_test_error; | |
441 | } | |
442 | ||
46cc906d | 443 | /* REMOVE IN LXC 3.0 |
444 | legacy lxc.logfile key | |
445 | */ | |
8c582655 CB |
446 | if (set_get_compare_clear_save_load(c, "lxc.logfile", "/some/path", |
447 | tmpf, true) < 0) { | |
9c61a6d6 CB |
448 | lxc_error("%s\n", "lxc.logfile"); |
449 | goto non_test_error; | |
450 | } | |
451 | ||
46cc906d | 452 | |
453 | /* lxc.log.level */ | |
454 | if (set_get_compare_clear_save_load(c, "lxc.log.level", "DEBUG", tmpf, | |
455 | true) < 0) { | |
456 | lxc_error("%s\n", "lxc.log.level"); | |
457 | goto non_test_error; | |
458 | } | |
459 | ||
460 | /* lxc.log */ | |
461 | if (set_get_compare_clear_save_load(c, "lxc.log.file", "/some/path", | |
462 | tmpf, true) < 0) { | |
463 | lxc_error("%s\n", "lxc.log.file"); | |
464 | goto non_test_error; | |
465 | } | |
466 | ||
9c61a6d6 | 467 | /* lxc.mount */ |
8c582655 CB |
468 | if (set_get_compare_clear_save_load(c, "lxc.mount", "/some/path", NULL, |
469 | true) < 0) { | |
9c61a6d6 CB |
470 | lxc_error("%s\n", "lxc.mount"); |
471 | goto non_test_error; | |
472 | } | |
473 | ||
ae4ad10d CB |
474 | /* lxc.mount.auto |
475 | * Note that we cannot compare the values since the getter for | |
476 | * lxc.mount.auto does not preserve ordering. | |
477 | */ | |
8c582655 CB |
478 | if (set_get_compare_clear_save_load(c, "lxc.mount.auto", |
479 | "proc:rw sys:rw cgroup-full:rw", | |
480 | tmpf, false) < 0) { | |
9c61a6d6 CB |
481 | lxc_error("%s\n", "lxc.mount.auto"); |
482 | goto non_test_error; | |
483 | } | |
484 | ||
ae4ad10d CB |
485 | /* lxc.mount.entry |
486 | * Note that we cannot compare the values since the getter for | |
487 | * lxc.mount.entry appends newlines. | |
488 | */ | |
489 | if (set_get_compare_clear_save_load( | |
9c61a6d6 | 490 | c, "lxc.mount.entry", |
8c582655 CB |
491 | "/dev/dri dev/dri none bind,optional,create=dir", tmpf, |
492 | false) < 0) { | |
9c61a6d6 CB |
493 | lxc_error("%s\n", "lxc.mount.entry"); |
494 | goto non_test_error; | |
495 | } | |
496 | ||
497 | /* lxc.rootfs */ | |
8c582655 CB |
498 | if (set_get_compare_clear_save_load(c, "lxc.rootfs", "/some/path", tmpf, |
499 | true) < 0) { | |
9c61a6d6 CB |
500 | lxc_error("%s\n", "lxc.rootfs"); |
501 | goto non_test_error; | |
502 | } | |
503 | ||
504 | /* lxc.rootfs.mount */ | |
8c582655 CB |
505 | if (set_get_compare_clear_save_load(c, "lxc.rootfs.mount", "/some/path", |
506 | tmpf, true) < 0) { | |
9c61a6d6 CB |
507 | lxc_error("%s\n", "lxc.rootfs.mount"); |
508 | goto non_test_error; | |
509 | } | |
510 | ||
511 | /* lxc.rootfs.options */ | |
8c582655 CB |
512 | if (set_get_compare_clear_save_load(c, "lxc.rootfs.options", |
513 | "ext4,discard", tmpf, true) < 0) { | |
9c61a6d6 CB |
514 | lxc_error("%s\n", "lxc.rootfs.options"); |
515 | goto non_test_error; | |
516 | } | |
517 | ||
518 | /* lxc.rootfs.backend */ | |
8c582655 CB |
519 | if (set_get_compare_clear_save_load(c, "lxc.rootfs.backend", "btrfs", |
520 | tmpf, true) < 0) { | |
9c61a6d6 CB |
521 | lxc_error("%s\n", "lxc.rootfs.backend"); |
522 | goto non_test_error; | |
523 | } | |
524 | ||
525 | /* lxc.utsname */ | |
8c582655 CB |
526 | if (set_get_compare_clear_save_load(c, "lxc.utsname", "the-shire", tmpf, |
527 | true) < 0) { | |
9c61a6d6 CB |
528 | lxc_error("%s\n", "lxc.utsname"); |
529 | goto non_test_error; | |
530 | } | |
531 | ||
532 | /* lxc.hook.pre-start */ | |
8c582655 CB |
533 | if (set_get_compare_clear_save_load( |
534 | c, "lxc.hook.pre-start", "/some/pre-start", tmpf, false) < 0) { | |
9c61a6d6 CB |
535 | lxc_error("%s\n", "lxc.hook.pre-start"); |
536 | goto non_test_error; | |
537 | } | |
538 | ||
539 | /* lxc.hook.pre-mount */ | |
8c582655 CB |
540 | if (set_get_compare_clear_save_load( |
541 | c, "lxc.hook.pre-mount", "/some/pre-mount", tmpf, false) < 0) { | |
9c61a6d6 CB |
542 | lxc_error("%s\n", "lxc.hook.pre-mount"); |
543 | goto non_test_error; | |
544 | } | |
545 | ||
546 | /* lxc.hook.mount */ | |
8c582655 CB |
547 | if (set_get_compare_clear_save_load(c, "lxc.hook.mount", "/some/mount", |
548 | tmpf, false) < 0) { | |
9c61a6d6 CB |
549 | lxc_error("%s\n", "lxc.hook.mount"); |
550 | goto non_test_error; | |
551 | } | |
552 | ||
553 | /* lxc.hook.autodev */ | |
8c582655 CB |
554 | if (set_get_compare_clear_save_load(c, "lxc.hook.autodev", |
555 | "/some/autodev", tmpf, false) < 0) { | |
9c61a6d6 CB |
556 | lxc_error("%s\n", "lxc.hook.autodev"); |
557 | goto non_test_error; | |
558 | } | |
559 | ||
560 | /* lxc.hook.start */ | |
8c582655 CB |
561 | if (set_get_compare_clear_save_load(c, "lxc.hook.start", "/some/start", |
562 | tmpf, false) < 0) { | |
9c61a6d6 CB |
563 | lxc_error("%s\n", "lxc.hook.start"); |
564 | goto non_test_error; | |
565 | } | |
566 | ||
567 | /* lxc.hook.stop */ | |
8c582655 CB |
568 | if (set_get_compare_clear_save_load(c, "lxc.hook.stop", "/some/stop", |
569 | tmpf, false) < 0) { | |
9c61a6d6 CB |
570 | lxc_error("%s\n", "lxc.hook.stop"); |
571 | goto non_test_error; | |
572 | } | |
573 | ||
574 | /* lxc.hook.post-stop */ | |
8c582655 CB |
575 | if (set_get_compare_clear_save_load( |
576 | c, "lxc.hook.post-stop", "/some/post-stop", tmpf, false) < 0) { | |
9c61a6d6 CB |
577 | lxc_error("%s\n", "lxc.hook.post-stop"); |
578 | goto non_test_error; | |
579 | } | |
580 | ||
581 | /* lxc.hook.clone */ | |
8c582655 CB |
582 | if (set_get_compare_clear_save_load(c, "lxc.hook.clone", "/some/clone", |
583 | tmpf, false) < 0) { | |
9c61a6d6 CB |
584 | lxc_error("%s\n", "lxc.hook.clone"); |
585 | goto non_test_error; | |
586 | } | |
587 | ||
588 | /* lxc.hook.destroy */ | |
8c582655 CB |
589 | if (set_get_compare_clear_save_load(c, "lxc.hook.destroy", |
590 | "/some/destroy", tmpf, false) < 0) { | |
9c61a6d6 CB |
591 | lxc_error("%s\n", "lxc.hook.destroy"); |
592 | goto non_test_error; | |
593 | } | |
594 | ||
595 | /* lxc.cap.drop */ | |
8c582655 CB |
596 | if (set_get_compare_clear_save_load(c, "lxc.cap.drop", |
597 | "sys_module mknod setuid net_raw", | |
598 | tmpf, false) < 0) { | |
9c61a6d6 CB |
599 | lxc_error("%s\n", "lxc.cap.drop"); |
600 | goto non_test_error; | |
601 | } | |
602 | ||
603 | /* lxc.cap.keep */ | |
8c582655 CB |
604 | if (set_get_compare_clear_save_load(c, "lxc.cap.keep", |
605 | "sys_module mknod setuid net_raw", | |
606 | tmpf, false) < 0) { | |
9c61a6d6 CB |
607 | lxc_error("%s\n", "lxc.cap.keep"); |
608 | goto non_test_error; | |
609 | } | |
610 | ||
611 | /* lxc.console */ | |
8c582655 CB |
612 | if (set_get_compare_clear_save_load(c, "lxc.console", "none", tmpf, |
613 | true) < 0) { | |
9c61a6d6 CB |
614 | lxc_error("%s\n", "lxc.console"); |
615 | goto non_test_error; | |
616 | } | |
617 | ||
618 | /* lxc.console.logfile */ | |
8c582655 CB |
619 | if (set_get_compare_clear_save_load(c, "lxc.console.logfile", |
620 | "/some/logfile", tmpf, true) < 0) { | |
9c61a6d6 CB |
621 | lxc_error("%s\n", "lxc.console.logfile"); |
622 | goto non_test_error; | |
623 | } | |
624 | ||
625 | /* lxc.seccomp */ | |
8c582655 CB |
626 | if (set_get_compare_clear_save_load( |
627 | c, "lxc.seccomp", "/some/seccomp/file", tmpf, true) < 0) { | |
9c61a6d6 CB |
628 | lxc_error("%s\n", "lxc.seccomp"); |
629 | goto non_test_error; | |
630 | } | |
631 | ||
632 | /* lxc.autodev */ | |
8c582655 CB |
633 | if (set_get_compare_clear_save_load(c, "lxc.autodev", "1", tmpf, true) < |
634 | 0) { | |
9c61a6d6 CB |
635 | lxc_error("%s\n", "lxc.autodev"); |
636 | goto non_test_error; | |
637 | } | |
638 | ||
639 | /* lxc.haltsignal */ | |
8c582655 CB |
640 | if (set_get_compare_clear_save_load(c, "lxc.haltsignal", "1", tmpf, |
641 | true) < 0) { | |
9c61a6d6 CB |
642 | lxc_error("%s\n", "lxc.haltsignal"); |
643 | goto non_test_error; | |
644 | } | |
645 | ||
646 | /* lxc.rebootsignal */ | |
8c582655 CB |
647 | if (set_get_compare_clear_save_load(c, "lxc.rebootsignal", "1", tmpf, |
648 | true) < 0) { | |
9c61a6d6 CB |
649 | lxc_error("%s\n", "lxc.rebootsignal"); |
650 | goto non_test_error; | |
651 | } | |
652 | ||
653 | /* lxc.stopsignal */ | |
8c582655 CB |
654 | if (set_get_compare_clear_save_load(c, "lxc.stopsignal", "1", tmpf, |
655 | true) < 0) { | |
9c61a6d6 CB |
656 | lxc_error("%s\n", "lxc.stopsignal"); |
657 | goto non_test_error; | |
658 | } | |
659 | ||
660 | /* lxc.start.auto */ | |
8c582655 CB |
661 | if (set_get_compare_clear_save_load(c, "lxc.start.auto", "1", tmpf, |
662 | true) < 0) { | |
9c61a6d6 CB |
663 | lxc_error("%s\n", "lxc.start.auto"); |
664 | goto non_test_error; | |
665 | } | |
666 | ||
667 | /* lxc.start.delay */ | |
8c582655 CB |
668 | if (set_get_compare_clear_save_load(c, "lxc.start.delay", "5", tmpf, |
669 | true) < 0) { | |
9c61a6d6 CB |
670 | lxc_error("%s\n", "lxc.start.delay"); |
671 | goto non_test_error; | |
672 | } | |
673 | ||
674 | /* lxc.start.order */ | |
8c582655 CB |
675 | if (set_get_compare_clear_save_load(c, "lxc.start.order", "1", tmpf, |
676 | true) < 0) { | |
9c61a6d6 CB |
677 | lxc_error("%s\n", "lxc.start.order"); |
678 | goto non_test_error; | |
679 | } | |
680 | ||
46cc906d | 681 | /* lxc.log.syslog */ |
682 | if (set_get_compare_clear_save_load(c, "lxc.log.syslog", "local0", tmpf, | |
8c582655 | 683 | true) < 0) { |
46cc906d | 684 | lxc_error("%s\n", "lxc.log.syslog"); |
9c61a6d6 CB |
685 | goto non_test_error; |
686 | } | |
687 | ||
688 | /* lxc.utsname */ | |
8c582655 CB |
689 | if (set_get_compare_clear_save_load(c, "lxc.utsname", "get-schwifty", |
690 | tmpf, true) < 0) { | |
9c61a6d6 CB |
691 | lxc_error("%s\n", "lxc.utsname"); |
692 | goto non_test_error; | |
693 | } | |
694 | ||
695 | /* lxc.monitor.unshare */ | |
8c582655 CB |
696 | if (set_get_compare_clear_save_load(c, "lxc.monitor.unshare", "1", tmpf, |
697 | true) < 0) { | |
9c61a6d6 CB |
698 | lxc_error("%s\n", "lxc.monitor.unshare"); |
699 | goto non_test_error; | |
700 | } | |
701 | ||
702 | /* lxc.group */ | |
8c582655 CB |
703 | if (set_get_compare_clear_save_load( |
704 | c, "lxc.group", "some,container,groups", tmpf, false) < 0) { | |
9c61a6d6 CB |
705 | lxc_error("%s\n", "lxc.group"); |
706 | goto non_test_error; | |
707 | } | |
708 | ||
709 | /* lxc.environment */ | |
8c582655 CB |
710 | if (set_get_compare_clear_save_load(c, "lxc.environment", "FOO=BAR", |
711 | tmpf, false) < 0) { | |
9c61a6d6 CB |
712 | lxc_error("%s\n", "lxc.environment"); |
713 | goto non_test_error; | |
714 | } | |
715 | ||
9dcf7b4d | 716 | /* REMOVE IN LXC 3.0 |
717 | legacy lxc.init_cmd key | |
718 | */ | |
8c582655 CB |
719 | if (set_get_compare_clear_save_load(c, "lxc.init_cmd", "/bin/bash", |
720 | tmpf, true) < 0) { | |
9c61a6d6 CB |
721 | lxc_error("%s\n", "lxc.init_cmd"); |
722 | goto non_test_error; | |
723 | } | |
724 | ||
9dcf7b4d | 725 | /* lxc.init.cmd */ |
726 | if (set_get_compare_clear_save_load(c, "lxc.init.cmd", "/bin/bash", | |
727 | tmpf, true) < 0) { | |
728 | lxc_error("%s\n", "lxc.init.cmd"); | |
729 | goto non_test_error; | |
730 | } | |
731 | ||
732 | /* REMOVE IN LXC 3.0 | |
733 | legacy lxc.init_uid key | |
734 | */ | |
8c582655 CB |
735 | if (set_get_compare_clear_save_load(c, "lxc.init_uid", "1000", tmpf, |
736 | true) < 0) { | |
9c61a6d6 CB |
737 | lxc_error("%s\n", "lxc.init_uid"); |
738 | goto non_test_error; | |
739 | } | |
740 | ||
9dcf7b4d | 741 | /* lxc.init.uid */ |
742 | if (set_get_compare_clear_save_load(c, "lxc.init.uid", "1000", tmpf, | |
743 | true) < 0) { | |
744 | lxc_error("%s\n", "lxc.init.uid"); | |
745 | goto non_test_error; | |
746 | } | |
747 | ||
748 | /* REMOVE IN LXC 3.0 | |
749 | legacy lxc.init_gid key | |
750 | */ | |
8c582655 CB |
751 | if (set_get_compare_clear_save_load(c, "lxc.init_gid", "1000", tmpf, |
752 | true) < 0) { | |
9c61a6d6 CB |
753 | lxc_error("%s\n", "lxc.init_gid"); |
754 | goto non_test_error; | |
755 | } | |
756 | ||
9dcf7b4d | 757 | /* lxc.init.gid */ |
758 | if (set_get_compare_clear_save_load(c, "lxc.init.gid", "1000", tmpf, | |
759 | true) < 0) { | |
760 | lxc_error("%s\n", "lxc.init.gid"); | |
761 | goto non_test_error; | |
762 | } | |
763 | ||
9c61a6d6 | 764 | /* lxc.ephemeral */ |
8c582655 CB |
765 | if (set_get_compare_clear_save_load(c, "lxc.ephemeral", "1", tmpf, |
766 | true) < 0) { | |
9c61a6d6 CB |
767 | lxc_error("%s\n", "lxc.ephemeral"); |
768 | goto non_test_error; | |
769 | } | |
770 | ||
771 | /* lxc.no_new_privs */ | |
8c582655 CB |
772 | if (set_get_compare_clear_save_load(c, "lxc.no_new_privs", "1", tmpf, |
773 | true) < 0) { | |
9c61a6d6 CB |
774 | lxc_error("%s\n", "lxc.no_new_privs"); |
775 | goto non_test_error; | |
776 | } | |
777 | ||
240d4b74 | 778 | /* REMOVE IN LXC 3.0 |
779 | legacy lxc.limit.* key | |
780 | */ | |
8c582655 CB |
781 | if (set_get_compare_clear_save_load(c, "lxc.limit.nofile", "65536", |
782 | tmpf, true) < 0) { | |
9c61a6d6 CB |
783 | lxc_error("%s\n", "lxc.limit.nofile"); |
784 | goto non_test_error; | |
240d4b74 | 785 | } |
786 | ||
787 | /* lxc.prlimit.nofile */ | |
788 | if (set_get_compare_clear_save_load(c, "lxc.prlimit.nofile", "65536", | |
789 | tmpf, true) < 0) { | |
790 | lxc_error("%s\n", "lxc.prlimit.nofile"); | |
791 | goto non_test_error; | |
9c61a6d6 CB |
792 | } |
793 | ||
77803ee7 CB |
794 | if (test_idmap_parser() < 0) { |
795 | lxc_error("%s\n", "failed to test parser for \"lxc.id_map\""); | |
796 | goto non_test_error; | |
797 | } | |
798 | ||
01aebbc3 | 799 | if (set_get_compare_clear_save_load(c, "lxc.net.0.type", "veth", |
8c582655 | 800 | tmpf, true)) { |
01aebbc3 | 801 | lxc_error("%s\n", "lxc.net.0.type"); |
8c582655 CB |
802 | goto non_test_error; |
803 | } | |
804 | ||
01aebbc3 | 805 | if (set_get_compare_clear_save_load(c, "lxc.net.2.type", "none", |
8c582655 | 806 | tmpf, true)) { |
01aebbc3 | 807 | lxc_error("%s\n", "lxc.net.2.type"); |
8c582655 CB |
808 | goto non_test_error; |
809 | } | |
810 | ||
01aebbc3 | 811 | if (set_get_compare_clear_save_load(c, "lxc.net.3.type", "empty", |
8c582655 | 812 | tmpf, true)) { |
01aebbc3 | 813 | lxc_error("%s\n", "lxc.net.3.type"); |
8c582655 CB |
814 | goto non_test_error; |
815 | } | |
816 | ||
01aebbc3 | 817 | if (set_get_compare_clear_save_load(c, "lxc.net.4.type", "vlan", |
8c582655 | 818 | tmpf, true)) { |
01aebbc3 | 819 | lxc_error("%s\n", "lxc.net.4.type"); |
8c582655 CB |
820 | goto non_test_error; |
821 | } | |
822 | ||
01aebbc3 | 823 | if (set_get_compare_clear_save_load(c, "lxc.net.0.type", "macvlan", |
8c582655 | 824 | tmpf, true)) { |
01aebbc3 | 825 | lxc_error("%s\n", "lxc.net.0.type"); |
8c582655 CB |
826 | goto non_test_error; |
827 | } | |
828 | ||
01aebbc3 | 829 | if (set_get_compare_clear_save_load(c, "lxc.net.1000.type", "phys", |
8c582655 | 830 | tmpf, true)) { |
01aebbc3 | 831 | lxc_error("%s\n", "lxc.net.1000.type"); |
8c582655 CB |
832 | goto non_test_error; |
833 | } | |
834 | ||
01aebbc3 | 835 | if (set_get_compare_clear_save_load(c, "lxc.net.0.flags", "up", |
8c582655 | 836 | tmpf, true)) { |
01aebbc3 | 837 | lxc_error("%s\n", "lxc.net.0.flags"); |
8c582655 CB |
838 | goto non_test_error; |
839 | } | |
840 | ||
01aebbc3 | 841 | if (set_get_compare_clear_save_load(c, "lxc.net.0.name", "eth0", |
8c582655 | 842 | tmpf, true)) { |
01aebbc3 | 843 | lxc_error("%s\n", "lxc.net.0.name"); |
8c582655 CB |
844 | goto non_test_error; |
845 | } | |
846 | ||
01aebbc3 | 847 | if (set_get_compare_clear_save_load(c, "lxc.net.0.link", "bla", |
8c582655 | 848 | tmpf, true)) { |
01aebbc3 | 849 | lxc_error("%s\n", "lxc.net.0.link"); |
8c582655 CB |
850 | goto non_test_error; |
851 | } | |
852 | ||
853 | if (set_get_compare_clear_save_load_network( | |
01aebbc3 | 854 | c, "lxc.net.0.macvlan.mode", "private", tmpf, true, |
8c582655 | 855 | "macvlan")) { |
01aebbc3 | 856 | lxc_error("%s\n", "lxc.net.0.macvlan.mode"); |
8c582655 CB |
857 | goto non_test_error; |
858 | } | |
859 | ||
860 | if (set_get_compare_clear_save_load_network( | |
01aebbc3 | 861 | c, "lxc.net.0.macvlan.mode", "vepa", tmpf, true, |
8c582655 | 862 | "macvlan")) { |
01aebbc3 | 863 | lxc_error("%s\n", "lxc.net.0.macvlan.mode"); |
8c582655 CB |
864 | goto non_test_error; |
865 | } | |
866 | ||
867 | if (set_get_compare_clear_save_load_network( | |
01aebbc3 | 868 | c, "lxc.net.0.macvlan.mode", "bridge", tmpf, true, |
8c582655 | 869 | "macvlan")) { |
01aebbc3 | 870 | lxc_error("%s\n", "lxc.net.0.macvlan.mode"); |
8c582655 CB |
871 | goto non_test_error; |
872 | } | |
873 | ||
874 | if (set_get_compare_clear_save_load_network( | |
01aebbc3 | 875 | c, "lxc.net.0.veth.pair", "clusterfuck", tmpf, true, |
8c582655 | 876 | "veth")) { |
01aebbc3 | 877 | lxc_error("%s\n", "lxc.net.0.veth.pair"); |
8c582655 CB |
878 | goto non_test_error; |
879 | } | |
880 | ||
01aebbc3 | 881 | if (set_get_compare_clear_save_load(c, "lxc.net.0.script.up", |
8c582655 | 882 | "/some/up/path", tmpf, true)) { |
01aebbc3 | 883 | lxc_error("%s\n", "lxc.net.0.script.up"); |
8c582655 CB |
884 | goto non_test_error; |
885 | } | |
886 | ||
01aebbc3 | 887 | if (set_get_compare_clear_save_load(c, "lxc.net.0.script.down", |
8c582655 | 888 | "/some/down/path", tmpf, true)) { |
01aebbc3 | 889 | lxc_error("%s\n", "lxc.net.0.script.down"); |
8c582655 CB |
890 | goto non_test_error; |
891 | } | |
892 | ||
01aebbc3 | 893 | if (set_get_compare_clear_save_load(c, "lxc.net.0.hwaddr", |
8c582655 | 894 | "52:54:00:80:7a:5d", tmpf, true)) { |
01aebbc3 | 895 | lxc_error("%s\n", "lxc.net.0.hwaddr"); |
8c582655 CB |
896 | goto non_test_error; |
897 | } | |
898 | ||
01aebbc3 | 899 | if (set_get_compare_clear_save_load(c, "lxc.net.0.mtu", "2000", |
8c582655 | 900 | tmpf, true)) { |
01aebbc3 | 901 | lxc_error("%s\n", "lxc.net.0.mtu"); |
8c582655 CB |
902 | goto non_test_error; |
903 | } | |
904 | ||
01aebbc3 | 905 | if (set_get_compare_clear_save_load_network(c, "lxc.net.0.vlan.id", |
8c582655 | 906 | "2", tmpf, true, "vlan")) { |
01aebbc3 | 907 | lxc_error("%s\n", "lxc.net.0.vlan.id"); |
8c582655 CB |
908 | goto non_test_error; |
909 | } | |
910 | ||
01aebbc3 | 911 | if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4.gateway", |
8c582655 | 912 | "10.0.2.2", tmpf, true)) { |
01aebbc3 | 913 | lxc_error("%s\n", "lxc.net.0.ipv4.gateway"); |
8c582655 CB |
914 | goto non_test_error; |
915 | } | |
916 | ||
01aebbc3 | 917 | if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv6.gateway", |
8c582655 | 918 | "2003:db8:1::1", tmpf, true)) { |
01aebbc3 | 919 | lxc_error("%s\n", "lxc.net.0.ipv6.gateway"); |
8c582655 CB |
920 | goto non_test_error; |
921 | } | |
922 | ||
01aebbc3 | 923 | if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4", |
8c582655 | 924 | "10.0.2.3/24", tmpf, true)) { |
01aebbc3 | 925 | lxc_error("%s\n", "lxc.net.0.ipv4"); |
8c582655 CB |
926 | goto non_test_error; |
927 | } | |
928 | ||
929 | if (set_get_compare_clear_save_load( | |
01aebbc3 | 930 | c, "lxc.net.0.ipv6", "2003:db8:1:0:214:1234:fe0b:3596/64", |
8c582655 | 931 | tmpf, true)) { |
01aebbc3 | 932 | lxc_error("%s\n", "lxc.net.0.ipv6"); |
8c582655 CB |
933 | goto non_test_error; |
934 | } | |
935 | ||
936 | if (set_and_clear_complete_netdev(c) < 0) { | |
937 | lxc_error("%s\n", "failed to clear whole network"); | |
938 | goto non_test_error; | |
939 | } | |
940 | ||
9c61a6d6 CB |
941 | ret = EXIT_SUCCESS; |
942 | non_test_error: | |
8c582655 | 943 | (void)unlink(tmpf); |
9c61a6d6 CB |
944 | c->destroy(c); |
945 | lxc_container_put(c); | |
946 | exit(ret); | |
947 | } |