]>
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
);
46 lxc_container_put(c2
);
50 if ((c
= lxc_container_new(MYNAME
, NULL
)) == NULL
) {
51 fprintf(stderr
, "%d: error opening lxc_container %s\n", __LINE__
, MYNAME
);
55 c
->save_config(c
, NULL
);
56 if (!c
->createl(c
, "busybox", NULL
, NULL
, 0, NULL
)) {
57 fprintf(stderr
, "%d: failed to create a container\n", __LINE__
);
60 c
->load_config(c
, NULL
);
62 if (!c
->is_defined(c
)) {
63 fprintf(stderr
, "%d: %s thought it was not defined\n", __LINE__
, MYNAME
);
67 c2
= c
->clone(c
, MYNAME2
, NULL
, 0, NULL
, NULL
, 0, NULL
);
69 fprintf(stderr
, "%d: %s clone returned NULL\n", __LINE__
, MYNAME2
);
73 if (!c2
->is_defined(c2
)) {
74 fprintf(stderr
, "%d: %s not defined after clone\n", __LINE__
, MYNAME2
);
78 fprintf(stderr
, "directory backing store tests passed\n");
81 // Only do this if clonetestlvm1 exists - user has to set this up
84 lxc_container_put(c2
);
89 c2
= lxc_container_new("clonetestlvm2", NULL
);
91 if (c2
->is_defined(c2
))
93 lxc_container_put(c2
);
95 c2
= lxc_container_new("clonetest-o1", NULL
);
97 if (c2
->is_defined(c2
))
99 lxc_container_put(c2
);
101 c2
= lxc_container_new("clonetest-o2", NULL
);
103 if (c2
->is_defined(c2
))
105 lxc_container_put(c2
);
110 c
= lxc_container_new("clonetestlvm1", NULL
);
112 fprintf(stderr
, "failed loading clonetestlvm1\n");
115 if (!c
->is_defined(c
)) {
116 fprintf(stderr
, "clonetestlvm1 does not exist, skipping lvm tests\n");
121 if ((c2
= c
->clone(c
, "clonetestlvm2", NULL
, 0, NULL
, NULL
, 0, NULL
)) == NULL
) {
122 fprintf(stderr
, "lvm clone failed\n");
126 lxc_container_put(c2
);
129 c2
= lxc_container_new("clonetestlvm3", NULL
);
131 if (c2
->is_defined(c2
))
133 lxc_container_put(c2
);
137 if ((c2
= c
->clone(c
, "clonetestlvm3", NULL
, LXC_CLONE_SNAPSHOT
, NULL
, NULL
, 0, NULL
)) == NULL
) {
138 fprintf(stderr
, "lvm clone failed\n");
141 lxc_container_put(c2
);
142 lxc_container_put(c
);
145 if ((c
= lxc_container_new(MYNAME
, NULL
)) == NULL
) {
146 fprintf(stderr
, "error opening original container for overlay test\n");
150 // Now create an overlayfs clone of a dir-backed container
151 if ((c2
= c
->clone(c
, "clonetest-o1", NULL
, LXC_CLONE_SNAPSHOT
, "overlayfs", NULL
, 0, NULL
)) == NULL
) {
152 fprintf(stderr
, "overlayfs clone of dir failed\n");
156 // Now create an overlayfs clone of the overlayfs clone
157 if ((c3
= c2
->clone(c2
, "clonetest-o2", NULL
, LXC_CLONE_SNAPSHOT
, "overlayfs", NULL
, 0, NULL
)) == NULL
) {
158 fprintf(stderr
, "overlayfs clone of overlayfs failed\n");
162 fprintf(stderr
, "all clone tests passed for %s\n", c
->name
);
167 lxc_container_put(c3
);
171 lxc_container_put(c2
);
175 lxc_container_put(c
);