1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

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)
This commit is contained in:
Dan Prince 2012-12-07 16:45:01 -05:00
parent 11591b3ed9
commit a1f13bb04f
3 changed files with 44 additions and 14 deletions

View file

@ -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,

View file

@ -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

View file

@ -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