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

103 lines
3.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' => {
2012-02-29 22:24:36 -05:00
'vlan' => Fog::Nullable::String,
2011-12-02 13:27:44 -05:00
'type' => Integer,
'ip' => String,
'hostname' => String,
},
'productCodes' => Array,
'requestId' => String,
'imageId' => String,
'launchTime' => Integer,
'id' => String,
'ip' => Fog::Nullable::String,
2011-12-02 13:27:44 -05:00
'volumes' => Array,
'root-only' => Fog::Nullable::String,
'isMiniEphemeral' => Fog::Nullable::String,
2011-12-02 13:27:44 -05:00
'instanceType' => String,
'diskSize' => Fog::Nullable::String,
2011-12-02 13:27:44 -05:00
'requestName' => String,
'secondaryIP' => Array,
'status' => Integer,
'software' => Array,
'expirationTime'=> Integer,
'owner' => String,
2011-12-02 13:27:44 -05:00
}
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)
2012-02-28 23:51:37 -05:00
@image_id = "20010001"
2011-12-02 13:27:44 -05:00
@instance_type = "COP32.1/2048/60"
2012-02-28 23:51:37 -05:00
@location = "41"
@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
Fog::Compute[:ibm].servers.get(@instance_id).wait_for(Fog::IBM.timeout) { 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
@expiration_time = (Time.now.to_i + 10) * 1000
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
if Fog::Compute[:ibm].servers.get(@instance_id).wait_for(Fog::IBM.timeout) { ready? }
data = Fog::Compute[:ibm].delete_instance(@instance_id)
else
pending
end
2011-12-02 13:27:44 -05:00
end
if @key.wait_for(Fog::IBM.timeout) { instance_ids.empty? }
@key.destroy
else
pending
end
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
tests('#create_instance => 412') do
raises(Excon::Errors::PreconditionFailed) do
Fog::Compute[:ibm].create_instance("FAIL: 412", @image_id, @instance_type, @location, :key_name => "invalid")
end
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