]>
Commit | Line | Data |
---|---|---|
9be53773 SH |
1 | /* liblxcapi |
2 | * | |
3 | * Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>. | |
4 | * Copyright © 2012 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 | */ | |
e49c56d6 CB |
19 | |
20 | #include "config.h" | |
21 | ||
948955a2 | 22 | #include <lxc/lxccontainer.h> |
9be53773 SH |
23 | |
24 | #include <unistd.h> | |
25 | #include <signal.h> | |
26 | #include <stdio.h> | |
27 | #include <sys/types.h> | |
28 | #include <sys/wait.h> | |
29 | #include <stdlib.h> | |
30 | #include <errno.h> | |
31 | ||
32 | #define MYNAME "clonetest1" | |
33 | #define MYNAME2 "clonetest2" | |
34 | ||
35 | int main(int argc, char *argv[]) | |
36 | { | |
37 | struct lxc_container *c = NULL, *c2 = NULL, *c3 = NULL; | |
38 | int ret = 1; | |
39 | ||
40 | c = lxc_container_new(MYNAME, NULL); | |
41 | c2 = lxc_container_new(MYNAME2, NULL); | |
42 | if (c) { | |
43 | c->destroy(c); | |
44 | lxc_container_put(c); | |
45 | c = NULL; | |
46 | } | |
1c95b732 | 47 | |
9be53773 SH |
48 | if (c2) { |
49 | c2->destroy(c2); | |
50 | lxc_container_put(c2); | |
51 | c2 = NULL; | |
52 | } | |
53 | ||
54 | if ((c = lxc_container_new(MYNAME, NULL)) == NULL) { | |
55 | fprintf(stderr, "%d: error opening lxc_container %s\n", __LINE__, MYNAME); | |
56 | ret = 1; | |
57 | goto out; | |
58 | } | |
1c95b732 | 59 | |
9be53773 | 60 | c->save_config(c, NULL); |
1c95b732 | 61 | |
787c3ebe | 62 | if (!c->createl(c, "busybox", NULL, NULL, 0, NULL)) { |
9be53773 SH |
63 | fprintf(stderr, "%d: failed to create a container\n", __LINE__); |
64 | goto out; | |
65 | } | |
1c95b732 | 66 | |
9be53773 SH |
67 | c->load_config(c, NULL); |
68 | ||
69 | if (!c->is_defined(c)) { | |
70 | fprintf(stderr, "%d: %s thought it was not defined\n", __LINE__, MYNAME); | |
71 | goto out; | |
72 | } | |
73 | ||
481624b3 | 74 | c2 = c->clone(c, MYNAME2, NULL, 0, NULL, NULL, 0, NULL); |
9be53773 SH |
75 | if (!c2) { |
76 | fprintf(stderr, "%d: %s clone returned NULL\n", __LINE__, MYNAME2); | |
77 | goto out; | |
78 | } | |
79 | ||
3856bc9f | 80 | if (!c2->is_defined(c2)) { |
9be53773 SH |
81 | fprintf(stderr, "%d: %s not defined after clone\n", __LINE__, MYNAME2); |
82 | goto out; | |
83 | } | |
84 | ||
85 | fprintf(stderr, "directory backing store tests passed\n"); | |
86 | ||
87 | // now test with lvm | |
88 | // Only do this if clonetestlvm1 exists - user has to set this up | |
89 | // in advance | |
0898897a | 90 | c2->destroy(c2); |
9be53773 | 91 | lxc_container_put(c2); |
0898897a | 92 | c->destroy(c); |
9be53773 SH |
93 | lxc_container_put(c); |
94 | c = NULL; | |
95 | ||
96 | c2 = lxc_container_new("clonetestlvm2", NULL); | |
97 | if (c2) { | |
98 | if (c2->is_defined(c2)) | |
99 | c2->destroy(c2); | |
100 | lxc_container_put(c2); | |
101 | } | |
1c95b732 | 102 | |
9be53773 SH |
103 | c2 = lxc_container_new("clonetest-o1", NULL); |
104 | if (c2) { | |
105 | if (c2->is_defined(c2)) | |
106 | c2->destroy(c2); | |
107 | lxc_container_put(c2); | |
108 | } | |
1c95b732 | 109 | |
9be53773 SH |
110 | c2 = lxc_container_new("clonetest-o2", NULL); |
111 | if (c2) { | |
112 | if (c2->is_defined(c2)) | |
113 | c2->destroy(c2); | |
114 | lxc_container_put(c2); | |
115 | } | |
116 | c2 = NULL; | |
117 | ||
118 | // lvm-copied | |
119 | c = lxc_container_new("clonetestlvm1", NULL); | |
120 | if (!c) { | |
121 | fprintf(stderr, "failed loading clonetestlvm1\n"); | |
122 | goto out; | |
123 | } | |
1c95b732 | 124 | |
9be53773 SH |
125 | if (!c->is_defined(c)) { |
126 | fprintf(stderr, "clonetestlvm1 does not exist, skipping lvm tests\n"); | |
127 | ret = 0; | |
128 | goto out; | |
129 | } | |
130 | ||
481624b3 | 131 | if ((c2 = c->clone(c, "clonetestlvm2", NULL, 0, NULL, NULL, 0, NULL)) == NULL) { |
9be53773 SH |
132 | fprintf(stderr, "lvm clone failed\n"); |
133 | goto out; | |
134 | } | |
135 | ||
136 | lxc_container_put(c2); | |
137 | ||
138 | // lvm-snapshot | |
139 | c2 = lxc_container_new("clonetestlvm3", NULL); | |
140 | if (c2) { | |
141 | if (c2->is_defined(c2)) | |
142 | c2->destroy(c2); | |
143 | lxc_container_put(c2); | |
144 | c2 = NULL; | |
145 | } | |
146 | ||
481624b3 | 147 | if ((c2 = c->clone(c, "clonetestlvm3", NULL, LXC_CLONE_SNAPSHOT, NULL, NULL, 0, NULL)) == NULL) { |
9be53773 SH |
148 | fprintf(stderr, "lvm clone failed\n"); |
149 | goto out; | |
150 | } | |
1c95b732 | 151 | |
9be53773 SH |
152 | lxc_container_put(c2); |
153 | lxc_container_put(c); | |
154 | c = c2 = NULL; | |
155 | ||
156 | if ((c = lxc_container_new(MYNAME, NULL)) == NULL) { | |
157 | fprintf(stderr, "error opening original container for overlay test\n"); | |
158 | goto out; | |
159 | } | |
160 | ||
161 | // Now create an overlayfs clone of a dir-backed container | |
481624b3 | 162 | if ((c2 = c->clone(c, "clonetest-o1", NULL, LXC_CLONE_SNAPSHOT, "overlayfs", NULL, 0, NULL)) == NULL) { |
9be53773 SH |
163 | fprintf(stderr, "overlayfs clone of dir failed\n"); |
164 | goto out; | |
165 | } | |
166 | ||
167 | // Now create an overlayfs clone of the overlayfs clone | |
481624b3 | 168 | if ((c3 = c2->clone(c2, "clonetest-o2", NULL, LXC_CLONE_SNAPSHOT, "overlayfs", NULL, 0, NULL)) == NULL) { |
9be53773 SH |
169 | fprintf(stderr, "overlayfs clone of overlayfs failed\n"); |
170 | goto out; | |
171 | } | |
172 | ||
173 | fprintf(stderr, "all clone tests passed for %s\n", c->name); | |
174 | ret = 0; | |
175 | ||
176 | out: | |
177 | if (c3) { | |
178 | lxc_container_put(c3); | |
179 | } | |
1c95b732 | 180 | |
9be53773 | 181 | if (c2) { |
0898897a | 182 | c2->destroy(c2); |
9be53773 SH |
183 | lxc_container_put(c2); |
184 | } | |
1c95b732 | 185 | |
9be53773 | 186 | if (c) { |
0898897a | 187 | c->destroy(c); |
9be53773 SH |
188 | lxc_container_put(c); |
189 | } | |
1c95b732 | 190 | |
9be53773 SH |
191 | exit(ret); |
192 | } |