[ec2] Update the mock for addresses to support setting the server IP address correctly

This commit is contained in:
Tim Carey-Smith 2010-05-14 04:59:33 +08:00 committed by Wesley Beary
parent 11243063b6
commit a65f65dbc6
5 changed files with 20 additions and 2 deletions

View File

@ -46,6 +46,14 @@ module Fog
sprintf("%0.10f", rand / 100).to_f
end
def self.dns_name_for(ip_address)
"ec2-#{ip_address.gsub('.','-')}.compute-1.amazonaws.com"
end
def self.private_dns_name_for(ip_address)
"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

View File

@ -34,6 +34,9 @@ module Fog
address = @data[:addresses][public_ip]
if instance && address
address['instanceId'] = instance_id
instance['originalIpAddress'] = instance['ipAddress']
instance['ipAddress'] = public_ip
instance['dnsName'] = Fog::AWS::Mock.dns_name_for(public_ip)
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id,

View File

@ -78,9 +78,9 @@ module Fog
when 'pending'
if Time.now - instance['launchTime'] > Fog::Mock.delay
instance['ipAddress'] = Fog::AWS::Mock.ip_address
instance['dnsName'] = "ec2-#{instance['ipAddress'].gsub('.','-')}.compute-1.amazonaws.com"
instance['dnsName'] = Fog::AWS::Mock.dns_name_for(instance['ipAddress'])
instance['privateIpAddress'] = Fog::AWS::Mock.ip_address
instance['privateDnsName'] = "ip-#{instance['privateIpAddress'].gsub('.','-')}.ec2.internal"
instance['privateDnsName'] = Fog::AWS::Mock.private_dns_name_for(instance['privateIpAddress'])
instance['instanceState'] = { 'code' => 16, 'name' => 'running' }
end
when 'rebooting'

View File

@ -29,6 +29,10 @@ module Fog
response = Excon::Response.new
response.status = 200
if address = @data[:addresses][public_ip]
instance_id = address['instanceId']
instance = @data[:instances][instance_id]
instance['ipAddress'] = instance['originalIpAddress']
instance['dnsName'] = Fog::AWS::Mock.dns_name_for(instance['ipAddress'])
address['instanceId'] = nil
response.status = 200
response.body = {

View File

@ -2,6 +2,7 @@ Shindo.tests('AWS::EC2 | address requests', ['aws']) do
@server = AWS[:ec2].servers.create(:image_id => GENTOO_AMI)
@server.wait_for { ready? }
@ip_address = @server.ip_address
tests('success') do
@ -32,11 +33,13 @@ Shindo.tests('AWS::EC2 | address requests', ['aws']) do
test("#associate_address('#{@server.identity}', '#{@public_ip}')") do
@data = AWS[:ec2].associate_address(@server.identity, @public_ip).body
has_format(@data, AWS::EC2::Formats::BASIC)
@server.reload.ip_address == @public_ip
end
test("#disassociate_address('#{@public_ip}')") do
@data = AWS[:ec2].disassociate_address(@public_ip).body
has_format(@data, AWS::EC2::Formats::BASIC)
@server.reload.ip_address == @ip_address
end
test("#release_address('#{@public_ip}')") do