mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Cleanups and crazy long sleep to ensure ALIAS zone is found
This commit is contained in:
parent
309ae2ae3a
commit
7cdf222c69
1 changed files with 41 additions and 66 deletions
|
@ -3,43 +3,19 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do
|
||||||
@org_zone_count = 0
|
@org_zone_count = 0
|
||||||
@zone_id = ''
|
@zone_id = ''
|
||||||
@change_id = ''
|
@change_id = ''
|
||||||
@new_records =[]
|
@new_records = []
|
||||||
|
@domain_name = generate_unique_domain
|
||||||
|
|
||||||
# NOTE: can't use generate_unique_domain() as we do in other DNS provider
|
|
||||||
# test suites as AWS charges $1/mth for each domain, even if it exists
|
|
||||||
# on AWS for only the time that this test suite runs!!
|
|
||||||
# http://aws.amazon.com/route53/pricing/
|
|
||||||
@test_domain = 'test-343246324434.com'
|
|
||||||
@elb_connection = Fog::AWS::ELB.new
|
@elb_connection = Fog::AWS::ELB.new
|
||||||
|
@r53_connection = Fog::DNS[:aws]
|
||||||
|
|
||||||
tests( 'success') do
|
tests('success') do
|
||||||
|
|
||||||
test('see if test domain already exists') do
|
|
||||||
pending if Fog.mocking?
|
|
||||||
|
|
||||||
@zone_id = nil
|
|
||||||
|
|
||||||
response = Fog::DNS[:aws].list_hosted_zones()
|
|
||||||
if response.status == 200
|
|
||||||
@hosted_zones = response.body['HostedZones']
|
|
||||||
end
|
|
||||||
|
|
||||||
#go through zones for this account
|
|
||||||
@hosted_zones.each { |zone|
|
|
||||||
domain = zone['Name']
|
|
||||||
if domain.chomp == @test_domain
|
|
||||||
@zone_id = zone['Id']
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
@zone_id.nil?
|
|
||||||
end
|
|
||||||
|
|
||||||
test('get current zone count') do
|
test('get current zone count') do
|
||||||
pending if Fog.mocking?
|
pending if Fog.mocking?
|
||||||
|
|
||||||
@org_zone_count= 0
|
@org_zone_count= 0
|
||||||
response = Fog::DNS[:aws].list_hosted_zones()
|
response = @r53_connection.list_hosted_zones
|
||||||
if response.status == 200
|
if response.status == 200
|
||||||
@hosted_zones = response.body['HostedZones']
|
@hosted_zones = response.body['HostedZones']
|
||||||
@org_zone_count = @hosted_zones.count
|
@org_zone_count = @hosted_zones.count
|
||||||
|
@ -53,12 +29,12 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do
|
||||||
|
|
||||||
result = false
|
result = false
|
||||||
|
|
||||||
response = Fog::DNS[:aws].create_hosted_zone( @test_domain)
|
response = @r53_connection.create_hosted_zone(@domain_name)
|
||||||
if response.status == 201
|
if response.status == 201
|
||||||
|
|
||||||
zone= response.body['HostedZone']
|
zone = response.body['HostedZone']
|
||||||
change_info = response.body['ChangeInfo']
|
change_info = response.body['ChangeInfo']
|
||||||
ns_servers = response.body['NameServers']
|
ns_servers = response.body['NameServers']
|
||||||
|
|
||||||
if (zone and change_info and ns_servers)
|
if (zone and change_info and ns_servers)
|
||||||
|
|
||||||
|
@ -82,11 +58,11 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do
|
||||||
pending if Fog.mocking?
|
pending if Fog.mocking?
|
||||||
|
|
||||||
result = false
|
result = false
|
||||||
response = Fog::DNS[:aws].get_change(@change_id)
|
response = @r53_connection.get_change(@change_id)
|
||||||
if response.status == 200
|
if response.status == 200
|
||||||
status = response.body['Status']
|
status = response.body['Status']
|
||||||
if (status == 'PENDING') or (status == 'INSYNC')
|
if (status == 'PENDING') or (status == 'INSYNC')
|
||||||
result= true
|
result = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -98,7 +74,7 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do
|
||||||
|
|
||||||
result = false
|
result = false
|
||||||
|
|
||||||
response = Fog::DNS[:aws].get_hosted_zone( @zone_id)
|
response = @r53_connection.get_hosted_zone(@zone_id)
|
||||||
if response.status == 200
|
if response.status == 200
|
||||||
zone = response.body['HostedZone']
|
zone = response.body['HostedZone']
|
||||||
zone_id = zone['Id']
|
zone_id = zone['Id']
|
||||||
|
@ -108,7 +84,7 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do
|
||||||
|
|
||||||
# AWS returns domain with a dot at end - so when compare, remove dot
|
# AWS returns domain with a dot at end - so when compare, remove dot
|
||||||
|
|
||||||
if (zone_id == @zone_id) and (name.chop == @test_domain) and (caller_ref.length > 0) and
|
if (zone_id == @zone_id) and (name.chop == @domain_name) and (caller_ref.length > 0) and
|
||||||
(ns_servers.count > 0)
|
(ns_servers.count > 0)
|
||||||
result = true
|
result = true
|
||||||
end
|
end
|
||||||
|
@ -122,12 +98,12 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do
|
||||||
|
|
||||||
result = false
|
result = false
|
||||||
|
|
||||||
response = Fog::DNS[:aws].list_hosted_zones()
|
response = @r53_connection.list_hosted_zones
|
||||||
if response.status == 200
|
if response.status == 200
|
||||||
|
|
||||||
zones= response.body['HostedZones']
|
zones= response.body['HostedZones']
|
||||||
if (zones.count > 0)
|
if (zones.count > 0)
|
||||||
zone= zones[0]
|
zone = zones[0]
|
||||||
zone_id = zone['Id']
|
zone_id = zone['Id']
|
||||||
zone_name= zone['Name']
|
zone_name= zone['Name']
|
||||||
caller_ref = zone['CallerReference']
|
caller_ref = zone['CallerReference']
|
||||||
|
@ -146,18 +122,16 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do
|
||||||
test("add a A resource record") {
|
test("add a A resource record") {
|
||||||
pending if Fog.mocking?
|
pending if Fog.mocking?
|
||||||
|
|
||||||
result = false
|
|
||||||
|
|
||||||
# create an A resource record
|
# create an A resource record
|
||||||
host = 'www.' + @test_domain
|
host = 'www.' + @domain_name
|
||||||
ip_addrs = ['1.2.3.4']
|
ip_addrs = ['1.2.3.4']
|
||||||
resource_record = { :name => host, :type => 'A', :ttl => 3600, :resource_records => ip_addrs }
|
resource_record = { :name => host, :type => 'A', :ttl => 3600, :resource_records => ip_addrs }
|
||||||
resource_record_set = resource_record.merge( :action => 'CREATE')
|
resource_record_set = resource_record.merge(:action => 'CREATE')
|
||||||
|
|
||||||
change_batch = []
|
change_batch = []
|
||||||
change_batch << resource_record_set
|
change_batch << resource_record_set
|
||||||
options = { :comment => 'add A record to domain'}
|
options = { :comment => 'add A record to domain'}
|
||||||
response = Fog::DNS[:aws].change_resource_record_sets( @zone_id, change_batch, options)
|
response = @r53_connection.change_resource_record_sets(@zone_id, change_batch, options)
|
||||||
if response.status == 200
|
if response.status == 200
|
||||||
change_id = response.body['Id']
|
change_id = response.body['Id']
|
||||||
status = response.body['Status']
|
status = response.body['Status']
|
||||||
|
@ -170,18 +144,16 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do
|
||||||
test("add a CNAME resource record") {
|
test("add a CNAME resource record") {
|
||||||
pending if Fog.mocking?
|
pending if Fog.mocking?
|
||||||
|
|
||||||
result = false
|
|
||||||
|
|
||||||
# create a CNAME resource record
|
# create a CNAME resource record
|
||||||
host = 'mail.' + @test_domain
|
host = 'mail.' + @domain_name
|
||||||
value = ['www.' + @test_domain]
|
value = ['www.' + @domain_name]
|
||||||
resource_record = { :name => host, :type => 'CNAME', :ttl => 3600, :resource_records => value }
|
resource_record = { :name => host, :type => 'CNAME', :ttl => 3600, :resource_records => value }
|
||||||
resource_record_set = resource_record.merge( :action => 'CREATE')
|
resource_record_set = resource_record.merge(:action => 'CREATE')
|
||||||
|
|
||||||
change_batch = []
|
change_batch = []
|
||||||
change_batch << resource_record_set
|
change_batch << resource_record_set
|
||||||
options = { :comment => 'add CNAME record to domain'}
|
options = { :comment => 'add CNAME record to domain'}
|
||||||
response = Fog::DNS[:aws].change_resource_record_sets( @zone_id, change_batch, options)
|
response = @r53_connection.change_resource_record_sets( @zone_id, change_batch, options)
|
||||||
if response.status == 200
|
if response.status == 200
|
||||||
change_id = response.body['Id']
|
change_id = response.body['Id']
|
||||||
status = response.body['Status']
|
status = response.body['Status']
|
||||||
|
@ -194,18 +166,16 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do
|
||||||
test("add a MX resource record") {
|
test("add a MX resource record") {
|
||||||
pending if Fog.mocking?
|
pending if Fog.mocking?
|
||||||
|
|
||||||
result = false
|
|
||||||
|
|
||||||
# create a MX resource record
|
# create a MX resource record
|
||||||
host = @test_domain
|
host = @domain_name
|
||||||
value = ['7 mail.' + @test_domain]
|
value = ['7 mail.' + @domain_name]
|
||||||
resource_record = { :name => host, :type => 'MX', :ttl => 3600, :resource_records => value }
|
resource_record = { :name => host, :type => 'MX', :ttl => 3600, :resource_records => value }
|
||||||
resource_record_set = resource_record.merge( :action => 'CREATE')
|
resource_record_set = resource_record.merge( :action => 'CREATE')
|
||||||
|
|
||||||
change_batch = []
|
change_batch = []
|
||||||
change_batch << resource_record_set
|
change_batch << resource_record_set
|
||||||
options = { :comment => 'add MX record to domain'}
|
options = { :comment => 'add MX record to domain'}
|
||||||
response = Fog::DNS[:aws].change_resource_record_sets( @zone_id, change_batch, options)
|
response = @r53_connection.change_resource_record_sets( @zone_id, change_batch, options)
|
||||||
if response.status == 200
|
if response.status == 200
|
||||||
change_id = response.body['Id']
|
change_id = response.body['Id']
|
||||||
status = response.body['Status']
|
status = response.body['Status']
|
||||||
|
@ -220,18 +190,17 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do
|
||||||
|
|
||||||
# create a load balancer
|
# create a load balancer
|
||||||
@elb_connection.create_load_balancer(["us-east-1a"], "fog", [{"Protocol" => "HTTP", "LoadBalancerPort" => "80", "InstancePort" => "80"}])
|
@elb_connection.create_load_balancer(["us-east-1a"], "fog", [{"Protocol" => "HTTP", "LoadBalancerPort" => "80", "InstancePort" => "80"}])
|
||||||
|
|
||||||
elb_response = @elb_connection.describe_load_balancers("fog")
|
elb_response = @elb_connection.describe_load_balancers("fog")
|
||||||
elb = elb_response.body["DescribeLoadBalancersResult"]["LoadBalancerDescriptions"].first
|
elb = elb_response.body["DescribeLoadBalancersResult"]["LoadBalancerDescriptions"].first
|
||||||
hosted_zone_id = elb["CanonicalHostedZoneNameID"]
|
hosted_zone_id = elb["CanonicalHostedZoneNameID"]
|
||||||
dns_name = elb["DNSName"]
|
dns_name = elb["DNSName"]
|
||||||
|
|
||||||
result = false
|
|
||||||
|
|
||||||
# create an ALIAS record
|
# create an ALIAS record
|
||||||
host = @test_domain
|
host = @domain_name
|
||||||
alias_target = {
|
alias_target = {
|
||||||
hosted_zone_id: hosted_zone_id,
|
:hosted_zone_id => hosted_zone_id,
|
||||||
dns_name: dns_name
|
:dns_name => dns_name
|
||||||
}
|
}
|
||||||
resource_record = { :name => host, :type => 'A', :alias_target => alias_target }
|
resource_record = { :name => host, :type => 'A', :alias_target => alias_target }
|
||||||
resource_record_set = resource_record.merge(:action => 'CREATE')
|
resource_record_set = resource_record.merge(:action => 'CREATE')
|
||||||
|
@ -239,7 +208,13 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do
|
||||||
change_batch = []
|
change_batch = []
|
||||||
change_batch << resource_record_set
|
change_batch << resource_record_set
|
||||||
options = { :comment => 'add ALIAS record to domain'}
|
options = { :comment => 'add ALIAS record to domain'}
|
||||||
response = Fog::DNS[:aws].change_resource_record_sets(@zone_id, change_batch, options)
|
|
||||||
|
puts "Hosted Zone ID (ELB): #{hosted_zone_id}"
|
||||||
|
puts "DNS Name (ELB): #{dns_name}"
|
||||||
|
puts "Zone ID for Route 53: #{@zone_id}"
|
||||||
|
|
||||||
|
sleep 120
|
||||||
|
response = @r53_connection.change_resource_record_sets(@zone_id, change_batch, options)
|
||||||
if response.status == 200
|
if response.status == 200
|
||||||
change_id = response.body['Id']
|
change_id = response.body['Id']
|
||||||
status = response.body['Status']
|
status = response.body['Status']
|
||||||
|
@ -253,7 +228,7 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do
|
||||||
pending if Fog.mocking?
|
pending if Fog.mocking?
|
||||||
|
|
||||||
# get resource records for zone
|
# get resource records for zone
|
||||||
response = Fog::DNS[:aws].list_resource_record_sets( @zone_id)
|
response = @r53_connection.list_resource_record_sets( @zone_id)
|
||||||
if response.status == 200
|
if response.status == 200
|
||||||
record_sets= response.body['ResourceRecordSets']
|
record_sets= response.body['ResourceRecordSets']
|
||||||
num_records= record_sets.count
|
num_records= record_sets.count
|
||||||
|
@ -273,7 +248,7 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do
|
||||||
change_batch << resource_record_set
|
change_batch << resource_record_set
|
||||||
}
|
}
|
||||||
options = { :comment => 'remove records from domain'}
|
options = { :comment => 'remove records from domain'}
|
||||||
response = Fog::DNS[:aws].change_resource_record_sets(@zone_id, change_batch, options)
|
response = @r53_connection.change_resource_record_sets(@zone_id, change_batch, options)
|
||||||
if response.status != 200
|
if response.status != 200
|
||||||
result = false
|
result = false
|
||||||
break
|
break
|
||||||
|
@ -288,7 +263,7 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do
|
||||||
# cleanup the ELB as well
|
# cleanup the ELB as well
|
||||||
@elb_connection.delete_load_balancer("fog")
|
@elb_connection.delete_load_balancer("fog")
|
||||||
|
|
||||||
response = Fog::DNS[:aws].delete_hosted_zone(@zone_id)
|
response = @r53_connection.delete_hosted_zone(@zone_id)
|
||||||
|
|
||||||
response.status == 200
|
response.status == 200
|
||||||
}
|
}
|
||||||
|
@ -296,16 +271,16 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
tests( 'failure') do
|
tests('failure') do
|
||||||
tests('create hosted zone using invalid domain name').raises(Excon::Errors::BadRequest) do
|
tests('create hosted zone using invalid domain name').raises(Excon::Errors::BadRequest) do
|
||||||
pending if Fog.mocking?
|
pending if Fog.mocking?
|
||||||
response = Fog::DNS[:aws].create_hosted_zone('invalid-domain')
|
response = @r53_connection.create_hosted_zone('invalid-domain')
|
||||||
end
|
end
|
||||||
|
|
||||||
tests('get hosted zone using invalid ID').raises(Excon::Errors::Forbidden) do
|
tests('get hosted zone using invalid ID').raises(Excon::Errors::Forbidden) do
|
||||||
pending if Fog.mocking?
|
pending if Fog.mocking?
|
||||||
zone_id = 'dummy-id'
|
zone_id = 'dummy-id'
|
||||||
response = Fog::DNS[:aws].get_hosted_zone(zone_id)
|
response = @r53_connection.get_hosted_zone(zone_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue