4
ensure_import_testimage
5
ensure_has_localhost_remote "${LXD_ADDR}"
10
# FIXME: make this backend agnostic
11
if [ "${LXD_BACKEND}" = "dir" ]; then
12
[ -d "${LXD_DIR}/snapshots/foo/snap0" ]
16
# FIXME: make this backend agnostic
17
if [ "${LXD_BACKEND}" = "dir" ]; then
18
[ -d "${LXD_DIR}/snapshots/foo/snap1" ]
21
lxc snapshot foo tester
22
# FIXME: make this backend agnostic
23
if [ "${LXD_BACKEND}" = "dir" ]; then
24
[ -d "${LXD_DIR}/snapshots/foo/tester" ]
27
lxc copy foo/tester foosnap1
28
# FIXME: make this backend agnostic
29
if [ "${LXD_BACKEND}" != "lvm" ]; then
30
[ -d "${LXD_DIR}/containers/foosnap1/rootfs" ]
34
# FIXME: make this backend agnostic
35
if [ "${LXD_BACKEND}" = "dir" ]; then
36
[ ! -d "${LXD_DIR}/snapshots/foo/snap0" ]
39
# no CLI for this, so we use the API directly (rename a snapshot)
40
wait_for "${LXD_ADDR}" my_curl -X POST "https://${LXD_ADDR}/1.0/containers/foo/snapshots/tester" -d "{\"name\":\"tester2\"}"
41
# FIXME: make this backend agnostic
42
if [ "${LXD_BACKEND}" = "dir" ]; then
43
[ ! -d "${LXD_DIR}/snapshots/foo/tester" ]
46
lxc move foo/tester2 foo/tester-two
47
lxc delete foo/tester-two
48
# FIXME: make this backend agnostic
49
if [ "${LXD_BACKEND}" = "dir" ]; then
50
[ ! -d "${LXD_DIR}/snapshots/foo/tester-two" ]
53
lxc snapshot foo namechange
54
# FIXME: make this backend agnostic
55
if [ "${LXD_BACKEND}" = "dir" ]; then
56
[ -d "${LXD_DIR}/snapshots/foo/namechange" ]
59
[ ! -d "${LXD_DIR}/containers/foo" ]
60
[ -d "${LXD_DIR}/containers/foople" ]
61
# FIXME: make this backend agnostic
62
if [ "${LXD_BACKEND}" = "dir" ]; then
63
[ -d "${LXD_DIR}/snapshots/foople/namechange" ]
64
[ -d "${LXD_DIR}/snapshots/foople/namechange" ]
69
[ ! -d "${LXD_DIR}/containers/foople" ]
70
[ ! -d "${LXD_DIR}/containers/foosnap1" ]
74
ensure_import_testimage
75
ensure_has_localhost_remote "${LXD_ADDR}"
77
##########################################################
79
##########################################################
81
## create some state we will check for when snapshot is restored
84
lxc launch testimage bar
86
lxc file push state bar/root/state
87
lxc file push state bar/root/file_only_in_snap0
89
mkdir "${LXD_DIR}/containers/bar/rootfs/root/dir_only_in_snap0"
90
cd "${LXD_DIR}/containers/bar/rootfs/root/"
91
ln -s ./file_only_in_snap0 statelink
95
lxc snapshot bar snap0
100
lxc file push state bar/root/state
101
lxc file push state bar/root/file_only_in_snap1
103
cd "${LXD_DIR}/containers/bar/rootfs/root/"
104
rmdir dir_only_in_snap0
105
rm file_only_in_snap0
107
ln -s ./file_only_in_snap1 statelink
108
mkdir dir_only_in_snap1
112
# Delete the state file we created to prevent leaking.
115
lxc config set bar limits.cpu 1
117
lxc snapshot bar snap1
119
##########################################################
121
# FIXME: make this backend agnostic
122
if [ "${LXD_BACKEND}" = "dir" ]; then
123
# The problem here is that you can't `zfs rollback` to a snapshot with a
124
# parent, which snap0 has (snap1).
125
restore_and_compare_fs snap0
127
# Check container config has been restored (limits.cpu is unset)
128
cpus=$(lxc config get bar limits.cpu)
129
if [ -n "${cpus}" ]; then
130
echo "==> config didn't match expected value after restore (${cpus})"
135
##########################################################
137
# test restore using full snapshot name
138
restore_and_compare_fs snap1
140
# Check config value in snapshot has been restored
141
cpus=$(lxc config get bar limits.cpu)
142
if [ "${cpus}" != "1" ]; then
143
echo "==> config didn't match expected value after restore (${cpus})"
147
##########################################################
149
# Start container and then restore snapshot to verify the running state after restore.
152
# FIXME: make this backend agnostic
153
if [ "${LXD_BACKEND}" = "dir" ]; then
154
# see comment above about snap0
155
restore_and_compare_fs snap0
157
# check container is running after restore
158
lxc list | grep bar | grep RUNNING
166
restore_and_compare_fs() {
168
echo "==> Restoring ${snap}"
170
lxc restore bar "${snap}"
172
# FIXME: make this backend agnostic
173
if [ "${LXD_BACKEND}" = "dir" ]; then
174
# Recursive diff of container FS
175
diff -r "${LXD_DIR}/containers/bar/rootfs" "${LXD_DIR}/snapshots/bar/${snap}/rootfs"