]> git.proxmox.com Git - mirror_lxc.git/blob - src/tests/shutdowntest.c
replace all lxc.network* with lxc.net*
[mirror_lxc.git] / src / tests / shutdowntest.c
1
2 /* liblxcapi
3 *
4 * Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>.
5 * Copyright © 2012 Canonical Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2, as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20 #include <lxc/lxccontainer.h>
21
22 #include <unistd.h>
23 #include <signal.h>
24 #include <stdio.h>
25 #include <sys/types.h>
26 #include <sys/wait.h>
27 #include <stdlib.h>
28 #include <errno.h>
29
30 #define MYNAME "lxctest1"
31
32 int main(int argc, char *argv[])
33 {
34 struct lxc_container *c;
35 int ret = 1;
36
37 if ((c = lxc_container_new(MYNAME, NULL)) == NULL) {
38 fprintf(stderr, "%d: error opening lxc_container %s\n", __LINE__, MYNAME);
39 ret = 1;
40 goto out;
41 }
42
43 if (c->is_defined(c)) {
44 fprintf(stderr, "%d: %s thought it was defined\n", __LINE__, MYNAME);
45 goto out;
46 }
47
48 if (!c->set_config_item(c, "lxc.net.0.type", "veth")) {
49 fprintf(stderr, "%d: failed to set network type\n", __LINE__);
50 goto out;
51 }
52 c->set_config_item(c, "lxc.net.0.link", "lxcbr0");
53 c->set_config_item(c, "lxc.net.0.flags", "up");
54 if (!c->createl(c, "busybox", NULL, NULL, 0, NULL)) {
55 fprintf(stderr, "%d: failed to create a container\n", __LINE__);
56 goto out;
57 }
58
59 if (!c->is_defined(c)) {
60 fprintf(stderr, "%d: %s thought it was not defined\n", __LINE__, MYNAME);
61 goto out;
62 }
63
64 c->clear_config(c);
65 c->load_config(c, NULL);
66 c->want_daemonize(c, true);
67 if (!c->startl(c, 0, NULL)) {
68 fprintf(stderr, "%d: failed to start %s\n", __LINE__, MYNAME);
69 goto out;
70 }
71
72 /* Wait for init to be ready for SIGPWR */
73 sleep(20);
74
75 if (!c->shutdown(c, 120)) {
76 fprintf(stderr, "%d: failed to shut down %s\n", __LINE__, MYNAME);
77 if (!c->stop(c)) {
78 fprintf(stderr, "%d: failed to kill %s\n", __LINE__, MYNAME);
79 }
80 goto out;
81 }
82
83 if (!c->destroy(c)) {
84 fprintf(stderr, "%d: error deleting %s\n", __LINE__, MYNAME);
85 goto out;
86 }
87
88 if (c->is_defined(c)) {
89 fprintf(stderr, "%d: %s thought it was defined\n", __LINE__, MYNAME);
90 goto out;
91 }
92
93 fprintf(stderr, "all lxc_container tests passed for %s\n", c->name);
94 ret = 0;
95 out:
96 if (c && c->is_defined(c)) {
97 c->destroy(c);
98 }
99
100 lxc_container_put(c);
101 exit(ret);
102 }