From 67cede19a5e262c0fc6481be7f1fd927f0e5d7f3 Mon Sep 17 00:00:00 2001 From: Jeff McCune Date: Thu, 19 Jan 2012 11:38:25 -0800 Subject: [PATCH] Fix linked clone mocked test unhandled exception Without this patch, the test for the vSphere linked clone option to the vm_clone request throws an exception. For the full exception please see GH-697 discussion comments on Github at [1] This patch fixes the issue by removing the cleanup code which is not necessary for a Mocked test. The cleanup code was calling a method on the response_linked object which is not actually in scope. [1] https://github.com/fog/fog/pull/697 --- lib/fog/vsphere/requests/compute/vm_clone.rb | 6 +++++- tests/vsphere/requests/compute/vm_clone_tests.rb | 16 ++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/fog/vsphere/requests/compute/vm_clone.rb b/lib/fog/vsphere/requests/compute/vm_clone.rb index ac1f0cbce..fe7acf59c 100644 --- a/lib/fog/vsphere/requests/compute/vm_clone.rb +++ b/lib/fog/vsphere/requests/compute/vm_clone.rb @@ -5,7 +5,11 @@ module Fog module Shared private def vm_clone_check_options(options) - options = { 'force' => false }.merge(options) + default_options = { + 'force' => false, + 'linked_clone' => false, + } + options = default_options.merge(options) required_options = %w{ path name } required_options.each do |param| raise ArgumentError, "#{required_options.join(', ')} are required" unless options.has_key? param diff --git a/tests/vsphere/requests/compute/vm_clone_tests.rb b/tests/vsphere/requests/compute/vm_clone_tests.rb index 895f65762..2e4fe470a 100644 --- a/tests/vsphere/requests/compute/vm_clone_tests.rb +++ b/tests/vsphere/requests/compute/vm_clone_tests.rb @@ -13,20 +13,16 @@ Shindo.tests("Fog::Compute[:vsphere] | vm_clone request", 'vsphere') do test("have a #{key} key") { response.has_key? key } end end - template = "/Datacenters/Solutions/vm/Jeff/Templates/cloning_vm" + + template = "/Datacenters/Solutions/vm/Jeff/Templates/centos56gm2" tests("Linked Clone | The return value should") do - response_linked = compute.vm_clone('path' => template, 'name' => 'cloning_vm_linked', 'wait' => 1) - test("be a kind of Hash") { response_linked.kind_of? Hash } + response = compute.vm_clone('path' => template, 'name' => 'cloning_vm_linked', 'wait' => 1, 'linked_clone' => true) + test("be a kind of Hash") { response.kind_of? Hash } %w{ vm_ref task_ref }.each do |key| - test("have a #{key} key") { response_linked.has_key? key } + test("have a #{key} key") { response.has_key? key } end end - ## clean up afterward as in the aws tests. - compute.vm_power_off('uuid' => response_linked['vm_attributes']['uuid'], 'instance_uuid' => response_linked['vm_attributes']['instance_uuid'], 'force' => 1) - compute.vm_destroy('instance_uuid' => response_linked['vm_attributes']['instance_uuid']) - compute.vm_power_off('uuid' => response['vm_attributes']['uuid'], 'instance_uuid' => response['vm_attributes']['instance_uuid'], 'force' => 1) - compute.vm_destroy('instance_uuid' => response['vm_attributes']['instance_uuid']) - + tests("When invalid input is presented") do raises(ArgumentError, 'it should raise ArgumentError') { compute.vm_clone(:foo => 1) } raises(Fog::Compute::Vsphere::NotFound, 'it should raise Fog::Compute::Vsphere::NotFound when the UUID is not a string') do