2009-08-17 15:55:30 -07:00
|
|
|
require File.dirname(__FILE__) + '/../../../spec_helper'
|
2009-07-06 20:45:16 -07:00
|
|
|
|
2009-07-08 21:58:02 -07:00
|
|
|
describe 'EC2.describe_instances' do
|
2009-08-19 20:32:57 -07:00
|
|
|
describe 'success' do
|
2009-07-06 20:45:16 -07:00
|
|
|
|
2010-04-30 14:32:10 -07:00
|
|
|
before(:all) do
|
2010-01-23 12:35:16 -08:00
|
|
|
run_instances = AWS[:ec2].run_instances(GENTOO_AMI, 1, 1).body
|
2009-08-19 20:32:57 -07:00
|
|
|
@instance_id = run_instances['instancesSet'].first['instanceId']
|
|
|
|
@reservation_id = run_instances['reservationId']
|
2010-05-05 13:39:41 -07:00
|
|
|
Fog.wait_for { AWS[:ec2].servers.get(@instance_id) }
|
2010-04-30 14:32:10 -07:00
|
|
|
AWS[:ec2].servers.get(@instance_id).wait_for { ready? }
|
2009-08-19 20:32:57 -07:00
|
|
|
end
|
2009-07-19 21:46:45 -07:00
|
|
|
|
2010-04-30 14:32:10 -07:00
|
|
|
after(:all) do
|
2010-01-23 12:35:16 -08:00
|
|
|
AWS[:ec2].terminate_instances([@instance_id])
|
2009-08-19 20:32:57 -07:00
|
|
|
end
|
2009-07-19 21:46:45 -07:00
|
|
|
|
2009-08-19 20:32:57 -07:00
|
|
|
it "should return proper attributes with no params" do
|
2010-01-23 12:35:16 -08:00
|
|
|
actual = AWS[:ec2].describe_instances
|
2009-08-19 20:32:57 -07:00
|
|
|
reservation = actual.body['reservationSet'].select {|reservation| reservation['reservationId'] == @reservation_id}.first
|
|
|
|
reservation['groupSet'].should be_an(Array)
|
|
|
|
reservation['groupSet'].first.should be_a(String)
|
|
|
|
reservation['ownerId'].should be_a(String)
|
|
|
|
reservation['reservationId'].should be_a(String)
|
|
|
|
instance = reservation['instancesSet'].select {|instance| instance['instanceId'] == @instance_id}.first
|
|
|
|
instance['amiLaunchIndex'].should be_an(Integer)
|
2010-02-20 13:40:46 -08:00
|
|
|
# instance['architecture'].should be_a(String)
|
|
|
|
instance['blockDeviceMapping'].should be_an(Array)
|
2009-08-19 20:32:57 -07:00
|
|
|
instance['dnsName'].should be_a(String)
|
|
|
|
instance['imageId'].should be_a(String)
|
|
|
|
instance['instanceId'].should be_a(String)
|
|
|
|
instance['instanceState'].should be_a(Hash)
|
2009-08-23 11:01:37 -07:00
|
|
|
instance['instanceState']['code'].should be_a(Integer)
|
2009-08-19 20:32:57 -07:00
|
|
|
instance['instanceState']['name'].should be_a(String)
|
|
|
|
instance['instanceType'].should be_a(String)
|
2010-02-20 13:40:46 -08:00
|
|
|
# instance['ipAddress'].should be_a(String)
|
2009-08-19 20:32:57 -07:00
|
|
|
instance['kernelId'].should be_a(String)
|
|
|
|
instance['keyName'].should be_a(String) if instance['keyName']
|
|
|
|
instance['launchTime'].should be_a(Time)
|
|
|
|
instance['monitoring'].should be_a(Hash)
|
|
|
|
[true, false].should include(instance['monitoring']['state'])
|
2009-08-23 11:01:37 -07:00
|
|
|
instance['placement'].should be_a(Hash)
|
|
|
|
instance['placement']['availabilityZone'].should be_a(String)
|
2009-08-19 20:32:57 -07:00
|
|
|
instance['privateDnsName'].should be_a(String)
|
2010-02-20 13:40:46 -08:00
|
|
|
# instance['privateIpAddress'].should be_a(String)
|
2009-08-19 20:32:57 -07:00
|
|
|
instance['productCodes'].should be_an(Array)
|
|
|
|
instance['productCodes'].first.should be_a(String) if instance['productCodes'].first
|
|
|
|
instance['ramdiskId'].should be_a(String)
|
2010-05-05 13:39:41 -07:00
|
|
|
if instance['reason']
|
|
|
|
instance['reason'].should be_a(String)
|
|
|
|
end
|
2010-02-20 13:40:46 -08:00
|
|
|
# instance['rootDeviceName'].should be_a(String)
|
|
|
|
instance['rootDeviceType'].should be_a(String)
|
2009-08-19 20:32:57 -07:00
|
|
|
end
|
2009-07-06 20:45:16 -07:00
|
|
|
|
2009-08-19 20:32:57 -07:00
|
|
|
it "should return proper attributes with params" do
|
2010-01-23 12:35:16 -08:00
|
|
|
actual = AWS[:ec2].describe_instances(@instance_id)
|
2009-08-19 20:32:57 -07:00
|
|
|
reservation = actual.body['reservationSet'].select {|reservation| reservation['reservationId'] == @reservation_id}.first
|
|
|
|
reservation['groupSet'].should be_an(Array)
|
|
|
|
reservation['groupSet'].first.should be_a(String)
|
|
|
|
reservation['ownerId'].should be_a(String)
|
|
|
|
reservation['reservationId'].should be_a(String)
|
|
|
|
instance = reservation['instancesSet'].select {|instance| instance['instanceId'] == @instance_id}.first
|
|
|
|
instance['amiLaunchIndex'].should be_an(Integer)
|
2010-02-20 13:40:46 -08:00
|
|
|
# instance['architecture'].should be_a(String)
|
|
|
|
instance['blockDeviceMapping'].should be_an(Array)
|
2009-08-19 20:32:57 -07:00
|
|
|
instance['dnsName'].should be_a(String)
|
|
|
|
instance['imageId'].should be_a(String)
|
|
|
|
instance['instanceId'].should be_a(String)
|
|
|
|
instance['instanceState'].should be_a(Hash)
|
2009-08-23 11:01:37 -07:00
|
|
|
instance['instanceState']['code'].should be_a(Integer)
|
2009-08-19 20:32:57 -07:00
|
|
|
instance['instanceState']['name'].should be_a(String)
|
|
|
|
instance['instanceType'].should be_a(String)
|
2010-02-20 13:40:46 -08:00
|
|
|
# instance['ipAddress'].should be_a(String)
|
2009-08-19 20:32:57 -07:00
|
|
|
instance['kernelId'].should be_a(String)
|
|
|
|
instance['keyName'].should be_a(String) if instance['keyName']
|
|
|
|
instance['launchTime'].should be_a(Time)
|
|
|
|
instance['monitoring'].should be_a(Hash)
|
|
|
|
[true, false].should include(instance['monitoring']['state'])
|
2009-08-23 11:01:37 -07:00
|
|
|
instance['placement'].should be_a(Hash)
|
|
|
|
instance['placement']['availabilityZone'].should be_a(String)
|
2009-08-19 20:32:57 -07:00
|
|
|
instance['privateDnsName'].should be_a(String)
|
2010-02-20 13:40:46 -08:00
|
|
|
# instance['privateIpAddress'].should be_a(String)
|
2009-08-19 20:32:57 -07:00
|
|
|
instance['productCodes'].should be_an(Array)
|
|
|
|
instance['productCodes'].first.should be_a(String) if instance['productCodes'].first
|
|
|
|
instance['ramdiskId'].should be_a(String)
|
2010-05-05 13:39:41 -07:00
|
|
|
if instance['reason']
|
|
|
|
instance['reason'].should be_a(String)
|
|
|
|
end
|
2010-02-20 13:40:46 -08:00
|
|
|
# instance['rootDeviceName'].should be_a(String)
|
|
|
|
instance['rootDeviceType'].should be_a(String)
|
2009-08-19 20:32:57 -07:00
|
|
|
end
|
2009-07-06 20:45:16 -07:00
|
|
|
|
2009-08-19 20:32:57 -07:00
|
|
|
end
|
2009-08-23 11:01:37 -07:00
|
|
|
describe 'failure' do
|
|
|
|
|
|
|
|
it 'should raise a BadRequest error if the instance does not exist' do
|
|
|
|
lambda {
|
2010-01-23 12:35:16 -08:00
|
|
|
AWS[:ec2].describe_instances('i-00000000')
|
2009-10-31 12:26:49 -07:00
|
|
|
}.should raise_error(Excon::Errors::BadRequest)
|
2009-08-23 11:01:37 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-07-06 20:45:16 -07:00
|
|
|
end
|