Do not force to use Hyper-V daemons

Hyper-V sync folder plugin will leverage possible approaches instead
of forcing to use Hyper-V daemons to upload files to guest.
This commit is contained in:
Zhongcheng Lao 2019-06-29 15:56:15 +08:00
parent c0102812f4
commit e4fa7ee946
4 changed files with 33 additions and 38 deletions

View File

@ -41,18 +41,6 @@ module VagrantPlugins
class SystemAccessRequired < HyperVError
error_key(:system_access_required)
end
class DaemonsNotInstalledInGuest < HyperVError
error_key(:daemons_not_installed_in_guest)
end
class DaemonsNotEnabledInGuest < HyperVError
error_key(:daemons_not_enabled_in_guest)
end
class DaemonsEnableFailedInGuest < HyperVError
error_key(:daemons_enable_failed_in_guest)
end
end
end
end

View File

@ -18,7 +18,7 @@ module VagrantPlugins
end
def enable(machine, folders, _opts)
return unless configure_hv_daemons(machine)
machine.ui.warn I18n.t("vagrant_hyperv.share_folders.no_daemons") unless configure_hv_daemons(machine)
# short guestpaths first, so we don't step on ourselves
folders = folders.sort_by do |id, data|
@ -62,18 +62,27 @@ module VagrantPlugins
installed = machine.guest.capability(:hyperv_daemons_installed)
unless installed
can_install = machine.guest.capability?(:hyperv_daemons_install)
raise Errors::DaemonsNotInstalledInGuest unless can_install
unless can_install
machine.ui.warn I18n.t("vagrant_hyperv.daemons.unable_to_install")
return false
end
machine.ui.info I18n.t("vagrant_hyperv.daemons.installing")
machine.guest.capability(:hyperv_daemons_install)
end
can_activate = machine.guest.capability?(:hyperv_daemons_activate)
raise Errors::DaemonsNotEnabledInGuest unless can_activate
unless can_activate
machine.ui.warn I18n.t("vagrant_hyperv.daemons.unable_to_activate")
return false
end
machine.ui.info I18n.t("vagrant_hyperv.daemons.activating")
activated = machine.guest.capability(:hyperv_daemons_activate)
raise Errors::DaemonsEnableFailedInGuest unless activated
unless activated
machine.ui.warn I18n.t("vagrant_hyperv.daemons.activation_failed")
return false
end
end
true
end

View File

@ -14,11 +14,22 @@ en:
syncing: Syncing shared folders...
syncing_entry: "%{guestpath} => %{hostpath}"
nosync_entry: "Sync disabled: %{hostpath}"
no_daemons: |-
Hyper-V daemons are not running on the guest operation system.
This may impact the performance.
daemons:
installing: |-
Installing Hyper-V daemons...
activating: |-
Activating Hyper-V daemons...
unable_to_install: |-
Hyper-V daemons cannot be installed in the guest operation system.
unable_to_activate: |-
Hyper-V daemons cannot be activated in the guest operation system
as no Hyper-V daemons activation approach is provided on the guest
operation system.
activation_failed: |-
Failed to activate in the guest operation system.
sync:
auto_initial: |-
Doing an initial sync...
@ -141,18 +152,3 @@ en:
problem:
icacls.exe %{root_dir} /T /Q /grant "NT AUTHORITY\SYSTEM:(IO)(CI)(F)"
daemons_not_installed_in_guest: |-
Hyper-V daemons are not installed in the guest operation system.
Hyper-V shared folder plugin relies on Hyper-V daemons to function
properly. For guest operation system which does not support Hyper-V
daemons, you may use Rsync or SMB plugin instead.
daemons_not_enabled_in_guest: |-
Hyper-V daemons are not enabled in the guest operation system.
Hyper-V shared folder plugin relies on Hyper-V daemons to function
properly. For guest operation system which does not support Hyper-V
daemons, you may use Rsync or SMB plugin instead.
daemons_enable_failed_in_guest: |-
Failed to enable Hyper-V daemons in the guest operation system.
Hyper-V shared folder plugin relies on Hyper-V daemons to function
properly. For guest operation system which does not support Hyper-V
daemons, you may use Rsync or SMB plugin instead.

