From 60ef0d7d9caef59d05342894bd01b13318f0ab3a Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Mon, 27 Jul 2020 13:46:03 -0700 Subject: [PATCH] Use existing disk structure rather than finding port/device again --- plugins/providers/virtualbox/cap/configure_disks.rb | 13 +++++-------- .../virtualbox/cap/configure_disks_test.rb | 11 +---------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/plugins/providers/virtualbox/cap/configure_disks.rb b/plugins/providers/virtualbox/cap/configure_disks.rb index 5eb7e7d60..48dd2a336 100644 --- a/plugins/providers/virtualbox/cap/configure_disks.rb +++ b/plugins/providers/virtualbox/cap/configure_disks.rb @@ -338,9 +338,6 @@ module VagrantPlugins def self.resize_disk(machine, disk_config, defined_disk, controller) machine.ui.detail(I18n.t("vagrant.cap.configure_disks.resize_disk", name: disk_config.name), prefix: true) - # grab disk to be resized port and device number - disk_info = machine.provider.driver.get_port_and_device(defined_disk[:uuid]) - if defined_disk[:storage_format] == "VMDK" LOGGER.warn("Disk type VMDK cannot be resized in VirtualBox. Vagrant will convert disk to VDI format to resize first, and then convert resized disk back to VMDK format") @@ -356,7 +353,7 @@ module VagrantPlugins begin # Danger Zone # remove and close original volume - machine.provider.driver.remove_disk(controller.name, disk_info[:port], disk_info[:device]) + machine.provider.driver.remove_disk(controller.name, defined_disk[:port], defined_disk[:device]) # Create a backup of the original disk if something goes wrong LOGGER.warn("Making a backup of the original disk at #{defined_disk[:location]}") FileUtils.mv(defined_disk[:location], backup_disk_location) @@ -368,8 +365,8 @@ module VagrantPlugins # clone back to original vmdk format and attach resized disk vmdk_disk_file = machine.provider.driver.vdi_to_vmdk(vdi_disk_file) machine.provider.driver.attach_disk(controller.name, - disk_info[:port], - disk_info[:device], + defined_disk[:port], + defined_disk[:device], "hdd", vmdk_disk_file) rescue ScriptError, SignalException, StandardError @@ -377,7 +374,7 @@ module VagrantPlugins machine.ui.error(I18n.t("vagrant.cap.configure_disks.recovery_from_resize", location: original_disk[:location], name: machine.name)) - recover_from_resize(machine, disk_info, backup_disk_location, original_disk, vdi_disk_file, controller) + recover_from_resize(machine, defined_disk, backup_disk_location, original_disk, vdi_disk_file, controller) raise ensure # Remove backup disk file if all goes well @@ -398,7 +395,7 @@ module VagrantPlugins end disk_metadata = { uuid: defined_disk[:uuid], name: disk_config.name, controller: controller.name, - port: disk_info[:port], device: disk_info[:device] } + port: defined_disk[:port], device: defined_disk[:device] } disk_metadata end diff --git a/test/unit/plugins/providers/virtualbox/cap/configure_disks_test.rb b/test/unit/plugins/providers/virtualbox/cap/configure_disks_test.rb index 81d112ac8..a791780ee 100644 --- a/test/unit/plugins/providers/virtualbox/cap/configure_disks_test.rb +++ b/test/unit/plugins/providers/virtualbox/cap/configure_disks_test.rb @@ -484,9 +484,6 @@ describe VagrantPlugins::ProviderVirtualBox::Cap::ConfigureDisks do expect(FileUtils).to receive(:mv).with(vmdk_disk_file, "#{vmdk_disk_file}.backup"). and_return(true) - expect(driver).to receive(:get_port_and_device).with("12345"). - and_return(attach_info) - expect(driver).to receive(:vmdk_to_vdi).with(all_disks[0][:location]). and_return(vdi_disk_file) @@ -516,9 +513,6 @@ describe VagrantPlugins::ProviderVirtualBox::Cap::ConfigureDisks do expect(FileUtils).to receive(:mv).with(vmdk_disk_file, "#{vmdk_disk_file}.backup"). and_return(true) - expect(driver).to receive(:get_port_and_device).with("12345"). - and_return(attach_info) - expect(driver).to receive(:vmdk_to_vdi).with(all_disks[0][:location]). and_return(vdi_disk_file) @@ -530,7 +524,7 @@ describe VagrantPlugins::ProviderVirtualBox::Cap::ConfigureDisks do allow(driver).to receive(:vdi_to_vmdk).and_raise(StandardError) - expect(subject).to receive(:recover_from_resize).with(machine, attach_info, "#{vmdk_disk_file}.backup", all_disks[0], vdi_disk_file, controller) + expect(subject).to receive(:recover_from_resize).with(machine, all_disks[0], "#{vmdk_disk_file}.backup", all_disks[0], vdi_disk_file, controller) expect{subject.resize_disk(machine, disk_config, all_disks[0], controller)}.to raise_error(Exception) end @@ -543,9 +537,6 @@ describe VagrantPlugins::ProviderVirtualBox::Cap::ConfigureDisks do it "resizes the disk" do expect(driver).to receive(:resize_disk).with(all_disks[1][:location], disk_config.size.to_i) - expect(driver).to receive(:get_port_and_device).with(all_disks[1][:uuid]). - and_return({port: "1", device: "0"}) - subject.resize_disk(machine, disk_config, all_disks[1], controller) end end