diff --git a/lib/fog/aws/dns.rb b/lib/fog/aws/dns.rb index 30c1d983f..e8f2c2f8a 100644 --- a/lib/fog/aws/dns.rb +++ b/lib/fog/aws/dns.rb @@ -89,7 +89,7 @@ module Fog @persistent = options[:persistent] || true @port = options[:port] || 443 @scheme = options[:scheme] || 'https' - @version = options[:version] || '2010-10-01' + @version = options[:version] || '2011-05-05' @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options) end @@ -104,7 +104,7 @@ module Fog params[:headers] ||= {} params[:headers]['Date'] = Fog::Time.now.to_date_header params[:headers]['X-Amzn-Authorization'] = "AWS3-HTTPS AWSAccessKeyId=#{@aws_access_key_id},Algorithm=HmacSHA1,Signature=#{signature(params)}" - params[:path] = "/#{@version}/#{params[:path]}" + params[:path] = "/#{@version}/#{params[:path]}" @connection.request(params, &block) end diff --git a/lib/fog/aws/parsers/dns/list_resource_record_sets.rb b/lib/fog/aws/parsers/dns/list_resource_record_sets.rb index 62fa180b7..da93e97ca 100644 --- a/lib/fog/aws/parsers/dns/list_resource_record_sets.rb +++ b/lib/fog/aws/parsers/dns/list_resource_record_sets.rb @@ -9,11 +9,12 @@ module Fog @resource_record = [] @resource_record_set = {} @resource_record_set['ResourceRecords'] = [] + @alias_target = {} @response = {} @response['ResourceRecordSets'] = [] @section = :resource_record_set end - + def end_element(name) if @section == :resource_record_set case name @@ -21,6 +22,11 @@ module Fog @resource_record_set[name] = value when 'Value' @resource_record_set['ResourceRecords'] << value + when 'AliasTarget' + @resource_record_set[name] = @alias_target + @alias_target = {} + when 'HostedZoneId', 'DNSName' + @alias_target[name] = value when 'ResourceRecordSet' @response['ResourceRecordSets'] << @resource_record_set @resource_record_set = {} @@ -29,12 +35,12 @@ module Fog @section = :main end elsif @section == :main - case name - when 'MaxItems' - @response[name]= value.to_i - when 'IsTruncated', 'NextRecordName', 'NextRecordType' - @response[name]= value - end + case name + when 'MaxItems' + @response[name] = value.to_i + when 'IsTruncated', 'NextRecordName', 'NextRecordType' + @response[name] = value + end end end diff --git a/lib/fog/aws/requests/dns/change_resource_record_sets.rb b/lib/fog/aws/requests/dns/change_resource_record_sets.rb index 23728e62c..0f07ae74b 100644 --- a/lib/fog/aws/requests/dns/change_resource_record_sets.rb +++ b/lib/fog/aws/requests/dns/change_resource_record_sets.rb @@ -13,11 +13,14 @@ module Fog # * comment<~String> - Any comments you want to include about the change. # * change_batch<~Array> - The information for a change request # * changes<~Hash> - - # * action<~String> - 'CREATE' or 'DELETE' + # * action<~String> - 'CREATE' or 'DELETE' # * name<~String> - This must be a fully-specified name, ending with a final period - # * type<~String> - A | AAAA | CNAME | MX | NS | PTR | SOA | SPF | SRV | TXT - # * ttl<~Integer> - - # * resource_record<~String> + # * type<~String> - A | AAAA | CNAME | MX | NS | PTR | SOA | SPF | SRV | TXT + # * ttl<~Integer> - Time-to-live value - omit if using an alias record + # * resource_record<~String> - Omit if using an alias record + # * alias_target<~Hash> - Information about the domain to which you are redirecting traffic (Alias record sets only) + # * dns_name<~String> - The Elastic Load Balancing domain to which you want to reroute traffic + # * hosted_zone_id<~String> - The ID of the hosted zone that contains the Elastic Load Balancing domain to which you want to reroute traffic # # ==== Returns # * response<~Excon::Response>: @@ -29,43 +32,55 @@ module Fog # * status<~Integer> - 201 when successful def change_resource_record_sets(zone_id, change_batch, options = {}) - # AWS methods return zone_ids that looks like '/hostedzone/id'. Let the caller either use + # AWS methods return zone_ids that looks like '/hostedzone/id'. Let the caller either use # that form or just the actual id (which is what this request needs) zone_id = zone_id.sub('/hostedzone/', '') optional_tags = '' - options.each { |option, value| + options.each do |option, value| case option when :comment - optional_tags+= "#{value}" + optional_tags += "#{value}" end - } - - #build XML - if change_batch.count > 0 - - changes= "#{optional_tags}" - - change_batch.each { |change_item| - action_tag = %Q{#{change_item[:action]}} - name_tag = %Q{#{change_item[:name]}} - type_tag = %Q{#{change_item[:type]}} - ttl_tag = %Q{#{change_item[:ttl]}} - resource_records= change_item[:resource_records] - resource_record_tags = '' - resource_records.each { |record| - resource_record_tags+= %Q{#{record}} - } - resource_tag= %Q{#{resource_record_tags}} - - change_tags = %Q{#{action_tag}#{name_tag}#{type_tag}#{ttl_tag}#{resource_tag}} - changes+= change_tags - } - - changes+= '' end - body = %Q{#{changes}} + #build XML + if change_batch.count > 0 + + changes = "#{optional_tags}" + + change_batch.each do |change_item| + action_tag = %Q{#{change_item[:action]}} + name_tag = %Q{#{change_item[:name]}} + type_tag = %Q{#{change_item[:type]}} + + # TTL must be omitted if using an alias record + ttl_tag = '' + ttl_tag += %Q{#{change_item[:ttl]}} unless change_item[:alias_target] + + resource_records = change_item[:resource_records] || [] + resource_record_tags = '' + resource_records.each do |record| + resource_record_tags += %Q{#{record}} + end + + # ResourceRecords must be omitted if using an alias record + resource_tag = '' + resource_tag += %Q{#{resource_record_tags}} if resource_records.any? + + alias_target_tag = '' + if change_item[:alias_target] + alias_target_tag += %Q{#{change_item[:alias_target][:hosted_zone_id]}#{change_item[:alias_target][:dns_name]}} + end + + change_tags = %Q{#{action_tag}#{name_tag}#{type_tag}#{ttl_tag}#{resource_tag}#{alias_target_tag}} + changes += change_tags + end + + changes += '' + end + + body = %Q{#{changes}} request({ :body => body, :parser => Fog::Parsers::DNS::AWS::ChangeResourceRecordSets.new, diff --git a/lib/fog/aws/requests/dns/create_hosted_zone.rb b/lib/fog/aws/requests/dns/create_hosted_zone.rb index 4a26142cd..c07345fa8 100644 --- a/lib/fog/aws/requests/dns/create_hosted_zone.rb +++ b/lib/fog/aws/requests/dns/create_hosted_zone.rb @@ -12,7 +12,7 @@ module Fog # * options<~Hash> # * caller_ref<~String> - unique string that identifies the request & allows failed # calls to be retried without the risk of executing the operation twice - # * comment<~Integer> - + # * comment<~String> - # # ==== Returns # * response<~Excon::Response>: @@ -33,22 +33,22 @@ module Fog optional_tags = '' if options[:caller_ref] - optional_tags+= "#{options[:caller_ref]}" + optional_tags += "#{options[:caller_ref]}" else #make sure we have a unique call reference caller_ref = "ref-#{rand(1000000).to_s}" - optional_tags+= "#{caller_ref}" + optional_tags += "#{caller_ref}" end if options[:comment] - optional_tags+= "#{options[:comment]}" + optional_tags += "#{options[:comment]}" end request({ - :body => %Q{#{name}#{optional_tags}}, - :parser => Fog::Parsers::DNS::AWS::CreateHostedZone.new, - :expects => 201, - :method => 'POST', - :path => "hostedzone" + :body => %Q{#{name}#{optional_tags}}, + :parser => Fog::Parsers::DNS::AWS::CreateHostedZone.new, + :expects => 201, + :method => 'POST', + :path => "hostedzone" }) end diff --git a/lib/fog/aws/requests/dns/delete_hosted_zone.rb b/lib/fog/aws/requests/dns/delete_hosted_zone.rb index 9b860695a..307909b87 100644 --- a/lib/fog/aws/requests/dns/delete_hosted_zone.rb +++ b/lib/fog/aws/requests/dns/delete_hosted_zone.rb @@ -8,7 +8,7 @@ module Fog # Delete a hosted zone # # ==== Parameters - # * zone_id<~String> - + # * zone_id<~String> - # # ==== Returns # * response<~Excon::Response>: @@ -20,15 +20,15 @@ module Fog # * status<~Integer> - 200 when successful def delete_hosted_zone(zone_id) - # AWS methods return zone_ids that looks like '/hostedzone/id'. Let the caller either use + # AWS methods return zone_ids that looks like '/hostedzone/id'. Let the caller either use # that form or just the actual id (which is what this request needs) zone_id = zone_id.sub('/hostedzone/', '') - + request({ - :expects => 200, - :parser => Fog::Parsers::DNS::AWS::DeleteHostedZone.new, - :method => 'DELETE', - :path => "hostedzone/#{zone_id}" + :expects => 200, + :parser => Fog::Parsers::DNS::AWS::DeleteHostedZone.new, + :method => 'DELETE', + :path => "hostedzone/#{zone_id}" }) end diff --git a/lib/fog/aws/requests/dns/get_change.rb b/lib/fog/aws/requests/dns/get_change.rb index 2910d2237..5f2808c96 100644 --- a/lib/fog/aws/requests/dns/get_change.rb +++ b/lib/fog/aws/requests/dns/get_change.rb @@ -19,15 +19,15 @@ module Fog # * status<~Integer> - 200 when successful def get_change(change_id) - # AWS methods return change_ids that looks like '/change/id'. Let the caller either use + # AWS methods return change_ids that looks like '/change/id'. Let the caller either use # that form or just the actual id (which is what this request needs) change_id = change_id.sub('/change/', '') request({ - :expects => 200, - :parser => Fog::Parsers::DNS::AWS::GetChange.new, - :method => 'GET', - :path => "change/#{change_id}" + :expects => 200, + :parser => Fog::Parsers::DNS::AWS::GetChange.new, + :method => 'GET', + :path => "change/#{change_id}" }) end diff --git a/lib/fog/aws/requests/dns/get_hosted_zone.rb b/lib/fog/aws/requests/dns/get_hosted_zone.rb index b9ea88b93..2fa86dd0d 100644 --- a/lib/fog/aws/requests/dns/get_hosted_zone.rb +++ b/lib/fog/aws/requests/dns/get_hosted_zone.rb @@ -14,24 +14,24 @@ module Fog # * response<~Excon::Response>: # * body<~Hash>: # * 'HostedZone'<~Hash>: - # * 'Id'<~String> - - # * 'Name'<~String> - + # * 'Id'<~String> - + # * 'Name'<~String> - # * 'CallerReference'<~String> - # * 'Comment'<~String> - + # * 'Comment'<~String> - # * 'NameServers'<~Array> # * 'NameServer'<~String> # * status<~Integer> - 201 when successful def get_hosted_zone(zone_id) - # AWS methods return zone_ids that looks like '/hostedzone/id'. Let the caller either use + # AWS methods return zone_ids that looks like '/hostedzone/id'. Let the caller either use # that form or just the actual id (which is what this request needs) zone_id = zone_id.sub('/hostedzone/', '') request({ - :expects => 200, - :parser => Fog::Parsers::DNS::AWS::GetHostedZone.new, - :method => 'GET', - :path => "hostedzone/#{zone_id}" + :expects => 200, + :parser => Fog::Parsers::DNS::AWS::GetHostedZone.new, + :method => 'GET', + :path => "hostedzone/#{zone_id}" }) end diff --git a/lib/fog/aws/requests/dns/list_hosted_zones.rb b/lib/fog/aws/requests/dns/list_hosted_zones.rb index 8b4d28c66..df6f87860 100644 --- a/lib/fog/aws/requests/dns/list_hosted_zones.rb +++ b/lib/fog/aws/requests/dns/list_hosted_zones.rb @@ -9,7 +9,7 @@ module Fog # # ==== Parameters # * options<~Hash> - # * marker<~String> - Indicates where to begin in your list of hosted zones. + # * marker<~String> - Indicates where to begin in your list of hosted zones. # * max_items<~Integer> - The maximum number of hosted zones to be included in the response body # # ==== Returns @@ -17,33 +17,33 @@ module Fog # * body<~Hash>: # * 'HostedZones'<~Array>: # * 'HostedZone'<~Hash>: - # * 'Id'<~String> - - # * 'Name'<~String> - + # * 'Id'<~String> - + # * 'Name'<~String> - # * 'CallerReference'<~String> - # * 'Comment'<~String> - - # * 'Marker'<~String> - - # * 'MaxItems'<~Integer> - - # * 'IsTruncated'<~String> - + # * 'Comment'<~String> - + # * 'Marker'<~String> - + # * 'MaxItems'<~Integer> - + # * 'IsTruncated'<~String> - # * 'NextMarket'<~String> # * status<~Integer> - 200 when successful def list_hosted_zones(options = {}) parameters = {} - options.each { |option, value| + options.each do |option, value| case option when :marker parameters[option] = value when :max_items parameters[:maxitems] = value end - } - + end + request({ - :query => parameters, - :parser => Fog::Parsers::DNS::AWS::ListHostedZones.new, - :expects => 200, - :method => 'GET', - :path => "hostedzone" + :query => parameters, + :parser => Fog::Parsers::DNS::AWS::ListHostedZones.new, + :expects => 200, + :method => 'GET', + :path => "hostedzone" }) end diff --git a/lib/fog/aws/requests/dns/list_resource_record_sets.rb b/lib/fog/aws/requests/dns/list_resource_record_sets.rb index 1c16046ca..5b890278b 100644 --- a/lib/fog/aws/requests/dns/list_resource_record_sets.rb +++ b/lib/fog/aws/requests/dns/list_resource_record_sets.rb @@ -8,48 +8,51 @@ module Fog # list your resource record sets # # ==== Parameters - # * zone_id<~String> - + # * zone_id<~String> - # * options<~Hash> - # * type<~String> - + # * type<~String> - # * name<~String> - - # * max_items<~Integer> - + # * max_items<~Integer> - # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * 'ResourceRecordSet'<~Array>: - # * 'Name'<~String> - - # * 'Type'<~String> - - # * 'TTL'<~Integer> - + # * 'Name'<~String> - + # * 'Type'<~String> - + # * 'TTL'<~Integer> - + # * 'AliasTarget'<~Hash> - + # * 'HostedZoneId'<~String> - + # * 'DNSName'<~String> - # * 'ResourceRecords'<~Array> - # * 'Value'<~String> - - # * 'IsTruncated'<~String> - - # * 'MaxItems'<~String> - + # * 'Value'<~String> - + # * 'IsTruncated'<~String> - + # * 'MaxItems'<~String> - # * 'NextRecordName'<~String> # * 'NexRecordType'<~String> # * status<~Integer> - 201 when successful def list_resource_record_sets(zone_id, options = {}) - # AWS methods return zone_ids that looks like '/hostedzone/id'. Let the caller either use + # AWS methods return zone_ids that looks like '/hostedzone/id'. Let the caller either use # that form or just the actual id (which is what this request needs) zone_id = zone_id.sub('/hostedzone/', '') parameters = {} - options.each { |option, value| + options.each do |option, value| case option when :type, :name - parameters[option]= "#{value}" + parameters[option] = "#{value}" when :max_items - parameters['maxitems']= "#{value}" + parameters['maxitems'] = "#{value}" end - } - + end + request({ - :query => parameters, - :parser => Fog::Parsers::DNS::AWS::ListResourceRecordSets.new, - :expects => 200, - :method => 'GET', - :path => "hostedzone/#{zone_id}/rrset" + :query => parameters, + :parser => Fog::Parsers::DNS::AWS::ListResourceRecordSets.new, + :expects => 200, + :method => 'GET', + :path => "hostedzone/#{zone_id}/rrset" }) end diff --git a/tests/aws/requests/dns/dns_tests.rb b/tests/aws/requests/dns/dns_tests.rb index c1cbe964d..65983d912 100644 --- a/tests/aws/requests/dns/dns_tests.rb +++ b/tests/aws/requests/dns/dns_tests.rb @@ -3,42 +3,19 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do @org_zone_count = 0 @zone_id = '' @change_id = '' - @new_records =[] - - # 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' - - tests( 'success') do + @new_records = [] + @domain_name = generate_unique_domain - 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 + @elb_connection = Fog::AWS::ELB.new + @r53_connection = Fog::DNS[:aws] + + tests('success') do - #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 pending if Fog.mocking? @org_zone_count= 0 - response = Fog::DNS[:aws].list_hosted_zones() + response = @r53_connection.list_hosted_zones if response.status == 200 @hosted_zones = response.body['HostedZones'] @org_zone_count = @hosted_zones.count @@ -51,13 +28,13 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do pending if Fog.mocking? result = false - - response = Fog::DNS[:aws].create_hosted_zone( @test_domain) + + response = @r53_connection.create_hosted_zone(@domain_name) if response.status == 201 - zone= response.body['HostedZone'] + zone = response.body['HostedZone'] change_info = response.body['ChangeInfo'] - ns_servers = response.body['NameServers'] + ns_servers = response.body['NameServers'] if (zone and change_info and ns_servers) @@ -66,7 +43,7 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do @change_id = change_info['Id'] status = change_info['Status'] ns_srv_count = ns_servers.count - + if (@zone_id.length > 0) and (caller_ref.length > 0) and (@change_id.length > 0) and (status.length > 0) and (ns_srv_count > 0) result = true @@ -76,28 +53,28 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do result } - + test("get status of change #{@change_id}") { pending if Fog.mocking? result = false - response = Fog::DNS[:aws].get_change(@change_id) + response = @r53_connection.get_change(@change_id) if response.status == 200 status = response.body['Status'] if (status == 'PENDING') or (status == 'INSYNC') - result= true + result = true end end - + result } - + test("get info on hosted zone #{@zone_id}") { pending if Fog.mocking? result = false - - response = Fog::DNS[:aws].get_hosted_zone( @zone_id) + + response = @r53_connection.get_hosted_zone(@zone_id) if response.status == 200 zone = response.body['HostedZone'] zone_id = zone['Id'] @@ -106,111 +83,144 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do ns_servers = response.body['NameServers'] # 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) result = true end end - + result } - + test('list zones') do pending if Fog.mocking? result = false - - response = Fog::DNS[:aws].list_hosted_zones() + + response = @r53_connection.list_hosted_zones if response.status == 200 - + zones= response.body['HostedZones'] if (zones.count > 0) - zone= zones[0] + zone = zones[0] zone_id = zone['Id'] zone_name= zone['Name'] caller_ref = zone['CallerReference'] end max_items = response.body['MaxItems'] - - if (zone_id.length > 0) and (zone_name.length > 0) and (caller_ref.length > 0) and + + if (zone_id.length > 0) and (zone_name.length > 0) and (caller_ref.length > 0) and (max_items > 0) result = true - end + end end result end - + test("add a A resource record") { pending if Fog.mocking? - result = false - # create an A resource record - host = 'www.' + @test_domain + host = 'www.' + @domain_name ip_addrs = ['1.2.3.4'] 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 << resource_record_set - options = { :comment => 'add A record to domain'} - response = Fog::DNS[:aws].change_resource_record_sets( @zone_id, change_batch, options) + options = { :comment => 'add A record to domain'} + response = @r53_connection.change_resource_record_sets(@zone_id, change_batch, options) if response.status == 200 change_id = response.body['Id'] status = response.body['Status'] @new_records << resource_record end - + response.status == 200 } test("add a CNAME resource record") { pending if Fog.mocking? - result = false - # create a CNAME resource record - host = 'mail.' + @test_domain - value = ['www.' + @test_domain] + host = 'mail.' + @domain_name + value = ['www.' + @domain_name] 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 << resource_record_set - options = { :comment => 'add CNAME record to domain'} - response = Fog::DNS[:aws].change_resource_record_sets( @zone_id, change_batch, options) + options = { :comment => 'add CNAME record to domain'} + response = @r53_connection.change_resource_record_sets( @zone_id, change_batch, options) if response.status == 200 change_id = response.body['Id'] status = response.body['Status'] @new_records << resource_record end - + response.status == 200 } - + test("add a MX resource record") { pending if Fog.mocking? - result = false - # create a MX resource record - host = @test_domain - value = ['7 mail.' + @test_domain] + host = @domain_name + value = ['7 mail.' + @domain_name] resource_record = { :name => host, :type => 'MX', :ttl => 3600, :resource_records => value } resource_record_set = resource_record.merge( :action => 'CREATE') - + change_batch = [] change_batch << resource_record_set - options = { :comment => 'add MX record to domain'} - response = Fog::DNS[:aws].change_resource_record_sets( @zone_id, change_batch, options) + options = { :comment => 'add MX record to domain'} + response = @r53_connection.change_resource_record_sets( @zone_id, change_batch, options) if response.status == 200 change_id = response.body['Id'] status = response.body['Status'] @new_records << resource_record end - + + response.status == 200 + } + + test("add an ALIAS resource record") { + pending if Fog.mocking? + + # create a load balancer + @elb_connection.create_load_balancer(["us-east-1a"], "fog", [{"Protocol" => "HTTP", "LoadBalancerPort" => "80", "InstancePort" => "80"}]) + + elb_response = @elb_connection.describe_load_balancers("fog") + elb = elb_response.body["DescribeLoadBalancersResult"]["LoadBalancerDescriptions"].first + hosted_zone_id = elb["CanonicalHostedZoneNameID"] + dns_name = elb["DNSName"] + + # create an ALIAS record + host = @domain_name + alias_target = { + :hosted_zone_id => hosted_zone_id, + :dns_name => dns_name + } + resource_record = { :name => host, :type => 'A', :alias_target => alias_target } + resource_record_set = resource_record.merge(:action => 'CREATE') + + change_batch = [] + change_batch << resource_record_set + options = { :comment => 'add ALIAS record to domain'} + + 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 + change_id = response.body['Id'] + status = response.body['Status'] + @new_records << resource_record + end + response.status == 200 } @@ -218,7 +228,7 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do pending if Fog.mocking? # 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 record_sets= response.body['ResourceRecordSets'] num_records= record_sets.count @@ -231,14 +241,14 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do pending if Fog.mocking? result = true - + change_batch = [] - @new_records.each { |record| + @new_records.each { |record| resource_record_set = record.merge( :action => 'DELETE') change_batch << resource_record_set } - options = { :comment => 'remove records from domain'} - response = Fog::DNS[:aws].change_resource_record_sets( @zone_id, change_batch, options) + options = { :comment => 'remove records from domain'} + response = @r53_connection.change_resource_record_sets(@zone_id, change_batch, options) if response.status != 200 result = false break @@ -246,31 +256,34 @@ Shindo.tests('Fog::DNS[:aws] | DNS requests', ['aws', 'dns']) do result } - + test("delete hosted zone #{@zone_id}") { pending if Fog.mocking? - response = Fog::DNS[:aws].delete_hosted_zone( @zone_id) + # cleanup the ELB as well + @elb_connection.delete_load_balancer("fog") + + response = @r53_connection.delete_hosted_zone(@zone_id) response.status == 200 } - + end - tests( 'failure') do + tests('failure') do tests('create hosted zone using invalid domain name').raises(Excon::Errors::BadRequest) do pending if Fog.mocking? - response = Fog::DNS[:aws].create_hosted_zone('invalid-domain') + response = @r53_connection.create_hosted_zone('invalid-domain') end - + tests('get hosted zone using invalid ID').raises(Excon::Errors::Forbidden) do pending if Fog.mocking? zone_id = 'dummy-id' - response = Fog::DNS[:aws].get_hosted_zone(zone_id) + response = @r53_connection.get_hosted_zone(zone_id) end - + end - + end