View File

@ -72,6 +72,11 @@ describe VagrantPlugins::HyperV::SyncedFolder do
end
describe "#configure_hv_daemons" do
before do
allow(ui).to receive(:info)
allow(ui).to receive(:warn)
end
it "runs guest which does not support capability :hyperv_daemons_running" do
allow(guest).to receive(:capability?).with(:hyperv_daemons_running).and_return(false)
expect(subject.send(:configure_hv_daemons, machine)).to be_falsy
@ -89,7 +94,6 @@ describe VagrantPlugins::HyperV::SyncedFolder do
allow(guest).to receive(:capability).with(:hyperv_daemons_installed).and_return(true)
allow(guest).to receive(:capability?).with(:hyperv_daemons_activate).and_return(true)
allow(guest).to receive(:capability).with(:hyperv_daemons_activate).and_return(true)
allow(ui).to receive(:info)
expect(subject.send(:configure_hv_daemons, machine)).to be_truthy
end
@ -98,7 +102,7 @@ describe VagrantPlugins::HyperV::SyncedFolder do
allow(guest).to receive(:capability).with(:hyperv_daemons_running).and_return(false)
allow(guest).to receive(:capability).with(:hyperv_daemons_installed).and_return(true)
allow(guest).to receive(:capability?).with(:hyperv_daemons_activate).and_return(false)
expect { subject.send(:configure_hv_daemons, machine) }.to raise_error(VagrantPlugins::HyperV::Errors::DaemonsNotEnabledInGuest)
expect(subject.send(:configure_hv_daemons, machine)).to be_falsy
end
it "runs guest which has hyperv daemons installed but activate failed" do
@ -107,8 +111,7 @@ describe VagrantPlugins::HyperV::SyncedFolder do
allow(guest).to receive(:capability).with(:hyperv_daemons_installed).and_return(true)
allow(guest).to receive(:capability?).with(:hyperv_daemons_activate).and_return(true)
allow(guest).to receive(:capability).with(:hyperv_daemons_activate).and_return(false)
allow(ui).to receive(:info)
expect { subject.send(:configure_hv_daemons, machine) }.to raise_error(VagrantPlugins::HyperV::Errors::DaemonsEnableFailedInGuest)
expect(subject.send(:configure_hv_daemons, machine)).to be_falsy
end
it "runs guest which has no hyperv daemons and unable to install" do
@ -116,7 +119,7 @@ describe VagrantPlugins::HyperV::SyncedFolder do
allow(guest).to receive(:capability).with(:hyperv_daemons_running).and_return(false)
allow(guest).to receive(:capability).with(:hyperv_daemons_installed).and_return(false)
allow(guest).to receive(:capability?).with(:hyperv_daemons_install).and_return(false)
expect { subject.send(:configure_hv_daemons, machine) }.to raise_error(VagrantPlugins::HyperV::Errors::DaemonsNotInstalledInGuest)
expect(subject.send(:configure_hv_daemons, machine)).to be_falsy
end
it "runs guest which has hyperv daemons newly installed but failed to activate" do
@ -127,8 +130,7 @@ describe VagrantPlugins::HyperV::SyncedFolder do
allow(guest).to receive(:capability).with(:hyperv_daemons_install).and_return(true)
allow(guest).to receive(:capability?).with(:hyperv_daemons_activate).and_return(true)
allow(guest).to receive(:capability).with(:hyperv_daemons_activate).and_return(false)
allow(ui).to receive(:info)
expect { subject.send(:configure_hv_daemons, machine) }.to raise_error(VagrantPlugins::HyperV::Errors::DaemonsEnableFailedInGuest)
expect(subject.send(:configure_hv_daemons, machine)).to be_falsy
end
end
end