providers/docker: Fix usability check
In commit7980178d19
(#10879) I added a `usable?` class method to `VagrantPlugins::DockerProvider::Provider`. However, commit34e53a5a4b
(#10890) incorrectly changed it to an instance method. This rendered it ineffective because it’s called on the class, not an instance. Change it back to a class method. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
parent
b28e6d95a6
commit
5b4dcf9443
|
@ -11,6 +11,14 @@ module VagrantPlugins
|
||||||
class Provider < Vagrant.plugin("2", :provider)
|
class Provider < Vagrant.plugin("2", :provider)
|
||||||
@@host_vm_mutex = Mutex.new
|
@@host_vm_mutex = Mutex.new
|
||||||
|
|
||||||
|
def self.usable?(raise_error=false)
|
||||||
|
Driver.new.execute("docker", "version")
|
||||||
|
true
|
||||||
|
rescue Vagrant::Errors::CommandUnavailable, Errors::ExecuteError
|
||||||
|
raise if raise_error
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(machine)
|
def initialize(machine)
|
||||||
@logger = Log4r::Logger.new("vagrant::provider::docker")
|
@logger = Log4r::Logger.new("vagrant::provider::docker")
|
||||||
@machine = machine
|
@machine = machine
|
||||||
|
@ -45,14 +53,6 @@ module VagrantPlugins
|
||||||
@driver
|
@driver
|
||||||
end
|
end
|
||||||
|
|
||||||
def usable?(raise_error=false)
|
|
||||||
driver.execute("docker", "version")
|
|
||||||
true
|
|
||||||
rescue Vagrant::Errors::CommandUnavailable, Errors::ExecuteError
|
|
||||||
raise if raise_error
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
# This returns the {Vagrant::Machine} that is our host machine.
|
# This returns the {Vagrant::Machine} that is our host machine.
|
||||||
# It does not perform any action on the machine or verify it is
|
# It does not perform any action on the machine or verify it is
|
||||||
# running.
|
# running.
|
||||||
|
|
|
@ -3,6 +3,7 @@ require_relative "../../../../../../plugins/providers/docker/action/destroy_netw
|
||||||
|
|
||||||
describe VagrantPlugins::DockerProvider::Action::DestroyNetwork do
|
describe VagrantPlugins::DockerProvider::Action::DestroyNetwork do
|
||||||
include_context "unit"
|
include_context "unit"
|
||||||
|
include_context "virtualbox"
|
||||||
|
|
||||||
let(:sandbox) { isolated_environment }
|
let(:sandbox) { isolated_environment }
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,12 @@ describe VagrantPlugins::DockerProvider::Provider do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".usable?" do
|
describe ".usable?" do
|
||||||
|
subject { described_class }
|
||||||
|
|
||||||
it "returns true if usable" do
|
it "returns true if usable" do
|
||||||
|
allow(VagrantPlugins::DockerProvider::Driver).to receive(:new).and_return(driver_obj)
|
||||||
allow(provider_config).to receive(:compose).and_return(false)
|
allow(provider_config).to receive(:compose).and_return(false)
|
||||||
allow(subject.driver).to receive(:execute).with("docker", "version").and_return(true)
|
allow(driver_obj).to receive(:execute).with("docker", "version").and_return(true)
|
||||||
expect(subject).to be_usable
|
expect(subject).to be_usable
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,11 @@ shared_context "virtualbox" do
|
||||||
allow(subprocess).to receive(:execute).
|
allow(subprocess).to receive(:execute).
|
||||||
with("VBoxManage", "showvminfo", kind_of(String), kind_of(Hash)).
|
with("VBoxManage", "showvminfo", kind_of(String), kind_of(Hash)).
|
||||||
and_return(subprocess_result(exit_code: 0))
|
and_return(subprocess_result(exit_code: 0))
|
||||||
|
|
||||||
|
# apparently this is also used in docker tests
|
||||||
|
allow(subprocess).to receive(:execute).
|
||||||
|
with("docker", "version", an_instance_of(Hash)).
|
||||||
|
and_return(subprocess_result(exit_code: 0))
|
||||||
end
|
end
|
||||||
|
|
||||||
around do |example|
|
around do |example|
|
||||||
|
|
Loading…
Reference in New Issue