1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[aws|dns] Preserves change_id. Support for checking sync status via reload.

This commit is contained in:
George Scott 2012-03-26 12:23:42 -07:00
parent 62488b4335
commit ad81386d98
2 changed files with 31 additions and 0 deletions

View file

@ -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)

View file

@ -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