diff --git a/app/models/manageiq/providers/vmware/infra_manager/vm/reconfigure.rb b/app/models/manageiq/providers/vmware/infra_manager/vm/reconfigure.rb index a7f31ed3c..7220a9400 100644 --- a/app/models/manageiq/providers/vmware/infra_manager/vm/reconfigure.rb +++ b/app/models/manageiq/providers/vmware/infra_manager/vm/reconfigure.rb @@ -162,6 +162,25 @@ def disk_mode(dependent, persistent) end end + def validate_device_backing(backing) + case backing.xsiType + when 'VirtualDiskFlatVer2BackingInfo' + 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] @@ -187,6 +206,8 @@ def add_disk_config_spec(vmcs, options) bck.fileName = backing_filename end end + + validate_device(vdcs.device) end end diff --git a/spec/models/manageiq/providers/vmware/infra_manager/vm/reconfigure_spec.rb b/spec/models/manageiq/providers/vmware/infra_manager/vm/reconfigure_spec.rb index 9e7a0008e..24720a691 100644 --- a/spec/models/manageiq/providers/vmware/infra_manager/vm/reconfigure_spec.rb +++ b/spec/models/manageiq/providers/vmware/infra_manager/vm/reconfigure_spec.rb @@ -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