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-05-09 18:28:54 -04:00
|
|
|
'kernelId' => Fog::Nullable::String,
|
|
|
|
'keyName' => Fog::Nullable::String,
|
2010-05-27 14:27:08 -04:00
|
|
|
'launchTime' => Time,
|
|
|
|
'monitoring' => {'state' => Fog::Boolean},
|
|
|
|
'placement' => {'availabilityZone' => String},
|
|
|
|
'privateDnsName' => NilClass,
|
|
|
|
# 'privateIpAddress' => String,
|
|
|
|
'productCodes' => [],
|
2011-05-09 18:28:54 -04:00
|
|
|
'ramdiskId' => Fog::Nullable::String,
|
|
|
|
'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
|
|
|
|
}
|
|
|
|
|
|
|
|
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-06-23 14:51:31 -04:00
|
|
|
@windows_ami = 'ami-1cbd4475' # Microsoft Windows Server 2008 R2 Base 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-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-06-16 19:28:54 -04:00
|
|
|
Fog::Compute[:aws].describe_instances.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
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|