]> git.proxmox.com Git - mirror_lxc.git/blame - src/tests/parse_config_file.c
confile: lxc.net.ipv6 --> lxc.net.ipv6.address
[mirror_lxc.git] / src / tests / parse_config_file.c
CommitLineData
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
34static 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
91static 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
9ff60df2
CB
98 if (!c->set_config_item(c, "lxc.net.1.ipv4.address", "10.0.2.3/24")) {
99 lxc_error("%s\n", "lxc.net.1.ipv4.address");
8c582655
CB
100 return -1;
101 }
102
9ff60df2
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.gateway");
8c582655
CB
105 return -1;
106 }
107
2e44ae28 108 if (!c->set_config_item(c, "lxc.net.1.ipv6.address",
8c582655 109 "2003:db8:1:0:214:1234:fe0b:3596/64")) {
2e44ae28 110 lxc_error("%s\n", "lxc.net.1.ipv6.address");
8c582655
CB
111 return -1;
112 }
113
2e44ae28 114 if (!c->set_config_item(c, "lxc.net.1.ipv6.gateway",
8c582655 115 "2003:db8:1:0::1")) {
2e44ae28 116 lxc_error("%s\n", "lxc.net.1.ipv6.gateway");
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
157int 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
208static 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
274int 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
42e53c29 317 /* REMOVE IN LXC 3.0
318 legacy devttydir keys
319 */
8c582655
CB
320 if (set_get_compare_clear_save_load(c, "lxc.devttydir", "not-dev", tmpf,
321 true) < 0) {
9c61a6d6
CB
322 lxc_error("%s\n", "lxc.devttydir");
323 goto non_test_error;
324 }
325
42e53c29 326 /* lxc.tty.dir */
327 if (set_get_compare_clear_save_load(c, "lxc.tty.dir", "not-dev", tmpf,
328 true) < 0) {
329 lxc_error("%s\n", "lxc.tty.dir");
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_profile", "unconfined",
337 tmpf, true) < 0) {
9c61a6d6
CB
338 lxc_error("%s\n", "lxc.aa_profile");
339 goto non_test_error;
340 }
341
953fe44f
CB
342 /* REMOVE IN LXC 3.0
343 legacy security keys
344 */
8c582655
CB
345 if (set_get_compare_clear_save_load(c, "lxc.aa_allow_incomplete", "1",
346 tmpf, true) < 0) {
9c61a6d6
CB
347 lxc_error("%s\n", "lxc.aa_allow_incomplete");
348 goto non_test_error;
349 }
350
953fe44f
CB
351 /* REMOVE IN LXC 3.0
352 legacy security keys
353 */
354 if (set_get_compare_clear_save_load(c, "lxc.se_context", "system_u:system_r:lxc_t:s0:c22",
355 tmpf, true) < 0) {
356 lxc_error("%s\n", "lxc.apparmor.se_context");
357 goto non_test_error;
358 }
359
360 /* lxc.apparmor.profile */
361 if (set_get_compare_clear_save_load(c, "lxc.apparmor.profile", "unconfined",
362 tmpf, true) < 0) {
363 lxc_error("%s\n", "lxc.apparmor.profile");
364 goto non_test_error;
365 }
366
367 /* lxc.apparmor.allow_incomplete */
368 if (set_get_compare_clear_save_load(c, "lxc.apparmor.allow_incomplete", "1",
369 tmpf, true) < 0) {
370 lxc_error("%s\n", "lxc.apparmor.allow_incomplete");
371 goto non_test_error;
372 }
373
374 /* lxc.selinux.context */
375 if (set_get_compare_clear_save_load(c, "lxc.selinux.context", "system_u:system_r:lxc_t:s0:c22",
376 tmpf, true) < 0) {
377 lxc_error("%s\n", "lxc.apparmor.selinux.context");
378 goto non_test_error;
379 }
380
9c61a6d6 381 /* lxc.cgroup.cpuset.cpus */
8c582655
CB
382 if (set_get_compare_clear_save_load(c, "lxc.cgroup.cpuset.cpus",
383 "1-100", tmpf, false) < 0) {
9c61a6d6
CB
384 lxc_error("%s\n", "lxc.cgroup.cpuset.cpus");
385 goto non_test_error;
386 }
387
388 /* lxc.cgroup */
389 if (!c->set_config_item(c, "lxc.cgroup.cpuset.cpus", "1-100")) {
390 lxc_error("%s\n", "failed to set config item "
391 "\"lxc.cgroup.cpuset.cpus\" to \"1-100\"");
392 return -1;
393 }
394
395 if (!c->set_config_item(c, "lxc.cgroup.memory.limit_in_bytes",
396 "123456789")) {
397 lxc_error(
398 "%s\n",
399 "failed to set config item "
400 "\"lxc.cgroup.memory.limit_in_bytes\" to \"123456789\"");
401 return -1;
402 }
403
404 if (!c->get_config_item(c, "lxc.cgroup", retval, sizeof(retval))) {
405 lxc_error("%s\n", "failed to get config item \"lxc.cgroup\"");
406 return -1;
407 }
408
409 c->clear_config(c);
410 c->lxc_conf = NULL;
411
412 /* lxc.id_map
413 * We can't really save the config here since save_config() wants to
414 * chown the container's directory but we haven't created an on-disk
415 * container. So let's test set-get-clear.
416 */
8c582655
CB
417 if (set_get_compare_clear_save_load(
418 c, "lxc.id_map", "u 0 100000 1000000000", NULL, false) < 0) {
9c61a6d6
CB
419 lxc_error("%s\n", "lxc.id_map");
420 goto non_test_error;
421 }
422
423 if (!c->set_config_item(c, "lxc.id_map", "u 1 100000 10000000")) {
424 lxc_error("%s\n", "failed to set config item "
425 "\"lxc.id_map\" to \"u 1 100000 10000000\"");
426 return -1;
427 }
428
429 if (!c->set_config_item(c, "lxc.id_map", "g 1 100000 10000000")) {
430 lxc_error("%s\n", "failed to set config item "
431 "\"lxc.id_map\" to \"g 1 100000 10000000\"");
432 return -1;
433 }
434
435 if (!c->get_config_item(c, "lxc.id_map", retval, sizeof(retval))) {
436 lxc_error("%s\n", "failed to get config item \"lxc.cgroup\"");
437 return -1;
438 }
439
440 c->clear_config(c);
441 c->lxc_conf = NULL;
442
46cc906d 443 /* REMOVE IN LXC 3.0
444 legacy lxc.loglevel key
445 */
8c582655
CB
446 if (set_get_compare_clear_save_load(c, "lxc.loglevel", "DEBUG", tmpf,
447 true) < 0) {
9c61a6d6
CB
448 lxc_error("%s\n", "lxc.loglevel");
449 goto non_test_error;
450 }
451
46cc906d 452 /* REMOVE IN LXC 3.0
453 legacy lxc.logfile key
454 */
8c582655
CB
455 if (set_get_compare_clear_save_load(c, "lxc.logfile", "/some/path",
456 tmpf, true) < 0) {
9c61a6d6
CB
457 lxc_error("%s\n", "lxc.logfile");
458 goto non_test_error;
459 }
460
46cc906d 461
462 /* lxc.log.level */
463 if (set_get_compare_clear_save_load(c, "lxc.log.level", "DEBUG", tmpf,
464 true) < 0) {
465 lxc_error("%s\n", "lxc.log.level");
466 goto non_test_error;
467 }
468
469 /* lxc.log */
470 if (set_get_compare_clear_save_load(c, "lxc.log.file", "/some/path",
471 tmpf, true) < 0) {
472 lxc_error("%s\n", "lxc.log.file");
473 goto non_test_error;
474 }
475
47148e96
CB
476 /* REMOVE IN LXC 3.0
477 legacy lxc.mount key
478 */
8c582655
CB
479 if (set_get_compare_clear_save_load(c, "lxc.mount", "/some/path", NULL,
480 true) < 0) {
9c61a6d6
CB
481 lxc_error("%s\n", "lxc.mount");
482 goto non_test_error;
483 }
484
47148e96
CB
485 /* lxc.mount.fstab */
486 if (set_get_compare_clear_save_load(c, "lxc.mount.fstab", "/some/path", NULL,
487 true) < 0) {
488 lxc_error("%s\n", "lxc.mount.fstab");
489 goto non_test_error;
490 }
491
ae4ad10d
CB
492 /* lxc.mount.auto
493 * Note that we cannot compare the values since the getter for
494 * lxc.mount.auto does not preserve ordering.
495 */
8c582655
CB
496 if (set_get_compare_clear_save_load(c, "lxc.mount.auto",
497 "proc:rw sys:rw cgroup-full:rw",
498 tmpf, false) < 0) {
9c61a6d6
CB
499 lxc_error("%s\n", "lxc.mount.auto");
500 goto non_test_error;
501 }
502
ae4ad10d
CB
503 /* lxc.mount.entry
504 * Note that we cannot compare the values since the getter for
505 * lxc.mount.entry appends newlines.
506 */
507 if (set_get_compare_clear_save_load(
9c61a6d6 508 c, "lxc.mount.entry",
8c582655
CB
509 "/dev/dri dev/dri none bind,optional,create=dir", tmpf,
510 false) < 0) {
9c61a6d6
CB
511 lxc_error("%s\n", "lxc.mount.entry");
512 goto non_test_error;
513 }
514
7a96a068
CB
515 /* REMOVE IN LXC 3.0
516 legacy lxc.rootfs key
517 */
8c582655
CB
518 if (set_get_compare_clear_save_load(c, "lxc.rootfs", "/some/path", tmpf,
519 true) < 0) {
9c61a6d6
CB
520 lxc_error("%s\n", "lxc.rootfs");
521 goto non_test_error;
522 }
523
7a96a068
CB
524 /* lxc.rootfs.path */
525 if (set_get_compare_clear_save_load(c, "lxc.rootfs.path", "/some/path", tmpf,
526 true) < 0) {
527 lxc_error("%s\n", "lxc.rootfs.path");
528 goto non_test_error;
529 }
530
9c61a6d6 531 /* lxc.rootfs.mount */
8c582655
CB
532 if (set_get_compare_clear_save_load(c, "lxc.rootfs.mount", "/some/path",
533 tmpf, true) < 0) {
9c61a6d6
CB
534 lxc_error("%s\n", "lxc.rootfs.mount");
535 goto non_test_error;
536 }
537
538 /* lxc.rootfs.options */
8c582655
CB
539 if (set_get_compare_clear_save_load(c, "lxc.rootfs.options",
540 "ext4,discard", tmpf, true) < 0) {
9c61a6d6
CB
541 lxc_error("%s\n", "lxc.rootfs.options");
542 goto non_test_error;
543 }
544
b67771bc 545 /* REMOVE IN LXC 3.0
546 legacy lxc.utsname key
547 */
8c582655
CB
548 if (set_get_compare_clear_save_load(c, "lxc.utsname", "the-shire", tmpf,
549 true) < 0) {
9c61a6d6
CB
550 lxc_error("%s\n", "lxc.utsname");
551 goto non_test_error;
552 }
553
b67771bc 554 /* lxc.uts.name */
555 if (set_get_compare_clear_save_load(c, "lxc.uts.name", "the-shire", tmpf,
556 true) < 0) {
557 lxc_error("%s\n", "lxc.uts.name");
558 goto non_test_error;
559 }
560
9c61a6d6 561 /* lxc.hook.pre-start */
8c582655
CB
562 if (set_get_compare_clear_save_load(
563 c, "lxc.hook.pre-start", "/some/pre-start", tmpf, false) < 0) {
9c61a6d6
CB
564 lxc_error("%s\n", "lxc.hook.pre-start");
565 goto non_test_error;
566 }
567
568 /* lxc.hook.pre-mount */
8c582655
CB
569 if (set_get_compare_clear_save_load(
570 c, "lxc.hook.pre-mount", "/some/pre-mount", tmpf, false) < 0) {
9c61a6d6
CB
571 lxc_error("%s\n", "lxc.hook.pre-mount");
572 goto non_test_error;
573 }
574
575 /* lxc.hook.mount */
8c582655
CB
576 if (set_get_compare_clear_save_load(c, "lxc.hook.mount", "/some/mount",
577 tmpf, false) < 0) {
9c61a6d6
CB
578 lxc_error("%s\n", "lxc.hook.mount");
579 goto non_test_error;
580 }
581
582 /* lxc.hook.autodev */
8c582655
CB
583 if (set_get_compare_clear_save_load(c, "lxc.hook.autodev",
584 "/some/autodev", tmpf, false) < 0) {
9c61a6d6
CB
585 lxc_error("%s\n", "lxc.hook.autodev");
586 goto non_test_error;
587 }
588
589 /* lxc.hook.start */
8c582655
CB
590 if (set_get_compare_clear_save_load(c, "lxc.hook.start", "/some/start",
591 tmpf, false) < 0) {
9c61a6d6
CB
592 lxc_error("%s\n", "lxc.hook.start");
593 goto non_test_error;
594 }
595
596 /* lxc.hook.stop */
8c582655
CB
597 if (set_get_compare_clear_save_load(c, "lxc.hook.stop", "/some/stop",
598 tmpf, false) < 0) {
9c61a6d6
CB
599 lxc_error("%s\n", "lxc.hook.stop");
600 goto non_test_error;
601 }
602
603 /* lxc.hook.post-stop */
8c582655
CB
604 if (set_get_compare_clear_save_load(
605 c, "lxc.hook.post-stop", "/some/post-stop", tmpf, false) < 0) {
9c61a6d6
CB
606 lxc_error("%s\n", "lxc.hook.post-stop");
607 goto non_test_error;
608 }
609
610 /* lxc.hook.clone */
8c582655
CB
611 if (set_get_compare_clear_save_load(c, "lxc.hook.clone", "/some/clone",
612 tmpf, false) < 0) {
9c61a6d6
CB
613 lxc_error("%s\n", "lxc.hook.clone");
614 goto non_test_error;
615 }
616
617 /* lxc.hook.destroy */
8c582655
CB
618 if (set_get_compare_clear_save_load(c, "lxc.hook.destroy",
619 "/some/destroy", tmpf, false) < 0) {
9c61a6d6
CB
620 lxc_error("%s\n", "lxc.hook.destroy");
621 goto non_test_error;
622 }
623
624 /* lxc.cap.drop */
8c582655
CB
625 if (set_get_compare_clear_save_load(c, "lxc.cap.drop",
626 "sys_module mknod setuid net_raw",
627 tmpf, false) < 0) {
9c61a6d6
CB
628 lxc_error("%s\n", "lxc.cap.drop");
629 goto non_test_error;
630 }
631
632 /* lxc.cap.keep */
8c582655
CB
633 if (set_get_compare_clear_save_load(c, "lxc.cap.keep",
634 "sys_module mknod setuid net_raw",
635 tmpf, false) < 0) {
9c61a6d6
CB
636 lxc_error("%s\n", "lxc.cap.keep");
637 goto non_test_error;
638 }
639
3aed4934
CB
640 /* REMOVE IN LXC 3.0
641 legacy lxc.console key
642 */
8c582655
CB
643 if (set_get_compare_clear_save_load(c, "lxc.console", "none", tmpf,
644 true) < 0) {
9c61a6d6
CB
645 lxc_error("%s\n", "lxc.console");
646 goto non_test_error;
647 }
648
3aed4934
CB
649 /* lxc.console.path */
650 if (set_get_compare_clear_save_load(c, "lxc.console.path", "none", tmpf,
651 true) < 0) {
652 lxc_error("%s\n", "lxc.console.path");
653 goto non_test_error;
654 }
655
9c61a6d6 656 /* lxc.console.logfile */
8c582655
CB
657 if (set_get_compare_clear_save_load(c, "lxc.console.logfile",
658 "/some/logfile", tmpf, true) < 0) {
9c61a6d6
CB
659 lxc_error("%s\n", "lxc.console.logfile");
660 goto non_test_error;
661 }
662
663 /* lxc.seccomp */
8c582655
CB
664 if (set_get_compare_clear_save_load(
665 c, "lxc.seccomp", "/some/seccomp/file", tmpf, true) < 0) {
9c61a6d6
CB
666 lxc_error("%s\n", "lxc.seccomp");
667 goto non_test_error;
668 }
669
670 /* lxc.autodev */
8c582655
CB
671 if (set_get_compare_clear_save_load(c, "lxc.autodev", "1", tmpf, true) <
672 0) {
9c61a6d6
CB
673 lxc_error("%s\n", "lxc.autodev");
674 goto non_test_error;
675 }
676
55c84efc 677 /* REMOVE IN LXC 3.0
678 legacy lxc.haltsignal key
679 */
8c582655
CB
680 if (set_get_compare_clear_save_load(c, "lxc.haltsignal", "1", tmpf,
681 true) < 0) {
9c61a6d6
CB
682 lxc_error("%s\n", "lxc.haltsignal");
683 goto non_test_error;
684 }
685
55c84efc 686 /* lxc.signal.halt */
687 if (set_get_compare_clear_save_load(c, "lxc.signal.halt", "1", tmpf,
688 true) < 0) {
689 lxc_error("%s\n", "lxc.signal.halt");
690 goto non_test_error;
691 }
692
693 /* REMOVE IN LXC 3.0
694 legacy lxc.rebootsignal key
695 */
8c582655
CB
696 if (set_get_compare_clear_save_load(c, "lxc.rebootsignal", "1", tmpf,
697 true) < 0) {
9c61a6d6
CB
698 lxc_error("%s\n", "lxc.rebootsignal");
699 goto non_test_error;
700 }
701
55c84efc 702 /* lxc.signal.reboot */
703 if (set_get_compare_clear_save_load(c, "lxc.signal.reboot", "1", tmpf,
704 true) < 0) {
705 lxc_error("%s\n", "lxc.signal.reboot");
706 goto non_test_error;
707 }
708
709 /* REMOVE IN LXC 3.0
710 legacy lxc.stopsignal key
711 */
8c582655
CB
712 if (set_get_compare_clear_save_load(c, "lxc.stopsignal", "1", tmpf,
713 true) < 0) {
9c61a6d6
CB
714 lxc_error("%s\n", "lxc.stopsignal");
715 goto non_test_error;
716 }
717
55c84efc 718 /* lxc.signal.stop */
719 if (set_get_compare_clear_save_load(c, "lxc.signal.stop", "1", tmpf,
720 true) < 0) {
721 lxc_error("%s\n", "lxc.signal.stop");
722 goto non_test_error;
723 }
724
9c61a6d6 725 /* lxc.start.auto */
8c582655
CB
726 if (set_get_compare_clear_save_load(c, "lxc.start.auto", "1", tmpf,
727 true) < 0) {
9c61a6d6
CB
728 lxc_error("%s\n", "lxc.start.auto");
729 goto non_test_error;
730 }
731
732 /* lxc.start.delay */
8c582655
CB
733 if (set_get_compare_clear_save_load(c, "lxc.start.delay", "5", tmpf,
734 true) < 0) {
9c61a6d6
CB
735 lxc_error("%s\n", "lxc.start.delay");
736 goto non_test_error;
737 }
738
739 /* lxc.start.order */
8c582655
CB
740 if (set_get_compare_clear_save_load(c, "lxc.start.order", "1", tmpf,
741 true) < 0) {
9c61a6d6
CB
742 lxc_error("%s\n", "lxc.start.order");
743 goto non_test_error;
744 }
745
46cc906d 746 /* lxc.log.syslog */
747 if (set_get_compare_clear_save_load(c, "lxc.log.syslog", "local0", tmpf,
8c582655 748 true) < 0) {
46cc906d 749 lxc_error("%s\n", "lxc.log.syslog");
9c61a6d6
CB
750 goto non_test_error;
751 }
752
753 /* lxc.utsname */
8c582655
CB
754 if (set_get_compare_clear_save_load(c, "lxc.utsname", "get-schwifty",
755 tmpf, true) < 0) {
9c61a6d6
CB
756 lxc_error("%s\n", "lxc.utsname");
757 goto non_test_error;
758 }
759
760 /* lxc.monitor.unshare */
8c582655
CB
761 if (set_get_compare_clear_save_load(c, "lxc.monitor.unshare", "1", tmpf,
762 true) < 0) {
9c61a6d6
CB
763 lxc_error("%s\n", "lxc.monitor.unshare");
764 goto non_test_error;
765 }
766
767 /* lxc.group */
8c582655
CB
768 if (set_get_compare_clear_save_load(
769 c, "lxc.group", "some,container,groups", tmpf, false) < 0) {
9c61a6d6
CB
770 lxc_error("%s\n", "lxc.group");
771 goto non_test_error;
772 }
773
774 /* lxc.environment */
8c582655
CB
775 if (set_get_compare_clear_save_load(c, "lxc.environment", "FOO=BAR",
776 tmpf, false) < 0) {
9c61a6d6
CB
777 lxc_error("%s\n", "lxc.environment");
778 goto non_test_error;
779 }
780
9dcf7b4d 781 /* REMOVE IN LXC 3.0
782 legacy lxc.init_cmd key
783 */
8c582655
CB
784 if (set_get_compare_clear_save_load(c, "lxc.init_cmd", "/bin/bash",
785 tmpf, true) < 0) {
9c61a6d6
CB
786 lxc_error("%s\n", "lxc.init_cmd");
787 goto non_test_error;
788 }
789
9dcf7b4d 790 /* lxc.init.cmd */
791 if (set_get_compare_clear_save_load(c, "lxc.init.cmd", "/bin/bash",
792 tmpf, true) < 0) {
793 lxc_error("%s\n", "lxc.init.cmd");
794 goto non_test_error;
795 }
796
797 /* REMOVE IN LXC 3.0
798 legacy lxc.init_uid key
799 */
8c582655
CB
800 if (set_get_compare_clear_save_load(c, "lxc.init_uid", "1000", tmpf,
801 true) < 0) {
9c61a6d6
CB
802 lxc_error("%s\n", "lxc.init_uid");
803 goto non_test_error;
804 }
805
9dcf7b4d 806 /* lxc.init.uid */
807 if (set_get_compare_clear_save_load(c, "lxc.init.uid", "1000", tmpf,
808 true) < 0) {
809 lxc_error("%s\n", "lxc.init.uid");
810 goto non_test_error;
811 }
812
813 /* REMOVE IN LXC 3.0
814 legacy lxc.init_gid key
815 */
8c582655
CB
816 if (set_get_compare_clear_save_load(c, "lxc.init_gid", "1000", tmpf,
817 true) < 0) {
9c61a6d6
CB
818 lxc_error("%s\n", "lxc.init_gid");
819 goto non_test_error;
820 }
821
9dcf7b4d 822 /* lxc.init.gid */
823 if (set_get_compare_clear_save_load(c, "lxc.init.gid", "1000", tmpf,
824 true) < 0) {
825 lxc_error("%s\n", "lxc.init.gid");
826 goto non_test_error;
827 }
828
9c61a6d6 829 /* lxc.ephemeral */
8c582655
CB
830 if (set_get_compare_clear_save_load(c, "lxc.ephemeral", "1", tmpf,
831 true) < 0) {
9c61a6d6
CB
832 lxc_error("%s\n", "lxc.ephemeral");
833 goto non_test_error;
834 }
835
836 /* lxc.no_new_privs */
8c582655
CB
837 if (set_get_compare_clear_save_load(c, "lxc.no_new_privs", "1", tmpf,
838 true) < 0) {
9c61a6d6
CB
839 lxc_error("%s\n", "lxc.no_new_privs");
840 goto non_test_error;
841 }
842
240d4b74 843 /* REMOVE IN LXC 3.0
844 legacy lxc.limit.* key
845 */
8c582655
CB
846 if (set_get_compare_clear_save_load(c, "lxc.limit.nofile", "65536",
847 tmpf, true) < 0) {
9c61a6d6
CB
848 lxc_error("%s\n", "lxc.limit.nofile");
849 goto non_test_error;
240d4b74 850 }
851
852 /* lxc.prlimit.nofile */
853 if (set_get_compare_clear_save_load(c, "lxc.prlimit.nofile", "65536",
854 tmpf, true) < 0) {
855 lxc_error("%s\n", "lxc.prlimit.nofile");
856 goto non_test_error;
9c61a6d6
CB
857 }
858
77803ee7
CB
859 if (test_idmap_parser() < 0) {
860 lxc_error("%s\n", "failed to test parser for \"lxc.id_map\"");
861 goto non_test_error;
862 }
863
01aebbc3 864 if (set_get_compare_clear_save_load(c, "lxc.net.0.type", "veth",
8c582655 865 tmpf, true)) {
01aebbc3 866 lxc_error("%s\n", "lxc.net.0.type");
8c582655
CB
867 goto non_test_error;
868 }
869
01aebbc3 870 if (set_get_compare_clear_save_load(c, "lxc.net.2.type", "none",
8c582655 871 tmpf, true)) {
01aebbc3 872 lxc_error("%s\n", "lxc.net.2.type");
8c582655
CB
873 goto non_test_error;
874 }
875
01aebbc3 876 if (set_get_compare_clear_save_load(c, "lxc.net.3.type", "empty",
8c582655 877 tmpf, true)) {
01aebbc3 878 lxc_error("%s\n", "lxc.net.3.type");
8c582655
CB
879 goto non_test_error;
880 }
881
01aebbc3 882 if (set_get_compare_clear_save_load(c, "lxc.net.4.type", "vlan",
8c582655 883 tmpf, true)) {
01aebbc3 884 lxc_error("%s\n", "lxc.net.4.type");
8c582655
CB
885 goto non_test_error;
886 }
887
01aebbc3 888 if (set_get_compare_clear_save_load(c, "lxc.net.0.type", "macvlan",
8c582655 889 tmpf, true)) {
01aebbc3 890 lxc_error("%s\n", "lxc.net.0.type");
8c582655
CB
891 goto non_test_error;
892 }
893
01aebbc3 894 if (set_get_compare_clear_save_load(c, "lxc.net.1000.type", "phys",
8c582655 895 tmpf, true)) {
01aebbc3 896 lxc_error("%s\n", "lxc.net.1000.type");
8c582655
CB
897 goto non_test_error;
898 }
899
01aebbc3 900 if (set_get_compare_clear_save_load(c, "lxc.net.0.flags", "up",
8c582655 901 tmpf, true)) {
01aebbc3 902 lxc_error("%s\n", "lxc.net.0.flags");
8c582655
CB
903 goto non_test_error;
904 }
905
01aebbc3 906 if (set_get_compare_clear_save_load(c, "lxc.net.0.name", "eth0",
8c582655 907 tmpf, true)) {
01aebbc3 908 lxc_error("%s\n", "lxc.net.0.name");
8c582655
CB
909 goto non_test_error;
910 }
911
01aebbc3 912 if (set_get_compare_clear_save_load(c, "lxc.net.0.link", "bla",
8c582655 913 tmpf, true)) {
01aebbc3 914 lxc_error("%s\n", "lxc.net.0.link");
8c582655
CB
915 goto non_test_error;
916 }
917
918 if (set_get_compare_clear_save_load_network(
01aebbc3 919 c, "lxc.net.0.macvlan.mode", "private", tmpf, true,
8c582655 920 "macvlan")) {
01aebbc3 921 lxc_error("%s\n", "lxc.net.0.macvlan.mode");
8c582655
CB
922 goto non_test_error;
923 }
924
925 if (set_get_compare_clear_save_load_network(
01aebbc3 926 c, "lxc.net.0.macvlan.mode", "vepa", tmpf, true,
8c582655 927 "macvlan")) {
01aebbc3 928 lxc_error("%s\n", "lxc.net.0.macvlan.mode");
8c582655
CB
929 goto non_test_error;
930 }
931
932 if (set_get_compare_clear_save_load_network(
01aebbc3 933 c, "lxc.net.0.macvlan.mode", "bridge", tmpf, true,
8c582655 934 "macvlan")) {
01aebbc3 935 lxc_error("%s\n", "lxc.net.0.macvlan.mode");
8c582655
CB
936 goto non_test_error;
937 }
938
939 if (set_get_compare_clear_save_load_network(
01aebbc3 940 c, "lxc.net.0.veth.pair", "clusterfuck", tmpf, true,
8c582655 941 "veth")) {
01aebbc3 942 lxc_error("%s\n", "lxc.net.0.veth.pair");
8c582655
CB
943 goto non_test_error;
944 }
945
01aebbc3 946 if (set_get_compare_clear_save_load(c, "lxc.net.0.script.up",
8c582655 947 "/some/up/path", tmpf, true)) {
01aebbc3 948 lxc_error("%s\n", "lxc.net.0.script.up");
8c582655
CB
949 goto non_test_error;
950 }
951
01aebbc3 952 if (set_get_compare_clear_save_load(c, "lxc.net.0.script.down",
8c582655 953 "/some/down/path", tmpf, true)) {
01aebbc3 954 lxc_error("%s\n", "lxc.net.0.script.down");
8c582655
CB
955 goto non_test_error;
956 }
957
01aebbc3 958 if (set_get_compare_clear_save_load(c, "lxc.net.0.hwaddr",
8c582655 959 "52:54:00:80:7a:5d", tmpf, true)) {
01aebbc3 960 lxc_error("%s\n", "lxc.net.0.hwaddr");
8c582655
CB
961 goto non_test_error;
962 }
963
01aebbc3 964 if (set_get_compare_clear_save_load(c, "lxc.net.0.mtu", "2000",
8c582655 965 tmpf, true)) {
01aebbc3 966 lxc_error("%s\n", "lxc.net.0.mtu");
8c582655
CB
967 goto non_test_error;
968 }
969
01aebbc3 970 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.vlan.id",
8c582655 971 "2", tmpf, true, "vlan")) {
01aebbc3 972 lxc_error("%s\n", "lxc.net.0.vlan.id");
8c582655
CB
973 goto non_test_error;
974 }
975
01aebbc3 976 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4.gateway",
8c582655 977 "10.0.2.2", tmpf, true)) {
01aebbc3 978 lxc_error("%s\n", "lxc.net.0.ipv4.gateway");
8c582655
CB
979 goto non_test_error;
980 }
981
01aebbc3 982 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv6.gateway",
8c582655 983 "2003:db8:1::1", tmpf, true)) {
01aebbc3 984 lxc_error("%s\n", "lxc.net.0.ipv6.gateway");
8c582655
CB
985 goto non_test_error;
986 }
987
9ff60df2 988 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4.address",
8c582655 989 "10.0.2.3/24", tmpf, true)) {
9ff60df2 990 lxc_error("%s\n", "lxc.net.0.ipv4.address");
8c582655
CB
991 goto non_test_error;
992 }
993
994 if (set_get_compare_clear_save_load(
2e44ae28 995 c, "lxc.net.0.ipv6.address", "2003:db8:1:0:214:1234:fe0b:3596/64",
8c582655 996 tmpf, true)) {
2e44ae28 997 lxc_error("%s\n", "lxc.net.0.ipv6.address");
8c582655
CB
998 goto non_test_error;
999 }
1000
1001 if (set_and_clear_complete_netdev(c) < 0) {
1002 lxc_error("%s\n", "failed to clear whole network");
1003 goto non_test_error;
1004 }
1005
9c61a6d6
CB
1006 ret = EXIT_SUCCESS;
1007non_test_error:
8c582655 1008 (void)unlink(tmpf);
9c61a6d6
CB
1009 c->destroy(c);
1010 lxc_container_put(c);
1011 exit(ret);
1012}