From 41cbff4accef1237f863a5b75aa7d5084a4b2f85 Mon Sep 17 00:00:00 2001 From: Lincoln Stoll Date: Wed, 11 May 2011 10:15:39 -0700 Subject: [PATCH] [ninefold|compute] Fix data formats for virtual machines. --- tests/compute/requests/ninefold/helper.rb | 15 +++++++++++++++ .../requests/ninefold/virtual_machine_tests.rb | 10 +++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/compute/requests/ninefold/helper.rb b/tests/compute/requests/ninefold/helper.rb index 2d58607ef..9c8ffb528 100644 --- a/tests/compute/requests/ninefold/helper.rb +++ b/tests/compute/requests/ninefold/helper.rb @@ -141,6 +141,21 @@ class Ninefold }] end module VirtualMachines + # Sometimes a few fields are missing from VM data - this method + # will fill them in if they don't exist, to ensure the format passes + def fill_virtual_machine_data(vms) + if vms.kind_of? Hash + vms['cpuused'] ||= '' + vms['networkkbsread'] ||= 0 + vms['networkkbswrite'] ||= 0 + elsif vms.kind_of? Array + vms.each {|vm| fill_virtual_machine_data(vm) } + end + vms + end + + module_function :fill_virtual_machine_data + PENDING_VIRTUAL_MACHINE = {"id" => Integer, "jobid" => Integer} ASYNC_VIRTUAL_MACHINE = {"jobid" => Integer} VIRTUAL_MACHINE = { diff --git a/tests/compute/requests/ninefold/virtual_machine_tests.rb b/tests/compute/requests/ninefold/virtual_machine_tests.rb index 7d47de1b8..d8f4c6786 100644 --- a/tests/compute/requests/ninefold/virtual_machine_tests.rb +++ b/tests/compute/requests/ninefold/virtual_machine_tests.rb @@ -28,12 +28,7 @@ Shindo.tests('Ninefold::Compute | server requests', ['ninefold']) do pending if Fog.mocking? vms = Ninefold[:compute].list_virtual_machines # This is a hack to work around the changing format - these fields may or may not exist. - vms.each do |vm| - vm['cpuused'] ||= '' - vm['networkkbsread'] ||= 0 - vm['networkkbswrite'] ||= 0 - end - vms + Ninefold::Compute::Formats::VirtualMachines::fill_virtual_machine_data(vms) end tests("#reboot_virtual_machine()").formats(Ninefold::Compute::Formats::VirtualMachines::ASYNC_VIRTUAL_MACHINE) do @@ -57,8 +52,9 @@ Shindo.tests('Ninefold::Compute | server requests', ['ninefold']) do tests("#change_service_for_virtual_machine()").formats(Ninefold::Compute::Formats::VirtualMachines::VIRTUAL_MACHINE) do pending if Fog.mocking? - Ninefold[:compute].change_service_for_virtual_machine(:id => @newvmid, + vms = Ninefold[:compute].change_service_for_virtual_machine(:id => @newvmid, :serviceofferingid => Ninefold::Compute::TestSupport::ALT_SERVICE_OFFERING) + Ninefold::Compute::Formats::VirtualMachines::fill_virtual_machine_data(vms) end tests("#start_virtual_machine()").formats(Ninefold::Compute::Formats::VirtualMachines::ASYNC_VIRTUAL_MACHINE) do