]>
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> |
df24d436 | 29 | #include <libgen.h> |
9c61a6d6 | 30 | |
77803ee7 | 31 | #include "confile_utils.h" |
9c61a6d6 CB |
32 | #include "lxc/state.h" |
33 | #include "lxctest.h" | |
dd5c5a5d | 34 | #include "utils.h" |
9c61a6d6 | 35 | |
ae4ad10d CB |
36 | static int set_get_compare_clear_save_load(struct lxc_container *c, |
37 | const char *key, const char *value, | |
38 | const char *config_file, | |
39 | bool compare) | |
9c61a6d6 CB |
40 | { |
41 | char retval[4096] = {0}; | |
42 | int ret; | |
43 | ||
44 | if (!c->set_config_item(c, key, value)) { | |
45 | lxc_error("failed to set config item \"%s\" to \"%s\"\n", key, | |
46 | value); | |
47 | return -1; | |
48 | } | |
49 | ||
50 | ret = c->get_config_item(c, key, retval, sizeof(retval)); | |
51 | if (ret < 0) { | |
52 | lxc_error("failed to get config item \"%s\"\n", key); | |
53 | return -1; | |
54 | } | |
55 | ||
ae4ad10d CB |
56 | if (compare) { |
57 | ret = strcmp(retval, value); | |
58 | if (ret != 0) { | |
59 | lxc_error( | |
60 | "expected value \"%s\" and retrieved value \"%s\" " | |
61 | "for config key \"%s\" do not match\n", | |
62 | value, retval, key); | |
63 | return -1; | |
64 | } | |
65 | } | |
66 | ||
9c61a6d6 CB |
67 | if (config_file) { |
68 | if (!c->save_config(c, config_file)) { | |
69 | lxc_error("%s\n", "failed to save config file"); | |
70 | return -1; | |
71 | } | |
72 | ||
73 | c->clear_config(c); | |
74 | c->lxc_conf = NULL; | |
75 | ||
76 | if (!c->load_config(c, config_file)) { | |
77 | lxc_error("%s\n", "failed to load config file"); | |
78 | return -1; | |
79 | } | |
80 | } | |
81 | ||
82 | if (!c->clear_config_item(c, key)) { | |
83 | lxc_error("failed to clear config item \"%s\"\n", key); | |
84 | return -1; | |
85 | } | |
86 | ||
8c582655 CB |
87 | c->clear_config(c); |
88 | c->lxc_conf = NULL; | |
9c61a6d6 | 89 | |
8c582655 CB |
90 | return 0; |
91 | } | |
9c61a6d6 | 92 | |
8c582655 CB |
93 | static int set_and_clear_complete_netdev(struct lxc_container *c) |
94 | { | |
01aebbc3 CB |
95 | if (!c->set_config_item(c, "lxc.net.1.type", "veth")) { |
96 | lxc_error("%s\n", "lxc.net.1.type"); | |
8c582655 CB |
97 | return -1; |
98 | } | |
99 | ||
9ff60df2 CB |
100 | if (!c->set_config_item(c, "lxc.net.1.ipv4.address", "10.0.2.3/24")) { |
101 | lxc_error("%s\n", "lxc.net.1.ipv4.address"); | |
8c582655 CB |
102 | return -1; |
103 | } | |
104 | ||
9ff60df2 CB |
105 | if (!c->set_config_item(c, "lxc.net.1.ipv4.gateway", "10.0.2.2")) { |
106 | lxc_error("%s\n", "lxc.net.1.ipv4.gateway"); | |
8c582655 CB |
107 | return -1; |
108 | } | |
109 | ||
2e44ae28 | 110 | if (!c->set_config_item(c, "lxc.net.1.ipv6.address", |
8c582655 | 111 | "2003:db8:1:0:214:1234:fe0b:3596/64")) { |
2e44ae28 | 112 | lxc_error("%s\n", "lxc.net.1.ipv6.address"); |
8c582655 CB |
113 | return -1; |
114 | } | |
115 | ||
2e44ae28 | 116 | if (!c->set_config_item(c, "lxc.net.1.ipv6.gateway", |
8c582655 | 117 | "2003:db8:1:0::1")) { |
2e44ae28 | 118 | lxc_error("%s\n", "lxc.net.1.ipv6.gateway"); |
8c582655 CB |
119 | return -1; |
120 | } | |
121 | ||
01aebbc3 CB |
122 | if (!c->set_config_item(c, "lxc.net.1.flags", "up")) { |
123 | lxc_error("%s\n", "lxc.net.1.flags"); | |
8c582655 CB |
124 | return -1; |
125 | } | |
126 | ||
01aebbc3 CB |
127 | if (!c->set_config_item(c, "lxc.net.1.link", "br0")) { |
128 | lxc_error("%s\n", "lxc.net.1.link"); | |
8c582655 CB |
129 | return -1; |
130 | } | |
131 | ||
01aebbc3 CB |
132 | if (!c->set_config_item(c, "lxc.net.1.veth.pair", "bla")) { |
133 | lxc_error("%s\n", "lxc.net.1.veth.pair"); | |
8c582655 CB |
134 | return -1; |
135 | } | |
136 | ||
01aebbc3 | 137 | if (!c->set_config_item(c, "lxc.net.1.hwaddr", |
8c582655 | 138 | "52:54:00:80:7a:5d")) { |
01aebbc3 | 139 | lxc_error("%s\n", "lxc.net.1.hwaddr"); |
8c582655 CB |
140 | return -1; |
141 | } | |
142 | ||
01aebbc3 CB |
143 | if (!c->set_config_item(c, "lxc.net.1.mtu", "2000")) { |
144 | lxc_error("%s\n", "lxc.net.1.mtu"); | |
8c582655 CB |
145 | return -1; |
146 | } | |
147 | ||
01aebbc3 CB |
148 | if (!c->clear_config_item(c, "lxc.net.1")) { |
149 | lxc_error("%s", "failed to clear \"lxc.net.1\"\n"); | |
8c582655 | 150 | return -1; |
9c61a6d6 CB |
151 | } |
152 | ||
153 | c->clear_config(c); | |
154 | c->lxc_conf = NULL; | |
155 | ||
156 | return 0; | |
157 | } | |
158 | ||
8bc6d539 FA |
159 | static int set_invalid_netdev(struct lxc_container *c) { |
160 | if (c->set_config_item(c, "lxc.net.0.asdf", "veth")) { | |
161 | lxc_error("%s\n", "lxc.net.0.asdf should be invalid"); | |
162 | return -1; | |
163 | } | |
164 | ||
165 | if (c->set_config_item(c, "lxc.net.2147483647.type", "veth")) { | |
166 | lxc_error("%s\n", "lxc.net.2147483647.type should be invalid"); | |
167 | return -1; | |
168 | } | |
169 | ||
24fa7df6 FA |
170 | if (c->set_config_item(c, "lxc.net.0.", "veth")) { |
171 | lxc_error("%s\n", "lxc.net.0. should be invalid"); | |
172 | return -1; | |
173 | } | |
174 | ||
8bc6d539 FA |
175 | c->clear_config(c); |
176 | c->lxc_conf = NULL; | |
177 | ||
178 | return 0; | |
179 | } | |
180 | ||
77803ee7 CB |
181 | int test_idmap_parser(void) |
182 | { | |
183 | size_t i; | |
184 | struct idmap_check { | |
185 | bool is_valid; | |
186 | const char *idmap; | |
187 | }; | |
188 | static struct idmap_check idmaps[] = { | |
8c582655 CB |
189 | /* valid idmaps */ |
190 | { true, "u 0 0 1" }, | |
191 | { true, "g 0 0 1" }, | |
192 | { true, "u 1 100001 999999999" }, | |
193 | { true, "g 1 100001 999999999" }, | |
194 | { true, "u 0 0 0" }, | |
195 | { true, "g 0 0 0" }, | |
196 | { true, "u 1000 165536 65536" }, | |
197 | { true, "g 999 999 1" }, | |
198 | { true, "u 0 5000 100000" }, | |
199 | { true, "g 577 789 5" }, | |
200 | { true, "u 65536 65536 1 " }, | |
201 | /* invalid idmaps */ | |
202 | { false, "1u 0 0 0" }, | |
203 | { false, "1g 0 0 0a" }, | |
204 | { false, "1 u 0 0 0" }, | |
205 | { false, "1g 0 0 0 1" }, | |
206 | { false, "1u a0 b0 c0 d1" }, | |
207 | { false, "1g 0 b0 0 d1" }, | |
208 | { false, "1u a0 0 c0 1" }, | |
209 | { false, "g -1 0 -10" }, | |
210 | { false, "a 1 0 10" }, | |
211 | { false, "u 1 1 0 10" }, | |
212 | { false, "g 1 0 10 z " }, | |
77803ee7 CB |
213 | }; |
214 | ||
215 | for (i = 0; i < sizeof(idmaps) / sizeof(struct idmap_check); i++) { | |
216 | unsigned long hostid, nsid, range; | |
217 | char type; | |
218 | int ret; | |
219 | ret = parse_idmaps(idmaps[i].idmap, &type, &nsid, &hostid, | |
220 | &range); | |
221 | if ((ret < 0 && idmaps[i].is_valid) || | |
222 | (ret == 0 && !idmaps[i].is_valid)) { | |
223 | lxc_error("failed to parse idmap \"%s\"\n", | |
224 | idmaps[i].idmap); | |
225 | return -1; | |
226 | } | |
227 | } | |
228 | ||
229 | return 0; | |
230 | } | |
231 | ||
8c582655 CB |
232 | static int set_get_compare_clear_save_load_network( |
233 | struct lxc_container *c, const char *key, const char *value, | |
234 | const char *config_file, bool compare, const char *network_type) | |
235 | { | |
236 | char retval[4096] = {0}; | |
237 | int ret; | |
238 | ||
01aebbc3 CB |
239 | if (!c->set_config_item(c, "lxc.net.0.type", network_type)) { |
240 | lxc_error("%s\n", "lxc.net.0.type"); | |
8c582655 CB |
241 | return -1; |
242 | } | |
243 | ||
244 | if (!c->set_config_item(c, key, value)) { | |
245 | lxc_error("failed to set config item \"%s\" to \"%s\"\n", key, | |
246 | value); | |
247 | return -1; | |
248 | } | |
249 | ||
250 | ret = c->get_config_item(c, key, retval, sizeof(retval)); | |
251 | if (ret < 0) { | |
252 | lxc_error("failed to get config item \"%s\"\n", key); | |
253 | return -1; | |
254 | } | |
255 | ||
256 | if (compare) { | |
257 | ret = strcmp(retval, value); | |
258 | if (ret != 0) { | |
259 | lxc_error( | |
260 | "expected value \"%s\" and retrieved value \"%s\" " | |
261 | "for config key \"%s\" do not match\n", | |
262 | value, retval, key); | |
263 | return -1; | |
264 | } | |
265 | } | |
266 | ||
267 | if (config_file) { | |
268 | if (!c->save_config(c, config_file)) { | |
269 | lxc_error("%s\n", "failed to save config file"); | |
270 | return -1; | |
271 | } | |
272 | ||
273 | c->clear_config(c); | |
274 | c->lxc_conf = NULL; | |
275 | ||
276 | if (!c->load_config(c, config_file)) { | |
277 | lxc_error("%s\n", "failed to load config file"); | |
278 | return -1; | |
279 | } | |
280 | } | |
281 | ||
282 | if (!c->clear_config_item(c, key)) { | |
283 | lxc_error("failed to clear config item \"%s\"\n", key); | |
284 | return -1; | |
285 | } | |
286 | ||
01aebbc3 CB |
287 | if (!c->clear_config_item(c, "lxc.net.0.type")) { |
288 | lxc_error("%s\n", "lxc.net.0.type"); | |
8c582655 CB |
289 | return -1; |
290 | } | |
291 | ||
292 | c->clear_config(c); | |
293 | c->lxc_conf = NULL; | |
294 | ||
295 | return 0; | |
296 | } | |
297 | ||
9c61a6d6 CB |
298 | int main(int argc, char *argv[]) |
299 | { | |
44ae0fb6 | 300 | int ret; |
9c61a6d6 | 301 | struct lxc_container *c; |
44ae0fb6 | 302 | int fd = -1, fret = EXIT_FAILURE; |
9c61a6d6 CB |
303 | char tmpf[] = "lxc-parse-config-file-XXXXXX"; |
304 | char retval[4096] = {0}; | |
305 | ||
dd5c5a5d | 306 | fd = lxc_make_tmpfile(tmpf, false); |
9c61a6d6 CB |
307 | if (fd < 0) { |
308 | lxc_error("%s\n", "Could not create temporary file"); | |
44ae0fb6 | 309 | exit(fret); |
9c61a6d6 CB |
310 | } |
311 | close(fd); | |
312 | ||
6cd5db20 LW |
313 | c = lxc_container_new(tmpf, NULL); |
314 | if (!c) { | |
315 | lxc_error("%s\n", "Failed to create new container"); | |
316 | exit(EXIT_FAILURE); | |
317 | } | |
8c582655 | 318 | |
8c582655 CB |
319 | if (set_get_compare_clear_save_load(c, "lxc.arch", "x86_64", tmpf, |
320 | true) < 0) { | |
9c61a6d6 CB |
321 | lxc_error("%s\n", "lxc.arch"); |
322 | goto non_test_error; | |
323 | } | |
324 | ||
2a6d08c6 | 325 | if (set_get_compare_clear_save_load(c, "lxc.pty.max", "1000", tmpf, true) < 0) { |
6fba98b5 | 326 | lxc_error("%s\n", "lxc.pty.max"); |
9c61a6d6 CB |
327 | goto non_test_error; |
328 | } | |
329 | ||
2a6d08c6 | 330 | if (set_get_compare_clear_save_load(c, "lxc.tty.max", "4", tmpf, true) < 0) { |
fe1c5887 | 331 | lxc_error("%s\n", "lxc.tty.max"); |
9c61a6d6 CB |
332 | goto non_test_error; |
333 | } | |
334 | ||
2a6d08c6 | 335 | if (set_get_compare_clear_save_load(c, "lxc.tty.dir", "not-dev", tmpf, true) < 0) { |
42e53c29 | 336 | lxc_error("%s\n", "lxc.tty.dir"); |
337 | goto non_test_error; | |
338 | } | |
339 | ||
2a6d08c6 | 340 | if (set_get_compare_clear_save_load(c, "lxc.apparmor.profile", "unconfined", tmpf, true) < 0) { |
953fe44f CB |
341 | lxc_error("%s\n", "lxc.apparmor.profile"); |
342 | goto non_test_error; | |
343 | } | |
344 | ||
2a6d08c6 | 345 | if (set_get_compare_clear_save_load(c, "lxc.apparmor.allow_incomplete", "1", tmpf, true) < 0) { |
953fe44f CB |
346 | lxc_error("%s\n", "lxc.apparmor.allow_incomplete"); |
347 | goto non_test_error; | |
348 | } | |
349 | ||
2a6d08c6 | 350 | if (set_get_compare_clear_save_load(c, "lxc.selinux.context", "system_u:system_r:lxc_t:s0:c22", tmpf, true) < 0) { |
f30ab9fe | 351 | lxc_error("%s\n", "lxc.selinux.context"); |
953fe44f CB |
352 | goto non_test_error; |
353 | } | |
354 | ||
8c582655 CB |
355 | if (set_get_compare_clear_save_load(c, "lxc.cgroup.cpuset.cpus", |
356 | "1-100", tmpf, false) < 0) { | |
9c61a6d6 CB |
357 | lxc_error("%s\n", "lxc.cgroup.cpuset.cpus"); |
358 | goto non_test_error; | |
359 | } | |
360 | ||
9c61a6d6 | 361 | if (!c->set_config_item(c, "lxc.cgroup.cpuset.cpus", "1-100")) { |
2a6d08c6 | 362 | lxc_error("%s\n", "failed to set config item \"lxc.cgroup.cpuset.cpus\" to \"1-100\""); |
9c61a6d6 CB |
363 | return -1; |
364 | } | |
365 | ||
2a6d08c6 CB |
366 | if (!c->set_config_item(c, "lxc.cgroup.memory.limit_in_bytes", "123456789")) { |
367 | lxc_error("%s\n", "failed to set config item \"lxc.cgroup.memory.limit_in_bytes\" to \"123456789\""); | |
9c61a6d6 CB |
368 | return -1; |
369 | } | |
370 | ||
371 | if (!c->get_config_item(c, "lxc.cgroup", retval, sizeof(retval))) { | |
372 | lxc_error("%s\n", "failed to get config item \"lxc.cgroup\""); | |
373 | return -1; | |
374 | } | |
375 | ||
376 | c->clear_config(c); | |
377 | c->lxc_conf = NULL; | |
378 | ||
bdcbb6b3 CB |
379 | /* lxc.idmap |
380 | * We can't really save the config here since save_config() wants to | |
381 | * chown the container's directory but we haven't created an on-disk | |
382 | * container. So let's test set-get-clear. | |
383 | */ | |
2a6d08c6 | 384 | if (set_get_compare_clear_save_load(c, "lxc.idmap", "u 0 100000 1000000000", NULL, false) < 0) { |
bdcbb6b3 CB |
385 | lxc_error("%s\n", "lxc.idmap"); |
386 | goto non_test_error; | |
387 | } | |
388 | ||
389 | if (!c->set_config_item(c, "lxc.idmap", "u 1 100000 10000000")) { | |
2a6d08c6 | 390 | lxc_error("%s\n", "failed to set config item \"lxc.idmap\" to \"u 1 100000 10000000\""); |
bdcbb6b3 CB |
391 | return -1; |
392 | } | |
393 | ||
394 | if (!c->set_config_item(c, "lxc.idmap", "g 1 100000 10000000")) { | |
2a6d08c6 | 395 | lxc_error("%s\n", "failed to set config item \"lxc.idmap\" to \"g 1 100000 10000000\""); |
bdcbb6b3 CB |
396 | return -1; |
397 | } | |
398 | ||
399 | if (!c->get_config_item(c, "lxc.idmap", retval, sizeof(retval))) { | |
d6bec4ab | 400 | lxc_error("%s\n", "failed to get config item \"lxc.idmap\""); |
bdcbb6b3 CB |
401 | return -1; |
402 | } | |
403 | ||
9c61a6d6 CB |
404 | c->clear_config(c); |
405 | c->lxc_conf = NULL; | |
406 | ||
2a6d08c6 | 407 | if (set_get_compare_clear_save_load(c, "lxc.log.level", "DEBUG", tmpf, true) < 0) { |
46cc906d | 408 | lxc_error("%s\n", "lxc.log.level"); |
409 | goto non_test_error; | |
410 | } | |
411 | ||
2a6d08c6 | 412 | if (set_get_compare_clear_save_load(c, "lxc.log.file", "/some/path", tmpf, true) < 0) { |
46cc906d | 413 | lxc_error("%s\n", "lxc.log.file"); |
414 | goto non_test_error; | |
415 | } | |
416 | ||
2a6d08c6 | 417 | if (set_get_compare_clear_save_load(c, "lxc.mount.fstab", "/some/path", NULL, true) < 0) { |
47148e96 CB |
418 | lxc_error("%s\n", "lxc.mount.fstab"); |
419 | goto non_test_error; | |
420 | } | |
421 | ||
ae4ad10d CB |
422 | /* lxc.mount.auto |
423 | * Note that we cannot compare the values since the getter for | |
424 | * lxc.mount.auto does not preserve ordering. | |
425 | */ | |
2a6d08c6 | 426 | if (set_get_compare_clear_save_load(c, "lxc.mount.auto", "proc:rw sys:rw cgroup-full:rw", tmpf, false) < 0) { |
9c61a6d6 CB |
427 | lxc_error("%s\n", "lxc.mount.auto"); |
428 | goto non_test_error; | |
429 | } | |
430 | ||
ae4ad10d CB |
431 | /* lxc.mount.entry |
432 | * Note that we cannot compare the values since the getter for | |
433 | * lxc.mount.entry appends newlines. | |
434 | */ | |
2a6d08c6 | 435 | if (set_get_compare_clear_save_load(c, "lxc.mount.entry", "/dev/dri dev/dri none bind,optional,create=dir", tmpf, false) < 0) { |
9c61a6d6 CB |
436 | lxc_error("%s\n", "lxc.mount.entry"); |
437 | goto non_test_error; | |
438 | } | |
439 | ||
2a6d08c6 | 440 | if (set_get_compare_clear_save_load(c, "lxc.rootfs.path", "/some/path", tmpf, true) < 0) { |
7a96a068 CB |
441 | lxc_error("%s\n", "lxc.rootfs.path"); |
442 | goto non_test_error; | |
443 | } | |
444 | ||
2a6d08c6 | 445 | if (set_get_compare_clear_save_load(c, "lxc.rootfs.mount", "/some/path", tmpf, true) < 0) { |
9c61a6d6 CB |
446 | lxc_error("%s\n", "lxc.rootfs.mount"); |
447 | goto non_test_error; | |
448 | } | |
449 | ||
2a6d08c6 | 450 | if (set_get_compare_clear_save_load(c, "lxc.rootfs.options", "ext4,discard", tmpf, true) < 0) { |
9c61a6d6 CB |
451 | lxc_error("%s\n", "lxc.rootfs.options"); |
452 | goto non_test_error; | |
453 | } | |
454 | ||
2a6d08c6 | 455 | if (set_get_compare_clear_save_load(c, "lxc.uts.name", "the-shire", tmpf, true) < 0) { |
b67771bc | 456 | lxc_error("%s\n", "lxc.uts.name"); |
457 | goto non_test_error; | |
458 | } | |
459 | ||
8c582655 CB |
460 | if (set_get_compare_clear_save_load( |
461 | c, "lxc.hook.pre-start", "/some/pre-start", tmpf, false) < 0) { | |
9c61a6d6 CB |
462 | lxc_error("%s\n", "lxc.hook.pre-start"); |
463 | goto non_test_error; | |
464 | } | |
465 | ||
8c582655 CB |
466 | if (set_get_compare_clear_save_load( |
467 | c, "lxc.hook.pre-mount", "/some/pre-mount", tmpf, false) < 0) { | |
9c61a6d6 CB |
468 | lxc_error("%s\n", "lxc.hook.pre-mount"); |
469 | goto non_test_error; | |
470 | } | |
471 | ||
2a6d08c6 | 472 | if (set_get_compare_clear_save_load(c, "lxc.hook.mount", "/some/mount", tmpf, false) < 0) { |
9c61a6d6 CB |
473 | lxc_error("%s\n", "lxc.hook.mount"); |
474 | goto non_test_error; | |
475 | } | |
476 | ||
2a6d08c6 | 477 | if (set_get_compare_clear_save_load(c, "lxc.hook.autodev", "/some/autodev", tmpf, false) < 0) { |
9c61a6d6 CB |
478 | lxc_error("%s\n", "lxc.hook.autodev"); |
479 | goto non_test_error; | |
480 | } | |
481 | ||
2a6d08c6 | 482 | if (set_get_compare_clear_save_load(c, "lxc.hook.start", "/some/start", tmpf, false) < 0) { |
9c61a6d6 CB |
483 | lxc_error("%s\n", "lxc.hook.start"); |
484 | goto non_test_error; | |
485 | } | |
486 | ||
2a6d08c6 | 487 | if (set_get_compare_clear_save_load(c, "lxc.hook.stop", "/some/stop", tmpf, false) < 0) { |
9c61a6d6 CB |
488 | lxc_error("%s\n", "lxc.hook.stop"); |
489 | goto non_test_error; | |
490 | } | |
491 | ||
2a6d08c6 | 492 | if (set_get_compare_clear_save_load(c, "lxc.hook.post-stop", "/some/post-stop", tmpf, false) < 0) { |
9c61a6d6 CB |
493 | lxc_error("%s\n", "lxc.hook.post-stop"); |
494 | goto non_test_error; | |
495 | } | |
496 | ||
2a6d08c6 | 497 | if (set_get_compare_clear_save_load(c, "lxc.hook.clone", "/some/clone", tmpf, false) < 0) { |
9c61a6d6 CB |
498 | lxc_error("%s\n", "lxc.hook.clone"); |
499 | goto non_test_error; | |
500 | } | |
501 | ||
2a6d08c6 | 502 | if (set_get_compare_clear_save_load(c, "lxc.hook.destroy", "/some/destroy", tmpf, false) < 0) { |
9c61a6d6 CB |
503 | lxc_error("%s\n", "lxc.hook.destroy"); |
504 | goto non_test_error; | |
505 | } | |
506 | ||
2a6d08c6 | 507 | if (set_get_compare_clear_save_load(c, "lxc.cap.drop", "sys_module mknod setuid net_raw", tmpf, false) < 0) { |
9c61a6d6 CB |
508 | lxc_error("%s\n", "lxc.cap.drop"); |
509 | goto non_test_error; | |
510 | } | |
511 | ||
2a6d08c6 | 512 | if (set_get_compare_clear_save_load(c, "lxc.cap.keep", "sys_module mknod setuid net_raw", tmpf, false) < 0) { |
9c61a6d6 CB |
513 | lxc_error("%s\n", "lxc.cap.keep"); |
514 | goto non_test_error; | |
515 | } | |
516 | ||
2a6d08c6 | 517 | if (set_get_compare_clear_save_load(c, "lxc.console.path", "none", tmpf, true) < 0) { |
3aed4934 CB |
518 | lxc_error("%s\n", "lxc.console.path"); |
519 | goto non_test_error; | |
520 | } | |
521 | ||
2a6d08c6 | 522 | if (set_get_compare_clear_save_load(c, "lxc.console.logfile", "/some/logfile", tmpf, true) < 0) { |
9c61a6d6 CB |
523 | lxc_error("%s\n", "lxc.console.logfile"); |
524 | goto non_test_error; | |
525 | } | |
526 | ||
2a6d08c6 | 527 | if (set_get_compare_clear_save_load(c, "lxc.seccomp.profile", "/some/seccomp/file", tmpf, true) < 0) { |
0b427da0 CB |
528 | lxc_error("%s\n", "lxc.seccomp.profile"); |
529 | goto non_test_error; | |
530 | } | |
531 | ||
8c582655 CB |
532 | if (set_get_compare_clear_save_load(c, "lxc.autodev", "1", tmpf, true) < |
533 | 0) { | |
9c61a6d6 CB |
534 | lxc_error("%s\n", "lxc.autodev"); |
535 | goto non_test_error; | |
536 | } | |
537 | ||
2a6d08c6 | 538 | if (set_get_compare_clear_save_load(c, "lxc.signal.halt", "1", tmpf, true) < 0) { |
55c84efc | 539 | lxc_error("%s\n", "lxc.signal.halt"); |
540 | goto non_test_error; | |
541 | } | |
542 | ||
2a6d08c6 | 543 | if (set_get_compare_clear_save_load(c, "lxc.signal.reboot", "1", tmpf, true) < 0) { |
55c84efc | 544 | lxc_error("%s\n", "lxc.signal.reboot"); |
545 | goto non_test_error; | |
546 | } | |
547 | ||
2a6d08c6 | 548 | if (set_get_compare_clear_save_load(c, "lxc.signal.stop", "1", tmpf, true) < 0) { |
55c84efc | 549 | lxc_error("%s\n", "lxc.signal.stop"); |
550 | goto non_test_error; | |
551 | } | |
552 | ||
2a6d08c6 | 553 | if (set_get_compare_clear_save_load(c, "lxc.start.auto", "1", tmpf, true) < 0) { |
9c61a6d6 CB |
554 | lxc_error("%s\n", "lxc.start.auto"); |
555 | goto non_test_error; | |
556 | } | |
557 | ||
2a6d08c6 | 558 | if (set_get_compare_clear_save_load(c, "lxc.start.delay", "5", tmpf, true) < 0) { |
9c61a6d6 CB |
559 | lxc_error("%s\n", "lxc.start.delay"); |
560 | goto non_test_error; | |
561 | } | |
562 | ||
2a6d08c6 | 563 | if (set_get_compare_clear_save_load(c, "lxc.start.order", "1", tmpf, true) < 0) { |
9c61a6d6 CB |
564 | lxc_error("%s\n", "lxc.start.order"); |
565 | goto non_test_error; | |
566 | } | |
567 | ||
2a6d08c6 | 568 | if (set_get_compare_clear_save_load(c, "lxc.log.syslog", "local0", tmpf, true) < 0) { |
46cc906d | 569 | lxc_error("%s\n", "lxc.log.syslog"); |
9c61a6d6 CB |
570 | goto non_test_error; |
571 | } | |
572 | ||
2a6d08c6 | 573 | if (set_get_compare_clear_save_load(c, "lxc.monitor.unshare", "1", tmpf, true) < 0) { |
9c61a6d6 CB |
574 | lxc_error("%s\n", "lxc.monitor.unshare"); |
575 | goto non_test_error; | |
576 | } | |
577 | ||
2a6d08c6 | 578 | if (set_get_compare_clear_save_load(c, "lxc.group", "some,container,groups", tmpf, false) < 0) { |
9c61a6d6 CB |
579 | lxc_error("%s\n", "lxc.group"); |
580 | goto non_test_error; | |
581 | } | |
582 | ||
2a6d08c6 | 583 | if (set_get_compare_clear_save_load(c, "lxc.environment", "FOO=BAR", tmpf, false) < 0) { |
9c61a6d6 CB |
584 | lxc_error("%s\n", "lxc.environment"); |
585 | goto non_test_error; | |
586 | } | |
587 | ||
2a6d08c6 | 588 | if (set_get_compare_clear_save_load(c, "lxc.init.cmd", "/bin/bash", tmpf, true) < 0) { |
9dcf7b4d | 589 | lxc_error("%s\n", "lxc.init.cmd"); |
590 | goto non_test_error; | |
591 | } | |
592 | ||
2a6d08c6 | 593 | if (set_get_compare_clear_save_load(c, "lxc.init.uid", "1000", tmpf, true) < 0) { |
9dcf7b4d | 594 | lxc_error("%s\n", "lxc.init.uid"); |
595 | goto non_test_error; | |
596 | } | |
597 | ||
2a6d08c6 | 598 | if (set_get_compare_clear_save_load(c, "lxc.init.gid", "1000", tmpf, true) < 0) { |
9dcf7b4d | 599 | lxc_error("%s\n", "lxc.init.gid"); |
600 | goto non_test_error; | |
601 | } | |
602 | ||
2a6d08c6 | 603 | if (set_get_compare_clear_save_load(c, "lxc.ephemeral", "1", tmpf, true) < 0) { |
9c61a6d6 CB |
604 | lxc_error("%s\n", "lxc.ephemeral"); |
605 | goto non_test_error; | |
606 | } | |
607 | ||
2a6d08c6 | 608 | if (set_get_compare_clear_save_load(c, "lxc.no_new_privs", "1", tmpf, true) < 0) { |
9c61a6d6 CB |
609 | lxc_error("%s\n", "lxc.no_new_privs"); |
610 | goto non_test_error; | |
611 | } | |
612 | ||
2a6d08c6 | 613 | if (set_get_compare_clear_save_load(c, "lxc.sysctl.net.core.somaxconn", "256", tmpf, true) < 0) { |
7edd0540 L |
614 | lxc_error("%s\n", "lxc.sysctl.net.core.somaxconn"); |
615 | goto non_test_error; | |
616 | } | |
617 | ||
2a6d08c6 | 618 | if (set_get_compare_clear_save_load(c, "lxc.proc.oom_score_adj", "10", tmpf, true) < 0) { |
61d7a733 YT |
619 | lxc_error("%s\n", "lxc.proc.oom_score_adj"); |
620 | goto non_test_error; | |
621 | } | |
622 | ||
2a6d08c6 | 623 | if (set_get_compare_clear_save_load(c, "lxc.prlimit.nofile", "65536", tmpf, true) < 0) { |
240d4b74 | 624 | lxc_error("%s\n", "lxc.prlimit.nofile"); |
625 | goto non_test_error; | |
9c61a6d6 CB |
626 | } |
627 | ||
77803ee7 CB |
628 | if (test_idmap_parser() < 0) { |
629 | lxc_error("%s\n", "failed to test parser for \"lxc.id_map\""); | |
630 | goto non_test_error; | |
631 | } | |
632 | ||
2a6d08c6 | 633 | if (set_get_compare_clear_save_load(c, "lxc.net.0.type", "veth", tmpf, true)) { |
01aebbc3 | 634 | lxc_error("%s\n", "lxc.net.0.type"); |
8c582655 CB |
635 | goto non_test_error; |
636 | } | |
637 | ||
2a6d08c6 | 638 | if (set_get_compare_clear_save_load(c, "lxc.net.2.type", "none", tmpf, true)) { |
01aebbc3 | 639 | lxc_error("%s\n", "lxc.net.2.type"); |
8c582655 CB |
640 | goto non_test_error; |
641 | } | |
642 | ||
2a6d08c6 | 643 | if (set_get_compare_clear_save_load(c, "lxc.net.3.type", "empty", tmpf, true)) { |
01aebbc3 | 644 | lxc_error("%s\n", "lxc.net.3.type"); |
8c582655 CB |
645 | goto non_test_error; |
646 | } | |
647 | ||
2a6d08c6 | 648 | if (set_get_compare_clear_save_load(c, "lxc.net.4.type", "vlan", tmpf, true)) { |
01aebbc3 | 649 | lxc_error("%s\n", "lxc.net.4.type"); |
8c582655 CB |
650 | goto non_test_error; |
651 | } | |
652 | ||
2a6d08c6 | 653 | if (set_get_compare_clear_save_load(c, "lxc.net.0.type", "macvlan", tmpf, true)) { |
01aebbc3 | 654 | lxc_error("%s\n", "lxc.net.0.type"); |
8c582655 CB |
655 | goto non_test_error; |
656 | } | |
657 | ||
2a6d08c6 | 658 | if (set_get_compare_clear_save_load(c, "lxc.net.1000.type", "phys", tmpf, true)) { |
01aebbc3 | 659 | lxc_error("%s\n", "lxc.net.1000.type"); |
8c582655 CB |
660 | goto non_test_error; |
661 | } | |
662 | ||
2a6d08c6 | 663 | if (set_get_compare_clear_save_load(c, "lxc.net.0.flags", "up", tmpf, true)) { |
01aebbc3 | 664 | lxc_error("%s\n", "lxc.net.0.flags"); |
8c582655 CB |
665 | goto non_test_error; |
666 | } | |
667 | ||
2a6d08c6 | 668 | if (set_get_compare_clear_save_load(c, "lxc.net.0.name", "eth0", tmpf, true)) { |
01aebbc3 | 669 | lxc_error("%s\n", "lxc.net.0.name"); |
8c582655 CB |
670 | goto non_test_error; |
671 | } | |
672 | ||
2a6d08c6 | 673 | if (set_get_compare_clear_save_load(c, "lxc.net.0.link", "bla", tmpf, true)) { |
01aebbc3 | 674 | lxc_error("%s\n", "lxc.net.0.link"); |
8c582655 CB |
675 | goto non_test_error; |
676 | } | |
677 | ||
2a6d08c6 | 678 | if (set_get_compare_clear_save_load_network(c, "lxc.net.0.macvlan.mode", "private", tmpf, true, "macvlan")) { |
01aebbc3 | 679 | lxc_error("%s\n", "lxc.net.0.macvlan.mode"); |
8c582655 CB |
680 | goto non_test_error; |
681 | } | |
682 | ||
2a6d08c6 | 683 | if (set_get_compare_clear_save_load_network(c, "lxc.net.0.macvlan.mode", "vepa", tmpf, true, "macvlan")) { |
01aebbc3 | 684 | lxc_error("%s\n", "lxc.net.0.macvlan.mode"); |
8c582655 CB |
685 | goto non_test_error; |
686 | } | |
687 | ||
2a6d08c6 | 688 | if (set_get_compare_clear_save_load_network(c, "lxc.net.0.macvlan.mode", "bridge", tmpf, true, "macvlan")) { |
01aebbc3 | 689 | lxc_error("%s\n", "lxc.net.0.macvlan.mode"); |
8c582655 CB |
690 | goto non_test_error; |
691 | } | |
692 | ||
2a6d08c6 | 693 | if (set_get_compare_clear_save_load_network(c, "lxc.net.0.veth.pair", "clusterfuck", tmpf, true, "veth")) { |
01aebbc3 | 694 | lxc_error("%s\n", "lxc.net.0.veth.pair"); |
8c582655 CB |
695 | goto non_test_error; |
696 | } | |
697 | ||
2a6d08c6 | 698 | if (set_get_compare_clear_save_load(c, "lxc.net.0.script.up", "/some/up/path", tmpf, true)) { |
01aebbc3 | 699 | lxc_error("%s\n", "lxc.net.0.script.up"); |
8c582655 CB |
700 | goto non_test_error; |
701 | } | |
702 | ||
2a6d08c6 | 703 | if (set_get_compare_clear_save_load(c, "lxc.net.0.script.down", "/some/down/path", tmpf, true)) { |
01aebbc3 | 704 | lxc_error("%s\n", "lxc.net.0.script.down"); |
8c582655 CB |
705 | goto non_test_error; |
706 | } | |
707 | ||
2a6d08c6 | 708 | if (set_get_compare_clear_save_load(c, "lxc.net.0.hwaddr", "52:54:00:80:7a:5d", tmpf, true)) { |
01aebbc3 | 709 | lxc_error("%s\n", "lxc.net.0.hwaddr"); |
8c582655 CB |
710 | goto non_test_error; |
711 | } | |
712 | ||
2a6d08c6 | 713 | if (set_get_compare_clear_save_load(c, "lxc.net.0.mtu", "2000", tmpf, true)) { |
01aebbc3 | 714 | lxc_error("%s\n", "lxc.net.0.mtu"); |
8c582655 CB |
715 | goto non_test_error; |
716 | } | |
717 | ||
2a6d08c6 | 718 | if (set_get_compare_clear_save_load_network(c, "lxc.net.0.vlan.id", "2", tmpf, true, "vlan")) { |
01aebbc3 | 719 | lxc_error("%s\n", "lxc.net.0.vlan.id"); |
8c582655 CB |
720 | goto non_test_error; |
721 | } | |
722 | ||
2a6d08c6 | 723 | if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4.gateway", "10.0.2.2", tmpf, true)) { |
01aebbc3 | 724 | lxc_error("%s\n", "lxc.net.0.ipv4.gateway"); |
8c582655 CB |
725 | goto non_test_error; |
726 | } | |
727 | ||
2a6d08c6 | 728 | if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv6.gateway", "2003:db8:1::1", tmpf, true)) { |
01aebbc3 | 729 | lxc_error("%s\n", "lxc.net.0.ipv6.gateway"); |
8c582655 CB |
730 | goto non_test_error; |
731 | } | |
732 | ||
2a6d08c6 | 733 | if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4.address", "10.0.2.3/24", tmpf, true)) { |
9ff60df2 | 734 | lxc_error("%s\n", "lxc.net.0.ipv4.address"); |
8c582655 CB |
735 | goto non_test_error; |
736 | } | |
737 | ||
2a6d08c6 | 738 | if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv6.address", "2003:db8:1:0:214:1234:fe0b:3596/64", tmpf, true)) { |
2e44ae28 | 739 | lxc_error("%s\n", "lxc.net.0.ipv6.address"); |
8c582655 CB |
740 | goto non_test_error; |
741 | } | |
742 | ||
2a6d08c6 | 743 | if (set_get_compare_clear_save_load(c, "lxc.cgroup.dir", "lxd", tmpf, true)) { |
dae8c253 CB |
744 | lxc_error("%s\n", "lxc.cgroup.dir"); |
745 | goto non_test_error; | |
746 | } | |
747 | ||
8c582655 CB |
748 | if (set_and_clear_complete_netdev(c) < 0) { |
749 | lxc_error("%s\n", "failed to clear whole network"); | |
750 | goto non_test_error; | |
751 | } | |
752 | ||
8bc6d539 FA |
753 | if (set_invalid_netdev(c) < 0) { |
754 | lxc_error("%s\n", "failed to reject invalid configuration"); | |
755 | goto non_test_error; | |
756 | } | |
757 | ||
44ae0fb6 CB |
758 | ret = set_get_compare_clear_save_load(c, "lxc.hook.version", "1", tmpf, true); |
759 | if (ret < 0) { | |
760 | lxc_error("%s\n", "lxc.hook.version"); | |
761 | goto non_test_error; | |
762 | } | |
763 | ||
764 | ret = set_get_compare_clear_save_load(c, "lxc.hook.version", "2", tmpf, true); | |
765 | if (ret == 0) { | |
766 | lxc_error("%s\n", "lxc.hook.version"); | |
767 | goto non_test_error; | |
768 | } | |
769 | ||
e53cd6d8 CB |
770 | ret = set_get_compare_clear_save_load(c, "lxc.monitor.signal.pdeath", "SIGKILL", tmpf, true); |
771 | if (ret == 0) { | |
772 | lxc_error("%s\n", "lxc.hook.version"); | |
773 | goto non_test_error; | |
774 | } | |
775 | ||
6e0045bd CB |
776 | if (set_get_compare_clear_save_load(c, "lxc.rootfs.managed", "1", tmpf, true) < 0) { |
777 | lxc_error("%s\n", "lxc.rootfs.managed"); | |
778 | goto non_test_error; | |
779 | } | |
780 | ||
646e6c8b CB |
781 | if (c->set_config_item(c, "lxc.notaconfigkey", "invalid")) { |
782 | lxc_error("%s\n", "Managed to set to set invalid config item \"lxc.notaconfigkey\" to \"invalid\""); | |
783 | return -1; | |
784 | } | |
785 | ||
44ae0fb6 CB |
786 | fret = EXIT_SUCCESS; |
787 | ||
9c61a6d6 | 788 | non_test_error: |
8c582655 | 789 | (void)unlink(tmpf); |
df24d436 | 790 | (void)rmdir(dirname(c->configfile)); |
9c61a6d6 | 791 | lxc_container_put(c); |
44ae0fb6 | 792 | exit(fret); |
9c61a6d6 | 793 | } |