Fixes #10170: Check for modinfo in /sbin (#11178)

Check for modinfo in /sbin if it doesn't appear on the PATH.

If it's not found on the PATH or in /sbin, the command will default back to modinfo so the user sees the error message about adding it to their PATH.
This commit is contained in:
Jeff Bonhag 2019-11-06 16:10:24 -05:00 committed by GitHub
parent 89e0522659
commit 8a69c1205c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 1 deletions

View File

@ -93,7 +93,7 @@ module VagrantPlugins
"systemctl --no-pager --no-legend --plain list-unit-files --all --type=service " \
"| grep #{nfs_service_name_systemd}").exit_code == 0
else
Vagrant::Util::Subprocess.execute("modinfo", "nfsd").exit_code == 0 ||
Vagrant::Util::Subprocess.execute(modinfo_path, "nfsd").exit_code == 0 ||
Vagrant::Util::Subprocess.execute("grep", "nfsd", "/proc/filesystems").exit_code == 0
end
end
@ -261,6 +261,24 @@ module VagrantPlugins
Vagrant::Util::Subprocess.execute(*Shellwords.split(check_command)).exit_code == 0
end
def self.modinfo_path
if !defined?(@_modinfo_path)
@_modinfo_path = Vagrant::Util::Which.which("modinfo")
if @_modinfo_path.to_s.empty?
path = "/sbin/modinfo"
if File.file?(path)
@_modinfo_path = path
end
end
if @_modinfo_path.to_s.empty?
@_modinfo_path = "modinfo"
end
end
@_modinfo_path
end
# @private
# Reset the cached values for capability. This is not considered a public
# API and should only be used for testing.

View File

@ -337,4 +337,50 @@ EOH
end
end
end
describe ".modinfo_path" do
let(:cap){ VagrantPlugins::HostLinux::Cap::NFS }
context "with modinfo on PATH" do
before do
expect(Vagrant::Util::Which).to receive(:which).with("modinfo").and_return("/usr/bin/modinfo")
end
it "should use full path to modinfo" do
expect(cap.modinfo_path).to eq("/usr/bin/modinfo")
end
end
context "with modinfo at /sbin/modinfo" do
before do
expect(Vagrant::Util::Which).to receive(:which).with("modinfo").and_return(nil)
expect(File).to receive(:file?).with("/sbin/modinfo").and_return(true)
end
it "should use /sbin/modinfo" do
expect(cap.modinfo_path).to eq("/sbin/modinfo")
end
end
context "modinfo not found" do
before do
expect(Vagrant::Util::Which).to receive(:which).with("modinfo").and_return(nil)
expect(File).to receive(:file?).with("/sbin/modinfo").and_return(false)
end
it "should use modinfo" do
expect(cap.modinfo_path).to eq("modinfo")
end
end
context "with cached value for modinfo_path" do
before do
cap.instance_variable_set(:@_modinfo_path, "/usr/local/bin/modinfo")
end
it "should use cached value" do
expect(cap.modinfo_path).to eq("/usr/local/bin/modinfo")
end
end
end
end