mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[ec2] consolidate server tests and fix some breakage
This commit is contained in:
parent
14f91dabfa
commit
54a7fe2017
15 changed files with 151 additions and 277 deletions
|
@ -57,10 +57,6 @@ module Fog
|
|||
"ip-#{ip_address.gsub('.','-')}.ec2.internal"
|
||||
end
|
||||
|
||||
def self.console_output
|
||||
'This is my console. There are many like it, but this one is mine. My console is my best friend. It is my life. I must master it as I master my life. My console, without me, is useless. Without my console, I am useless.'
|
||||
end
|
||||
|
||||
def self.etag
|
||||
hex(32)
|
||||
end
|
||||
|
|
|
@ -14,8 +14,10 @@ module Fog
|
|||
when 'instanceId', 'requestId'
|
||||
@response[name] = @value
|
||||
when 'output'
|
||||
if @value
|
||||
@response[name] = Base64.decode64(@value)
|
||||
@response[name] = if @value
|
||||
Base64.decode64(@value)
|
||||
else
|
||||
nil
|
||||
end
|
||||
when 'timestamp'
|
||||
@response[name] = Time.parse(@value)
|
||||
|
|
|
@ -107,7 +107,7 @@ module Fog
|
|||
'ownerId' => instance['ownerId'],
|
||||
'reservationId' => instance['reservationId']
|
||||
}
|
||||
reservation_set[instance['reservationId']]['instancesSet'] << instance.reject{|key,value| !['amiLaunchIndex', 'blockDeviceMapping', 'dnsName', 'imageId', 'instanceId', 'instanceState', 'instanceType', 'ipAddress', 'kernelId', 'keyName', 'launchTime', 'monitoring', 'placement', 'privateDnsName', 'privateIpAddress', 'productCodes', 'ramdiskId', 'reason', 'rootDeviceType'].include?(key)}
|
||||
reservation_set[instance['reservationId']]['instancesSet'] << instance.reject{|key,value| !['amiLaunchIndex', 'architecture', 'blockDeviceMapping', 'dnsName', 'imageId', 'instanceId', 'instanceState', 'instanceType', 'ipAddress', 'kernelId', 'keyName', 'launchTime', 'monitoring', 'placement', 'privateDnsName', 'privateIpAddress', 'productCodes', 'ramdiskId', 'reason', 'rootDeviceType'].include?(key)}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ module Fog
|
|||
response.status = 200
|
||||
response.body = {
|
||||
'instanceId' => instance_id,
|
||||
'output' => Fog::AWS::Mock.console_output,
|
||||
'output' => nil,
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
'timestamp' => Time.now
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ module Fog
|
|||
'instanceState' => { 'code' => 0, 'name' => 'pending' },
|
||||
'instanceType' => options['InstanceType'] || 'm1.small',
|
||||
'kernelId' => options['KernelId'] || Fog::AWS::Mock.kernel_id,
|
||||
'keyName' => options['KeyName'] || '',
|
||||
# 'keyName' => options['KeyName'],
|
||||
'launchTime' => Time.now,
|
||||
'monitoring' => { 'state' => options['Monitoring.Enabled'] || false },
|
||||
'placement' => { 'availabilityZone' => options['Placement.AvailabilityZone'] || Fog::AWS::Mock.availability_zone },
|
||||
|
@ -134,6 +134,7 @@ module Fog
|
|||
}
|
||||
instances_set << instance
|
||||
@data[:instances][instance_id] = instance.merge({
|
||||
'architecture' => 'i386',
|
||||
'groupSet' => group_set,
|
||||
'ownerId' => @owner_id,
|
||||
'privateIpAddress' => nil,
|
||||
|
|
|
@ -61,7 +61,7 @@ describe 'Fog::AWS::EC2::Snapshots' do
|
|||
end
|
||||
|
||||
it "should return nil if no matching address exists" do
|
||||
AWS[:ec2].snapshots.get('vol-00000000').should be_nil
|
||||
AWS[:ec2].snapshots.get('snap-00000000').should be_nil
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,104 +0,0 @@
|
|||
require File.dirname(__FILE__) + '/../../../spec_helper'
|
||||
|
||||
describe 'EC2.describe_instances' do
|
||||
describe 'success' do
|
||||
|
||||
before(:all) do
|
||||
run_instances = AWS[:ec2].run_instances(GENTOO_AMI, 1, 1).body
|
||||
@instance_id = run_instances['instancesSet'].first['instanceId']
|
||||
@reservation_id = run_instances['reservationId']
|
||||
Fog.wait_for { AWS[:ec2].servers.get(@instance_id) }
|
||||
AWS[:ec2].servers.get(@instance_id).wait_for { ready? }
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
AWS[:ec2].terminate_instances([@instance_id])
|
||||
end
|
||||
|
||||
it "should return proper attributes with no params" do
|
||||
actual = AWS[:ec2].describe_instances
|
||||
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)
|
||||
# instance['architecture'].should be_a(String)
|
||||
instance['blockDeviceMapping'].should be_an(Array)
|
||||
instance['dnsName'].should be_a(String)
|
||||
instance['imageId'].should be_a(String)
|
||||
instance['instanceId'].should be_a(String)
|
||||
instance['instanceState'].should be_a(Hash)
|
||||
instance['instanceState']['code'].should be_a(Integer)
|
||||
instance['instanceState']['name'].should be_a(String)
|
||||
instance['instanceType'].should be_a(String)
|
||||
instance['ipAddress'].should be_a(String)
|
||||
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'])
|
||||
instance['placement'].should be_a(Hash)
|
||||
instance['placement']['availabilityZone'].should be_a(String)
|
||||
instance['privateDnsName'].should be_a(String)
|
||||
instance['privateIpAddress'].should be_a(String)
|
||||
instance['productCodes'].should be_an(Array)
|
||||
instance['productCodes'].first.should be_a(String) if instance['productCodes'].first
|
||||
instance['ramdiskId'].should be_a(String)
|
||||
if instance['reason']
|
||||
instance['reason'].should be_a(String)
|
||||
end
|
||||
# instance['rootDeviceName'].should be_a(String)
|
||||
instance['rootDeviceType'].should be_a(String)
|
||||
end
|
||||
|
||||
it "should return proper attributes with params" do
|
||||
actual = AWS[:ec2].describe_instances(@instance_id)
|
||||
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)
|
||||
# instance['architecture'].should be_a(String)
|
||||
instance['blockDeviceMapping'].should be_an(Array)
|
||||
instance['dnsName'].should be_a(String)
|
||||
instance['imageId'].should be_a(String)
|
||||
instance['instanceId'].should be_a(String)
|
||||
instance['instanceState'].should be_a(Hash)
|
||||
instance['instanceState']['code'].should be_a(Integer)
|
||||
instance['instanceState']['name'].should be_a(String)
|
||||
instance['instanceType'].should be_a(String)
|
||||
instance['ipAddress'].should be_a(String)
|
||||
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'])
|
||||
instance['placement'].should be_a(Hash)
|
||||
instance['placement']['availabilityZone'].should be_a(String)
|
||||
instance['privateDnsName'].should be_a(String)
|
||||
instance['privateIpAddress'].should be_a(String)
|
||||
instance['productCodes'].should be_an(Array)
|
||||
instance['productCodes'].first.should be_a(String) if instance['productCodes'].first
|
||||
instance['ramdiskId'].should be_a(String)
|
||||
if instance['reason']
|
||||
instance['reason'].should be_a(String)
|
||||
end
|
||||
# instance['rootDeviceName'].should be_a(String)
|
||||
instance['rootDeviceType'].should be_a(String)
|
||||
end
|
||||
|
||||
end
|
||||
describe 'failure' do
|
||||
|
||||
it 'should raise a Fog::AWS::EC2::Error if the instance does not exist' do
|
||||
lambda {
|
||||
AWS[:ec2].describe_instances('i-00000000')
|
||||
}.should raise_error(Fog::AWS::EC2::Error)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,35 +0,0 @@
|
|||
require File.dirname(__FILE__) + '/../../../spec_helper'
|
||||
|
||||
describe 'EC2.get_console_output' do
|
||||
describe 'success' do
|
||||
|
||||
before(:each) do
|
||||
@instance = AWS[:ec2].servers.create(:image_id => GENTOO_AMI)
|
||||
@instance.wait_for { ready? }
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
@instance.destroy
|
||||
end
|
||||
|
||||
it "should return proper attributes" do
|
||||
actual = AWS[:ec2].get_console_output(@instance.id).body
|
||||
actual['instanceId'].should be_a(String)
|
||||
if actual['output']
|
||||
actual['output'].should be_a(String)
|
||||
end
|
||||
actual['requestId'].should be_a(String)
|
||||
actual['timestamp'].should be_a(Time)
|
||||
end
|
||||
|
||||
end
|
||||
describe 'failure' do
|
||||
|
||||
it "should raise a Fog::AWS::EC2::Error if the instance does not exist" do
|
||||
lambda {
|
||||
AWS[:ec2].get_console_output('i-00000000')
|
||||
}.should raise_error(Fog::AWS::EC2::Error)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,30 +0,0 @@
|
|||
require File.dirname(__FILE__) + '/../../../spec_helper'
|
||||
|
||||
describe 'EC2.reboot_instances' do
|
||||
describe 'success' do
|
||||
|
||||
before(:each) do
|
||||
@instance_id = AWS[:ec2].run_instances(GENTOO_AMI, 1, 1).body['instancesSet'].first['instanceId']
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
AWS[:ec2].terminate_instances(@instance_id)
|
||||
end
|
||||
|
||||
it "should return proper attributes" do
|
||||
actual = AWS[:ec2].reboot_instances(@instance_id)
|
||||
actual.body['requestId'].should be_a(String)
|
||||
[false, true].should include(actual.body['return'])
|
||||
end
|
||||
|
||||
end
|
||||
describe 'failure' do
|
||||
|
||||
it "should raise a Fog::AWS::EC2::Error if the instance does not exist" do
|
||||
lambda {
|
||||
AWS[:ec2].reboot_instances('i-00000000')
|
||||
}.should raise_error(Fog::AWS::EC2::Error)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,48 +0,0 @@
|
|||
require File.dirname(__FILE__) + '/../../../spec_helper'
|
||||
|
||||
describe 'EC2.run_instances' do
|
||||
describe 'success' do
|
||||
|
||||
after(:each) do
|
||||
AWS[:ec2].terminate_instances(@instance_id)
|
||||
end
|
||||
|
||||
it "should return proper attributes" do
|
||||
# ami-5ee70037 = gentoo
|
||||
actual = AWS[:ec2].run_instances(GENTOO_AMI, 1, 1)
|
||||
@instance_id = actual.body['instancesSet'].first['instanceId']
|
||||
actual.body['groupSet'].should be_an(Array)
|
||||
actual.body['groupSet'].first.should be_a(String)
|
||||
actual.body['instancesSet'].should be_an(Array)
|
||||
instance = actual.body['instancesSet'].first
|
||||
instance['amiLaunchIndex'].should be_a(Integer)
|
||||
# instance['architecture'].should be_a(String)
|
||||
instance['blockDeviceMapping'].should be_an(Array)
|
||||
instance['dnsName'].should be_nil
|
||||
instance['imageId'].should be_a(String)
|
||||
instance['instanceId'].should be_a(String)
|
||||
instance['instanceState'].should be_an(Hash)
|
||||
instance['instanceState']['code'].should be_an(Integer)
|
||||
instance['instanceState']['name'].should be_an(String)
|
||||
instance['instanceType'].should be_a(String)
|
||||
# instance['ipAddress'].should be_a(String)
|
||||
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)
|
||||
[false, true].should include(instance['monitoring']['state'])
|
||||
instance['placement'].should be_a(Hash)
|
||||
instance['placement']['availabilityZone'].should be_a(String)
|
||||
instance['privateDnsName'].should be_nil
|
||||
# instance['privateIpAddress'].should be_a(String)
|
||||
instance['ramdiskId'].should be_a(String)
|
||||
instance['reason'].should be_nil
|
||||
actual.body['ownerId'].should be_a(String)
|
||||
actual.body['requestId'].should be_a(String)
|
||||
actual.body['reservationId'].should be_a(String)
|
||||
# instance['rootDeviceName'].should be_a(String)
|
||||
instance['rootDeviceType'].should be_a(String)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,35 +0,0 @@
|
|||
require File.dirname(__FILE__) + '/../../../spec_helper'
|
||||
|
||||
describe 'EC2.terminate_instances' do
|
||||
describe 'success' do
|
||||
|
||||
before(:each) do
|
||||
@instance_id = AWS[:ec2].run_instances(GENTOO_AMI, 1, 1).body['instancesSet'].first['instanceId']
|
||||
end
|
||||
|
||||
it "should return proper attributes" do
|
||||
actual = AWS[:ec2].terminate_instances(@instance_id)
|
||||
actual.body['requestId'].should be_a(String)
|
||||
actual.body['instancesSet'].should be_an(Array)
|
||||
instance = actual.body['instancesSet'].select {|instance| instance['instanceId'] == @instance_id}.first
|
||||
instance['previousState'].should be_a(Hash)
|
||||
previous_state = instance['previousState']
|
||||
previous_state['code'].should be_a(Integer)
|
||||
previous_state['name'].should be_a(String)
|
||||
instance['currentState'].should be_a(Hash)
|
||||
current_state = instance['currentState']
|
||||
current_state['code'].should be_a(Integer)
|
||||
current_state['name'].should be_a(String)
|
||||
end
|
||||
|
||||
end
|
||||
describe 'failure' do
|
||||
|
||||
it 'should raise a Fog::AWS::EC2::Error if the instance does not exist' do
|
||||
lambda {
|
||||
AWS[:ec2].terminate_instances('i-00000000')
|
||||
}.should raise_error(Fog::AWS::EC2::Error)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -18,7 +18,7 @@ shared_examples_for "Servers" do
|
|||
end
|
||||
|
||||
it "should return nil if no matching server exists" do
|
||||
@servers.get('0').should be_nil
|
||||
@servers.get('i-00000000').should be_nil
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,11 +1,3 @@
|
|||
# Boolean hax
|
||||
module Fog
|
||||
module Boolean
|
||||
end
|
||||
end
|
||||
FalseClass.send(:include, Fog::Boolean)
|
||||
TrueClass.send(:include, Fog::Boolean)
|
||||
|
||||
module AWS
|
||||
|
||||
class << self
|
||||
|
|
122
tests/aws/requests/ec2/instance_tests.rb
Normal file
122
tests/aws/requests/ec2/instance_tests.rb
Normal file
|
@ -0,0 +1,122 @@
|
|||
Shindo.tests('AWS::EC2 | instance requests', ['aws']) do
|
||||
|
||||
@instance_format = {
|
||||
# 'architecture' => String,
|
||||
'amiLaunchIndex' => Integer,
|
||||
'blockDeviceMapping' => [],
|
||||
'dnsName' => NilClass,
|
||||
'imageId' => String,
|
||||
'instanceId' => String,
|
||||
'instanceState' => {'code' => Integer, 'name' => String},
|
||||
'instanceType' => String,
|
||||
# 'ipAddress' => String,
|
||||
'kernelId' => String,
|
||||
# 'keyName' => String,
|
||||
'launchTime' => Time,
|
||||
'monitoring' => {'state' => Fog::Boolean},
|
||||
'placement' => {'availabilityZone' => String},
|
||||
'privateDnsName' => NilClass,
|
||||
# 'privateIpAddress' => String,
|
||||
'productCodes' => [],
|
||||
'ramdiskId' => String,
|
||||
'reason' => NilClass,
|
||||
# 'rootDeviceName' => String,
|
||||
'rootDeviceType' => String
|
||||
}
|
||||
|
||||
@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,
|
||||
'dnsName' => String,
|
||||
'ipAddress' => String,
|
||||
'privateDnsName' => String,
|
||||
'privateIpAddress' => String
|
||||
)],
|
||||
'ownerId' => String,
|
||||
'reservationId' => String
|
||||
}],
|
||||
'requestId' => String
|
||||
}
|
||||
|
||||
@get_console_output_format = {
|
||||
'instanceId' => String,
|
||||
'output' => NilClass,
|
||||
'requestId' => String,
|
||||
'timestamp' => Time
|
||||
}
|
||||
|
||||
@terminate_instances_format = {
|
||||
'instancesSet' => [{
|
||||
'currentState' => {'code' => Integer, 'name' => String},
|
||||
'instanceId' => String,
|
||||
'previousState' => {'code' => Integer, 'name' => String},
|
||||
}],
|
||||
'requestId' => String
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
@instance_id = nil
|
||||
|
||||
tests("#run_instances('#{GENTOO_AMI}', 1, 1)").formats(@run_instances_format) do
|
||||
data = AWS[:ec2].run_instances(GENTOO_AMI, 1, 1).body
|
||||
@instance_id = data['instancesSet'].first['instanceId']
|
||||
data
|
||||
end
|
||||
|
||||
AWS[:ec2].servers.get(@instance_id).wait_for { ready? }
|
||||
|
||||
# The format changes depending on state of instance, so this would be brittle
|
||||
# tests("#describe_instances").formats(@describe_instances_format) do
|
||||
# AWS[:ec2].describe_instances.body
|
||||
# end
|
||||
|
||||
tests("#describe_instances('#{@instance_id}')").formats(@describe_instances_format) do
|
||||
AWS[:ec2].describe_instances(@instance_id).body
|
||||
end
|
||||
|
||||
tests("#get_console_output('#{@instance_id}')").formats(@get_console_output_format) do
|
||||
AWS[:ec2].get_console_output(@instance_id).body
|
||||
end
|
||||
|
||||
tests("#reboot_instances('#{@instance_id}')").formats(AWS::EC2::Formats::BASIC) do
|
||||
AWS[:ec2].reboot_instances(@instance_id).body
|
||||
end
|
||||
|
||||
tests("#terminate_instances('#{@instance_id}')").formats(@terminate_instances_format) do
|
||||
AWS[:ec2].terminate_instances(@instance_id).body
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
|
||||
tests("#describe_instances('i-00000000')").raises(Fog::AWS::EC2::NotFound) do
|
||||
AWS[:ec2].describe_instances('i-00000000')
|
||||
end
|
||||
|
||||
tests("#get_console_output('i-00000000')").raises(Fog::AWS::EC2::NotFound) do
|
||||
AWS[:ec2].get_console_output('i-00000000')
|
||||
end
|
||||
|
||||
tests("#reboot_instances('i-00000000')").raises(Fog::AWS::EC2::NotFound) do
|
||||
AWS[:ec2].reboot_instances('i-00000000')
|
||||
end
|
||||
|
||||
tests("#terminate_instances('i-00000000')").raises(Fog::AWS::EC2::NotFound) do
|
||||
AWS[:ec2].terminate_instances('i-00000000')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -5,6 +5,14 @@ if ENV["FOG_MOCK"] == "true"
|
|||
Fog.mock!
|
||||
end
|
||||
|
||||
# Boolean hax
|
||||
module Fog
|
||||
module Boolean
|
||||
end
|
||||
end
|
||||
FalseClass.send(:include, Fog::Boolean)
|
||||
TrueClass.send(:include, Fog::Boolean)
|
||||
|
||||
module Shindo
|
||||
class Tests
|
||||
|
||||
|
@ -38,21 +46,26 @@ module Shindo
|
|||
case value
|
||||
when Array
|
||||
valid &&= datum.is_a?(Array)
|
||||
for element in datum
|
||||
type = value.first
|
||||
if type.is_a?(Hash)
|
||||
valid &&= formats_kernel({:element => element}, {:element => type}, false)
|
||||
else
|
||||
valid &&= element.is_a?(type)
|
||||
if datum.is_a?(Array)
|
||||
for element in datum
|
||||
type = value.first
|
||||
if type.is_a?(Hash)
|
||||
valid &&= formats_kernel({:element => element}, {:element => type}, false)
|
||||
else
|
||||
valid &&= element.is_a?(type)
|
||||
end
|
||||
end
|
||||
end
|
||||
when Hash
|
||||
valid &&= datum.is_a?(Hash)
|
||||
valid &&= formats_kernel(datum, value, false)
|
||||
else
|
||||
p "#{key} => #{value}" unless datum.is_a?(value)
|
||||
valid &&= datum.is_a?(value)
|
||||
end
|
||||
end
|
||||
p data unless data.empty?
|
||||
p format unless format.empty?
|
||||
valid &&= data.empty? && format.empty?
|
||||
if !valid && original
|
||||
@message = "#{original_data.inspect} does not match #{original_format.inspect}"
|
||||
|
|
Loading…
Add table
Reference in a new issue