]>
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"
23 #include "../lxc/lxc.h"
25 #define MYNAME "snapxxx1"
26 #define RESTNAME "snapxxx2"
30 struct lxc_container
*c
;
32 c
= lxc_container_new(RESTNAME
, NULL
);
38 snprintf(snappath
, 1024, "%ssnaps/%s", lxc_get_default_config_path(), MYNAME
);
39 c
= lxc_container_new("snap0", snappath
);
45 c
= lxc_container_new(MYNAME
, NULL
);
53 int main(int argc
, char *argv
[])
55 struct lxc_container
*c
;
56 char *template = "busybox";
62 c
= lxc_container_new(MYNAME
, NULL
);
64 fprintf(stderr
, "%s: %d: failed to load first container\n", __FILE__
, __LINE__
);
68 if (c
->is_defined(c
)) {
69 fprintf(stderr
, "%d: %s thought it was defined\n", __LINE__
, MYNAME
);
72 if (!c
->set_config_item(c
, "lxc.network.type", "empty")) {
73 fprintf(stderr
, "%s: %d: failed to set network type\n", __FILE__
, __LINE__
);
76 c
->save_config(c
, NULL
);
77 if (!c
->createl(c
, template, NULL
, NULL
, 0, NULL
)) {
78 fprintf(stderr
, "%s: %d: failed to create %s container\n", __FILE__
, __LINE__
, template);
81 c
->load_config(c
, NULL
);
83 if (c
->snapshot(c
, NULL
) != 0) {
84 fprintf(stderr
, "%s: %d: failed to create snapsot\n", __FILE__
, __LINE__
);
88 // rootfs should be ${lxcpath}snaps/${lxcname}/snap0/rootfs
92 snprintf(path
, 1024, "%ssnaps/%s/snap0/rootfs", lxc_get_default_config_path(), MYNAME
);
93 ret
= stat(path
, &sb
);
95 fprintf(stderr
, "%s: %d: snapshot was not actually created\n", __FILE__
, __LINE__
);
99 struct lxc_snapshot
*s
;
102 n
= c
->snapshot_list(c
, &s
);
104 fprintf(stderr
, "%s: %d: failed listing containers\n", __FILE__
, __LINE__
);
107 if (strcmp(s
->name
, "snap0") != 0) {
108 fprintf(stderr
, "%s: %d: snapshot had bad name\n", __FILE__
, __LINE__
);
111 for (i
=0; i
<n
; i
++) {
116 if (!c
->snapshot_restore(c
, "snap0", RESTNAME
)) {
117 fprintf(stderr
, "%s: %d: failed to restore snapshot\n", __FILE__
, __LINE__
);
121 printf("All tests passed\n");
122 lxc_container_put(c
);
126 lxc_container_put(c
);
127 fprintf(stderr
, "Exiting on error\n");