From 32ad91a777f0b482eb2b9d329d3009ad46b22293 Mon Sep 17 00:00:00 2001 From: Patrick McKenzie Date: Tue, 8 Nov 2011 13:11:08 +0900 Subject: [PATCH 01/11] Slicehost uses record-type and zone-id for their API, which messes with Fog internals, so changing these to record_type and zone_id in the parser. --- lib/fog/slicehost/parsers/dns/get_records.rb | 8 ++++++-- lib/fog/slicehost/requests/dns/get_records.rb | 15 +++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/fog/slicehost/parsers/dns/get_records.rb b/lib/fog/slicehost/parsers/dns/get_records.rb index fb18aef32..b170f8aee 100644 --- a/lib/fog/slicehost/parsers/dns/get_records.rb +++ b/lib/fog/slicehost/parsers/dns/get_records.rb @@ -12,9 +12,13 @@ module Fog def end_element(name) case name - when 'zone-id', 'ttl' + when 'zone-id' + @record["zone_id"] = value.to_i + when 'record-type' + @record["record_type"] = value + when 'ttl' @record[name] = value.to_i - when 'record-type', 'name', 'data', 'active', 'aux' + when 'name', 'data', 'active', 'aux' @record[name] = value when 'record' @response['records'] << @record diff --git a/lib/fog/slicehost/requests/dns/get_records.rb b/lib/fog/slicehost/requests/dns/get_records.rb index b56c6687e..c774e61bc 100644 --- a/lib/fog/slicehost/requests/dns/get_records.rb +++ b/lib/fog/slicehost/requests/dns/get_records.rb @@ -10,14 +10,13 @@ module Fog # ==== Returns # * response<~Excon::Response>: # * body<~Array>: - # * 'addresses'<~Array> - Ip addresses for the slice - # * 'backup-id'<~Integer> - Id of backup slice was booted from - # * 'flavor_id'<~Integer> - Id of flavor slice was booted from - # * 'id'<~Integer> - Id of the slice - # * 'image-id'<~Integer> - Id of image slice was booted from - # * 'name'<~String> - Name of the slice - # * 'progress'<~Integer> - Progress of current action, in percentage - # * 'status'<~String> - Current status of the slice + # * 'name'<~String> - Record NAME field (e.g. "example.org." or "www") + # * 'data'<~String> - Data contained by the record (e.g. an IP address, for A records) + # * 'record-type'<~String> - Type of record (A, CNAME, TXT, etc) + # * 'aux'<~String> - Aux data for the record, for those types which have it (e.g. TXT) + # * 'zone-id'<~Integer> - zone ID to which this record belongs + # * 'active'<~String> - whether this record is active in the Slicehost DNS (Y for yes, N for no) + # * 'ttl'<~Integer> - TTL in seconds def get_records request( :expects => 200, From c0cd1f506a2fc3361d0292150e643c1d7e20dd37 Mon Sep 17 00:00:00 2001 From: Patrick McKenzie Date: Tue, 8 Nov 2011 13:15:28 +0900 Subject: [PATCH 02/11] Did this do anything? --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 07303092b..730df7f18 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ Gemfile.lock rdoc pkg spec/credentials.yml +nbproject From 693815b484a2e60820c4715bf5e635e7c8f38c7a Mon Sep 17 00:00:00 2001 From: Patrick McKenzie Date: Tue, 8 Nov 2011 13:15:40 +0900 Subject: [PATCH 03/11] Revert "Slicehost uses record-type and zone-id for their API, which messes with Fog internals, so changing these to record_type and zone_id in the parser." This reverts commit 32ad91a777f0b482eb2b9d329d3009ad46b22293. --- lib/fog/slicehost/parsers/dns/get_records.rb | 8 ++------ lib/fog/slicehost/requests/dns/get_records.rb | 15 ++++++++------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/fog/slicehost/parsers/dns/get_records.rb b/lib/fog/slicehost/parsers/dns/get_records.rb index b170f8aee..fb18aef32 100644 --- a/lib/fog/slicehost/parsers/dns/get_records.rb +++ b/lib/fog/slicehost/parsers/dns/get_records.rb @@ -12,13 +12,9 @@ module Fog def end_element(name) case name - when 'zone-id' - @record["zone_id"] = value.to_i - when 'record-type' - @record["record_type"] = value - when 'ttl' + when 'zone-id', 'ttl' @record[name] = value.to_i - when 'name', 'data', 'active', 'aux' + when 'record-type', 'name', 'data', 'active', 'aux' @record[name] = value when 'record' @response['records'] << @record diff --git a/lib/fog/slicehost/requests/dns/get_records.rb b/lib/fog/slicehost/requests/dns/get_records.rb index c774e61bc..b56c6687e 100644 --- a/lib/fog/slicehost/requests/dns/get_records.rb +++ b/lib/fog/slicehost/requests/dns/get_records.rb @@ -10,13 +10,14 @@ module Fog # ==== Returns # * response<~Excon::Response>: # * body<~Array>: - # * 'name'<~String> - Record NAME field (e.g. "example.org." or "www") - # * 'data'<~String> - Data contained by the record (e.g. an IP address, for A records) - # * 'record-type'<~String> - Type of record (A, CNAME, TXT, etc) - # * 'aux'<~String> - Aux data for the record, for those types which have it (e.g. TXT) - # * 'zone-id'<~Integer> - zone ID to which this record belongs - # * 'active'<~String> - whether this record is active in the Slicehost DNS (Y for yes, N for no) - # * 'ttl'<~Integer> - TTL in seconds + # * 'addresses'<~Array> - Ip addresses for the slice + # * 'backup-id'<~Integer> - Id of backup slice was booted from + # * 'flavor_id'<~Integer> - Id of flavor slice was booted from + # * 'id'<~Integer> - Id of the slice + # * 'image-id'<~Integer> - Id of image slice was booted from + # * 'name'<~String> - Name of the slice + # * 'progress'<~Integer> - Progress of current action, in percentage + # * 'status'<~String> - Current status of the slice def get_records request( :expects => 200, From 5e2e2413d98a7445a4cbda93a7346299669e7003 Mon Sep 17 00:00:00 2001 From: Patrick McKenzie Date: Tue, 8 Nov 2011 13:30:56 +0900 Subject: [PATCH 04/11] Not having the best of days with git. Revert the reversion of the commit that I really do want to make. This reverts commit 693815b484a2e60820c4715bf5e635e7c8f38c7a. --- lib/fog/slicehost/parsers/dns/get_records.rb | 8 ++++++-- lib/fog/slicehost/requests/dns/get_records.rb | 15 +++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/fog/slicehost/parsers/dns/get_records.rb b/lib/fog/slicehost/parsers/dns/get_records.rb index fb18aef32..b170f8aee 100644 --- a/lib/fog/slicehost/parsers/dns/get_records.rb +++ b/lib/fog/slicehost/parsers/dns/get_records.rb @@ -12,9 +12,13 @@ module Fog def end_element(name) case name - when 'zone-id', 'ttl' + when 'zone-id' + @record["zone_id"] = value.to_i + when 'record-type' + @record["record_type"] = value + when 'ttl' @record[name] = value.to_i - when 'record-type', 'name', 'data', 'active', 'aux' + when 'name', 'data', 'active', 'aux' @record[name] = value when 'record' @response['records'] << @record diff --git a/lib/fog/slicehost/requests/dns/get_records.rb b/lib/fog/slicehost/requests/dns/get_records.rb index b56c6687e..c774e61bc 100644 --- a/lib/fog/slicehost/requests/dns/get_records.rb +++ b/lib/fog/slicehost/requests/dns/get_records.rb @@ -10,14 +10,13 @@ module Fog # ==== Returns # * response<~Excon::Response>: # * body<~Array>: - # * 'addresses'<~Array> - Ip addresses for the slice - # * 'backup-id'<~Integer> - Id of backup slice was booted from - # * 'flavor_id'<~Integer> - Id of flavor slice was booted from - # * 'id'<~Integer> - Id of the slice - # * 'image-id'<~Integer> - Id of image slice was booted from - # * 'name'<~String> - Name of the slice - # * 'progress'<~Integer> - Progress of current action, in percentage - # * 'status'<~String> - Current status of the slice + # * 'name'<~String> - Record NAME field (e.g. "example.org." or "www") + # * 'data'<~String> - Data contained by the record (e.g. an IP address, for A records) + # * 'record-type'<~String> - Type of record (A, CNAME, TXT, etc) + # * 'aux'<~String> - Aux data for the record, for those types which have it (e.g. TXT) + # * 'zone-id'<~Integer> - zone ID to which this record belongs + # * 'active'<~String> - whether this record is active in the Slicehost DNS (Y for yes, N for no) + # * 'ttl'<~Integer> - TTL in seconds def get_records request( :expects => 200, From 426815d01d7bf4ac8265c8dc923024337b4e8c85 Mon Sep 17 00:00:00 2001 From: Patrick McKenzie Date: Tue, 8 Nov 2011 13:11:08 +0900 Subject: [PATCH 05/11] Slicehost uses record-type and zone-id for their API, which messes with Fog internals, so changing these to record_type and zone_id in the parser. --- lib/fog/slicehost/parsers/dns/get_records.rb | 8 ++++++-- lib/fog/slicehost/requests/dns/get_records.rb | 15 +++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/fog/slicehost/parsers/dns/get_records.rb b/lib/fog/slicehost/parsers/dns/get_records.rb index fb18aef32..b170f8aee 100644 --- a/lib/fog/slicehost/parsers/dns/get_records.rb +++ b/lib/fog/slicehost/parsers/dns/get_records.rb @@ -12,9 +12,13 @@ module Fog def end_element(name) case name - when 'zone-id', 'ttl' + when 'zone-id' + @record["zone_id"] = value.to_i + when 'record-type' + @record["record_type"] = value + when 'ttl' @record[name] = value.to_i - when 'record-type', 'name', 'data', 'active', 'aux' + when 'name', 'data', 'active', 'aux' @record[name] = value when 'record' @response['records'] << @record diff --git a/lib/fog/slicehost/requests/dns/get_records.rb b/lib/fog/slicehost/requests/dns/get_records.rb index b56c6687e..c774e61bc 100644 --- a/lib/fog/slicehost/requests/dns/get_records.rb +++ b/lib/fog/slicehost/requests/dns/get_records.rb @@ -10,14 +10,13 @@ module Fog # ==== Returns # * response<~Excon::Response>: # * body<~Array>: - # * 'addresses'<~Array> - Ip addresses for the slice - # * 'backup-id'<~Integer> - Id of backup slice was booted from - # * 'flavor_id'<~Integer> - Id of flavor slice was booted from - # * 'id'<~Integer> - Id of the slice - # * 'image-id'<~Integer> - Id of image slice was booted from - # * 'name'<~String> - Name of the slice - # * 'progress'<~Integer> - Progress of current action, in percentage - # * 'status'<~String> - Current status of the slice + # * 'name'<~String> - Record NAME field (e.g. "example.org." or "www") + # * 'data'<~String> - Data contained by the record (e.g. an IP address, for A records) + # * 'record-type'<~String> - Type of record (A, CNAME, TXT, etc) + # * 'aux'<~String> - Aux data for the record, for those types which have it (e.g. TXT) + # * 'zone-id'<~Integer> - zone ID to which this record belongs + # * 'active'<~String> - whether this record is active in the Slicehost DNS (Y for yes, N for no) + # * 'ttl'<~Integer> - TTL in seconds def get_records request( :expects => 200, From bea05e7fcc3722ca84caa117ee3b3607b575a57c Mon Sep 17 00:00:00 2001 From: Patrick McKenzie Date: Tue, 8 Nov 2011 13:42:29 +0900 Subject: [PATCH 06/11] Do not touch .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 730df7f18..07303092b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,3 @@ Gemfile.lock rdoc pkg spec/credentials.yml -nbproject From efeee6f9047c0c0ebeede6821559f4874739de9b Mon Sep 17 00:00:00 2001 From: Patrick McKenzie Date: Tue, 8 Nov 2011 16:14:30 +0900 Subject: [PATCH 07/11] Fixing Slicehost DNS so that a) tests pass b) token names map to what Fog expects -- record_type not record-type, value not data, etc c) creation of new DNS records possible --- lib/fog/slicehost/models/dns/record.rb | 2 +- .../slicehost/parsers/dns/create_record.rb | 10 +++++++-- lib/fog/slicehost/parsers/dns/get_record.rb | 22 ++++++++++++++----- lib/fog/slicehost/parsers/dns/get_records.rb | 6 ++++- tests/slicehost/requests/dns/dns_tests.rb | 19 ++++++++-------- 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/lib/fog/slicehost/models/dns/record.rb b/lib/fog/slicehost/models/dns/record.rb index 686292f45..305fc46f0 100644 --- a/lib/fog/slicehost/models/dns/record.rb +++ b/lib/fog/slicehost/models/dns/record.rb @@ -12,7 +12,7 @@ module Fog identity :id attribute :active - attribute :value, :aliases => 'ip' + attribute :value, :aliases => ['ip', 'data'] attribute :name attribute :description, :aliases => 'aux' attribute :ttl diff --git a/lib/fog/slicehost/parsers/dns/create_record.rb b/lib/fog/slicehost/parsers/dns/create_record.rb index 49eb4030d..2a202e106 100644 --- a/lib/fog/slicehost/parsers/dns/create_record.rb +++ b/lib/fog/slicehost/parsers/dns/create_record.rb @@ -11,9 +11,15 @@ module Fog def end_element(name) case name - when 'zone-id', 'ttl', 'id' + when 'zone_id' + @response["zone-id"] = value.to_i + when 'record_type' + @response["record-type"] = value + when 'ttl', 'id' @response[name] = value.to_i - when 'record-type', 'name', 'data', 'active', 'aux' + when 'value' + @response["data"] = value + when 'name', 'data', 'active', 'aux' @response[name] = value end end diff --git a/lib/fog/slicehost/parsers/dns/get_record.rb b/lib/fog/slicehost/parsers/dns/get_record.rb index b4ae56a06..c1e20319b 100644 --- a/lib/fog/slicehost/parsers/dns/get_record.rb +++ b/lib/fog/slicehost/parsers/dns/get_record.rb @@ -6,15 +6,27 @@ module Fog class GetRecord < Fog::Parsers::Base def reset + @record = {} @response = { } end def end_element(name) case name - when 'zone-id', 'ttl' - @response[name] = value.to_i - when 'record-type', 'name', 'data', 'active', 'aux' - @response[name] = value + when 'id' + @record["id"] = value.to_i + when 'zone-id' + @record["zone_id"] = value.to_i + when 'record-type' + @record["record_type"] = value + when 'ttl' + @record[name] = value.to_i + when 'data' + @record["value"] = value + when 'name', 'active', 'aux' + @record[name] = value + when 'record' + @response = @record + @record = {} end end @@ -23,4 +35,4 @@ module Fog end end end -end +end \ No newline at end of file diff --git a/lib/fog/slicehost/parsers/dns/get_records.rb b/lib/fog/slicehost/parsers/dns/get_records.rb index b170f8aee..8f95694fc 100644 --- a/lib/fog/slicehost/parsers/dns/get_records.rb +++ b/lib/fog/slicehost/parsers/dns/get_records.rb @@ -12,13 +12,17 @@ module Fog def end_element(name) case name + when 'id' + @record["id"] = value.to_i when 'zone-id' @record["zone_id"] = value.to_i when 'record-type' @record["record_type"] = value when 'ttl' @record[name] = value.to_i - when 'name', 'data', 'active', 'aux' + when 'data' + @record["value"] = value + when 'name', 'active', 'aux' @record[name] = value when 'record' @response['records'] << @record diff --git a/tests/slicehost/requests/dns/dns_tests.rb b/tests/slicehost/requests/dns/dns_tests.rb index 7ffc6d5d5..819b30a1e 100644 --- a/tests/slicehost/requests/dns/dns_tests.rb +++ b/tests/slicehost/requests/dns/dns_tests.rb @@ -184,10 +184,10 @@ Shindo.tests('Fog::DNS[:slicehost] | DNS requests', ['slicehost', 'dns']) do if response.status == 200 mail_domain = 'mail.' + @domain record = response.body['records'][0] - if (record['record-type'] == 'MX') and (record['name'] == @domain) and - (record['data'] == mail_domain) and (record['ttl'] == 3600) and (record['active'] == 'N') and + if (record['record_type'] == 'MX') and (record['name'] == @domain) and + (record['value'] == mail_domain) and (record['ttl'] == 3600) and (record['active'] == 'N') and (record['aux'] == "10") - result= true + result = true end end @@ -197,7 +197,7 @@ Shindo.tests('Fog::DNS[:slicehost] | DNS requests', ['slicehost', 'dns']) do test('get records - verify all parameters for one record') do pending if Fog.mocking? - result= false + result = false response = Fog::DNS[:slicehost].get_records() if response.status == 200 @@ -205,16 +205,15 @@ Shindo.tests('Fog::DNS[:slicehost] | DNS requests', ['slicehost', 'dns']) do #find mx record records.each {|record| - if record['record-type'] == 'MX' + if (record['record_type'] == 'MX') and (record['name'] == @domain) mail_domain = 'mail.' + @domain - if (record['record-type'] == 'MX') and (record['name'] == @domain) and - (record['data'] == mail_domain) and (record['ttl'] == 3600) and (record['active'] == 'N') and + if (record['record_type'] == 'MX') and (record['name'] == @domain) and + (record['value'] == mail_domain) and (record['ttl'] == 3600) and (record['active'] == 'N') and (record['aux'] == "10") - result= true - break + result = true end - + break end } end From 8c680f0d800d89b1f5ec87930d19e317eaf933d4 Mon Sep 17 00:00:00 2001 From: Patrick McKenzie Date: Tue, 8 Nov 2011 16:34:37 +0900 Subject: [PATCH 08/11] 1) Fix so that getting a single record actually works. 2) zone.records currently returns all records in account, not just records for that zone. Add failing test (temporarily, assumes test account has existing zones for this to actually fail) + fix. 3) Add in data alias for record.value, just in case someone needs it, as Slicehost calls this data. --- lib/fog/slicehost/models/dns/zone.rb | 2 +- lib/fog/slicehost/requests/dns/get_records.rb | 4 ++-- tests/slicehost/requests/dns/dns_tests.rb | 9 +++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/fog/slicehost/models/dns/zone.rb b/lib/fog/slicehost/models/dns/zone.rb index 5fc63fc03..ace4f05ce 100644 --- a/lib/fog/slicehost/models/dns/zone.rb +++ b/lib/fog/slicehost/models/dns/zone.rb @@ -39,7 +39,7 @@ module Fog Fog::DNS::Slicehost::Records.new( :zone => self, :connection => connection - ) + ).reject {|record| record.zone_id != id} end end diff --git a/lib/fog/slicehost/requests/dns/get_records.rb b/lib/fog/slicehost/requests/dns/get_records.rb index c774e61bc..064945076 100644 --- a/lib/fog/slicehost/requests/dns/get_records.rb +++ b/lib/fog/slicehost/requests/dns/get_records.rb @@ -12,9 +12,9 @@ module Fog # * body<~Array>: # * 'name'<~String> - Record NAME field (e.g. "example.org." or "www") # * 'data'<~String> - Data contained by the record (e.g. an IP address, for A records) - # * 'record-type'<~String> - Type of record (A, CNAME, TXT, etc) + # * 'record_type'<~String> - Type of record (A, CNAME, TXT, etc) # * 'aux'<~String> - Aux data for the record, for those types which have it (e.g. TXT) - # * 'zone-id'<~Integer> - zone ID to which this record belongs + # * 'zone_id'<~Integer> - zone ID to which this record belongs # * 'active'<~String> - whether this record is active in the Slicehost DNS (Y for yes, N for no) # * 'ttl'<~Integer> - TTL in seconds def get_records diff --git a/tests/slicehost/requests/dns/dns_tests.rb b/tests/slicehost/requests/dns/dns_tests.rb index 819b30a1e..4ff32960c 100644 --- a/tests/slicehost/requests/dns/dns_tests.rb +++ b/tests/slicehost/requests/dns/dns_tests.rb @@ -220,6 +220,15 @@ Shindo.tests('Fog::DNS[:slicehost] | DNS requests', ['slicehost', 'dns']) do result end + + test("newly created zone returns only records which we added to it, not other records already in account") do + pending if Fog.mocking? + + @new_zone = Fog::DNS[:slicehost].zones.get(@zone_id) + + records = @new_zone.records + records.length == @new_records.length + end test("delete #{@new_records.count} records created") do pending if Fog.mocking? From c8c43245490a3b94843c25491614b3b258b80384 Mon Sep 17 00:00:00 2001 From: Patrick McKenzie Date: Tue, 8 Nov 2011 18:12:25 +0900 Subject: [PATCH 09/11] Allow updates of DNS records. Updates on zones not supported yet. --- lib/fog/slicehost/dns.rb | 1 + lib/fog/slicehost/models/dns/record.rb | 8 +++- .../slicehost/requests/dns/update_record.rb | 43 +++++++++++++++++++ tests/slicehost/requests/dns/dns_tests.rb | 40 +++++++++++++++++ 4 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 lib/fog/slicehost/requests/dns/update_record.rb diff --git a/lib/fog/slicehost/dns.rb b/lib/fog/slicehost/dns.rb index 405d5f6d9..18bdbef50 100644 --- a/lib/fog/slicehost/dns.rb +++ b/lib/fog/slicehost/dns.rb @@ -23,6 +23,7 @@ module Fog request :get_records request :get_zone request :get_zones + request :update_record class Mock diff --git a/lib/fog/slicehost/models/dns/record.rb b/lib/fog/slicehost/models/dns/record.rb index 305fc46f0..89ad55f54 100644 --- a/lib/fog/slicehost/models/dns/record.rb +++ b/lib/fog/slicehost/models/dns/record.rb @@ -45,13 +45,17 @@ module Fog end def save - raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity + requires :name, :type, :value, :zone options = {} options[:active] = active ? 'Y' : 'N' options[:aux] = description if description options[:ttl] = ttl if ttl - data = connection.create_record(type, zone.id, name, value, options) + if identity + data = connection.update_record(identity, type, zone.id, name, value, options) + else + data = connection.create_record(type, zone.id, name, value, options) + end merge_attributes(data.body) true end diff --git a/lib/fog/slicehost/requests/dns/update_record.rb b/lib/fog/slicehost/requests/dns/update_record.rb new file mode 100644 index 000000000..e3e4cb917 --- /dev/null +++ b/lib/fog/slicehost/requests/dns/update_record.rb @@ -0,0 +1,43 @@ +module Fog + module DNS + class Slicehost + class Real + + #require 'fog/slicehost/parsers/dns/update_record' + + # Get an individual DNS record from the specified zone + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + # * 'record_type'<~String> - type of DNS record to create (A, CNAME, etc) + # * 'zone_id'<~Integer> - ID of the zone to update + # * 'name'<~String> - host name this DNS record is for + # * 'data'<~String> - data for the DNS record (ie for an A record, the IP address) + # * 'ttl'<~Integer> - time to live in seconds + # * 'active'<~String> - whether this record is active or not ('Y' or 'N') + # * 'aux'<~String> - extra data required by the record + def update_record(record_id, record_type, zone_id, name, data, options = {}) + optional_tags= '' + options.each { |option, value| + case option + when :ttl + optional_tags+= "#{value}" + when :active + optional_tags+= "#{value}" + when :aux + optional_tags+= "#{value}" + end + } + request( + :body => %Q{#{record_type}#{zone_id}#{name}#{data}#{optional_tags}}, + :expects => 200, + :method => 'PUT', + :path => "records/#{record_id}.xml" + ) + end + + end + end + end +end diff --git a/tests/slicehost/requests/dns/dns_tests.rb b/tests/slicehost/requests/dns/dns_tests.rb index 4ff32960c..94f0b7ac4 100644 --- a/tests/slicehost/requests/dns/dns_tests.rb +++ b/tests/slicehost/requests/dns/dns_tests.rb @@ -221,6 +221,46 @@ Shindo.tests('Fog::DNS[:slicehost] | DNS requests', ['slicehost', 'dns']) do result end + test('update record - verify all parameters for one record') do + pending if Fog.mocking? + + result = false + + specific_record = nil + + response = Fog::DNS[:slicehost].get_records() + if response.status == 200 + records = response.body['records'] + + #find mx record + records.each {|record| + if (record['record_type'] == 'MX') and (record['name'] == @domain) + specific_record = record + break + end + } + end + + if (specific_record) #Try to change the TTL for this MX record if we've successfully created it. + response = Fog::DNS[:slicehost].update_record(specific_record['id'], specific_record['record_type'], specific_record['zone_id'], + specific_record['name'], specific_record['value'], {:ttl => 7200, :active => "N", :aux => "10"}) + + mail_domain = 'mail.' + @domain + + records = Fog::DNS[:slicehost].get_record(specific_record['id']).body["records"] + record = records[0] + + if (record['record_type'] == 'MX') and (record['name'] == @domain) and + (record['value'] == mail_domain) and (record['ttl'] == 7200) and (record['active'] == 'N') and + (record['aux'] == "10") + result = true + end + + end + + result + end + test("newly created zone returns only records which we added to it, not other records already in account") do pending if Fog.mocking? From 21e80718a5a56a02934e31a2e1f5fd9b152a8908 Mon Sep 17 00:00:00 2001 From: Patrick McKenzie Date: Tue, 8 Nov 2011 18:54:08 +0900 Subject: [PATCH 10/11] Fixing parsing of zone.records.get(id) so that it parses a single record properly rather than attempting to parse a list of records improperly. Fixing tests to match this (expected) behavior rather than work-around the broken way. --- lib/fog/slicehost/requests/dns/get_record.rb | 2 +- tests/slicehost/requests/dns/dns_tests.rb | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/fog/slicehost/requests/dns/get_record.rb b/lib/fog/slicehost/requests/dns/get_record.rb index fada77ff1..90f63ef0d 100644 --- a/lib/fog/slicehost/requests/dns/get_record.rb +++ b/lib/fog/slicehost/requests/dns/get_record.rb @@ -21,7 +21,7 @@ module Fog request( :expects => 200, :method => 'GET', - :parser => Fog::Parsers::DNS::Slicehost::GetRecords.new, + :parser => Fog::Parsers::DNS::Slicehost::GetRecord.new, :path => "records/#{record_id}.xml" ) end diff --git a/tests/slicehost/requests/dns/dns_tests.rb b/tests/slicehost/requests/dns/dns_tests.rb index 94f0b7ac4..400b32586 100644 --- a/tests/slicehost/requests/dns/dns_tests.rb +++ b/tests/slicehost/requests/dns/dns_tests.rb @@ -183,7 +183,7 @@ Shindo.tests('Fog::DNS[:slicehost] | DNS requests', ['slicehost', 'dns']) do response = Fog::DNS[:slicehost].get_record(@record_id) if response.status == 200 mail_domain = 'mail.' + @domain - record = response.body['records'][0] + record = response.body if (record['record_type'] == 'MX') and (record['name'] == @domain) and (record['value'] == mail_domain) and (record['ttl'] == 3600) and (record['active'] == 'N') and (record['aux'] == "10") @@ -247,8 +247,7 @@ Shindo.tests('Fog::DNS[:slicehost] | DNS requests', ['slicehost', 'dns']) do mail_domain = 'mail.' + @domain - records = Fog::DNS[:slicehost].get_record(specific_record['id']).body["records"] - record = records[0] + record = Fog::DNS[:slicehost].get_record(specific_record['id']).body if (record['record_type'] == 'MX') and (record['name'] == @domain) and (record['value'] == mail_domain) and (record['ttl'] == 7200) and (record['active'] == 'N') and From 7d84f8d040fe51d94ea25ad3eb14465c9a670bbe Mon Sep 17 00:00:00 2001 From: Patrick McKenzie Date: Tue, 8 Nov 2011 19:18:47 +0900 Subject: [PATCH 11/11] Getting it so zone.records works as expected (loads all records, for that zone only). --- lib/fog/slicehost/models/dns/zone.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fog/slicehost/models/dns/zone.rb b/lib/fog/slicehost/models/dns/zone.rb index ace4f05ce..286641f2d 100644 --- a/lib/fog/slicehost/models/dns/zone.rb +++ b/lib/fog/slicehost/models/dns/zone.rb @@ -39,7 +39,7 @@ module Fog Fog::DNS::Slicehost::Records.new( :zone => self, :connection => connection - ).reject {|record| record.zone_id != id} + ).all end end