Skip to content

Commit

Permalink
Skip over disks with size less than 0
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Barker <[email protected]>
  • Loading branch information
josh-barker authored and Josh Barker committed Jun 3, 2018
1 parent a51d338 commit a0aa48f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions lib/chef/provisioning/vsphere_driver/vsphere_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def datacenter
vim # ensure connection is valid
@datacenter ||= begin
rootFolder = vim.serviceInstance.content.rootFolder
dc = traverse_folders_for_dc(vim.rootFolder, datacenter_name) || abort('vSphere Datacenter not found [#{datacenter_name}]')
dc = traverse_folders_for_dc(vim.rootFolder, datacenter_name) || abort("vSphere Datacenter not found [#{datacenter_name}]")
end
end

Expand Down Expand Up @@ -259,12 +259,12 @@ def virtual_disk_for(vm, datastore, size_gb)
# @param [Subject] datastore the datastore the disk will be created on.
# @param [Subject] size_gb the size of the disk.
def set_additional_disks_for(vm, datastore, additional_disk_size_gb)
(additional_disk_size_gb.is_a?(Array) ? additional_disk_size_gb : [additional_disk_size_gb]).each do |size|
raise ':datastore must be specified when adding a disk to a cloned vm' if datastore.to_s.empty? && additional_disk_size_gb

Array(additional_disk_size_gb).each do |size|
size = size.to_i
next if size.zero?
if datastore.to_s.empty?
raise ':datastore must be specified when adding a disk to a cloned vm'
end
next if size <= 0

task = vm.ReconfigVM_Task(
spec: RbVmomi::VIM.VirtualMachineConfigSpec(
deviceChange: [
Expand Down
8 changes: 4 additions & 4 deletions spec/unit_tests/clone_spec_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
end

it 'raises an error' do
expect { subject }.to raise_error
expect { subject }.to raise_error(RuntimeError)
end
end

Expand Down Expand Up @@ -139,23 +139,23 @@
let(:hostname) { 'my_host' }

it 'raises an error' do
expect { subject }.to raise_error
expect { subject }.to raise_error(RuntimeError)
end
end

context 'starting with a dash' do
let(:hostname) { '-myhost' }

it 'raises an error' do
expect { subject }.to raise_error
expect { subject }.to raise_error(RuntimeError)
end
end

context 'ending with a dash' do
let(:hostname) { 'myhost-' }

it 'raises an error' do
expect { subject }.to raise_error
expect { subject }.to raise_error(RuntimeError)
end
end
end
Expand Down

0 comments on commit a0aa48f

Please sign in to comment.