Fix duplicate provisioning of running VMs (#1722)

Remove duplicate inclusion of Provision middleware when up is called
on an running machine resulting in a double provision.

Includes a unit test update to ensure expected actions are only called
once as well as a regression for calling up on a running machine.

Fixes #1710.
This commit is contained in:
Conner Crosby 2023-02-16 10:13:31 -08:00 committed by GitHub
parent 33962dd40b
commit 9e7d0f3ec8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 3 deletions

View File

@ -128,9 +128,7 @@ module VagrantPlugins
private_class_method def self.action_start
Vagrant::Action::Builder.new.tap do |b|
b.use Call, IsRunning do |env, b2|
# If the VM is running, run the necessary provisioners
if env[:result]
b2.use action_provision
next
end

View File

@ -58,7 +58,7 @@ describe VagrantPlugins::ProviderLibvirt::Action do
end
def receive_and_call_next(&block)
return receive(:call) { |cls, env| call_next(cls, env, &block) }
return receive(:call) { |cls, env| call_next(cls, env, &block) }.exactly(1).times
end
def call_next(cls, env)
@ -332,6 +332,25 @@ describe VagrantPlugins::ProviderLibvirt::Action do
end
end
end
context 'running' do
before do
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, true)
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsRunning, true)
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsSuspended, false)
end
it 'should call provision' do
expect_any_instance_of(Vagrant::Action::Builtin::BoxCheckOutdated).to receive_and_call_next
expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::Provision).to receive_and_call_next
# ideally following two actions should not be scheduled if the machine is already running
expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::ResolveDiskSettings).to receive_and_call_next
expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::CreateNetworks).to receive_and_call_next
expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::SetupComplete).to receive_and_call_next
expect(runner.run(subject.action_up)).to match(hash_including({:machine => machine}))
end
end
end
describe '#action_halt' do
@ -389,6 +408,48 @@ describe VagrantPlugins::ProviderLibvirt::Action do
end
end
describe '#action_reload' do
context 'when not created' do
before do
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, false)
end
it 'should report not created' do
expect(ui).to receive(:info).with('Domain is not created. Please run `vagrant up` first.')
expect(runner.run(subject.action_reload)).to match(hash_including({:machine => machine}))
end
end
context 'when halted' do
before do
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, true)
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsSuspended, false)
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsRunning, false)
end
it 'should call reload' do
expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::Provision).to receive_and_call_next
expect(subject).to receive(:action_halt).and_return(Vagrant::Action::Builder.new)
expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::ResolveDiskSettings).to receive_and_call_next
# start action
expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::PrepareNFSValidIds).to receive_and_call_next
expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::SyncedFolderCleanup).to receive_and_call_next
expect_any_instance_of(Vagrant::Action::Builtin::SyncedFolders).to receive_and_call_next
expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::PrepareNFSSettings).to receive_and_call_next
expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::ShareFolders).to receive_and_call_next
expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::SetBootOrder).to receive_and_call_next
expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::StartDomain).to receive_and_call_next
expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::WaitTillUp).to receive_and_call_next
expect_any_instance_of(Vagrant::Action::Builtin::WaitForCommunicator).to receive_and_call_next
expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::ForwardPorts).to receive_and_call_next
expect(runner.run(subject.action_reload)).to match(hash_including({:machine => machine}))
end
end
end
describe '#action_suspend' do
context 'not created' do
before do