[pve-devel] [PATCH v2 container 5/5] Add snapshot tests
Fabian Grünbichler
f.gruenbichler at proxmox.com
Mon Feb 22 13:31:29 CET 2016
tested so far:
-snapshot_prepare
-snapshot_commit
-snapshot_create
-snapshot_delete
---
Changes to v1:
skip rename of src/test/test-* to src/test/setup-* and associated
change in run_setup_tests.pl, to limit noise in the patch.
src/test/Makefile | 10 +-
src/test/run_setup_tests.pl | 98 +++++++
src/test/run_snapshot_tests.pl | 10 +
src/test/run_tests.pl | 98 -------
src/test/snapshot-expected/commit/lxc/101.conf | 23 ++
src/test/snapshot-expected/commit/lxc/102.conf | 37 +++
src/test/snapshot-expected/commit/lxc/201.conf | 9 +
src/test/snapshot-expected/commit/lxc/202.conf | 10 +
src/test/snapshot-expected/commit/lxc/203.conf | 23 ++
src/test/snapshot-expected/create/lxc/101.conf | 23 ++
src/test/snapshot-expected/create/lxc/102.conf | 37 +++
src/test/snapshot-expected/create/lxc/201.conf | 9 +
src/test/snapshot-expected/create/lxc/202.conf | 9 +
src/test/snapshot-expected/delete/lxc/101.conf | 9 +
src/test/snapshot-expected/delete/lxc/102.conf | 23 ++
src/test/snapshot-expected/delete/lxc/103.conf | 23 ++
src/test/snapshot-expected/delete/lxc/104.conf | 37 +++
src/test/snapshot-expected/delete/lxc/105.conf | 9 +
src/test/snapshot-expected/delete/lxc/201.conf | 24 ++
src/test/snapshot-expected/delete/lxc/202.conf | 24 ++
src/test/snapshot-expected/prepare/lxc/101.conf | 24 ++
src/test/snapshot-expected/prepare/lxc/102.conf | 39 +++
src/test/snapshot-expected/prepare/lxc/200.conf | 24 ++
src/test/snapshot-expected/prepare/lxc/201.conf | 23 ++
src/test/snapshot-expected/prepare/lxc/202.conf | 9 +
src/test/snapshot-expected/prepare/lxc/300.conf | 9 +
src/test/snapshot-input/commit/lxc/101.conf | 24 ++
src/test/snapshot-input/commit/lxc/102.conf | 39 +++
src/test/snapshot-input/commit/lxc/201.conf | 9 +
src/test/snapshot-input/commit/lxc/202.conf | 10 +
src/test/snapshot-input/commit/lxc/203.conf | 23 ++
src/test/snapshot-input/create/lxc/101.conf | 9 +
src/test/snapshot-input/create/lxc/102.conf | 23 ++
src/test/snapshot-input/create/lxc/201.conf | 9 +
src/test/snapshot-input/create/lxc/202.conf | 9 +
src/test/snapshot-input/delete/lxc/101.conf | 23 ++
src/test/snapshot-input/delete/lxc/102.conf | 37 +++
src/test/snapshot-input/delete/lxc/103.conf | 37 +++
src/test/snapshot-input/delete/lxc/104.conf | 51 ++++
src/test/snapshot-input/delete/lxc/105.conf | 23 ++
src/test/snapshot-input/delete/lxc/201.conf | 23 ++
src/test/snapshot-input/delete/lxc/202.conf | 24 ++
src/test/snapshot-input/prepare/lxc/101.conf | 9 +
src/test/snapshot-input/prepare/lxc/102.conf | 23 ++
src/test/snapshot-input/prepare/lxc/200.conf | 24 ++
src/test/snapshot-input/prepare/lxc/201.conf | 23 ++
src/test/snapshot-input/prepare/lxc/202.conf | 9 +
src/test/snapshot-input/prepare/lxc/300.conf | 9 +
src/test/snapshot-input/storage.cfg | 4 +
src/test/snapshot-test.pm | 332 ++++++++++++++++++++++++
50 files changed, 1377 insertions(+), 102 deletions(-)
create mode 100755 src/test/run_setup_tests.pl
create mode 100755 src/test/run_snapshot_tests.pl
delete mode 100755 src/test/run_tests.pl
create mode 100644 src/test/snapshot-expected/commit/lxc/101.conf
create mode 100644 src/test/snapshot-expected/commit/lxc/102.conf
create mode 100644 src/test/snapshot-expected/commit/lxc/201.conf
create mode 100644 src/test/snapshot-expected/commit/lxc/202.conf
create mode 100644 src/test/snapshot-expected/commit/lxc/203.conf
create mode 100644 src/test/snapshot-expected/create/lxc/101.conf
create mode 100644 src/test/snapshot-expected/create/lxc/102.conf
create mode 100644 src/test/snapshot-expected/create/lxc/201.conf
create mode 100644 src/test/snapshot-expected/create/lxc/202.conf
create mode 100644 src/test/snapshot-expected/delete/lxc/101.conf
create mode 100644 src/test/snapshot-expected/delete/lxc/102.conf
create mode 100644 src/test/snapshot-expected/delete/lxc/103.conf
create mode 100644 src/test/snapshot-expected/delete/lxc/104.conf
create mode 100644 src/test/snapshot-expected/delete/lxc/105.conf
create mode 100644 src/test/snapshot-expected/delete/lxc/201.conf
create mode 100644 src/test/snapshot-expected/delete/lxc/202.conf
create mode 100644 src/test/snapshot-expected/prepare/lxc/101.conf
create mode 100644 src/test/snapshot-expected/prepare/lxc/102.conf
create mode 100644 src/test/snapshot-expected/prepare/lxc/200.conf
create mode 100644 src/test/snapshot-expected/prepare/lxc/201.conf
create mode 100644 src/test/snapshot-expected/prepare/lxc/202.conf
create mode 100644 src/test/snapshot-expected/prepare/lxc/300.conf
create mode 100644 src/test/snapshot-input/commit/lxc/101.conf
create mode 100644 src/test/snapshot-input/commit/lxc/102.conf
create mode 100644 src/test/snapshot-input/commit/lxc/201.conf
create mode 100644 src/test/snapshot-input/commit/lxc/202.conf
create mode 100644 src/test/snapshot-input/commit/lxc/203.conf
create mode 100644 src/test/snapshot-input/create/lxc/101.conf
create mode 100644 src/test/snapshot-input/create/lxc/102.conf
create mode 100644 src/test/snapshot-input/create/lxc/201.conf
create mode 100644 src/test/snapshot-input/create/lxc/202.conf
create mode 100644 src/test/snapshot-input/delete/lxc/101.conf
create mode 100644 src/test/snapshot-input/delete/lxc/102.conf
create mode 100644 src/test/snapshot-input/delete/lxc/103.conf
create mode 100644 src/test/snapshot-input/delete/lxc/104.conf
create mode 100644 src/test/snapshot-input/delete/lxc/105.conf
create mode 100644 src/test/snapshot-input/delete/lxc/201.conf
create mode 100644 src/test/snapshot-input/delete/lxc/202.conf
create mode 100644 src/test/snapshot-input/prepare/lxc/101.conf
create mode 100644 src/test/snapshot-input/prepare/lxc/102.conf
create mode 100644 src/test/snapshot-input/prepare/lxc/200.conf
create mode 100644 src/test/snapshot-input/prepare/lxc/201.conf
create mode 100644 src/test/snapshot-input/prepare/lxc/202.conf
create mode 100644 src/test/snapshot-input/prepare/lxc/300.conf
create mode 100644 src/test/snapshot-input/storage.cfg
create mode 100644 src/test/snapshot-test.pm
diff --git a/src/test/Makefile b/src/test/Makefile
index 8105b7d..f3e260d 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -1,11 +1,13 @@
-
-
all:
-test:
- ./run_tests.pl
+test: test_setup test_snapshot
+
+test_setup: run_setup_tests.pl
+ ./run_setup_tests.pl
+test_snapshot: run_snapshot_tests.pl
+ ./run_snapshot_tests.pl
clean:
rm -rf tmprootfs
diff --git a/src/test/run_setup_tests.pl b/src/test/run_setup_tests.pl
new file mode 100755
index 0000000..3babf44
--- /dev/null
+++ b/src/test/run_setup_tests.pl
@@ -0,0 +1,98 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use PVE::Tools qw(run_command);
+
+use lib qw(..);
+
+use PVE::LXC;
+use PVE::LXC::Setup;
+
+sub test_file {
+ my ($exp_fn, $real_fn) = @_;
+
+ return if system("diff -u '$exp_fn' '$real_fn'") == 0;
+
+ die "files do not match\n";
+}
+
+sub run_test {
+ my ($testdir) = @_;
+
+ print "prepare $testdir\n";
+
+ my $rootfs = "./tmprootfs";
+
+ run_command("rm -rf $rootfs");
+ run_command("cp -a $testdir $rootfs");
+
+ my $config_fn = "$testdir/config";
+
+ my $raw = PVE::Tools::file_get_contents($config_fn);
+
+ my $conf = PVE::LXC::parse_pct_config("/lxc/100.conf", $raw);
+
+ $conf->{'testmode'} = 1;
+
+ my $lxc_setup = PVE::LXC::Setup->new($conf, $rootfs);
+
+ for (my $i = 0; $i < 2; $i++) {
+ # run tests twice, to make sure scripts are idempotent
+
+ srand(0);
+ $lxc_setup->post_create_hook('$TEST$ABCDEF');
+
+ my @testfiles = qw(/etc/hostname
+ /etc/hosts
+ /etc/inittab
+ /etc/network/interfaces
+ /etc/resolv.conf
+ /etc/passwd
+ /etc/shadow
+ /etc/sysconfig/network
+ /etc/sysconfig/network-scripts/ifcfg-eth0
+ /etc/sysconfig/network-scripts/route-eth0
+ /etc/sysconfig/network-scripts/ifcfg-eth1
+ /etc/sysconfig/network-scripts/route-eth1
+ /etc/sysconfig/network-scripts/ifcfg-eth2
+ /etc/sysconfig/network-scripts/route-eth2
+ /etc/sysconfig/network-scripts/ifcfg-eth3
+ /etc/sysconfig/network-scripts/route-eth3
+ /etc/sysconfig/network/ifcfg-eth0
+ /etc/sysconfig/network/ifroute-eth0
+ /etc/sysconfig/network/ifcfg-eth1
+ /etc/sysconfig/network/ifroute-eth1
+ /etc/sysconfig/network/ifcfg-eth2
+ /etc/sysconfig/network/ifroute-eth2
+ /etc/sysconfig/network/ifcfg-eth3
+ /etc/sysconfig/network/ifroute-eth3
+ /etc/init/start-ttys.conf
+ /etc/init/tty.conf
+ /etc/init/power-status-changed.conf
+ /etc/securetty
+ /etc/crontab);
+ foreach my $fn (@testfiles) {
+ next if !-f "$testdir/$fn.exp";
+ test_file("$testdir/$fn.exp", "$rootfs/$fn");
+ }
+ }
+
+ print "TEST $testdir => OK\n";
+}
+
+if (scalar(@ARGV)) {
+
+ foreach my $testdir (@ARGV) {
+ run_test($testdir);
+ }
+
+} else {
+
+ foreach my $testdir (<test-*>) {#
+ next if ! -d $testdir;
+ run_test($testdir);
+ }
+}
+
+exit(0);
diff --git a/src/test/run_snapshot_tests.pl b/src/test/run_snapshot_tests.pl
new file mode 100755
index 0000000..6def87f
--- /dev/null
+++ b/src/test/run_snapshot_tests.pl
@@ -0,0 +1,10 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use TAP::Harness;
+
+my $harness = TAP::Harness->new( { "verbosity" => -2 });
+$harness->runtests( "snapshot-test.pm");
+system( "rm -rf snapshot-working/");
diff --git a/src/test/run_tests.pl b/src/test/run_tests.pl
deleted file mode 100755
index 3babf44..0000000
--- a/src/test/run_tests.pl
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use PVE::Tools qw(run_command);
-
-use lib qw(..);
-
-use PVE::LXC;
-use PVE::LXC::Setup;
-
-sub test_file {
- my ($exp_fn, $real_fn) = @_;
-
- return if system("diff -u '$exp_fn' '$real_fn'") == 0;
-
- die "files do not match\n";
-}
-
-sub run_test {
- my ($testdir) = @_;
-
- print "prepare $testdir\n";
-
- my $rootfs = "./tmprootfs";
-
- run_command("rm -rf $rootfs");
- run_command("cp -a $testdir $rootfs");
-
- my $config_fn = "$testdir/config";
-
- my $raw = PVE::Tools::file_get_contents($config_fn);
-
- my $conf = PVE::LXC::parse_pct_config("/lxc/100.conf", $raw);
-
- $conf->{'testmode'} = 1;
-
- my $lxc_setup = PVE::LXC::Setup->new($conf, $rootfs);
-
- for (my $i = 0; $i < 2; $i++) {
- # run tests twice, to make sure scripts are idempotent
-
- srand(0);
- $lxc_setup->post_create_hook('$TEST$ABCDEF');
-
- my @testfiles = qw(/etc/hostname
- /etc/hosts
- /etc/inittab
- /etc/network/interfaces
- /etc/resolv.conf
- /etc/passwd
- /etc/shadow
- /etc/sysconfig/network
- /etc/sysconfig/network-scripts/ifcfg-eth0
- /etc/sysconfig/network-scripts/route-eth0
- /etc/sysconfig/network-scripts/ifcfg-eth1
- /etc/sysconfig/network-scripts/route-eth1
- /etc/sysconfig/network-scripts/ifcfg-eth2
- /etc/sysconfig/network-scripts/route-eth2
- /etc/sysconfig/network-scripts/ifcfg-eth3
- /etc/sysconfig/network-scripts/route-eth3
- /etc/sysconfig/network/ifcfg-eth0
- /etc/sysconfig/network/ifroute-eth0
- /etc/sysconfig/network/ifcfg-eth1
- /etc/sysconfig/network/ifroute-eth1
- /etc/sysconfig/network/ifcfg-eth2
- /etc/sysconfig/network/ifroute-eth2
- /etc/sysconfig/network/ifcfg-eth3
- /etc/sysconfig/network/ifroute-eth3
- /etc/init/start-ttys.conf
- /etc/init/tty.conf
- /etc/init/power-status-changed.conf
- /etc/securetty
- /etc/crontab);
- foreach my $fn (@testfiles) {
- next if !-f "$testdir/$fn.exp";
- test_file("$testdir/$fn.exp", "$rootfs/$fn");
- }
- }
-
- print "TEST $testdir => OK\n";
-}
-
-if (scalar(@ARGV)) {
-
- foreach my $testdir (@ARGV) {
- run_test($testdir);
- }
-
-} else {
-
- foreach my $testdir (<test-*>) {#
- next if ! -d $testdir;
- run_test($testdir);
- }
-}
-
-exit(0);
diff --git a/src/test/snapshot-expected/commit/lxc/101.conf b/src/test/snapshot-expected/commit/lxc/101.conf
new file mode 100644
index 0000000..ac8f306
--- /dev/null
+++ b/src/test/snapshot-expected/commit/lxc/101.conf
@@ -0,0 +1,23 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: somestore:somedisk
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-expected/commit/lxc/102.conf b/src/test/snapshot-expected/commit/lxc/102.conf
new file mode 100644
index 0000000..70b5bcf
--- /dev/null
+++ b/src/test/snapshot-expected/commit/lxc/102.conf
@@ -0,0 +1,37 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test2
+rootfs: somestore:somedisk
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+snaptime: 1234567890
+swap: 512
+
+[test2]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: somestore:somedisk
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-expected/commit/lxc/201.conf b/src/test/snapshot-expected/commit/lxc/201.conf
new file mode 100644
index 0000000..f871426
--- /dev/null
+++ b/src/test/snapshot-expected/commit/lxc/201.conf
@@ -0,0 +1,9 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+swap: 512
diff --git a/src/test/snapshot-expected/commit/lxc/202.conf b/src/test/snapshot-expected/commit/lxc/202.conf
new file mode 100644
index 0000000..e7a3843
--- /dev/null
+++ b/src/test/snapshot-expected/commit/lxc/202.conf
@@ -0,0 +1,10 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+lock: snapshot
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+swap: 512
diff --git a/src/test/snapshot-expected/commit/lxc/203.conf b/src/test/snapshot-expected/commit/lxc/203.conf
new file mode 100644
index 0000000..96a775f
--- /dev/null
+++ b/src/test/snapshot-expected/commit/lxc/203.conf
@@ -0,0 +1,23 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+lock: snapshot
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-expected/create/lxc/101.conf b/src/test/snapshot-expected/create/lxc/101.conf
new file mode 100644
index 0000000..092c185
--- /dev/null
+++ b/src/test/snapshot-expected/create/lxc/101.conf
@@ -0,0 +1,23 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: local:snapshotable-disk-1
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:snapshotable-disk-1
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-expected/create/lxc/102.conf b/src/test/snapshot-expected/create/lxc/102.conf
new file mode 100644
index 0000000..d702822
--- /dev/null
+++ b/src/test/snapshot-expected/create/lxc/102.conf
@@ -0,0 +1,37 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test2
+rootfs: local:snapshotable-disk-1
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:snapshotable-disk-1
+snaptime: 1234567890
+swap: 512
+
+[test2]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: local:snapshotable-disk-1
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-expected/create/lxc/201.conf b/src/test/snapshot-expected/create/lxc/201.conf
new file mode 100644
index 0000000..da4d72c
--- /dev/null
+++ b/src/test/snapshot-expected/create/lxc/201.conf
@@ -0,0 +1,9 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:unsnapshotable-disk-1
+swap: 512
diff --git a/src/test/snapshot-expected/create/lxc/202.conf b/src/test/snapshot-expected/create/lxc/202.conf
new file mode 100644
index 0000000..c6d04c9
--- /dev/null
+++ b/src/test/snapshot-expected/create/lxc/202.conf
@@ -0,0 +1,9 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:snapshotable-disk-1
+swap: 512
diff --git a/src/test/snapshot-expected/delete/lxc/101.conf b/src/test/snapshot-expected/delete/lxc/101.conf
new file mode 100644
index 0000000..c6d04c9
--- /dev/null
+++ b/src/test/snapshot-expected/delete/lxc/101.conf
@@ -0,0 +1,9 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:snapshotable-disk-1
+swap: 512
diff --git a/src/test/snapshot-expected/delete/lxc/102.conf b/src/test/snapshot-expected/delete/lxc/102.conf
new file mode 100644
index 0000000..092c185
--- /dev/null
+++ b/src/test/snapshot-expected/delete/lxc/102.conf
@@ -0,0 +1,23 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: local:snapshotable-disk-1
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:snapshotable-disk-1
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-expected/delete/lxc/103.conf b/src/test/snapshot-expected/delete/lxc/103.conf
new file mode 100644
index 0000000..08bc80d
--- /dev/null
+++ b/src/test/snapshot-expected/delete/lxc/103.conf
@@ -0,0 +1,23 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test2
+rootfs: local:snapshotable-disk-1
+swap: 512
+
+[test2]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:snapshotable-disk-1
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-expected/delete/lxc/104.conf b/src/test/snapshot-expected/delete/lxc/104.conf
new file mode 100644
index 0000000..ce35c79
--- /dev/null
+++ b/src/test/snapshot-expected/delete/lxc/104.conf
@@ -0,0 +1,37 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test3
+rootfs: local:snapshotable-disk-1
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:snapshotable-disk-1
+snaptime: 1234567890
+swap: 512
+
+[test3]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: local:snapshotable-disk-1
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-expected/delete/lxc/105.conf b/src/test/snapshot-expected/delete/lxc/105.conf
new file mode 100644
index 0000000..c6d04c9
--- /dev/null
+++ b/src/test/snapshot-expected/delete/lxc/105.conf
@@ -0,0 +1,9 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:snapshotable-disk-1
+swap: 512
diff --git a/src/test/snapshot-expected/delete/lxc/201.conf b/src/test/snapshot-expected/delete/lxc/201.conf
new file mode 100644
index 0000000..b010dfb
--- /dev/null
+++ b/src/test/snapshot-expected/delete/lxc/201.conf
@@ -0,0 +1,24 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: local:snapshotable-disk-1
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:unsnapshotable-disk-1
+snapstate: delete
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-expected/delete/lxc/202.conf b/src/test/snapshot-expected/delete/lxc/202.conf
new file mode 100644
index 0000000..2b2c5e2
--- /dev/null
+++ b/src/test/snapshot-expected/delete/lxc/202.conf
@@ -0,0 +1,24 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+lock: backup
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: local:snapshotable-disk-1
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:snapshotable-disk-1
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-expected/prepare/lxc/101.conf b/src/test/snapshot-expected/prepare/lxc/101.conf
new file mode 100644
index 0000000..08f6734
--- /dev/null
+++ b/src/test/snapshot-expected/prepare/lxc/101.conf
@@ -0,0 +1,24 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+lock: snapshot
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+snapstate: prepare
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-expected/prepare/lxc/102.conf b/src/test/snapshot-expected/prepare/lxc/102.conf
new file mode 100644
index 0000000..fa59022
--- /dev/null
+++ b/src/test/snapshot-expected/prepare/lxc/102.conf
@@ -0,0 +1,39 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+lock: snapshot
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: somestore:somedisk
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+snaptime: 1234567890
+swap: 512
+
+[test2]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: somestore:somedisk
+snapstate: prepare
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-expected/prepare/lxc/200.conf b/src/test/snapshot-expected/prepare/lxc/200.conf
new file mode 100644
index 0000000..08f6734
--- /dev/null
+++ b/src/test/snapshot-expected/prepare/lxc/200.conf
@@ -0,0 +1,24 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+lock: snapshot
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+snapstate: prepare
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-expected/prepare/lxc/201.conf b/src/test/snapshot-expected/prepare/lxc/201.conf
new file mode 100644
index 0000000..ac8f306
--- /dev/null
+++ b/src/test/snapshot-expected/prepare/lxc/201.conf
@@ -0,0 +1,23 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: somestore:somedisk
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-expected/prepare/lxc/202.conf b/src/test/snapshot-expected/prepare/lxc/202.conf
new file mode 100644
index 0000000..f871426
--- /dev/null
+++ b/src/test/snapshot-expected/prepare/lxc/202.conf
@@ -0,0 +1,9 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+swap: 512
diff --git a/src/test/snapshot-expected/prepare/lxc/300.conf b/src/test/snapshot-expected/prepare/lxc/300.conf
new file mode 100644
index 0000000..f871426
--- /dev/null
+++ b/src/test/snapshot-expected/prepare/lxc/300.conf
@@ -0,0 +1,9 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+swap: 512
diff --git a/src/test/snapshot-input/commit/lxc/101.conf b/src/test/snapshot-input/commit/lxc/101.conf
new file mode 100644
index 0000000..08f6734
--- /dev/null
+++ b/src/test/snapshot-input/commit/lxc/101.conf
@@ -0,0 +1,24 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+lock: snapshot
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+snapstate: prepare
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-input/commit/lxc/102.conf b/src/test/snapshot-input/commit/lxc/102.conf
new file mode 100644
index 0000000..fa59022
--- /dev/null
+++ b/src/test/snapshot-input/commit/lxc/102.conf
@@ -0,0 +1,39 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+lock: snapshot
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: somestore:somedisk
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+snaptime: 1234567890
+swap: 512
+
+[test2]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: somestore:somedisk
+snapstate: prepare
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-input/commit/lxc/201.conf b/src/test/snapshot-input/commit/lxc/201.conf
new file mode 100644
index 0000000..f871426
--- /dev/null
+++ b/src/test/snapshot-input/commit/lxc/201.conf
@@ -0,0 +1,9 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+swap: 512
diff --git a/src/test/snapshot-input/commit/lxc/202.conf b/src/test/snapshot-input/commit/lxc/202.conf
new file mode 100644
index 0000000..e7a3843
--- /dev/null
+++ b/src/test/snapshot-input/commit/lxc/202.conf
@@ -0,0 +1,10 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+lock: snapshot
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+swap: 512
diff --git a/src/test/snapshot-input/commit/lxc/203.conf b/src/test/snapshot-input/commit/lxc/203.conf
new file mode 100644
index 0000000..96a775f
--- /dev/null
+++ b/src/test/snapshot-input/commit/lxc/203.conf
@@ -0,0 +1,23 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+lock: snapshot
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-input/create/lxc/101.conf b/src/test/snapshot-input/create/lxc/101.conf
new file mode 100644
index 0000000..c6d04c9
--- /dev/null
+++ b/src/test/snapshot-input/create/lxc/101.conf
@@ -0,0 +1,9 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:snapshotable-disk-1
+swap: 512
diff --git a/src/test/snapshot-input/create/lxc/102.conf b/src/test/snapshot-input/create/lxc/102.conf
new file mode 100644
index 0000000..092c185
--- /dev/null
+++ b/src/test/snapshot-input/create/lxc/102.conf
@@ -0,0 +1,23 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: local:snapshotable-disk-1
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:snapshotable-disk-1
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-input/create/lxc/201.conf b/src/test/snapshot-input/create/lxc/201.conf
new file mode 100644
index 0000000..da4d72c
--- /dev/null
+++ b/src/test/snapshot-input/create/lxc/201.conf
@@ -0,0 +1,9 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:unsnapshotable-disk-1
+swap: 512
diff --git a/src/test/snapshot-input/create/lxc/202.conf b/src/test/snapshot-input/create/lxc/202.conf
new file mode 100644
index 0000000..c6d04c9
--- /dev/null
+++ b/src/test/snapshot-input/create/lxc/202.conf
@@ -0,0 +1,9 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:snapshotable-disk-1
+swap: 512
diff --git a/src/test/snapshot-input/delete/lxc/101.conf b/src/test/snapshot-input/delete/lxc/101.conf
new file mode 100644
index 0000000..092c185
--- /dev/null
+++ b/src/test/snapshot-input/delete/lxc/101.conf
@@ -0,0 +1,23 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: local:snapshotable-disk-1
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:snapshotable-disk-1
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-input/delete/lxc/102.conf b/src/test/snapshot-input/delete/lxc/102.conf
new file mode 100644
index 0000000..d702822
--- /dev/null
+++ b/src/test/snapshot-input/delete/lxc/102.conf
@@ -0,0 +1,37 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test2
+rootfs: local:snapshotable-disk-1
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:snapshotable-disk-1
+snaptime: 1234567890
+swap: 512
+
+[test2]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: local:snapshotable-disk-1
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-input/delete/lxc/103.conf b/src/test/snapshot-input/delete/lxc/103.conf
new file mode 100644
index 0000000..d702822
--- /dev/null
+++ b/src/test/snapshot-input/delete/lxc/103.conf
@@ -0,0 +1,37 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test2
+rootfs: local:snapshotable-disk-1
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:snapshotable-disk-1
+snaptime: 1234567890
+swap: 512
+
+[test2]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: local:snapshotable-disk-1
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-input/delete/lxc/104.conf b/src/test/snapshot-input/delete/lxc/104.conf
new file mode 100644
index 0000000..9b7fb78
--- /dev/null
+++ b/src/test/snapshot-input/delete/lxc/104.conf
@@ -0,0 +1,51 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test3
+rootfs: local:snapshotable-disk-1
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:snapshotable-disk-1
+snaptime: 1234567890
+swap: 512
+
+[test2]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: local:snapshotable-disk-1
+snaptime: 1234567890
+swap: 512
+
+[test3]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test2
+rootfs: local:snapshotable-disk-1
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-input/delete/lxc/105.conf b/src/test/snapshot-input/delete/lxc/105.conf
new file mode 100644
index 0000000..ad0bdf1
--- /dev/null
+++ b/src/test/snapshot-input/delete/lxc/105.conf
@@ -0,0 +1,23 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: local:snapshotable-disk-1
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:unsnapshotable-disk-1
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-input/delete/lxc/201.conf b/src/test/snapshot-input/delete/lxc/201.conf
new file mode 100644
index 0000000..ad0bdf1
--- /dev/null
+++ b/src/test/snapshot-input/delete/lxc/201.conf
@@ -0,0 +1,23 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: local:snapshotable-disk-1
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:unsnapshotable-disk-1
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-input/delete/lxc/202.conf b/src/test/snapshot-input/delete/lxc/202.conf
new file mode 100644
index 0000000..2b2c5e2
--- /dev/null
+++ b/src/test/snapshot-input/delete/lxc/202.conf
@@ -0,0 +1,24 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+lock: backup
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: local:snapshotable-disk-1
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: local:snapshotable-disk-1
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-input/prepare/lxc/101.conf b/src/test/snapshot-input/prepare/lxc/101.conf
new file mode 100644
index 0000000..f871426
--- /dev/null
+++ b/src/test/snapshot-input/prepare/lxc/101.conf
@@ -0,0 +1,9 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+swap: 512
diff --git a/src/test/snapshot-input/prepare/lxc/102.conf b/src/test/snapshot-input/prepare/lxc/102.conf
new file mode 100644
index 0000000..ac8f306
--- /dev/null
+++ b/src/test/snapshot-input/prepare/lxc/102.conf
@@ -0,0 +1,23 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: somestore:somedisk
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-input/prepare/lxc/200.conf b/src/test/snapshot-input/prepare/lxc/200.conf
new file mode 100644
index 0000000..08f6734
--- /dev/null
+++ b/src/test/snapshot-input/prepare/lxc/200.conf
@@ -0,0 +1,24 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+lock: snapshot
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+snapstate: prepare
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-input/prepare/lxc/201.conf b/src/test/snapshot-input/prepare/lxc/201.conf
new file mode 100644
index 0000000..ac8f306
--- /dev/null
+++ b/src/test/snapshot-input/prepare/lxc/201.conf
@@ -0,0 +1,23 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+parent: test
+rootfs: somestore:somedisk
+swap: 512
+
+[test]
+#test comment
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+snaptime: 1234567890
+swap: 512
diff --git a/src/test/snapshot-input/prepare/lxc/202.conf b/src/test/snapshot-input/prepare/lxc/202.conf
new file mode 100644
index 0000000..f871426
--- /dev/null
+++ b/src/test/snapshot-input/prepare/lxc/202.conf
@@ -0,0 +1,9 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+swap: 512
diff --git a/src/test/snapshot-input/prepare/lxc/300.conf b/src/test/snapshot-input/prepare/lxc/300.conf
new file mode 100644
index 0000000..f871426
--- /dev/null
+++ b/src/test/snapshot-input/prepare/lxc/300.conf
@@ -0,0 +1,9 @@
+arch: amd64
+cpulimit: 1
+cpuunits: 1024
+hostname: test
+memory: 2048
+net0: bridge=vmbr0,hwaddr=12:34:56:78:90:12,ip=dhcp,ip6=dhcp,name=eth0,type=veth
+ostype: redhat
+rootfs: somestore:somedisk
+swap: 512
diff --git a/src/test/snapshot-input/storage.cfg b/src/test/snapshot-input/storage.cfg
new file mode 100644
index 0000000..e5b9703
--- /dev/null
+++ b/src/test/snapshot-input/storage.cfg
@@ -0,0 +1,4 @@
+dir: local
+ path tmp/storage/
+ maxfiles 0
+ content vztmpl,rootdir,iso,images
diff --git a/src/test/snapshot-test.pm b/src/test/snapshot-test.pm
new file mode 100644
index 0000000..f0ce678
--- /dev/null
+++ b/src/test/snapshot-test.pm
@@ -0,0 +1,332 @@
+package PVE::LXC;
+
+use strict;
+use warnings;
+
+use PVE::Storage;
+use PVE::Storage::Plugin;
+use PVE::LXC;
+use PVE::Tools;
+
+use Test::MockModule;
+use Test::More;
+
+my $nodename;
+my $snapshot_possible;
+my $vol_snapshot_possible = {};
+my $vol_snapshot_delete_possible = {};
+my $vol_snapshot = {};
+my $vol_snapshot_delete = {};
+my $running;
+my $freeze_possible;
+
+# Mocked methods
+
+sub mocked_volume_snapshot {
+ my ($storecfg, $volid, $snapname) = @_;
+ die "Storage config not mocked! aborting"
+ if defined($storecfg);
+ die "volid undefined"
+ if !defined($volid);
+ die "snapname undefined"
+ if !defined($snapname);
+ if ($vol_snapshot_possible->{$volid}) {
+ if (defined($vol_snapshot->{$volid})) {
+ $vol_snapshot->{$volid} .= ",$snapname";
+ } else {
+ $vol_snapshot->{$volid} = $snapname;
+ }
+ return 1;
+ } else {
+ die "volume snapshot disabled";
+ }
+}
+
+sub mocked_volume_snapshot_delete {
+ my ($storecfg, $volid, $snapname) = @_;
+ die "Storage config not mocked! aborting"
+ if defined($storecfg);
+ die "volid undefined"
+ if !defined($volid);
+ die "snapname undefined"
+ if !defined($snapname);
+ if ($vol_snapshot_delete_possible->{$volid}) {
+ if (defined($vol_snapshot_delete->{$volid})) {
+ $vol_snapshot_delete->{$volid} .= ",$snapname";
+ } else {
+ $vol_snapshot_delete->{$volid} = $snapname;
+ }
+ return 1;
+ } else {
+ die "volume snapshot delete disabled";
+ }
+}
+
+sub mocked_run_command {
+ my ($cmd, %param) = @_;
+ my $cmdstring;
+ if (my $ref = ref($cmd)) {
+ $cmdstring = PVE::Tools::cmd2string($cmd);
+ if ($cmdstring =~ m/.*\/lxc-(un)?freeze.*/) {
+ return 1 if $freeze_possible;
+ die "lxc-[un]freeze disabled";
+ }
+ }
+ die "unexpected run_command call, aborting";
+}
+
+# Testing methods
+
+sub test_file {
+ my ($exp_fn, $real_fn) = @_;
+ my $ret;
+ eval {
+ $ret = system("diff -u '$exp_fn' '$real_fn'");
+ };
+ die if $@;
+ return !$ret;
+}
+
+sub testcase_prepare {
+ my ($vmid, $snapname, $save_vmstate, $comment, $exp_err) = @_;
+ subtest "Preparing snapshot '$snapname' for vm '$vmid'" => sub {
+ plan tests => 2;
+ $@ = undef;
+ eval {
+ PVE::LXC::snapshot_prepare($vmid, $snapname, $save_vmstate, $comment);
+ };
+ is($@, $exp_err, "\$@ correct");
+ ok(test_file("snapshot-expected/prepare/lxc/$vmid.conf", "snapshot-working/prepare/lxc/$vmid.conf"), "config file correct");
+ };
+}
+
+sub testcase_commit {
+ my ($vmid, $snapname, $exp_err) = @_;
+ subtest "Committing snapshot '$snapname' for vm '$vmid'" => sub {
+ plan tests => 2;
+ $@ = undef;
+ eval {
+ PVE::LXC::snapshot_commit($vmid, $snapname);
+ };
+ is($@, $exp_err, "\$@ correct");
+ ok(test_file("snapshot-expected/commit/lxc/$vmid.conf", "snapshot-working/commit/lxc/$vmid.conf"), "config file correct");
+ }
+}
+
+sub testcase_create {
+ my ($vmid, $snapname, $save_vmstate, $comment, $exp_err, $exp_vol_snap, $exp_vol_snap_delete) = @_;
+ subtest "Creating snapshot '$snapname' for vm '$vmid'" => sub {
+ plan tests => 4;
+ $vol_snapshot = {};
+ $vol_snapshot_delete = {};
+ $exp_vol_snap = {} if !defined($exp_vol_snap);
+ $exp_vol_snap_delete = {} if !defined($exp_vol_snap_delete);
+ $@ = undef;
+ eval {
+ PVE::LXC::snapshot_create($vmid, $snapname, $save_vmstate, $comment);
+ };
+ is($@, $exp_err, "\$@ correct");
+ is_deeply($vol_snapshot, $exp_vol_snap, "created correct volume snapshots");
+ is_deeply($vol_snapshot_delete, $exp_vol_snap_delete, "deleted correct volume snapshots");
+ ok(test_file("snapshot-expected/create/lxc/$vmid.conf", "snapshot-working/create/lxc/$vmid.conf"), "config file correct");
+ };
+}
+
+sub testcase_delete {
+ my ($vmid, $snapname, $force, $exp_err, $exp_vol_snap_delete) = @_;
+ subtest "Deleting snapshot '$snapname' of vm '$vmid'" => sub {
+ plan tests => 3;
+ $vol_snapshot_delete = {};
+ $exp_vol_snap_delete = {} if !defined($exp_vol_snap_delete);
+ $@ = undef;
+ eval {
+ PVE::LXC::snapshot_delete($vmid, $snapname, $force);
+ };
+ is($@, $exp_err, "\$@ correct");
+ is_deeply($vol_snapshot_delete, $exp_vol_snap_delete, "deleted correct volume snapshots");
+ ok(test_file("snapshot-expected/delete/lxc/$vmid.conf", "snapshot-working/delete/lxc/$vmid.conf"), "config file correct");
+ };
+}
+
+# BEGIN redefine PVE::LXC methods
+sub config_file_lock {
+ return "snapshot-working/pve-test.lock";
+}
+
+sub cfs_config_path {
+ my ($vmid, $node) = @_;
+
+ $node = $nodename if !$node;
+ return "snapshot-working/$node/lxc/$vmid.conf";
+}
+
+sub load_config {
+ my ($vmid, $node) = @_;
+
+ my $filename = cfs_config_path($vmid, $node);
+
+ my $raw = PVE::Tools::file_get_contents($filename);
+
+ my $conf = PVE::LXC::parse_pct_config($filename, $raw);
+ return $conf;
+}
+
+sub write_config {
+ my ($vmid, $conf) = @_;
+
+ my $filename = cfs_config_path($vmid);
+
+ if ($conf->{snapshots}) {
+ foreach my $snapname (keys %{$conf->{snapshots}}) {
+ $conf->{snapshots}->{$snapname}->{snaptime} = "1234567890"
+ if $conf->{snapshots}->{$snapname}->{snaptime};
+ }
+ }
+
+ my $raw = PVE::LXC::write_pct_config($filename, $conf);
+
+ PVE::Tools::file_set_contents($filename, $raw);
+}
+
+sub has_feature {
+ my ($feature, $conf, $storecfg, $snapname) = @_;
+ return $snapshot_possible;
+}
+
+sub check_running {
+ return $running;
+}
+
+sub sync_container_namespace {
+ return;
+}
+
+# END redefine PVE::LXC methods
+
+PVE::Tools::run_command("rm -rf snapshot-working");
+PVE::Tools::run_command("cp -a snapshot-input snapshot-working");
+
+$running = 1;
+$freeze_possible = 1;
+
+printf("");
+printf("Running prepare tests");
+printf("");
+$nodename = "prepare";
+
+printf("");
+printf("Setting has_feature to return true");
+printf("");
+$snapshot_possible = 1;
+
+printf("Successful snapshot_prepare with no existing snapshots");
+testcase_prepare("101", "test", 0, "test comment", '');
+
+printf("Successful snapshot_prepare with one existing snapshot");
+testcase_prepare("102", "test2", 0, "test comment", "");
+
+printf("Expected error for snapshot_prepare on locked container");
+testcase_prepare("200", "test", 0, "test comment", "VM is locked (snapshot)\n");
+
+printf("Expected error for snapshot_prepare with duplicate snapshot name");
+testcase_prepare("201", "test", 0, "test comment", "snapshot name 'test' already used\n");
+
+printf("Expected error for snapshot_prepare with save_vmstate");
+testcase_prepare("202", "test", 1, "test comment", "implement me - snapshot_save_vmstate\n");
+
+printf("");
+printf("Setting has_feature to return false");
+printf("");
+$snapshot_possible = 0;
+
+printf("Expected error for snapshot_prepare if snapshots not possible");
+testcase_prepare("300", "test", 0, "test comment", "snapshot feature is not available\n");
+
+printf("");
+printf("Running commit tests");
+printf("");
+$nodename = "commit";
+
+printf("");
+printf("Setting has_feature to return true");
+printf("");
+$snapshot_possible = 1;
+
+printf("Successful snapshot_commit with one prepared snapshot");
+testcase_commit("101", "test", "");
+
+printf("Successful snapshot_commit with one committed and one prepared snapshot");
+testcase_commit("102", "test2", "");
+
+printf("Expected error for snapshot_commit with no snapshot lock");
+testcase_commit("201", "test", "missing snapshot lock\n");
+
+printf("Expected error for snapshot_commit with invalid snapshot name");
+testcase_commit("202", "test", "snapshot 'test' does not exist\n");
+
+printf("Expected error for snapshot_commit with invalid snapshot state");
+testcase_commit("203", "test", "wrong snapshot state\n");
+
+$vol_snapshot_possible->{"local:snapshotable-disk-1"} = 1;
+$vol_snapshot_delete_possible->{"local:snapshotable-disk-1"} = 1;
+printf("");
+printf("Setting up Mocking for PVE::Storage");
+my $storage_module = new Test::MockModule('PVE::Storage');
+$storage_module->mock('config', sub { return undef; });
+$storage_module->mock('volume_snapshot', \&mocked_volume_snapshot);
+$storage_module->mock('volume_snapshot_delete', \&mocked_volume_snapshot_delete);
+printf("\tconfig(), volume_snapshot() and volume_snapshot_delete() mocked");
+
+printf("");
+printf("Setting up Mocking for PVE::Tools");
+my $tools_module = new Test::MockModule('PVE::Tools');
+$tools_module->mock('run_command' => \&mocked_run_command);
+printf("\trun_command() mocked");
+
+$nodename = "create";
+printf("");
+printf("Running create tests");
+printf("");
+
+printf("Successful snapshot_create with no existing snapshots");
+testcase_create("101", "test", 0, "test comment", "", { "local:snapshotable-disk-1" => "test" });
+
+printf("Successful snapshot_create with one existing snapshots");
+testcase_create("102", "test2", 0, "test comment", "", { "local:snapshotable-disk-1" => "test2" });
+
+printf("Expected error for snapshot_create when volume snapshot is not possible");
+testcase_create("201", "test", 0, "test comment", "volume snapshot disabled at snapshot-test.pm line 41.\n\n");
+
+printf("Expected error for snapshot_create with broken lxc-freeze");
+$freeze_possible = 0;
+testcase_create("202", "test", 0, "test comment", "lxc-[un]freeze disabled at snapshot-test.pm line 72.\n\n", undef, { "local:snapshotable-disk-1" => "test" });
+$freeze_possible = 1;
+
+$nodename = "delete";
+printf("");
+printf("Running delete tests");
+printf("");
+
+printf("Successful snapshot_delete of only existing snapshot");
+testcase_delete("101", "test", 0, "", { "local:snapshotable-disk-1" => "test" });
+
+printf("Successful snapshot_delete of leaf snapshot");
+testcase_delete("102", "test2", 0, "", { "local:snapshotable-disk-1" => "test2" });
+
+printf("Successful snapshot_delete of root snapshot");
+testcase_delete("103", "test", 0, "", { "local:snapshotable-disk-1" => "test" });
+
+printf("Successful snapshot_delete of intermediate snapshot");
+testcase_delete("104", "test2", 0, "", { "local:snapshotable-disk-1" => "test2" });
+
+printf("Successful snapshot_delete with broken volume_snapshot_delete and force=1");
+testcase_delete("105", "test", 1, "");
+
+printf("Expected error when snapshot_delete fails with broken volume_snapshot_delete and force=0");
+testcase_delete("201", "test", 0, "volume snapshot delete disabled at snapshot-test.pm line 61.\n");
+
+printf("Expected error for snapshot_delete with locked config");
+testcase_delete("202", "test", 0, "VM is locked (backup)\n");
+
+
+done_testing();
--
2.1.4
More information about the pve-devel
mailing list