]>
git.proxmox.com Git - mirror_lxc.git/blob - src/tests/snapshot.c
3 * Copyright © 2013 Serge Hallyn <serge.hallyn@ubuntu.com>.
4 * Copyright © 2013 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 "../lxc/lxc.h"
26 #define MYNAME "snapxxx1"
27 #define RESTNAME "snapxxx2"
31 struct lxc_container
*c
;
33 c
= lxc_container_new(RESTNAME
, NULL
);
39 snprintf(snappath
, 1024, "%ssnaps/%s", lxc_get_default_config_path(), MYNAME
);
40 c
= lxc_container_new("snap0", snappath
);
46 c
= lxc_container_new(MYNAME
, NULL
);
54 int main(int argc
, char *argv
[])
56 struct lxc_container
*c
;
57 char *template = "busybox";
63 c
= lxc_container_new(MYNAME
, NULL
);
65 fprintf(stderr
, "%s: %d: failed to load first container\n", __FILE__
, __LINE__
);
69 if (c
->is_defined(c
)) {
70 fprintf(stderr
, "%d: %s thought it was defined\n", __LINE__
, MYNAME
);
73 if (!c
->set_config_item(c
, "lxc.network.type", "empty")) {
74 fprintf(stderr
, "%s: %d: failed to set network type\n", __FILE__
, __LINE__
);
77 c
->save_config(c
, NULL
);
78 if (!c
->createl(c
, template, NULL
, NULL
, 0, NULL
)) {
79 fprintf(stderr
, "%s: %d: failed to create %s container\n", __FILE__
, __LINE__
, template);
82 c
->load_config(c
, NULL
);
84 if (c
->snapshot(c
, NULL
) != 0) {
85 fprintf(stderr
, "%s: %d: failed to create snapsot\n", __FILE__
, __LINE__
);
89 // rootfs should be ${lxcpath}snaps/${lxcname}/snap0/rootfs
93 snprintf(path
, 1024, "%ssnaps/%s/snap0/rootfs", lxc_get_default_config_path(), MYNAME
);
94 ret
= stat(path
, &sb
);
96 fprintf(stderr
, "%s: %d: snapshot was not actually created\n", __FILE__
, __LINE__
);
100 struct lxc_snapshot
*s
;
103 n
= c
->snapshot_list(c
, &s
);
105 fprintf(stderr
, "%s: %d: failed listing containers\n", __FILE__
, __LINE__
);
108 if (strcmp(s
->name
, "snap0") != 0) {
109 fprintf(stderr
, "%s: %d: snapshot had bad name\n", __FILE__
, __LINE__
);
112 for (i
=0; i
<n
; i
++) {
117 if (!c
->snapshot_restore(c
, "snap0", RESTNAME
)) {
118 fprintf(stderr
, "%s: %d: failed to restore snapshot\n", __FILE__
, __LINE__
);
122 if (!c
->snapshot_destroy(c
, "snap0")) {
123 fprintf(stderr
, "%s: %d: failed to destroy snapshot\n", __FILE__
, __LINE__
);
127 if (!c
->destroy(c
)) {
128 fprintf(stderr
, "%s: %d: failed to destroy container\n", __FILE__
, __LINE__
);
132 lxc_container_put(c
);
135 printf("All tests passed\n");
138 lxc_container_put(c
);
141 fprintf(stderr
, "Exiting on error\n");