(#8719) Add force flag for box upgrade command
Prior to this commit, if a state was reached where the action_box_add command needed a force flag, it would fail requesting the user to provide that flag to override adding a new box. However that flag did not exist on the box update command, and could not be passed onto the action_box_add action. This commit updates that to include a force flag, and if used, pass that value onto the action_box_add action.
This commit is contained in:
parent
2a444198f2
commit
324a08bd75
|
@ -33,6 +33,10 @@ module VagrantPlugins
|
||||||
options[:provider] = p.to_sym
|
options[:provider] = p.to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
|
o.on("-f", "--force", "Overwrite an existing box if it exists") do |f|
|
||||||
|
options[:force] = f
|
||||||
|
end
|
||||||
|
|
||||||
build_download_options(o, download_options)
|
build_download_options(o, download_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -40,15 +44,15 @@ module VagrantPlugins
|
||||||
return if !argv
|
return if !argv
|
||||||
|
|
||||||
if options[:box]
|
if options[:box]
|
||||||
update_specific(options[:box], options[:provider], download_options)
|
update_specific(options[:box], options[:provider], download_options, options[:force])
|
||||||
else
|
else
|
||||||
update_vms(argv, options[:provider], download_options)
|
update_vms(argv, options[:provider], download_options, options[:force])
|
||||||
end
|
end
|
||||||
|
|
||||||
0
|
0
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_specific(name, provider, download_options)
|
def update_specific(name, provider, download_options, force)
|
||||||
boxes = {}
|
boxes = {}
|
||||||
@env.boxes.all.each do |n, v, p|
|
@env.boxes.all.each do |n, v, p|
|
||||||
boxes[n] ||= {}
|
boxes[n] ||= {}
|
||||||
|
@ -81,11 +85,11 @@ module VagrantPlugins
|
||||||
|
|
||||||
to_update.each do |n, p, v|
|
to_update.each do |n, p, v|
|
||||||
box = @env.boxes.find(n, p, v)
|
box = @env.boxes.find(n, p, v)
|
||||||
box_update(box, "> #{v}", @env.ui, download_options)
|
box_update(box, "> #{v}", @env.ui, download_options, force)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_vms(argv, provider, download_options)
|
def update_vms(argv, provider, download_options, force)
|
||||||
machines = {}
|
machines = {}
|
||||||
|
|
||||||
with_target_vms(argv, provider: provider) do |machine|
|
with_target_vms(argv, provider: provider) do |machine|
|
||||||
|
@ -120,11 +124,11 @@ module VagrantPlugins
|
||||||
if download_options[:insecure].nil?
|
if download_options[:insecure].nil?
|
||||||
download_options[:insecure] = machine.config.vm.box_download_insecure
|
download_options[:insecure] = machine.config.vm.box_download_insecure
|
||||||
end
|
end
|
||||||
box_update(box, version, machine.ui, download_options)
|
box_update(box, version, machine.ui, download_options, force)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def box_update(box, version, ui, download_options)
|
def box_update(box, version, ui, download_options, force)
|
||||||
ui.output(I18n.t("vagrant.box_update_checking", name: box.name))
|
ui.output(I18n.t("vagrant.box_update_checking", name: box.name))
|
||||||
ui.detail("Latest installed version: #{box.version}")
|
ui.detail("Latest installed version: #{box.version}")
|
||||||
ui.detail("Version constraints: #{version}")
|
ui.detail("Version constraints: #{version}")
|
||||||
|
@ -149,6 +153,7 @@ module VagrantPlugins
|
||||||
box_provider: update[2].name,
|
box_provider: update[2].name,
|
||||||
box_version: update[1].version,
|
box_version: update[1].version,
|
||||||
ui: ui,
|
ui: ui,
|
||||||
|
box_force: force,
|
||||||
box_client_cert: download_options[:client_cert],
|
box_client_cert: download_options[:client_cert],
|
||||||
box_download_ca_cert: download_options[:ca_cert],
|
box_download_ca_cert: download_options[:ca_cert],
|
||||||
box_download_ca_path: download_options[:ca_path],
|
box_download_ca_path: download_options[:ca_path],
|
||||||
|
|
|
@ -94,6 +94,7 @@ describe VagrantPlugins::CommandBox::Command::Update do
|
||||||
allow(action_runner).to receive(:run) do |action, opts|
|
allow(action_runner).to receive(:run) do |action, opts|
|
||||||
if opts[:box_provider]
|
if opts[:box_provider]
|
||||||
action_called = true
|
action_called = true
|
||||||
|
expect(opts[:box_force]).to eq(nil)
|
||||||
expect(opts[:box_url]).to eq(metadata_url.to_s)
|
expect(opts[:box_url]).to eq(metadata_url.to_s)
|
||||||
expect(opts[:box_provider]).to eq("virtualbox")
|
expect(opts[:box_provider]).to eq("virtualbox")
|
||||||
expect(opts[:box_version]).to eq("1.1")
|
expect(opts[:box_version]).to eq("1.1")
|
||||||
|
@ -356,6 +357,27 @@ describe VagrantPlugins::CommandBox::Command::Update do
|
||||||
subject.execute
|
subject.execute
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "force flag is specified on the command line" do
|
||||||
|
let(:argv) { ["--force"].concat(download_options) }
|
||||||
|
|
||||||
|
it "passes force through to action_box_add as true" do
|
||||||
|
expect(box).to receive(:has_update?).
|
||||||
|
with(machine.config.vm.box_version,
|
||||||
|
{download_options:
|
||||||
|
{ca_cert: "foo", ca_path: "bar", client_cert: "baz",
|
||||||
|
insecure: true}}).
|
||||||
|
and_return([md, md.version("1.1"),
|
||||||
|
md.version("1.1").provider("virtualbox")])
|
||||||
|
|
||||||
|
expect(action_runner).to receive(:run).with(any_args) { |action, opts|
|
||||||
|
expect(opts[:box_force]).to be(true)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
subject.execute
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue