From ad81386d9844a089336bf58c4bd723591a2ef789 Mon Sep 17 00:00:00 2001 From: George Scott Date: Mon, 26 Mar 2012 12:23:42 -0700 Subject: [PATCH] [aws|dns] Preserves change_id. Support for checking sync status via reload. --- lib/fog/aws/models/dns/record.rb | 19 +++++++++++++++++++ tests/aws/models/dns/record_tests.rb | 12 ++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/fog/aws/models/dns/record.rb b/lib/fog/aws/models/dns/record.rb index 1245a4623..f4e9272a7 100644 --- a/lib/fog/aws/models/dns/record.rb +++ b/lib/fog/aws/models/dns/record.rb @@ -17,6 +17,7 @@ module Fog attribute :status, :aliases => ['Status'] attribute :created_at, :aliases => ['SubmittedAt'] attribute :alias_target, :aliases => ['AliasTarget'] + attribute :change_id, :aliases => ['Id'] def initialize(attributes={}) self.ttl ||= 3600 @@ -55,6 +56,24 @@ module Fog true end + # Returns true if record is insync. May only be called for newly created or modified records that + # have a change_id and status set. + def insync? + requires :change_id, :status + status == 'INSYNC' + end + + def reload + # If we have a change_id (newly created or modified), then reload performs a get_change to update status. + if change_id + data = connection.get_change(change_id).body + merge_attributes(data) + self + else + super + end + end + private def zone=(new_zone) diff --git a/tests/aws/models/dns/record_tests.rb b/tests/aws/models/dns/record_tests.rb index 2c6d56415..82a93d389 100644 --- a/tests/aws/models/dns/record_tests.rb +++ b/tests/aws/models/dns/record_tests.rb @@ -8,11 +8,23 @@ Shindo.tests("Fog::Dns[:aws] | record", ['aws', 'dns']) do params = { :name => @zone.domain, :type => 'A', :ttl => 3600, :value => ['1.2.3.4'] } model_tests(@zone.records, params, false) do + + # Newly created records should have a change id + tests("#change_id") do + returns(true) { @instance.change_id != nil } + end + + # Waits for changes to sync to all Route 53 DNS servers. Usually takes ~30 seconds to complete. + tests("#insync? - may take a minute to complete...").succeeds do + @instance.wait_for { insync? } + end + tests("#modify") do new_value = ['5.5.5.5'] returns(true) { @instance.modify(:value => new_value) } returns(new_value) { @instance.value } end + end tests("zones#destroy").succeeds do