providers/docker: Fix usability check

In commit 7980178d19 (#10879) I added a
`usable?` class method to `VagrantPlugins::DockerProvider::Provider`.
However, commit 34e53a5a4b (#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:
Anders Kaseorg 2019-09-10 14:15:41 -07:00 committed by Brian Cain
parent b28e6d95a6
commit 5b4dcf9443
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
4 changed files with 18 additions and 9 deletions

View File

@ -11,6 +11,14 @@ module VagrantPlugins
class Provider < Vagrant.plugin("2", :provider)
@@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)
@logger = Log4r::Logger.new("vagrant::provider::docker")
@machine = machine
@ -45,14 +53,6 @@ module VagrantPlugins
@driver
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.
# It does not perform any action on the machine or verify it is
# running.

View File

@ -3,6 +3,7 @@ require_relative "../../../../../../plugins/providers/docker/action/destroy_netw
describe VagrantPlugins::DockerProvider::Action::DestroyNetwork do
include_context "unit"
include_context "virtualbox"
let(:sandbox) { isolated_environment }

View File

@ -21,9 +21,12 @@ describe VagrantPlugins::DockerProvider::Provider do
end
describe ".usable?" do
subject { described_class }
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(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
end

View File

@ -28,6 +28,11 @@ shared_context "virtualbox" do
allow(subprocess).to receive(:execute).
with("VBoxManage", "showvminfo", kind_of(String), kind_of(Hash)).
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
around do |example|