mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[ec2] Update the mock for addresses to support setting the server IP address correctly
This commit is contained in:
parent
11243063b6
commit
a65f65dbc6
5 changed files with 20 additions and 2 deletions
|
@ -46,6 +46,14 @@ module Fog
|
||||||
sprintf("%0.10f", rand / 100).to_f
|
sprintf("%0.10f", rand / 100).to_f
|
||||||
end
|
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
|
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.'
|
'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
|
end
|
||||||
|
|
|
@ -34,6 +34,9 @@ module Fog
|
||||||
address = @data[:addresses][public_ip]
|
address = @data[:addresses][public_ip]
|
||||||
if instance && address
|
if instance && address
|
||||||
address['instanceId'] = instance_id
|
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.status = 200
|
||||||
response.body = {
|
response.body = {
|
||||||
'requestId' => Fog::AWS::Mock.request_id,
|
'requestId' => Fog::AWS::Mock.request_id,
|
||||||
|
|
|
@ -78,9 +78,9 @@ module Fog
|
||||||
when 'pending'
|
when 'pending'
|
||||||
if Time.now - instance['launchTime'] > Fog::Mock.delay
|
if Time.now - instance['launchTime'] > Fog::Mock.delay
|
||||||
instance['ipAddress'] = Fog::AWS::Mock.ip_address
|
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['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' }
|
instance['instanceState'] = { 'code' => 16, 'name' => 'running' }
|
||||||
end
|
end
|
||||||
when 'rebooting'
|
when 'rebooting'
|
||||||
|
|
|
@ -29,6 +29,10 @@ module Fog
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
response.status = 200
|
response.status = 200
|
||||||
if address = @data[:addresses][public_ip]
|
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
|
address['instanceId'] = nil
|
||||||
response.status = 200
|
response.status = 200
|
||||||
response.body = {
|
response.body = {
|
||||||
|
|
|
@ -2,6 +2,7 @@ Shindo.tests('AWS::EC2 | address requests', ['aws']) do
|
||||||
|
|
||||||
@server = AWS[:ec2].servers.create(:image_id => GENTOO_AMI)
|
@server = AWS[:ec2].servers.create(:image_id => GENTOO_AMI)
|
||||||
@server.wait_for { ready? }
|
@server.wait_for { ready? }
|
||||||
|
@ip_address = @server.ip_address
|
||||||
|
|
||||||
tests('success') do
|
tests('success') do
|
||||||
|
|
||||||
|
@ -32,11 +33,13 @@ Shindo.tests('AWS::EC2 | address requests', ['aws']) do
|
||||||
test("#associate_address('#{@server.identity}', '#{@public_ip}')") do
|
test("#associate_address('#{@server.identity}', '#{@public_ip}')") do
|
||||||
@data = AWS[:ec2].associate_address(@server.identity, @public_ip).body
|
@data = AWS[:ec2].associate_address(@server.identity, @public_ip).body
|
||||||
has_format(@data, AWS::EC2::Formats::BASIC)
|
has_format(@data, AWS::EC2::Formats::BASIC)
|
||||||
|
@server.reload.ip_address == @public_ip
|
||||||
end
|
end
|
||||||
|
|
||||||
test("#disassociate_address('#{@public_ip}')") do
|
test("#disassociate_address('#{@public_ip}')") do
|
||||||
@data = AWS[:ec2].disassociate_address(@public_ip).body
|
@data = AWS[:ec2].disassociate_address(@public_ip).body
|
||||||
has_format(@data, AWS::EC2::Formats::BASIC)
|
has_format(@data, AWS::EC2::Formats::BASIC)
|
||||||
|
@server.reload.ip_address == @ip_address
|
||||||
end
|
end
|
||||||
|
|
||||||
test("#release_address('#{@public_ip}')") do
|
test("#release_address('#{@public_ip}')") do
|
||||||
|
|
Loading…
Add table
Reference in a new issue