2011-06-16 19:28:54 -04:00
|
|
|
Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
|
2010-05-27 14:27:08 -04:00
|
|
|
|
|
|
|
@instance_format = {
|
|
|
|
# 'architecture' => String,
|
|
|
|
'amiLaunchIndex' => Integer,
|
|
|
|
'blockDeviceMapping' => [],
|
2011-05-26 17:36:17 -04:00
|
|
|
'clientToken' => Fog::Nullable::String,
|
2010-05-27 14:27:08 -04:00
|
|
|
'dnsName' => NilClass,
|
|
|
|
'imageId' => String,
|
|
|
|
'instanceId' => String,
|
|
|
|
'instanceState' => {'code' => Integer, 'name' => String},
|
|
|
|
'instanceType' => String,
|
|
|
|
# 'ipAddress' => String,
|
2011-07-08 20:10:36 -04:00
|
|
|
'kernelId' => Fog::Nullable::String,
|
2011-05-09 18:28:54 -04:00
|
|
|
'keyName' => Fog::Nullable::String,
|
2010-05-27 14:27:08 -04:00
|
|
|
'launchTime' => Time,
|
|
|
|
'monitoring' => {'state' => Fog::Boolean},
|
2011-07-08 18:39:35 -04:00
|
|
|
'placement' => {
|
|
|
|
'availabilityZone' => String,
|
|
|
|
'groupName' => Fog::Nullable::String,
|
|
|
|
'tenancy' => String
|
|
|
|
},
|
2011-09-06 12:31:20 -04:00
|
|
|
'platform' => Fog::Nullable::String,
|
2010-05-27 14:27:08 -04:00
|
|
|
'privateDnsName' => NilClass,
|
|
|
|
# 'privateIpAddress' => String,
|
|
|
|
'productCodes' => [],
|
2011-07-08 18:39:35 -04:00
|
|
|
# 'ramdiskId' => Fog::Nullable::String,
|
2011-05-09 18:28:54 -04:00
|
|
|
'reason' => Fog::Nullable::String,
|
2010-05-27 14:27:08 -04:00
|
|
|
# 'rootDeviceName' => String,
|
2010-10-04 18:46:12 -04:00
|
|
|
'rootDeviceType' => String,
|
2010-05-27 14:27:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@run_instances_format = {
|
|
|
|
'groupSet' => [String],
|
|
|
|
'instancesSet' => [@instance_format],
|
|
|
|
'ownerId' => String,
|
|
|
|
'requestId' => String,
|
|
|
|
'reservationId' => String
|
|
|
|
}
|
|
|
|
|
|
|
|
@describe_instances_format = {
|
|
|
|
'reservationSet' => [{
|
|
|
|
'groupSet' => [String],
|
|
|
|
'instancesSet' => [@instance_format.merge(
|
|
|
|
'architecture' => String,
|
2011-05-09 18:28:54 -04:00
|
|
|
'dnsName' => Fog::Nullable::String,
|
|
|
|
'ipAddress' => Fog::Nullable::String,
|
|
|
|
'privateDnsName' => Fog::Nullable::String,
|
|
|
|
'privateIpAddress' => Fog::Nullable::String,
|
|
|
|
'stateReason' => Hash,
|
|
|
|
'tagSet' => Hash
|
2010-05-27 14:27:08 -04:00
|
|
|
)],
|
|
|
|
'ownerId' => String,
|
|
|
|
'reservationId' => String
|
|
|
|
}],
|
|
|
|
'requestId' => String
|
|
|
|
}
|
|
|
|
|
|
|
|
@get_console_output_format = {
|
|
|
|
'instanceId' => String,
|
2011-05-12 16:15:35 -04:00
|
|
|
'output' => Fog::Nullable::String,
|
2010-05-27 14:27:08 -04:00
|
|
|
'requestId' => String,
|
|
|
|
'timestamp' => Time
|
|
|
|
}
|
|
|
|
|
2011-05-09 18:28:54 -04:00
|
|
|
@get_password_data_format = {
|
|
|
|
'instanceId' => String,
|
2011-05-18 15:33:13 -04:00
|
|
|
'passwordData' => Fog::Nullable::String,
|
2011-05-09 18:28:54 -04:00
|
|
|
'requestId' => String,
|
|
|
|
'timestamp' => Time
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-27 14:27:08 -04:00
|
|
|
@terminate_instances_format = {
|
|
|
|
'instancesSet' => [{
|
|
|
|
'currentState' => {'code' => Integer, 'name' => String},
|
|
|
|
'instanceId' => String,
|
|
|
|
'previousState' => {'code' => Integer, 'name' => String},
|
|
|
|
}],
|
|
|
|
'requestId' => String
|
|
|
|
}
|
|
|
|
|
2011-07-12 20:48:53 -04:00
|
|
|
@describe_reserved_instances_offerings_format = {
|
|
|
|
'reservedInstancesOfferingsSet' => [{
|
|
|
|
'reservedInstancesOfferingId' => String,
|
|
|
|
'instanceType' => String,
|
|
|
|
'availabilityZone' => String,
|
|
|
|
'duration' => Integer,
|
|
|
|
'fixedPrice' => Float,
|
|
|
|
'usagePrice' => Float,
|
|
|
|
'productDescription' => String,
|
|
|
|
'instanceTenancy' => String,
|
|
|
|
'currencyCode' => String
|
|
|
|
}],
|
|
|
|
'requestId' => String
|
|
|
|
}
|
|
|
|
|
2011-07-13 02:54:13 -04:00
|
|
|
@purchase_reserved_instances_offering_format = {
|
|
|
|
'reservedInstancesId' => String,
|
|
|
|
'requestId' => String
|
|
|
|
}
|
|
|
|
|
2011-07-12 20:48:53 -04:00
|
|
|
@describe_reserved_instances_format = {
|
|
|
|
'reservedInstancesSet' => [{
|
|
|
|
'reservedInstancesId' => String,
|
|
|
|
'instanceType' => String,
|
|
|
|
'availabilityZone' => String,
|
|
|
|
'start' => Time,
|
|
|
|
'duration' => Integer,
|
|
|
|
'fixedPrice' => Float,
|
|
|
|
'usagePrice' => Float,
|
|
|
|
'instanceCount' => Integer,
|
|
|
|
'productDescription' => String,
|
|
|
|
'state' => String,
|
|
|
|
'tagSet' => [{
|
|
|
|
'key' => String,
|
|
|
|
'value' => String
|
|
|
|
}],
|
|
|
|
'instanceTenancy' => String,
|
|
|
|
'currencyCode' => String
|
|
|
|
}],
|
|
|
|
'requestId' => String
|
|
|
|
}
|
|
|
|
|
2011-12-02 18:27:08 -05:00
|
|
|
@describe_instance_status_format = {
|
|
|
|
'requestId' => String,
|
|
|
|
'instanceStatusSet' => [{
|
|
|
|
'instanceId' => String,
|
|
|
|
'availabilityZone' => String,
|
|
|
|
'instanceState' => {
|
|
|
|
'code' => Integer,
|
|
|
|
'name' => String
|
|
|
|
},
|
2012-02-03 21:56:37 -05:00
|
|
|
'systemStatus' => {
|
|
|
|
'status' => String,
|
|
|
|
'details' => [{
|
|
|
|
'name' => String,
|
|
|
|
'status' => String
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
'instanceStatus' => {
|
|
|
|
'status' => String,
|
|
|
|
'details' => [{
|
|
|
|
'name' => String,
|
|
|
|
'status' => String
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
'event' => {
|
2011-12-02 18:27:08 -05:00
|
|
|
'code' => String,
|
|
|
|
'description' => String,
|
|
|
|
'notBefore' => Time,
|
|
|
|
'notAfter' => Time
|
2012-02-03 21:56:37 -05:00
|
|
|
}
|
2011-12-02 18:27:08 -05:00
|
|
|
}]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-05-27 14:27:08 -04:00
|
|
|
tests('success') do
|
|
|
|
|
|
|
|
@instance_id = nil
|
2011-05-09 18:28:54 -04:00
|
|
|
# Use a MS Windows AMI to test #get_password_data
|
2011-11-10 12:35:53 -05:00
|
|
|
@windows_ami = 'ami-62bd440b' # Amazon Public Images - Basic Microsoft Windows Server 2008 64-bit
|
2010-05-27 14:27:08 -04:00
|
|
|
|
2011-05-09 18:28:54 -04:00
|
|
|
# Create a keypair for decrypting the password
|
|
|
|
key_name = 'fog-test-key'
|
2011-06-23 14:51:31 -04:00
|
|
|
key = Fog::Compute[:aws].key_pairs.create(:name => key_name)
|
2011-05-09 18:28:54 -04:00
|
|
|
|
|
|
|
tests("#run_instances").formats(@run_instances_format) do
|
2011-06-16 19:28:54 -04:00
|
|
|
data = Fog::Compute[:aws].run_instances(@windows_ami, 1, 1, 'InstanceType' => 't1.micro', 'KeyName' => key_name).body
|
2010-05-27 14:27:08 -04:00
|
|
|
@instance_id = data['instancesSet'].first['instanceId']
|
|
|
|
data
|
|
|
|
end
|
|
|
|
|
2011-10-13 09:25:11 -04:00
|
|
|
if Fog.mocking?
|
|
|
|
# Ensure the new instance doesn't show up in mock describe_instances right away
|
|
|
|
tests("#describe_instances").formats(@describe_instances_format) do
|
|
|
|
body = Fog::Compute[:aws].describe_instances.body
|
|
|
|
instance_ids = body['reservationSet'].map {|reservation| reservation['instancesSet'].map {|instance| instance['instanceId'] } }.flatten
|
|
|
|
test("doesn't include the new instance") { !instance_ids.include?(@instance_id) }
|
|
|
|
body
|
|
|
|
end
|
|
|
|
|
|
|
|
# But querying for the new instance directly should raise an error
|
|
|
|
tests("#describe_instances('instance-id' => '#{@instance_id}')").raises(Fog::Compute::AWS::NotFound) do
|
|
|
|
Fog::Compute[:aws].describe_instances('instance-id' => @instance_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-16 19:28:54 -04:00
|
|
|
server = Fog::Compute[:aws].servers.get(@instance_id)
|
2011-05-09 18:28:54 -04:00
|
|
|
while server.nil? do
|
|
|
|
# It may take a moment to get the server after launching it
|
|
|
|
sleep 0.1
|
2011-06-16 19:28:54 -04:00
|
|
|
server = Fog::Compute[:aws].servers.get(@instance_id)
|
2011-05-09 18:28:54 -04:00
|
|
|
end
|
|
|
|
server.wait_for { ready? }
|
2010-05-27 14:27:08 -04:00
|
|
|
|
2011-05-09 18:28:54 -04:00
|
|
|
tests("#describe_instances").formats(@describe_instances_format) do
|
2011-07-08 18:39:35 -04:00
|
|
|
Fog::Compute[:aws].describe_instances('instance-state-name' => 'running').body
|
2011-05-09 18:28:54 -04:00
|
|
|
end
|
2010-05-27 14:27:08 -04:00
|
|
|
|
2011-05-13 12:27:25 -04:00
|
|
|
# Launch another instance to test filters
|
2011-06-16 19:28:54 -04:00
|
|
|
another_server = Fog::Compute[:aws].servers.create
|
2011-05-13 12:27:25 -04:00
|
|
|
|
2010-10-04 18:46:12 -04:00
|
|
|
tests("#describe_instances('instance-id' => '#{@instance_id}')").formats(@describe_instances_format) do
|
2011-06-16 19:28:54 -04:00
|
|
|
body = Fog::Compute[:aws].describe_instances('instance-id' => @instance_id).body
|
2011-05-13 12:27:25 -04:00
|
|
|
tests("returns 1 instance").returns(1) { body['reservationSet'].size }
|
|
|
|
body
|
2010-05-27 14:27:08 -04:00
|
|
|
end
|
|
|
|
|
2011-05-13 12:27:25 -04:00
|
|
|
another_server.destroy
|
|
|
|
|
2010-05-27 14:27:08 -04:00
|
|
|
tests("#get_console_output('#{@instance_id}')").formats(@get_console_output_format) do
|
2011-06-16 19:28:54 -04:00
|
|
|
Fog::Compute[:aws].get_console_output(@instance_id).body
|
2010-05-27 14:27:08 -04:00
|
|
|
end
|
|
|
|
|
2011-05-09 18:28:54 -04:00
|
|
|
tests("#get_password_data('#{@instance_id}')").formats(@get_password_data_format) do
|
2011-06-16 19:28:54 -04:00
|
|
|
result = Fog::Compute[:aws].get_password_data(@instance_id).body
|
2011-05-09 18:28:54 -04:00
|
|
|
|
|
|
|
tests("key can decrypt passwordData").returns(true) do
|
2011-05-18 15:33:13 -04:00
|
|
|
|
|
|
|
pending if Fog.mocking?
|
|
|
|
|
|
|
|
password_data = result['passwordData']
|
|
|
|
Fog.wait_for do
|
2011-06-16 19:28:54 -04:00
|
|
|
password_data ||= Fog::Compute[:aws].get_password_data(@instance_id).body['passwordData']
|
2011-05-18 15:33:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
decoded_password = Base64.decode64(password_data)
|
2011-05-09 18:28:54 -04:00
|
|
|
pkey = OpenSSL::PKey::RSA.new(key.private_key)
|
|
|
|
String === pkey.private_decrypt(decoded_password)
|
|
|
|
end
|
|
|
|
result
|
2011-07-08 20:10:36 -04:00
|
|
|
end unless ENV['FASTER_TEST_PLEASE']
|
2011-05-09 18:28:54 -04:00
|
|
|
|
|
|
|
key.destroy
|
|
|
|
|
2010-09-09 20:50:38 -04:00
|
|
|
tests("#reboot_instances('#{@instance_id}')").formats(AWS::Compute::Formats::BASIC) do
|
2011-06-16 19:28:54 -04:00
|
|
|
Fog::Compute[:aws].reboot_instances(@instance_id).body
|
2010-05-27 14:27:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
tests("#terminate_instances('#{@instance_id}')").formats(@terminate_instances_format) do
|
2011-06-16 19:28:54 -04:00
|
|
|
Fog::Compute[:aws].terminate_instances(@instance_id).body
|
2010-05-27 14:27:08 -04:00
|
|
|
end
|
|
|
|
|
2011-07-12 20:48:53 -04:00
|
|
|
tests("#describe_reserved_instances_offerings").formats(@describe_reserved_instances_offerings_format) do
|
|
|
|
@reserved_instances = Fog::Compute[:aws].describe_reserved_instances_offerings.body
|
|
|
|
@reserved_instances
|
|
|
|
end
|
|
|
|
|
2011-12-02 18:27:08 -05:00
|
|
|
tests('#describe_instance_status').formats(@describe_instance_status_format) do
|
|
|
|
Fog::Compute[:aws].describe_instance_status.body
|
|
|
|
end
|
|
|
|
|
2011-07-12 20:48:53 -04:00
|
|
|
if Fog.mocking?
|
2011-07-13 02:54:13 -04:00
|
|
|
@reserved_instance_offering_id = @reserved_instances["reservedInstancesOfferingsSet"].first["reservedInstancesOfferingId"]
|
|
|
|
tests("#purchase_reserved_instances_offering('#{@reserved_instance_offering_id}')").formats(@purchase_reserved_instances_offering_format) do
|
2011-07-12 20:48:53 -04:00
|
|
|
Fog::Compute[:aws].purchase_reserved_instances_offering(@reserved_instance_offering_id, 1).body
|
|
|
|
end
|
|
|
|
|
|
|
|
tests("#describe_reserved_instances").formats(@describe_reserved_instances_format) do
|
|
|
|
Fog::Compute[:aws].describe_reserved_instances.body
|
|
|
|
end
|
|
|
|
end
|
2010-05-27 14:27:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('failure') do
|
|
|
|
|
2011-06-16 19:28:54 -04:00
|
|
|
tests("#get_console_output('i-00000000')").raises(Fog::Compute::AWS::NotFound) do
|
|
|
|
Fog::Compute[:aws].get_console_output('i-00000000')
|
2010-05-27 14:27:08 -04:00
|
|
|
end
|
|
|
|
|
2011-06-16 19:28:54 -04:00
|
|
|
tests("#get_password_data('i-00000000')").raises(Fog::Compute::AWS::NotFound) do
|
|
|
|
Fog::Compute[:aws].get_password_data('i-00000000')
|
2011-05-09 18:28:54 -04:00
|
|
|
end
|
|
|
|
|
2011-06-16 19:28:54 -04:00
|
|
|
tests("#reboot_instances('i-00000000')").raises(Fog::Compute::AWS::NotFound) do
|
|
|
|
Fog::Compute[:aws].reboot_instances('i-00000000')
|
2010-05-27 14:27:08 -04:00
|
|
|
end
|
|
|
|
|
2011-06-16 19:28:54 -04:00
|
|
|
tests("#terminate_instances('i-00000000')").raises(Fog::Compute::AWS::NotFound) do
|
|
|
|
Fog::Compute[:aws].terminate_instances('i-00000000')
|
2010-05-27 14:27:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|