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

[hp|compute_v2] Add tests for servers, images and metadata.

This commit is contained in:
Rupak Ganguly 2013-05-07 15:52:26 -04:00
parent 47399924c9
commit cb0412f8a8
5 changed files with 171 additions and 8 deletions

View file

@ -43,7 +43,7 @@ module Fog
# assign these attributes first to prevent race condition with new_record?
self.min_count = attributes.delete(:min_count)
self.max_count = attributes.delete(:max_count)
self.block_device_mapping = attributes.delete(:block_device_mapping)
#self.block_device_mapping = attributes.delete(:block_device_mapping)
super
end
@ -102,7 +102,7 @@ module Fog
def private_ip_address
addr = addresses.nil? ? nil : addresses.fetch(network_name, []).first
addr["addr"] if addr
addr['addr'] if addr
end
def private_key_path
@ -163,15 +163,15 @@ module Fog
@max_count = new_max_count
end
def block_device_mapping=(new_block_device_mapping)
@block_device_mapping = new_block_device_mapping
end
#def block_device_mapping=(new_block_device_mapping)
# @block_device_mapping = new_block_device_mapping
#end
def ready?
self.state == 'ACTIVE'
end
def windows_password()
def windows_password
requires :id
service.get_windows_password(id)
end
@ -182,9 +182,9 @@ module Fog
true
end
def rebuild(image_id, name, admin_pass=nil, metadata=nil, personality=nil)
def rebuild(image_id, name, admin_pass=nil, options={})
requires :id
service.rebuild_server(id, image_id, name, admin_pass, metadata, personality)
service.rebuild_server(id, image_id, name, admin_pass, options)
true
end

View file

@ -0,0 +1,63 @@
Shindo.tests("Fog::Compute::HPV2 | metadata for images", ['hp', 'v2', 'compute']) do
service = Fog::Compute.new(:provider => 'HP', :version => :v2)
@base_image_id = ENV['BASE_IMAGE_ID'] || '7f60b54c-cd15-433f-8bed-00acbcd25a17'
@server = service.servers.create(:name => 'fogsermdtests', :flavor_id => 100, :image_id => @base_image_id)
@server.wait_for { ready? }
response = @server.create_image('fogimgmetadatatests', :metadata => {'Meta1' => 'MetaValue1', 'Meta2' => 'MetaValue2'})
unless Fog.mocking?
sleep(10)
end
new_image_id = response.headers['Location'].split('/')[5]
@image = service.images.get(new_image_id)
tests('success') do
tests('#all').succeeds do
@image.metadata.all
end
tests("#get('Meta1')").succeeds do
pending if Fog.mocking?
@image.metadata.get('Meta1')
end
tests("#update({'Meta3' => 'MetaValue3'})").succeeds do
@data = @image.metadata.update({'Meta3' => 'MetaValue3'})
tests('metadata has updated correctly') do
@image.metadata.get('Meta3').value == 'MetaValue3'
end
end
tests("#set({'Meta4' => 'MetaValue4'})").succeeds do
@data = @image.metadata.set({'Meta4' => 'MetaValue4'})
tests('metadata has set correctly') do
@image.metadata.get('Meta4').value == 'MetaValue4'
end
end
tests("#save").succeeds do
m = @image.metadata.new(:key => 'Meta5', :value => 'MetaValue5')
@data = m.save
tests('metadata has saved correctly') do
@image.metadata.get('Meta5').value == 'MetaValue5'
end
end
tests("#destroy('Meta5')").succeeds do
@image.metadata.destroy('Meta5')
tests('metadata has been destroyed') do
@image.metadata.get('Meta5') == nil
end
end
end
unless Fog.mocking?
@image.destroy
end
@server.destroy
end

View file

@ -0,0 +1,56 @@
Shindo.tests("Fog::Compute::HPV2 | metadata for servers", ['hp', 'v2', 'compute']) do
service = Fog::Compute.new(:provider => 'HP', :version => :v2)
@base_image_id = ENV['BASE_IMAGE_ID'] || '7f60b54c-cd15-433f-8bed-00acbcd25a17'
@server = service.servers.create(:name => 'fogsermetadatatests', :flavor_id => 100, :image_id => @base_image_id, :metadata => {'Meta1' => 'MetaValue1', 'Meta2' => 'MetaValue2'})
@server.wait_for { ready? }
tests('success') do
tests('#all').succeeds do
@server.metadata.all
end
tests("#get('Meta1')").succeeds do
@data = @server.metadata.get('Meta1')
tests('metadata gets correct value') do
@data.value == 'MetaValue1'
end
end
tests("#update({'Meta3' => 'MetaValue3'})").succeeds do
@data = @server.metadata.update({'Meta3' => 'MetaValue3'})
tests('metadata has updated correctly') do
@server.metadata.get('Meta3').value == 'MetaValue3'
end
end
tests("#set({'Meta4' => 'MetaValue4'})").succeeds do
@data = @server.metadata.set({'Meta4' => 'MetaValue4'})
tests('metadata has set correctly') do
@server.metadata.get('Meta4').value == 'MetaValue4'
end
end
tests('#save').succeeds do
m = @server.metadata.new(:key => 'Meta5', :value => 'MetaValue5')
@data = m.save
tests('metadata has saved correctly') do
@server.metadata.get('Meta5').value == 'MetaValue5'
end
end
tests("#destroy('Meta5')").succeeds do
@data = @server.metadata.destroy('Meta5')
tests('metadata has been destroyed') do
@server.metadata.get('Meta5') == nil
end
end
end
@server.destroy
end

View file

@ -0,0 +1,35 @@
Shindo.tests("Fog::Compute::HPV2 | server model", ['hp', 'v2', 'compute']) do
service = Fog::Compute.new(:provider => 'HP', :version => :v2)
@base_image_id = ENV['BASE_IMAGE_ID'] || '7f60b54c-cd15-433f-8bed-00acbcd25a17'
model_tests(service.servers, {:name => 'fogservertest', :flavor_id => 100, :image_id => @base_image_id}, true) do
@server = service.servers.create(:name => 'fogservertest', :flavor_id => 100, :image_id => @base_image_id)
tests('#console_output(10)') do
@server.console_output(10)
end
tests('#vnc_console_url') do
@server.vnc_console_url
end
tests("#create_image('fogimgfromserver')") do
@server.create_image('fogimgfromserver')
end
tests("#reboot('SOFT')") do
pending unless Fog.mocking?
@server.reboot('SOFT')
end
tests("#rebuild(#{@base_image_id}, 'fogrebuildserver')") do
pending
@server.rebuild(@base_image_id, 'fogrebuildserver')
end
end
end

View file

@ -0,0 +1,9 @@
Shindo.tests("Fog::Compute::HPV2 | servers collection", ['hp', 'v2', 'compute']) do
service = Fog::Compute.new(:provider => 'HP', :version => :v2)
@base_image_id = ENV['BASE_IMAGE_ID'] || '7f60b54c-cd15-433f-8bed-00acbcd25a17'
collection_tests(service.servers, {:name => 'fogservercolltest', :flavor_id => 100, :image_id => @base_image_id}, true)
end