From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id ED9636098C for ; Thu, 13 Jan 2022 12:04:46 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2C9261D24A for ; Thu, 13 Jan 2022 12:04:16 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 9453E1D135 for ; Thu, 13 Jan 2022 12:04:11 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6D22E46021 for ; Thu, 13 Jan 2022 12:04:11 +0100 (CET) From: Fabian Ebner To: pve-devel@lists.proxmox.com Date: Thu, 13 Jan 2022 12:04:05 +0100 Message-Id: <20220113110405.67232-7-f.ebner@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220113110405.67232-1-f.ebner@proxmox.com> References: <20220113110405.67232-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.136 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [snapshot-test.pm, config.pm] Subject: [pve-devel] [PATCH v2 container 3/3] snapshot: implement __snapshot_activate_storages X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Jan 2022 11:04:47 -0000 Signed-off-by: Fabian Ebner --- Build depends on guest-common. src/PVE/LXC/Config.pm | 19 +++++++++++ .../snapshot-expected/create/lxc/204.conf | 10 ++++++ .../snapshot-expected/delete/lxc/204.conf | 25 +++++++++++++++ .../snapshot-expected/rollback/lxc/209.conf | 29 +++++++++++++++++ src/test/snapshot-input/create/lxc/204.conf | 10 ++++++ src/test/snapshot-input/delete/lxc/204.conf | 25 +++++++++++++++ src/test/snapshot-input/rollback/lxc/209.conf | 29 +++++++++++++++++ src/test/snapshot-test.pm | 32 +++++++++++++++++++ 8 files changed, 179 insertions(+) create mode 100644 src/test/snapshot-expected/create/lxc/204.conf create mode 100644 src/test/snapshot-expected/delete/lxc/204.conf create mode 100644 src/test/snapshot-expected/rollback/lxc/209.conf create mode 100644 src/test/snapshot-input/create/lxc/204.conf create mode 100644 src/test/snapshot-input/delete/lxc/204.conf create mode 100644 src/test/snapshot-input/rollback/lxc/209.conf diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm index 7db023c..9429c59 100644 --- a/src/PVE/LXC/Config.pm +++ b/src/PVE/LXC/Config.pm @@ -101,6 +101,25 @@ sub __snapshot_save_vmstate { die "implement me - snapshot_save_vmstate\n"; } +sub __snapshot_activate_storages { + my ($class, $conf, $include_vmstate) = @_; + + my $storecfg = PVE::Storage::config(); + my $opts = $include_vmstate ? { 'extra_keys' => ['vmstate'] } : {}; + my $storage_hash = {}; + + $class->foreach_volume_full($conf, $opts, sub { + my ($vs, $mountpoint) = @_; + + return if $mountpoint->{type} ne 'volume'; + + my ($storeid) = PVE::Storage::parse_volume_id($mountpoint->{volume}); + $storage_hash->{$storeid} = 1; + }); + + PVE::Storage::activate_storage_list($storecfg, [ sort keys $storage_hash->%* ]); +} + sub __snapshot_check_running { my ($class, $vmid) = @_; return PVE::LXC::check_running($vmid); diff --git a/src/test/snapshot-expected/create/lxc/204.conf b/src/test/snapshot-expected/create/lxc/204.conf new file mode 100644 index 0000000..4546668 --- /dev/null +++ b/src/test/snapshot-expected/create/lxc/204.conf @@ -0,0 +1,10 @@ +arch: amd64 +cpulimit: 1 +cpuunits: 1024 +hostname: test +memory: 2048 +mp0: local:unsnapshotable-disk-1,mp=/invalid/mountpoint +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/204.conf b/src/test/snapshot-expected/delete/lxc/204.conf new file mode 100644 index 0000000..a21c535 --- /dev/null +++ b/src/test/snapshot-expected/delete/lxc/204.conf @@ -0,0 +1,25 @@ +arch: amd64 +cpulimit: 1 +cpuunits: 1024 +hostname: test +memory: 2048 +mp0: local:unsnapshotable-disk-1,mp=/invalid/mountpoint +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 +mp0: local:unsnapshotable-disk-1,mp=/invalid/mountpoint +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/rollback/lxc/209.conf b/src/test/snapshot-expected/rollback/lxc/209.conf new file mode 100644 index 0000000..c9a23c9 --- /dev/null +++ b/src/test/snapshot-expected/rollback/lxc/209.conf @@ -0,0 +1,29 @@ +# should be preserved +arch: amd64 +cpulimit: 1 +cpuunits: 1024 +hostname: test +memory: 2048 +mp0: local:snapshotable-disk-2,mp=/invalid/mp0 +mp1: local:unsnapshotable-disk-1,mp=/invalid/mp1 +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 +unused0: preserved:some-disk-1 + +[test] +# should be thrown away +arch: amd64 +cpulimit: 2 +cpuunits: 2048 +hostname: test2 +memory: 4096 +mp0: local:snapshotable-disk-2,mp=/invalid/mp0 +mp1: local:snapshotable-disk-4,mp=/invalid/mp1 +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: 1024 diff --git a/src/test/snapshot-input/create/lxc/204.conf b/src/test/snapshot-input/create/lxc/204.conf new file mode 100644 index 0000000..4546668 --- /dev/null +++ b/src/test/snapshot-input/create/lxc/204.conf @@ -0,0 +1,10 @@ +arch: amd64 +cpulimit: 1 +cpuunits: 1024 +hostname: test +memory: 2048 +mp0: local:unsnapshotable-disk-1,mp=/invalid/mountpoint +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/204.conf b/src/test/snapshot-input/delete/lxc/204.conf new file mode 100644 index 0000000..a21c535 --- /dev/null +++ b/src/test/snapshot-input/delete/lxc/204.conf @@ -0,0 +1,25 @@ +arch: amd64 +cpulimit: 1 +cpuunits: 1024 +hostname: test +memory: 2048 +mp0: local:unsnapshotable-disk-1,mp=/invalid/mountpoint +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 +mp0: local:unsnapshotable-disk-1,mp=/invalid/mountpoint +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/rollback/lxc/209.conf b/src/test/snapshot-input/rollback/lxc/209.conf new file mode 100644 index 0000000..c9a23c9 --- /dev/null +++ b/src/test/snapshot-input/rollback/lxc/209.conf @@ -0,0 +1,29 @@ +# should be preserved +arch: amd64 +cpulimit: 1 +cpuunits: 1024 +hostname: test +memory: 2048 +mp0: local:snapshotable-disk-2,mp=/invalid/mp0 +mp1: local:unsnapshotable-disk-1,mp=/invalid/mp1 +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 +unused0: preserved:some-disk-1 + +[test] +# should be thrown away +arch: amd64 +cpulimit: 2 +cpuunits: 2048 +hostname: test2 +memory: 4096 +mp0: local:snapshotable-disk-2,mp=/invalid/mp0 +mp1: local:snapshotable-disk-4,mp=/invalid/mp1 +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: 1024 diff --git a/src/test/snapshot-test.pm b/src/test/snapshot-test.pm index 91a2af9..4fc735b 100644 --- a/src/test/snapshot-test.pm +++ b/src/test/snapshot-test.pm @@ -16,6 +16,7 @@ use PVE::ReplicationConfig; use Test::MockModule; use Test::More; +my $activate_storage_possible = 1; my $nodename; my $snapshot_possible; my $vol_snapshot_possible = {}; @@ -122,6 +123,15 @@ sub mocked_volume_snapshot_needs_fsfreeze { return 0; } +sub mocked_activate_storage { + my ($storecfg, $storeid) = @_; + die "Storage config not mocked! aborting\n" + if defined($storecfg); + die "storage activation failed\n" + if !$activate_storage_possible; + return; +} + sub mocked_vm_stop { if ($kill_possible) { $running = 0; @@ -390,6 +400,7 @@ $vol_snapshot_rollback_possible->{"local:snapshotable-disk-4"} = 1; printf("\n"); printf("Setting up Mocking for PVE::Storage\n"); my $storage_module = new Test::MockModule('PVE::Storage'); +$storage_module->mock('activate_storage', \&mocked_activate_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); @@ -429,6 +440,13 @@ $freeze_possible = 1; printf("Expected error for snapshot_create when mp volume snapshot is not possible\n"); testcase_create("203", "test", 0, "test comment", "volume snapshot disabled\n\n", { "local:snapshotable-disk-1" => "test" }, { "local:snapshotable-disk-1" => "test" }); +$activate_storage_possible = 0; + +printf("Expected error for snapshot_create when storage activation is not possible\n"); +testcase_create("204", "test", 0, "test comment", "storage activation failed\n\n"); + +$activate_storage_possible = 1; + $nodename = "delete"; printf("\n"); printf("Running delete tests\n"); @@ -461,6 +479,13 @@ testcase_delete("203", "test", 0, "volume snapshot delete disabled\n", { "local: printf("Expected error for snapshot_delete with locked config\n"); testcase_delete("202", "test", 0, "CT is locked (backup)\n"); +$activate_storage_possible = 0; + +printf("Expected error for snapshot_delete when storage activation is not possible\n"); +testcase_delete("204", "test", 0, "storage activation failed\n"); + +$activate_storage_possible = 1; + $nodename = "rollback"; printf("\n"); printf("Running rollback tests\n"); @@ -511,4 +536,11 @@ testcase_rollback("207", "test", "volume_rollback_is_possible failed\n"); printf("Expected error for snapshot_rollback with mp rollback failure (results in inconsistent state)\n"); testcase_rollback("208", "test", "volume snapshot rollback disabled\n", { "local:snapshotable-disk-1" => "test", "local:snapshotable-disk-2" => "test" }); +$activate_storage_possible = 0; + +printf("Expected error for snapshot_rollback when storage activation is not possible\n"); +testcase_rollback("209", "test", "storage activation failed\n"); + +$activate_storage_possible = 1; + done_testing(); -- 2.30.2