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 D003C60936 for ; Thu, 13 Jan 2022 12:04:16 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 21D2A1D249 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 3F42C1D129 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 18E5346021 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:02 +0100 Message-Id: <20220113110405.67232-4-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.137 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. [qemuconfig.pm, snapshot-test.pm] Subject: [pve-devel] [PATCH v2 qemu-server 1/1] 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:16 -0000 Signed-off-by: Fabian Ebner --- Build-depends on guest-common. PVE/QemuConfig.pm | 19 +++++++++++ .../create/qemu-server/303.conf | 13 +++++++ .../delete/qemu-server/204.conf | 33 ++++++++++++++++++ .../rollback/qemu-server/303.conf | 34 +++++++++++++++++++ .../create/qemu-server/303.conf | 13 +++++++ .../delete/qemu-server/204.conf | 33 ++++++++++++++++++ .../rollback/qemu-server/303.conf | 34 +++++++++++++++++++ test/snapshot-test.pm | 32 +++++++++++++++++ 8 files changed, 211 insertions(+) create mode 100644 test/snapshot-expected/create/qemu-server/303.conf create mode 100644 test/snapshot-expected/delete/qemu-server/204.conf create mode 100644 test/snapshot-expected/rollback/qemu-server/303.conf create mode 100644 test/snapshot-input/create/qemu-server/303.conf create mode 100644 test/snapshot-input/delete/qemu-server/204.conf create mode 100644 test/snapshot-input/rollback/qemu-server/303.conf diff --git a/PVE/QemuConfig.pm b/PVE/QemuConfig.pm index b993378..cfef8d3 100644 --- a/PVE/QemuConfig.pm +++ b/PVE/QemuConfig.pm @@ -241,6 +241,25 @@ sub __snapshot_save_vmstate { return $statefile; } +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 ($key, $drive) = @_; + + return if PVE::QemuServer::drive_is_cdrom($drive); + + my ($storeid) = PVE::Storage::parse_volume_id($drive->{file}); + $storage_hash->{$storeid} = 1; + }); + + PVE::Storage::activate_storage_list($storecfg, [ sort keys $storage_hash->%* ]); +} + sub __snapshot_check_running { my ($class, $vmid) = @_; return PVE::QemuServer::Helpers::vm_running_locally($vmid); diff --git a/test/snapshot-expected/create/qemu-server/303.conf b/test/snapshot-expected/create/qemu-server/303.conf new file mode 100644 index 0000000..2731bd1 --- /dev/null +++ b/test/snapshot-expected/create/qemu-server/303.conf @@ -0,0 +1,13 @@ +bootdisk: ide0 +cores: 4 +ide0: local:snapshotable-disk-1,discard=on,size=32G +ide2: none,media=cdrom +machine: q35 +memory: 8192 +name: win +net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1 +numa: 0 +ostype: win7 +smbios1: uuid=01234567-890a-bcde-f012-34567890abcd +sockets: 1 +vga: qxl diff --git a/test/snapshot-expected/delete/qemu-server/204.conf b/test/snapshot-expected/delete/qemu-server/204.conf new file mode 100644 index 0000000..c521154 --- /dev/null +++ b/test/snapshot-expected/delete/qemu-server/204.conf @@ -0,0 +1,33 @@ +agent: 1 +bootdisk: ide0 +cores: 4 +ide0: local:snapshotable-disk-1,discard=on,size=32G +ide2: none,media=cdrom +memory: 8192 +name: win +net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1 +numa: 0 +ostype: win7 +parent: test +smbios1: uuid=01234567-890a-bcde-f012-34567890abcd +sockets: 1 +vga: qxl + +[test] +#test comment +agent: 1 +bootdisk: ide0 +cores: 4 +ide0: local:snapshotable-disk-1,discard=on,size=32G +ide2: none,media=cdrom +machine: somemachine +memory: 8192 +name: win +net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1 +numa: 0 +ostype: win7 +smbios1: uuid=01234567-890a-bcde-f012-34567890abcd +snaptime: 1234567890 +sockets: 1 +vga: qxl +vmstate: somestorage:state-volume diff --git a/test/snapshot-expected/rollback/qemu-server/303.conf b/test/snapshot-expected/rollback/qemu-server/303.conf new file mode 100644 index 0000000..518c954 --- /dev/null +++ b/test/snapshot-expected/rollback/qemu-server/303.conf @@ -0,0 +1,34 @@ +agent: 1 +bootdisk: ide0 +cores: 4 +ide0: local:snapshotable-disk-1,discard=on,size=32G +ide2: none,media=cdrom +memory: 8192 +name: win +net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1 +numa: 0 +ostype: win7 +parent: test +smbios1: uuid=01234567-890a-bcde-f012-34567890abcd +sockets: 1 +vga: qxl + +[test] +#test comment +agent: 1 +bootdisk: ide0 +cores: 4 +ide0: local:snapshotable-disk-1,discard=on,size=32G +ide2: none,media=cdrom +machine: q35 +memory: 8192 +name: win +net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1 +numa: 0 +ostype: win7 +runningmachine: somemachine +smbios1: uuid=01234567-890a-bcde-f012-34567890abcd +snaptime: 1234567890 +sockets: 1 +vga: qxl +vmstate: somestorage:state-volume diff --git a/test/snapshot-input/create/qemu-server/303.conf b/test/snapshot-input/create/qemu-server/303.conf new file mode 100644 index 0000000..2731bd1 --- /dev/null +++ b/test/snapshot-input/create/qemu-server/303.conf @@ -0,0 +1,13 @@ +bootdisk: ide0 +cores: 4 +ide0: local:snapshotable-disk-1,discard=on,size=32G +ide2: none,media=cdrom +machine: q35 +memory: 8192 +name: win +net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1 +numa: 0 +ostype: win7 +smbios1: uuid=01234567-890a-bcde-f012-34567890abcd +sockets: 1 +vga: qxl diff --git a/test/snapshot-input/delete/qemu-server/204.conf b/test/snapshot-input/delete/qemu-server/204.conf new file mode 100644 index 0000000..c521154 --- /dev/null +++ b/test/snapshot-input/delete/qemu-server/204.conf @@ -0,0 +1,33 @@ +agent: 1 +bootdisk: ide0 +cores: 4 +ide0: local:snapshotable-disk-1,discard=on,size=32G +ide2: none,media=cdrom +memory: 8192 +name: win +net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1 +numa: 0 +ostype: win7 +parent: test +smbios1: uuid=01234567-890a-bcde-f012-34567890abcd +sockets: 1 +vga: qxl + +[test] +#test comment +agent: 1 +bootdisk: ide0 +cores: 4 +ide0: local:snapshotable-disk-1,discard=on,size=32G +ide2: none,media=cdrom +machine: somemachine +memory: 8192 +name: win +net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1 +numa: 0 +ostype: win7 +smbios1: uuid=01234567-890a-bcde-f012-34567890abcd +snaptime: 1234567890 +sockets: 1 +vga: qxl +vmstate: somestorage:state-volume diff --git a/test/snapshot-input/rollback/qemu-server/303.conf b/test/snapshot-input/rollback/qemu-server/303.conf new file mode 100644 index 0000000..518c954 --- /dev/null +++ b/test/snapshot-input/rollback/qemu-server/303.conf @@ -0,0 +1,34 @@ +agent: 1 +bootdisk: ide0 +cores: 4 +ide0: local:snapshotable-disk-1,discard=on,size=32G +ide2: none,media=cdrom +memory: 8192 +name: win +net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1 +numa: 0 +ostype: win7 +parent: test +smbios1: uuid=01234567-890a-bcde-f012-34567890abcd +sockets: 1 +vga: qxl + +[test] +#test comment +agent: 1 +bootdisk: ide0 +cores: 4 +ide0: local:snapshotable-disk-1,discard=on,size=32G +ide2: none,media=cdrom +machine: q35 +memory: 8192 +name: win +net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1 +numa: 0 +ostype: win7 +runningmachine: somemachine +smbios1: uuid=01234567-890a-bcde-f012-34567890abcd +snaptime: 1234567890 +sockets: 1 +vga: qxl +vmstate: somestorage:state-volume diff --git a/test/snapshot-test.pm b/test/snapshot-test.pm index cc04f01..3f1ac7c 100644 --- a/test/snapshot-test.pm +++ b/test/snapshot-test.pm @@ -15,6 +15,7 @@ use PVE::ReplicationConfig; use Test::MockModule; use Test::More; +my $activate_storage_possible = 1; my $nodename; my $snapshot_possible; my $vol_snapshot_possible = {}; @@ -105,6 +106,15 @@ sub mocked_volume_rollback_is_possible { die "volume_rollback_is_possible failed\n"; } +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_activate_volumes { my ($storecfg, $volumes) = @_; die "Storage config not mocked! aborting\n" @@ -410,6 +420,7 @@ $repl_config_module->mock('check_for_existing_jobs' => sub { return }); my $storage_module = Test::MockModule->new('PVE::Storage'); $storage_module->mock('config', sub { return; }); $storage_module->mock('path', sub { return "/some/store/statefile/path"; }); +$storage_module->mock('activate_storage', \&mocked_activate_storage); $storage_module->mock('activate_volumes', \&mocked_activate_volumes); $storage_module->mock('deactivate_volumes', \&mocked_deactivate_volumes); $storage_module->mock('vdisk_free', \&mocked_vdisk_free); @@ -555,6 +566,13 @@ $vm_mon->{savevm_start} = 1; printf("Successful snapshot_create with no existing snapshots but set machine type\n"); testcase_create("301", "test", 1, "test comment", "", { "local:snapshotable-disk-1" => "test" }); +$activate_storage_possible = 0; + +printf("Expected error for snapshot_create when storage activation is not possible\n"); +testcase_create("303", "test", 1, "test comment", "storage activation failed\n\n"); + +$activate_storage_possible = 1; + $nodename = "delete"; printf("\n"); printf("Running delete tests\n"); @@ -587,6 +605,13 @@ testcase_delete("202", "test", 0, "volume snapshot delete disabled\n", { "local: printf("Expected error for snapshot_delete with locked config\n"); testcase_delete("203", "test", 0, "VM 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"); @@ -643,6 +668,13 @@ testcase_rollback("301", "test", "", { "local:snapshotable-disk-1" => "test" }); printf("Successful snapshot_rollback with saved vmstate and machine config and runningmachine \n"); testcase_rollback("302", "test", "", { "local:snapshotable-disk-1" => "test" }); +$activate_storage_possible = 0; + +printf("Expected error for snapshot_rollback when storage activation is not possible\n"); +testcase_rollback("303", "test", "storage activation failed\n"); + +$activate_storage_possible = 1; + done_testing(); 1; -- 2.30.2