From efeee6f9047c0c0ebeede6821559f4874739de9b Mon Sep 17 00:00:00 2001 From: Patrick McKenzie Date: Tue, 8 Nov 2011 16:14:30 +0900 Subject: [PATCH] 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