mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #1807 from stormsilver/paginate_zerigo_zones
[Zerigo|DNS] Support pagination on Zerigo DNS zones
This commit is contained in:
commit
4776992f0c
3 changed files with 68 additions and 16 deletions
|
@ -9,8 +9,8 @@ module Fog
|
|||
|
||||
model Fog::DNS::Zerigo::Zone
|
||||
|
||||
def all
|
||||
data = service.list_zones.body['zones']
|
||||
def all(options = {})
|
||||
data = service.list_zones(options).body['zones']
|
||||
load(data)
|
||||
end
|
||||
|
||||
|
|
|
@ -7,6 +7,11 @@ module Fog
|
|||
|
||||
# Get list of all DNS zones hosted on Slicehost (for this account)
|
||||
#
|
||||
# ==== Parameters
|
||||
# * options<~Hash>
|
||||
# * page<~Integer> - Indicates where to begin in your list of zones.
|
||||
# * per_page<~Integer> - The maximum number of zones to be included in the response body
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
|
@ -30,8 +35,9 @@ module Fog
|
|||
# * 'axfr-ips'<~String>
|
||||
# * 'restrict-axfr'<~String>
|
||||
# * 'status'<~Integer> - 200 indicates success
|
||||
def list_zones
|
||||
def list_zones(options = {})
|
||||
request(
|
||||
:query => options,
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::DNS::Zerigo::ListZones.new,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
Shindo.tests('Fog::DNS[:zerigo] | DNS requests', ['zerigo', 'dns']) do
|
||||
|
||||
# tests assume have a free acccount - ie need to limit # of zones to max of 3
|
||||
|
||||
MAX_ZONE_COUNT = 3
|
||||
@domain = ''
|
||||
@org_zone_count = 0
|
||||
@new_zones = []
|
||||
|
@ -156,21 +156,67 @@ Shindo.tests('Fog::DNS[:zerigo] | DNS requests', ['zerigo', 'dns']) do
|
|||
|
||||
end
|
||||
|
||||
test('list zones - make sure total count is correct') do
|
||||
pending if Fog.mocking?
|
||||
test("list zones - make sure total count is #{@org_zone_count+1}") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
result= false
|
||||
result= false
|
||||
|
||||
response = Fog::DNS[:zerigo].list_zones()
|
||||
if response.status == 200
|
||||
zones = response.body['zones']
|
||||
if (@org_zone_count+1) == zones.count
|
||||
result= true;
|
||||
end
|
||||
end
|
||||
response = Fog::DNS[:zerigo].list_zones()
|
||||
if response.status == 200
|
||||
zones = response.body['zones']
|
||||
if (@org_zone_count+1) == zones.count
|
||||
result= true;
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
test('list zones with pagination') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
result = false
|
||||
|
||||
# make enough zones to paginate
|
||||
number_zones_to_create = MAX_ZONE_COUNT-@org_zone_count-1
|
||||
number_zones_to_create.times do |i|
|
||||
domain = generate_unique_domain
|
||||
options = { :nx_ttl => 1800, :active => 'N', :hostmaster => "netops@#{domain}",
|
||||
:notes => 'for client ABC', :tag_list=> "sample-tag-#{i}" }
|
||||
response = Fog::DNS[:zerigo].create_zone( domain, 14400, 'pri', options )
|
||||
if response.status == 201
|
||||
@new_zones << response.body['id']
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
total_zone_count_response = Fog::DNS[:zerigo].list_zones()
|
||||
if total_zone_count_response.status == 200
|
||||
if number_zones_to_create > 0
|
||||
zones_we_should_see = @new_zones.dup
|
||||
total_zone_count = total_zone_count_response.headers['X-Query-Count'].to_i
|
||||
else
|
||||
zones_we_should_see = total_zone_count_response.body['zones'].collect {|z| z['id']}
|
||||
total_zone_count = zones_we_should_see.count
|
||||
end
|
||||
|
||||
total_zone_count.times do |i|
|
||||
# zerigo pages are 1-indexed, not 0-indexed
|
||||
response = Fog::DNS[:zerigo].list_zones(:per_page => 1, :page => i+1)
|
||||
zones = response.body['zones']
|
||||
if 1 == zones.count
|
||||
zones_we_should_see.delete(zones.first['id'])
|
||||
end
|
||||
end
|
||||
|
||||
if zones_we_should_see.empty?
|
||||
result = true
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
test('create record - simple A record') do
|
||||
pending if Fog.mocking?
|
||||
|
|
Loading…
Reference in a new issue