Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to resize primary NVMe disk #133

Open
eszense opened this issue Dec 29, 2024 · 0 comments · May be fixed by #134
Open

Error when trying to resize primary NVMe disk #133

eszense opened this issue Dec 29, 2024 · 0 comments · May be fixed by #134

Comments

@eszense
Copy link
Contributor

eszense commented Dec 29, 2024

Reproducing the error

  1. Make a vagrant box with vmx defining a NVMe drive as the only disk
...
nvme0.present = "TRUE"
nvme0:0.fileName = "disk.vmdk"
nvme0:0.present = "TRUE"

(Without any of these lines: scsi0.present = "FALSE" or scsi0:0.present = "FALSE")

  1. Make a Vagrantfile containing config.vm.disk with primary: true
Vagrant.configure("2") do |config|
  config.vm.box = "private_repo/ubuntu_arm64"
  config.vm.disk :disk, size: "15GB", primary: true
  config.vm.provider "vmware_desktop" do |v|
    v.linked_clone = false
  end
end
  1. vagrant up

  2. Error as follows

NoMethodError: undefined method `[]' for nil:NilClass
/src/vagrant-vmware-desktop/lib/vagrant-vmware-desktop/cap/disk.rb:118:in `block in get_disk'

Expected outcome:
Resize the primary NVMe disk according to the Vagrantfile

Cause of error

This is caused by several bugs:

1. get_disk() looks up the disk_info hash table for the keys defined in PRIMARY_DISK_SLOTS but did not correctly handle cases where the entry itself is absent (when there is no line matching "scsi0:0.present = *" in the vmx)

PRIMARY_DISK_SLOTS.each do |primary_slot|
disk_info = all_disks[primary_slot]
@@logger.debug("disk info for primary slot #{primary_slot} - #{disk_info}")
return disk_info if disk_info["present"].to_s.upcase == "TRUE"
end

2. get_disk() does not return the expected nil value when a primary disk is not found

Fixing Item 1 and re-run will expose another bug with the following error due to get_disk() missing a nil return.

TypeError: no implicit conversion of String into Integer
  /src/vagrant-vmware-desktop/lib/vagrant-vmware-desktop/cap/disk.rb:151:in `[]'

Expected: get_disk() returns nil when the queried disk is not found
Current: get_disk() returns an irrelevant value ["scsi0:0", "sata0:0", "ide0:0"] (the last evaluated statement)
This leads to the plugin failing with error instead of creating a new disk in cases where the primary disk defined in config is not present in the vmx file

def self.get_disk(disk, all_disks)
if disk.primary
PRIMARY_DISK_SLOTS.each do |primary_slot|
disk_info = all_disks[primary_slot]
@@logger.debug("disk info for primary slot #{primary_slot} - #{disk_info}")
return disk_info if disk_info["present"].to_s.upcase == "TRUE"
end
else
if disk.type == :dvd
all_disks.values.detect { |v| v["filename"] == disk.file }
else
all_disks.values.detect do |v|
m_ext = File.extname(v["filename"])
m_fil = v["filename"].sub(/#{Regexp.escape(m_ext)}$/, "")
m_ext.sub!(".", "")
m_ext == disk.disk_ext &&
(m_fil == disk.name || m_fil =~ /^#{Regexp.escape(disk.name)}-\d+$/)
end
end
end
end

3. nvme0:0 is not in the search list of primary disk

PRIMARY_DISK_SLOTS = ["scsi0:0", "sata0:0", "ide0:0"].map(&:freeze).freeze

Environment:

Vagrant 2.2.11.dev
VMWare Fusion 13.6.2 (MacOS)
VAGRANT_EXPERIMENTAL=disks

eszense added a commit to eszense/vagrant-vmware-desktop that referenced this issue Dec 29, 2024
@eszense eszense linked a pull request Dec 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant