From de61b307aad0b448e4ca2e84b01120d2e451dbee Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Tue, 17 Dec 2019 10:45:33 -0800 Subject: [PATCH 1/2] Only run disk action if disk config present --- lib/vagrant/action/builtin/disk.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/vagrant/action/builtin/disk.rb b/lib/vagrant/action/builtin/disk.rb index a1abe7289..cf0ac6a80 100644 --- a/lib/vagrant/action/builtin/disk.rb +++ b/lib/vagrant/action/builtin/disk.rb @@ -12,11 +12,13 @@ module Vagrant defined_disks = get_disks(machine, env) # Call into providers machine implementation for disk management - if machine.provider.capability?(:configure_disks) - machine.provider.capability(:configure_disks, defined_disks) - else - env[:ui].warn(I18n.t("vagrant.actions.disk.provider_unsupported", - provider: machine.provider_name)) + if !defined_disks.empty? + if machine.provider.capability?(:configure_disks) + machine.provider.capability(:configure_disks, defined_disks) + else + env[:ui].warn(I18n.t("vagrant.actions.disk.provider_unsupported", + provider: machine.provider_name)) + end end # Continue On From 9f2261a6fc9e0743b484aeb486af67e31075f2a5 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Tue, 17 Dec 2019 10:56:48 -0800 Subject: [PATCH 2/2] Add test for builtin disk action --- test/unit/vagrant/action/builtin/disk_test.rb | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/unit/vagrant/action/builtin/disk_test.rb diff --git a/test/unit/vagrant/action/builtin/disk_test.rb b/test/unit/vagrant/action/builtin/disk_test.rb new file mode 100644 index 000000000..05f485602 --- /dev/null +++ b/test/unit/vagrant/action/builtin/disk_test.rb @@ -0,0 +1,50 @@ +require File.expand_path("../../../../base", __FILE__) + +describe Vagrant::Action::Builtin::Disk do + let(:app) { lambda { |env| } } + let(:vm) { double("vm") } + let(:config) { double("config", vm: vm) } + let(:provider) { double("provider") } + let(:machine) { double("machine", config: config, provider: provider, provider_name: "provider") } + let(:env) { { ui: ui, machine: machine} } + + let(:disks) { [double("disk")] } + + let(:ui) { double("ui") } + + describe "#call" do + it "calls configure_disks if disk config present" do + allow(vm).to receive(:disks).and_return(disks) + allow(machine).to receive(:disks).and_return(disks) + allow(machine.provider).to receive(:capability?).with(:configure_disks).and_return(true) + subject = described_class.new(app, env) + + expect(app).to receive(:call).with(env).ordered + expect(machine.provider).to receive(:capability).with(:configure_disks, disks) + + subject.call(env) + end + + it "continues on if no disk config present" do + allow(vm).to receive(:disks).and_return([]) + subject = described_class.new(app, env) + + expect(app).to receive(:call).with(env).ordered + expect(machine.provider).not_to receive(:capability).with(:configure_disks, disks) + + subject.call(env) + end + + it "prints a warning if disk config capability is unsupported" do + allow(vm).to receive(:disks).and_return(disks) + allow(machine.provider).to receive(:capability?).with(:configure_disks).and_return(false) + subject = described_class.new(app, env) + + expect(app).to receive(:call).with(env).ordered + expect(machine.provider).not_to receive(:capability).with(:configure_disks, disks) + expect(ui).to receive(:warn) + + subject.call(env) + end + end +end