mirror of
git://git.proxmox.com/git/qemu-server.git
synced 2025-01-21 18:03:56 +03:00
snapshot: implement __snapshot_activate_storages
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
This commit is contained in:
parent
4df8fe45b2
commit
fe2c506926
@ -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);
|
||||
|
13
test/snapshot-expected/create/qemu-server/303.conf
Normal file
13
test/snapshot-expected/create/qemu-server/303.conf
Normal file
@ -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
|
33
test/snapshot-expected/delete/qemu-server/204.conf
Normal file
33
test/snapshot-expected/delete/qemu-server/204.conf
Normal file
@ -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
|
34
test/snapshot-expected/rollback/qemu-server/303.conf
Normal file
34
test/snapshot-expected/rollback/qemu-server/303.conf
Normal file
@ -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
|
13
test/snapshot-input/create/qemu-server/303.conf
Normal file
13
test/snapshot-input/create/qemu-server/303.conf
Normal file
@ -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
|
33
test/snapshot-input/delete/qemu-server/204.conf
Normal file
33
test/snapshot-input/delete/qemu-server/204.conf
Normal file
@ -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
|
34
test/snapshot-input/rollback/qemu-server/303.conf
Normal file
34
test/snapshot-input/rollback/qemu-server/303.conf
Normal file
@ -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
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user