1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/tests/ibm/requests/compute/instance_tests.rb

91 lines
3 KiB
Ruby
Raw Normal View History

2011-12-02 13:27:44 -05:00
Shindo.tests('Fog::Compute[:ibm] | instance requests', ['ibm']) do
2012-02-13 10:51:03 -05:00
2011-12-02 13:27:44 -05:00
@instance_format = {
'name' => String,
'location' => String,
'keyName' => String,
'primaryIP' => {
'type' => Integer,
'ip' => String,
'hostname' => String,
},
'productCodes' => Array,
'requestId' => String,
'imageId' => String,
'launchTime' => Integer,
'id' => String,
'volumes' => Array,
'root-only' => String,
'instanceType' => String,
'diskSize' => String,
'requestName' => String,
'secondaryIP' => Array,
'status' => Integer,
'software' => Array,
'expirationTime'=> Integer,
'owner' => String
}
2012-02-13 10:51:03 -05:00
2011-12-02 13:27:44 -05:00
@instances_format = {
'instances' => [ @instance_format ]
}
2012-02-13 10:51:03 -05:00
2011-12-02 13:27:44 -05:00
tests('success') do
@instance_id = nil
@name = "fog-test-instance-" + Time.now.to_i.to_s(32)
2011-12-02 13:27:44 -05:00
@image_id = "20018425"
@instance_type = "COP32.1/2048/60"
@location = "101"
2012-02-13 10:51:03 -05:00
@expiration_time= (Time.now.tv_usec + 10000).to_f * 1000
@key_name = "fog-test-key-" + Time.now.to_i.to_s(32)
@key = Fog::Compute[:ibm].keys.create(:name => @key_name)
2011-12-02 13:27:44 -05:00
tests("#create_instance('#{@name}', '#{@image_id}', '#{@instance_type}', '#{@location}', :key_name => '#{@key_name}')").formats(@instances_format) do
response = Fog::Compute[:ibm].create_instance(@name, @image_id, @instance_type, @location, :key_name => @key_name).body
2011-12-02 13:27:44 -05:00
@instance_id = response['instances'][0]['id']
response
end
2012-02-13 10:51:03 -05:00
2011-12-02 13:27:44 -05:00
tests("#get_instance('#{@instance_id}')").formats(@instance_format) do
response = Fog::Compute[:ibm].get_instance(@instance_id).body
end
2012-02-13 10:51:03 -05:00
2011-12-02 13:27:44 -05:00
Fog::Compute[:ibm].servers.get(@instance_id).wait_for { ready? }
2012-02-13 10:51:03 -05:00
2011-12-02 13:27:44 -05:00
tests("#list_instances").formats(@instances_format) do
instances = Fog::Compute[:ibm].list_instances.body
end
2012-02-13 10:51:03 -05:00
tests("#modify_instance('#{@instance_id}', 'state' => 'restart')") do
returns(true) { Fog::Compute[:ibm].modify_instance(@instance_id, 'state' => 'restart').body["success"] }
2011-12-02 13:27:44 -05:00
end
2012-02-13 10:51:03 -05:00
tests("#modify_instance('#{@instance_id}', 'name' => '#{@name} 2')") do
returns(true) { Fog::Compute[:ibm].modify_instance(@instance_id, 'name' => @name + " 2").body["success"] }
2011-12-02 13:27:44 -05:00
end
tests("#modify_instance('#{@instance_id}', 'expirationTime' => '#{@expiration_time}')") do
returns(@expiration_time) { Fog::Compute[:ibm].modify_instance(@instance_id, 'expirationTime' => @expiration_time).body["expirationTime"] }
2011-12-02 13:27:44 -05:00
end
2012-02-13 10:51:03 -05:00
2011-12-02 13:27:44 -05:00
tests("#delete_instance('#{@instance_id}')") do
data = Fog::Compute[:ibm].delete_instance(@instance_id)
end
@key.wait_for { instance_ids.empty? }
@key.destroy
2011-12-02 13:27:44 -05:00
end
2012-02-13 10:51:03 -05:00
2011-12-02 13:27:44 -05:00
tests('failures') do
2012-02-13 10:51:03 -05:00
2011-12-02 13:27:44 -05:00
tests('#create_instance => 401') do
response = Fog::Compute[:ibm].create_instance("FAIL: 401", "123456", "12345", "101", :key_name => "invalid")
2012-02-13 10:51:03 -05:00
returns("401") { response.status }
2011-12-02 13:27:44 -05:00
end
2012-02-13 10:51:03 -05:00
2011-12-02 13:27:44 -05:00
end
end