mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Bail reporting an error before attempting to clone when required parameter is missing
This commit updates clone_vm in the vsphere provider to raise an error when a target folder can not be found. Without this change, if the target folder can not be found a clone is attempted anyway, resulting in an error and backtrace.
This commit is contained in:
parent
9634a724e5
commit
cb37d3b067
3 changed files with 15 additions and 2 deletions
|
|
@ -78,7 +78,7 @@ module Vmpooler
|
||||||
parsed_config[:config]['vm_lifetime_auth'] = string_to_int(ENV['VM_LIFETIME_AUTH']) if ENV['VM_LIFETIME_AUTH']
|
parsed_config[:config]['vm_lifetime_auth'] = string_to_int(ENV['VM_LIFETIME_AUTH']) if ENV['VM_LIFETIME_AUTH']
|
||||||
parsed_config[:config]['max_tries'] = string_to_int(ENV['MAX_TRIES']) if ENV['MAX_TRIES']
|
parsed_config[:config]['max_tries'] = string_to_int(ENV['MAX_TRIES']) if ENV['MAX_TRIES']
|
||||||
parsed_config[:config]['retry_factor'] = string_to_int(ENV['RETRY_FACTOR']) if ENV['RETRY_FACTOR']
|
parsed_config[:config]['retry_factor'] = string_to_int(ENV['RETRY_FACTOR']) if ENV['RETRY_FACTOR']
|
||||||
parsed_config[:config]['create_folders'] = ENV['CREATE_FOLDERS'] if ENV['CREATE_FOLDERS']
|
parsed_config[:config]['create_folders'] = true?(ENV['CREATE_FOLDERS']) if ENV['CREATE_FOLDERS']
|
||||||
parsed_config[:config]['create_template_delta_disks'] = ENV['CREATE_TEMPLATE_DELTA_DISKS'] if ENV['CREATE_TEMPLATE_DELTA_DISKS']
|
parsed_config[:config]['create_template_delta_disks'] = ENV['CREATE_TEMPLATE_DELTA_DISKS'] if ENV['CREATE_TEMPLATE_DELTA_DISKS']
|
||||||
set_linked_clone(parsed_config)
|
set_linked_clone(parsed_config)
|
||||||
parsed_config[:config]['experimental_features'] = ENV['EXPERIMENTAL_FEATURES'] if ENV['EXPERIMENTAL_FEATURES']
|
parsed_config[:config]['experimental_features'] = ENV['EXPERIMENTAL_FEATURES'] if ENV['EXPERIMENTAL_FEATURES']
|
||||||
|
|
|
||||||
|
|
@ -348,7 +348,7 @@ module Vmpooler
|
||||||
|
|
||||||
begin
|
begin
|
||||||
vm_target_folder = find_vm_folder(pool_name, connection)
|
vm_target_folder = find_vm_folder(pool_name, connection)
|
||||||
vm_target_folder = create_folder(connection, target_folder_path, target_datacenter_name) if vm_target_folder.nil? && @config[:config].key?('create_folders') && (@config[:config]['create_folders'] == true)
|
vm_target_folder ||= create_folder(connection, target_folder_path, target_datacenter_name) if @config[:config].key?('create_folders') && (@config[:config]['create_folders'] == true)
|
||||||
rescue StandardError
|
rescue StandardError
|
||||||
if @config[:config].key?('create_folders') && (@config[:config]['create_folders'] == true)
|
if @config[:config].key?('create_folders') && (@config[:config]['create_folders'] == true)
|
||||||
vm_target_folder = create_folder(connection, target_folder_path, target_datacenter_name)
|
vm_target_folder = create_folder(connection, target_folder_path, target_datacenter_name)
|
||||||
|
|
@ -356,6 +356,7 @@ module Vmpooler
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
raise ArgumentError, "Can not find the configured folder for #{pool_name} #{target_folder_path}" unless vm_target_folder
|
||||||
|
|
||||||
# Create the new VM
|
# Create the new VM
|
||||||
new_vm_object = template_vm_object.CloneVM_Task(
|
new_vm_object = template_vm_object.CloneVM_Task(
|
||||||
|
|
|
||||||
|
|
@ -646,6 +646,18 @@ EOT
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when create_vm_folder returns nil' do
|
||||||
|
before(:each) do
|
||||||
|
template_vm = new_template_object
|
||||||
|
allow(subject).to receive(:find_template_vm).and_return(new_template_object)
|
||||||
|
expect(subject).to receive(:find_vm_folder).and_return(nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should raise an error' do
|
||||||
|
expect{ subject.create_vm(poolname, vmname) }.to raise_error(ArgumentError)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'Given a successful creation' do
|
context 'Given a successful creation' do
|
||||||
let(:folder_object) { mock_RbVmomi_VIM_Folder({ :name => 'pool1'}) }
|
let(:folder_object) { mock_RbVmomi_VIM_Folder({ :name => 'pool1'}) }
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue