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

Validate deviceMode on a VirtualDisk Backing before reconfigure #24

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,25 @@ def disk_mode(dependent, persistent)
end
end

def validate_device_backing(backing)
case backing.xsiType
when 'VirtualDiskFlatVer2BackingInfo'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agrare
I'm confused with VirtualDiskFlatVer2BackingOption and VirtualDiskFlatVer2BackingInfo.
Looks like the valid modes defined here is for VirtualDiskFlatVer2BackingOption.
According to the ref, valid modes for VirtualDiskFlatVer2BackingInfo are:

The disk persistence mode. Valid modes are:
persistent
independent_persistent
independent_nonpersistent
nonpersistent
undoable
append

Copy link
Member Author

@agrare agrare Mar 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So they don't do a great job of documenting what modes are supported or not.
Those are all valid modes and the reconfigure will succeed, but if you actually use some of the modes the VM won't even power-on.

Those three modes are the ones that the vSphere client will let you select for the disk mode.

valid_flat_ver_2_backing_modes = [
VirtualDiskMode::Persistent,
VirtualDiskMode::Independent_persistent,
VirtualDiskMode::Independent_nonpersistent
].freeze

unless valid_flat_ver_2_backing_modes.include?(backing.diskMode)
raise MiqException::MiqVmError, "Disk mode #{backing.diskMode} is not supported for virtual disk"
end
end
end

def validate_device(device)
validate_device_backing(device.backing)
end

def add_disk_config_spec(vmcs, options)
raise "#{__method__}: Disk size is required to add a new disk." unless options[:disk_size_in_mb]

Expand All @@ -187,6 +206,8 @@ def add_disk_config_spec(vmcs, options)
bck.fileName = backing_filename
end
end

validate_device(vdcs.device)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@
expect(subject.fetch_path("device", "backing", "diskMode")).to eq("independent_nonpersistent")
expect(subject.fetch_path("device", "backing", "fileName")).to eq("[#{vm.storage.name}]")
end

it 'with invalid diskMode' do
@options[:dependent] = true
@options[:persistent] = false

expect { subject }.to raise_error(MiqException::MiqVmError, "Disk mode nonpersistent is not supported for virtual disk")
end
end

context '#remove_disk_config_spec' do
Expand Down