]>
git.proxmox.com Git - mirror_lxc.git/blob - src/tests/clonetest.c
3 * Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>.
4 * Copyright © 2012 Canonical Ltd.
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.
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.
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.
19 #include <lxc/lxccontainer.h>
24 #include <sys/types.h>
29 #define MYNAME "clonetest1"
30 #define MYNAME2 "clonetest2"
32 int main(int argc
, char *argv
[])
34 struct lxc_container
*c
= NULL
, *c2
= NULL
, *c3
= NULL
;
37 c
= lxc_container_new(MYNAME
, NULL
);
38 c2
= lxc_container_new(MYNAME2
, NULL
);
47 lxc_container_put(c2
);
51 if ((c
= lxc_container_new(MYNAME
, NULL
)) == NULL
) {
52 fprintf(stderr
, "%d: error opening lxc_container %s\n", __LINE__
, MYNAME
);
57 c
->save_config(c
, NULL
);
59 if (!c
->createl(c
, "busybox", NULL
, NULL
, 0, NULL
)) {
60 fprintf(stderr
, "%d: failed to create a container\n", __LINE__
);
64 c
->load_config(c
, NULL
);
66 if (!c
->is_defined(c
)) {
67 fprintf(stderr
, "%d: %s thought it was not defined\n", __LINE__
, MYNAME
);
71 c2
= c
->clone(c
, MYNAME2
, NULL
, 0, NULL
, NULL
, 0, NULL
);
73 fprintf(stderr
, "%d: %s clone returned NULL\n", __LINE__
, MYNAME2
);
77 if (!c2
->is_defined(c2
)) {
78 fprintf(stderr
, "%d: %s not defined after clone\n", __LINE__
, MYNAME2
);
82 fprintf(stderr
, "directory backing store tests passed\n");
85 // Only do this if clonetestlvm1 exists - user has to set this up
88 lxc_container_put(c2
);
93 c2
= lxc_container_new("clonetestlvm2", NULL
);
95 if (c2
->is_defined(c2
))
97 lxc_container_put(c2
);
100 c2
= lxc_container_new("clonetest-o1", NULL
);
102 if (c2
->is_defined(c2
))
104 lxc_container_put(c2
);
107 c2
= lxc_container_new("clonetest-o2", NULL
);
109 if (c2
->is_defined(c2
))
111 lxc_container_put(c2
);
116 c
= lxc_container_new("clonetestlvm1", NULL
);
118 fprintf(stderr
, "failed loading clonetestlvm1\n");
122 if (!c
->is_defined(c
)) {
123 fprintf(stderr
, "clonetestlvm1 does not exist, skipping lvm tests\n");
128 if ((c2
= c
->clone(c
, "clonetestlvm2", NULL
, 0, NULL
, NULL
, 0, NULL
)) == NULL
) {
129 fprintf(stderr
, "lvm clone failed\n");
133 lxc_container_put(c2
);
136 c2
= lxc_container_new("clonetestlvm3", NULL
);
138 if (c2
->is_defined(c2
))
140 lxc_container_put(c2
);
144 if ((c2
= c
->clone(c
, "clonetestlvm3", NULL
, LXC_CLONE_SNAPSHOT
, NULL
, NULL
, 0, NULL
)) == NULL
) {
145 fprintf(stderr
, "lvm clone failed\n");
149 lxc_container_put(c2
);
150 lxc_container_put(c
);
153 if ((c
= lxc_container_new(MYNAME
, NULL
)) == NULL
) {
154 fprintf(stderr
, "error opening original container for overlay test\n");
158 // Now create an overlayfs clone of a dir-backed container
159 if ((c2
= c
->clone(c
, "clonetest-o1", NULL
, LXC_CLONE_SNAPSHOT
, "overlayfs", NULL
, 0, NULL
)) == NULL
) {
160 fprintf(stderr
, "overlayfs clone of dir failed\n");
164 // Now create an overlayfs clone of the overlayfs clone
165 if ((c3
= c2
->clone(c2
, "clonetest-o2", NULL
, LXC_CLONE_SNAPSHOT
, "overlayfs", NULL
, 0, NULL
)) == NULL
) {
166 fprintf(stderr
, "overlayfs clone of overlayfs failed\n");
170 fprintf(stderr
, "all clone tests passed for %s\n", c
->name
);
175 lxc_container_put(c3
);
180 lxc_container_put(c2
);
185 lxc_container_put(c
);