Skip to content

Commit a3a71f2

Browse files
committed
[hyper-v] Move disabling automatic checkpoints to vm creation (#4205)
Currently, disabling automatic checkpoints causes issues when the VM is not in an appropriate state at the time the constructor is executed. This causes the daemon to crash since the command throws an exception. Fixes: #4204 MULTI-2061
1 parent 958b9af commit a3a71f2

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

src/platform/backends/hyperv/hyperv_virtual_machine.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,6 @@ auto instance_state_for(mp::PowerShell* power_shell, const QString& name)
106106
return mp::VirtualMachine::State::unknown;
107107
}
108108

109-
void delete_automatic_snapshots(mp::PowerShell* power_shell, const QString& name)
110-
{
111-
power_shell->easy_run(
112-
{"Get-VMCheckpoint -VMName",
113-
name,
114-
"| Where-Object { $_.IsAutomaticCheckpoint } | Remove-VMCheckpoint -Confirm:$false"},
115-
"Could not delete existing automatic checkpoints");
116-
}
117-
118109
void add_extra_net(mp::PowerShell& ps,
119110
const QString& vm_name,
120111
const mp::NetworkInterface& extra_interface)
@@ -193,6 +184,8 @@ mp::HyperVVirtualMachine::HyperVVirtualMachine(const VirtualMachineDescription&
193184
"Could not setup cloud-init drive");
194185
power_shell->easy_run({"Set-VMMemory", "-VMName", name, "-DynamicMemoryEnabled", "$false"},
195186
"Could not disable dynamic memory");
187+
power_shell->easy_run({"Set-VM", "-Name", name, "-AutomaticCheckpointsEnabled", "$false"},
188+
"Could not disable automatic snapshots");
196189

197190
setup_network_interfaces();
198191

@@ -202,12 +195,6 @@ mp::HyperVVirtualMachine::HyperVVirtualMachine(const VirtualMachineDescription&
202195
{
203196
state = instance_state_for(power_shell.get(), name);
204197
}
205-
206-
power_shell->easy_run({"Set-VM", "-Name", name, "-AutomaticCheckpointsEnabled", "$false"},
207-
"Could not disable automatic snapshots"); // TODO move to new VMs only in
208-
// a couple of releases
209-
delete_automatic_snapshots(power_shell.get(),
210-
name); // TODO drop in a couple of releases (going in on v1.13)
211198
}
212199

213200
mp::HyperVVirtualMachine::HyperVVirtualMachine(const std::string& source_vm_name,

tests/hyperv/test_hyperv_backend.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ struct HyperVBackend : public Test
114114
{"-EnableSecureBoot Off"},
115115
{"Set-VMProcessor"},
116116
{"Add-VMDvdDrive"},
117-
{"Set-VMMemory"}};
118-
inline static const std::vector<RunSpec> postfix_ctor_runs = {{"Set-VM"}, {"Get-VMCheckpoint"}};
117+
{"Set-VMMemory"},
118+
{"Set-VM"}};
119+
inline static const std::vector<RunSpec> postfix_ctor_runs = {};
119120
inline static const RunSpec default_network_run = {"Set-VMNetworkAdapter"};
120121
inline static const RunSpec min_dtor_run = {"-ExpandProperty State", "Off"};
121122

0 commit comments

Comments
 (0)