From a1f13bb04f3ab19e77e5d5510d56b1dd1b5a40d9 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Fri, 7 Dec 2012 16:45:01 -0500 Subject: [PATCH] OpenStack server test updates for real mode. Updates to the OpenStack server tests to get things running in *real* test mode. This patch also adds some useful helper functions which are now used to: -get the flavor ref for testing -get the image ref for testing -get the resize flavor ref for testing (defaults to flavor + 1) -disable password testing (not all hypervisors support this in OS) --- .../requests/compute/address_tests.rb | 4 +-- tests/openstack/requests/compute/helper.rb | 20 +++++++++++ .../requests/compute/server_tests.rb | 34 +++++++++++++------ 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/tests/openstack/requests/compute/address_tests.rb b/tests/openstack/requests/compute/address_tests.rb index b2bf884af..85031b4f8 100644 --- a/tests/openstack/requests/compute/address_tests.rb +++ b/tests/openstack/requests/compute/address_tests.rb @@ -1,10 +1,8 @@ Shindo.tests('Fog::Compute[:openstack] | address requests', ['openstack']) do compute = Fog::Compute[:openstack] - flavor_ref = ENV['OPENSTACK_FLAVOR_REF'] || compute.list_flavors.body['flavors'].first['links'].first['href'] - image_ref = ENV['OPENSTACK_IMAGE_REF'] || compute.list_images.body['images'].first['links'].first['href'] - @server_id = compute.create_server("shindo_test_server", image_ref, flavor_ref).body['server']['id'] + @server_id = compute.create_server("shindo_test_server", get_image_ref, get_flavor_ref).body['server']['id'] @address_format = { "instance_id" => NilClass, diff --git a/tests/openstack/requests/compute/helper.rb b/tests/openstack/requests/compute/helper.rb index 8d8e166c2..43a1b6d9b 100644 --- a/tests/openstack/requests/compute/helper.rb +++ b/tests/openstack/requests/compute/helper.rb @@ -15,3 +15,23 @@ class OpenStack end end + +def get_flavor_ref + compute = Fog::Compute[:openstack] + ENV['OPENSTACK_FLAVOR_REF'] || compute.list_flavors.body['flavors'].first['id'] +end + +def get_image_ref + compute = Fog::Compute[:openstack] + ENV['OPENSTACK_IMAGE_REF'] || compute.list_images.body['images'].first['id'] +end + +def get_flavor_ref_resize + # by default we simply add one to the default flavor ref + ENV['OPENSTACK_FLAVOR_REF_RESIZE'] || (get_flavor_ref.to_i + 1).to_s +end + +def set_password_enabled + pw_enabled = ENV['OPENSTACK_SET_PASSWORD_ENABLED'] || "true" + return pw_enabled == "true" +end diff --git a/tests/openstack/requests/compute/server_tests.rb b/tests/openstack/requests/compute/server_tests.rb index a173e6aee..4915a328e 100644 --- a/tests/openstack/requests/compute/server_tests.rb +++ b/tests/openstack/requests/compute/server_tests.rb @@ -1,6 +1,11 @@ Shindo.tests('Fog::Compute[:openstack] | server requests', ['openstack']) do @server_format = { + 'id' => String, + 'links' => Array, + } + + @detailed_server_format = { 'id' => String, 'addresses' => Hash, 'flavor' => Hash, @@ -33,9 +38,9 @@ Shindo.tests('Fog::Compute[:openstack] | server requests', ['openstack']) do tests('success') do - @image_id = Fog::Compute[:openstack].images[0].id + @image_id = get_image_ref @snapshot_id = nil - @flavor_id = 2 + @flavor_id = get_flavor_ref tests('#create_server("test", #{@image_id} , 19)').formats(@server_format.merge('adminPass' => String), false) do data = Fog::Compute[:openstack].create_server("test", @image_id, @flavor_id).body['server'] @@ -46,7 +51,7 @@ Shindo.tests('Fog::Compute[:openstack] | server requests', ['openstack']) do Fog::Compute[:openstack].servers.get(@server_id).wait_for { ready? } #CREATE - tests("#get_server_details(#{@server_id})").formats(@server_format, false) do + tests("#get_server_details(#{@server_id})").formats(@detailed_server_format, false) do Fog::Compute[:openstack].get_server_details(@server_id).body['server'] end @@ -57,15 +62,17 @@ Shindo.tests('Fog::Compute[:openstack] | server requests', ['openstack']) do end #DETAILS - tests('#list_servers_detail').formats({'servers' => [@server_format]}, false) do + tests('#list_servers_detail').formats({'servers' => [@detailed_server_format]}, false) do Fog::Compute[:openstack].list_servers_detail.body end #CHANGE PASSWORD - tests("#change_server_password(#{@server_id}, 'fogupdatedserver')").succeeds do - Fog::Compute[:openstack].change_server_password(@server_id, 'foggy') + if set_password_enabled + tests("#change_server_password(#{@server_id}, 'fogupdatedserver')").succeeds do + Fog::Compute[:openstack].change_server_password(@server_id, 'foggy') + end + Fog::Compute[:openstack].servers.get(@server_id).wait_for { ready? } end - Fog::Compute[:openstack].servers.get(@server_id).wait_for { ready? } #UPDATE SERVER NAME tests("#update_server(#{@server_id}, :name => 'fogupdatedserver')").succeeds do @@ -82,19 +89,19 @@ Shindo.tests('Fog::Compute[:openstack] | server requests', ['openstack']) do Fog::Compute[:openstack].images.get(@snapshot_id).wait_for { ready? } #REBUILD - tests("#rebuild_server(#{@server_id}, #{@snapshot_id}, 'fog')").formats({'server' => @server_format}, false) do + tests("#rebuild_server(#{@server_id}, #{@snapshot_id}, 'fog')").formats({'server' => @detailed_server_format}, false) do Fog::Compute[:openstack].rebuild_server(@server_id, @snapshot_id, 'fog', 'newpass', {"foo" => "bar"}).body end Fog::Compute[:openstack].servers.get(@server_id).wait_for { ready? } if not Fog.mocking? #RESIZE - tests("#resize_server(#{@server_id}, '3')").succeeds do - Fog::Compute[:openstack].resize_server(@server_id, 3) + tests("#resize_server(#{@server_id}, #{get_flavor_ref_resize})").succeeds do + Fog::Compute[:openstack].resize_server(@server_id, get_flavor_ref_resize) end Fog::Compute[:openstack].servers.get(@server_id).wait_for { self.state == 'VERIFY_RESIZE' } if not Fog.mocking? #RESIZE CONFIRM - tests("#resize_confirm(#{@server_id}, '3')").succeeds do + tests("#resize_confirm(#{@server_id}, #{get_flavor_ref_resize})").succeeds do Fog::Compute[:openstack].confirm_resize_server(@server_id) end Fog::Compute[:openstack].servers.get(@server_id).wait_for { ready? } if not Fog.mocking? @@ -118,6 +125,11 @@ Shindo.tests('Fog::Compute[:openstack] | server requests', ['openstack']) do Fog::Compute[:openstack].delete_server(@server_id) end + #DELETE IMAGE + tests("#delete_image(#{@snapshot_id})").succeeds do + Fog::Compute[:openstack].delete_image(@snapshot_id) + end + end tests('failure') do