Merge pull request #10917 from briancain/chef-install-check-update

Fixes #10912: Update chef install check for guests
This commit is contained in:
Brian Cain 2019-06-20 08:11:50 -07:00 committed by GitHub
commit 181e356a23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 170 additions and 6 deletions

View File

@ -10,7 +10,7 @@ module VagrantPlugins
command = "test -x #{knife}" command = "test -x #{knife}"
if version != :latest if version != :latest
command << "&& #{knife} --version | grep 'Chef: #{version}'" command << "&& #{knife} --version | grep '#{version}'"
end end
machine.communicate.test(command, sudo: true) machine.communicate.test(command, sudo: true)

View File

@ -10,7 +10,7 @@ module VagrantPlugins
command = "test -x #{knife}" command = "test -x #{knife}"
if version != :latest if version != :latest
command << "&& #{knife} --version | grep 'Chef: #{version}'" command << "&& #{knife} --version | grep '#{version}'"
end end
machine.communicate.test(command, sudo: true) machine.communicate.test(command, sudo: true)

View File

@ -11,7 +11,7 @@ module VagrantPlugins
command = "test -x #{knife}" command = "test -x #{knife}"
if version != :latest if version != :latest
command << "&& #{knife} --version | grep 'Chef: #{version}'" command << "&& #{knife} --version | grep '#{version}'"
end end
machine.communicate.test(command, sudo: true) machine.communicate.test(command, sudo: true)

View File

@ -7,9 +7,9 @@ module VagrantPlugins
# @return [true, false] # @return [true, false]
def self.chef_installed(machine, product, version) def self.chef_installed(machine, product, version)
if version != :latest if version != :latest
command = 'if ((&knife --version) -Match "Chef: ' + version.to_s + '"){ exit 0 } else { exit 1 }' command = 'if ((&knife --version) -Match "' + version.to_s + '"){ exit 0 } else { exit 1 }'
else else
command = 'if ((&knife --version) -Match "Chef: *"){ exit 0 } else { exit 1 }' command = 'if ((&knife --version) -Match "Chef*"){ exit 0 } else { exit 1 }'
end end
machine.communicate.test(command, sudo: true) machine.communicate.test(command, sudo: true)
end end

View File

@ -69,7 +69,7 @@ module VagrantPlugins
# Checks for the existence of chef binary and error if it # Checks for the existence of chef binary and error if it
# doesn't exist. # doesn't exist.
if windows? if windows?
command = "if ((&'#{binary}' -v) -Match 'Chef: *'){ exit 0 } else { exit 1 }" command = "if ((&'#{binary}' -v) -Match 'Chef*'){ exit 0 } else { exit 1 }"
else else
command = "sh -c 'command -v #{binary}'" command = "sh -c 'command -v #{binary}'"
end end

View File

@ -0,0 +1,41 @@
require_relative "../../../../../base"
require Vagrant.source_root.join("plugins/provisioners/chef/cap/freebsd/chef_installed")
describe VagrantPlugins::Chef::Cap::FreeBSD::ChefInstalled do
include_context "unit"
let(:iso_env) do
# We have to create a Vagrantfile so there is a root path
env = isolated_environment
env.vagrantfile("")
env.create_vagrant_env
end
let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) }
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
let(:config) { double("config") }
subject { described_class }
before do
allow(machine).to receive(:communicate).and_return(communicator)
end
describe "#chef_installed" do
let(:version) { "15.0.0" }
let(:command) { "test -x /opt/chef_solo/bin/knife&& /opt/chef_solo/bin/knife --version | grep '15.0.0'" }
it "returns true if installed" do
expect(machine.communicate).to receive(:test).
with(command, sudo: true).and_return(true)
subject.chef_installed(machine, "chef_solo", version)
end
it "returns false if not installed" do
expect(machine.communicate).to receive(:test).
with(command, sudo: true).and_return(false)
expect(subject.chef_installed(machine, "chef_solo", version)).to be_falsey
end
end
end

View File

@ -0,0 +1,41 @@
require_relative "../../../../../base"
require Vagrant.source_root.join("plugins/provisioners/chef/cap/linux/chef_installed")
describe VagrantPlugins::Chef::Cap::Linux::ChefInstalled do
include_context "unit"
let(:iso_env) do
# We have to create a Vagrantfile so there is a root path
env = isolated_environment
env.vagrantfile("")
env.create_vagrant_env
end
let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) }
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
let(:config) { double("config") }
subject { described_class }
before do
allow(machine).to receive(:communicate).and_return(communicator)
end
describe "#chef_installed" do
let(:version) { "15.0.0" }
let(:command) { "test -x /opt/chef_solo/bin/knife&& /opt/chef_solo/bin/knife --version | grep '15.0.0'" }
it "returns true if installed" do
expect(machine.communicate).to receive(:test).
with(command, sudo: true).and_return(true)
subject.chef_installed(machine, "chef_solo", version)
end
it "returns false if not installed" do
expect(machine.communicate).to receive(:test).
with(command, sudo: true).and_return(false)
expect(subject.chef_installed(machine, "chef_solo", version)).to be_falsey
end
end
end

View File

@ -0,0 +1,41 @@
require_relative "../../../../../base"
require Vagrant.source_root.join("plugins/provisioners/chef/cap/omnios/chef_installed")
describe VagrantPlugins::Chef::Cap::OmniOS::ChefInstalled do
include_context "unit"
let(:iso_env) do
# We have to create a Vagrantfile so there is a root path
env = isolated_environment
env.vagrantfile("")
env.create_vagrant_env
end
let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) }
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
let(:config) { double("config") }
subject { described_class }
before do
allow(machine).to receive(:communicate).and_return(communicator)
end
describe "#chef_installed" do
let(:version) { "15.0.0" }
let(:command) { "test -x /opt/chef_solo/bin/knife&& /opt/chef_solo/bin/knife --version | grep '15.0.0'" }
it "returns true if installed" do
expect(machine.communicate).to receive(:test).
with(command, sudo: true).and_return(true)
subject.chef_installed(machine, "chef_solo", version)
end
it "returns false if not installed" do
expect(machine.communicate).to receive(:test).
with(command, sudo: true).and_return(false)
expect(subject.chef_installed(machine, "chef_solo", version)).to be_falsey
end
end
end

View File

@ -0,0 +1,41 @@
require_relative "../../../../../base"
require Vagrant.source_root.join("plugins/provisioners/chef/cap/windows/chef_installed")
describe VagrantPlugins::Chef::Cap::Windows::ChefInstalled do
include_context "unit"
let(:iso_env) do
# We have to create a Vagrantfile so there is a root path
env = isolated_environment
env.vagrantfile("")
env.create_vagrant_env
end
let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) }
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
let(:config) { double("config") }
subject { described_class }
before do
allow(machine).to receive(:communicate).and_return(communicator)
end
describe "#chef_installed" do
let(:version) { "15.0.0" }
let(:command) { "if ((&knife --version) -Match \"15.0.0\"){ exit 0 } else { exit 1 }" }
it "returns true if installed" do
expect(machine.communicate).to receive(:test).
with(command, sudo: true).and_return(true)
subject.chef_installed(machine, "chef_solo", version)
end
it "returns false if not installed" do
expect(machine.communicate).to receive(:test).
with(command, sudo: true).and_return(false)
expect(subject.chef_installed(machine, "chef_solo", version)).to be_falsey
end
end
end