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

[aws|slicehost|linode|zerigo|dns] added support for Route 53 and full test cases for each DNS provider

This commit is contained in:
Athir Nuaimi 2010-12-17 18:08:56 -05:00
parent c319bb6bcd
commit 718029dc56
9 changed files with 833 additions and 270 deletions

View file

@ -4,110 +4,74 @@ require 'rubygems'
require File.join(File.dirname(File.expand_path(__FILE__)), '..', 'lib', 'fog')
require 'fog/core/bin'
Fog.bin = true
#mark true for each cloud you wish to enable/run the sample for
RUN_AWS_SAMPLE = true
RUN_LINODE_SAMPLE = false
RUN_SLICEHOST_SAMPLE = false
RUN_ZERIGO_SAMPLE = true
#sample data
TEST_DOMAIN='sample53-domain.com'
RUN_ZERIGO_SAMPLE = false
#domain to use in examples
TEST_DOMAIN = 'test-343246324434.com'
# example of how to use AWS Route 53 DNS calls
def show_aws_dns_usage
begin
aws = AWS[:dns].list_hosted_zones
debugger
#use to keep track of zone we create
zone_id= nil
response = AWS[:dns].create_hosted_zone( TEST_DOMAIN)
if response.status == 201
zone_id = response.body['HostedZone']['Id']
aws.delete_hosted_zone( zone_id)
(response.status == 200) ? true : false
end
#get a list of the zones AWS is hosting for this account
options= { :max_items => 50 }
response= AWS[:dns].list_hosted_zones( options)
# see if domain is already hosted on AWS
# important to check as AWS will let you create multiple zones with the same domain name
options= { :max_items => 200 }
response = AWS[:dns].list_hosted_zones( options)
if response.status == 200
domain_count = response.body['HostedZones'].count
puts "you have #{domain_count} zones hosted at AWS Route 53"
end
# debugger
#delete all the zones
zones= response.body['HostedZones']
zones.each { |zone|
zone_id = zone['Id']
puts "starting process of deleting zone #{zone_id}"
#get the list of record sets
options = { :max_items => 50 }
response = AWS[:dns].list_resource_record_sets( zone_id, options)
if response.status == 200
records= response.body['ResourceRecordSets']
count= records.count
if count > 0
puts "#{count} resource records to delete"
#need to build a change batch
change_batch = []
records.each { |record|
#can't delete NS or SOA that AWS added so skip
if record[:type] == 'NS' or record[:type] == 'SOA'
continue
else
#add to batch of records to delete
resource_record_set = { :action => 'DELETE', :name => record['Name'], :type => record['Type'],
:ttl => record['TTL'], :resource_records => record['ResourceRecords'] }
change_batch << resource_record_set
end
}
if change_batch.count > 0
response = AWS[:dns].change_resource_record_sets( zone_id, change_batch)
debugger
if response.status == 200
#zone should now be in a state where it can be deleted
end
end
zones = response.body['HostedZones']
zones.each { |zone|
domain_name = zone['Name']
if domain_name.chop == TEST_DOMAIN
zone_id = zone['Id'].sub('/hostedzone/', '')
end
end
#delete the records
response = AWS[:dns].delete_hosted_zone( zone_id)
if response.status == 200
change_id = response.body['ChangeInfo']['Id']
puts "request delete zone #{zone_id} is in progress and has change ID #{change_id}"
end
}
# debugger
}
end
#add a zone - note required period at end of domain
options= { :comment => 'for client ABC' }
response= AWS[:dns].create_hosted_zone( 'sample-domain.com.' )
if response.status == 201
zone_id = response.body['HostedZone']['Id']
change_id = response.body['ChangeInfo']['Id']
status = response.body['ChangeInfo']['Status']
#if domain not yet created, do so now
if zone_id.nil?
options= { :comment => 'test domain - not for production use' }
response = AWS[:dns].create_hosted_zone( TEST_DOMAIN, options)
if response.status == 201
zone_id = response.body['HostedZone']['Id']
change_id = response.body['ChangeInfo']['Id']
status = response.body['ChangeInfo']['Status']
end
end
#get details about zone including name servers (which AWS adds automatically)
response = AWS[:dns].get_hosted_zone( zone_id)
if response.status == 200
zone_info = response.body['HostedZone']
name_servers = response.body['NameServers']
num_ns_servers = name_servers.count
end
# debugger
#add an A record for www
change_batch = []
host = 'www.' + TEST_DOMAIN
ip_addr = '1.2.3.4'
record = { :name => host, :type => 'A', :resource_records => [ip_addr], :ttl => 3600 }
#wait until zone ready
resource_record_set = record.merge( :action => 'CREATE' )
change_batch << resource_record_set
options = { :comment => 'add A record for www'}
response = AWS[:dns].change_resource_record_sets( zone_id, change_batch, options)
if response.status == 200
change_id = response.body['Id']
status = response.body['Status']
end
debugger
#wait until new zone is live across all name servers
while status == 'PENDING'
sleep 2
response = AWS[:dns].get_change( change_id)
@ -118,70 +82,24 @@ def show_aws_dns_usage
puts "your changes are #{status}"
end
# debugger
response = AWS[:dns].get_hosted_zone( zone_id)
# get resource records for zone
response = AWS[:dns].list_resource_record_sets( zone_id)
if response.status == 200
name_servers = response.body['NameServers']
record_sets= response.body['ResourceRecordSets']
num_records= record_sets.count
end
debugger
#add resource records to zone
#now delete record for www
resource_record_set = record.merge( :action => 'DELETE' )
change_batch = []
resource_record_set = { :action => 'CREATE', :name => 'www.sample-domain.com.', :type => 'A',
:ttl => 3600, :resource_records => ['1.2.3.4'] }
change_batch << resource_record_set
=begin
resource_record_set = { :action => 'CREATE', :name => 'mail.sample-domain.com.', :type => 'CNAME',
:ttl => 3600, :resource_records => ['www.sample-domain.com'] }
change_batch << resource_record_set
resource_record_set = { :action => 'CREATE', :name => 'sample-domain.com.', :type => 'MX',
:ttl => 3600, :resource_records => ['10 mail.sample-domain.com'] }
change_batch << resource_record
=end
options = { :comment => 'migrate records from BIND'}
options = { :comment => 'remove A record for www'}
response = AWS[:dns].change_resource_record_sets( zone_id, change_batch, options)
if response.status == 200
change_id = response.body['Id']
status = response.body['Status']
end
debugger
#wait until zone ready
while status == 'PENDING'
sleep 2
response = AWS[:dns].get_change( change_id)
if response.status == 200
change_id = response.body['Id']
status = response.body['Id']
end
puts "your changes are #{status}"
end
#get a list of the zones AWS is hosting for this account
options= { :max_items => 5 }
response= AWS[:dns].list_hosted_zones( )
if response.status == 200
end
response = AWS[:dns].get_hosted_zone()
if response.status == 200
end
response = AWS[:dns].list_resource_record_sets
if response.status == 200
end
#delete the resource records
response = AWS[:dns].change_resource_record_sets( zone_id, change_batch, options)
if response.status == 200
change_id = response.body['ChangeInfo']['Id']
end
#wait?
#delete the zone
response = AWS[:dns].delete_hosted_zone( zone_id)
if response.status == 200
@ -348,6 +266,103 @@ def show_slicehost_dns_usage
true
end
# example of how to use Zerigo DNS calls
def show_zerigo_dns_usage
begin
#create a domain
options = { :nx_ttl => 1800 }
response = Zerigo[:compute].create_zone( "sample-domain.com", 3600, 'pri_sec', options)
if response.status == 201
zone_id = response.body['id']
end
#update zone
options = { :notes => "domain for client ABC"}
response = Zerigo[:compute].update_zone( zone_id, options)
if response.status == 200
puts "update of zone #{zone_id} worked"
end
#get details on the zone
response = Zerigo[:compute].get_zone( zone_id)
if response.status == 200
domain = response.body['domain']
hosts = response.body['hosts']
end
#get zone stats
response = Zerigo[:compute].get_zone_stats( zone_id)
if response.status == 200
queries = response.body['queries']
end
#list all domains on this accont
response= Zerigo[:compute].list_zones()
if response.status == 200
zone_count = response.headers['X-Query-Count'].to_i
end
#add an A record to the zone
options = { :hostname => 'www' }
response = Zerigo[:compute].create_host( zone_id, 'A', '1.2.3.4', options )
if response.status == 201
host_id = response.body['id']
end
#add an MX record to the zone
options = { :priority => 5 }
response = Zerigo[:compute].create_host( zone_id, 'MX', 'mail.sample-domain.com', options)
if response.status == 201
mail_host_id = response.body['id']
end
#update the record
options = { :priority => 10 }
response = Zerigo[:compute].update_host( mail_host_id, options)
if response.status == 200
#updated priority
end
#find a specific record
response = Zerigo[:compute].find_hosts( "sample-domain.com" )
if response.status == 200
hosts= response.body['hosts']
num_records = hosts.count
end
#get host record
response = Zerigo[:compute].get_host( host_id)
if response.status == 200
fqdn = response.body['fqdn']
end
#list hosts
response = Zerigo[:compute].list_hosts( zone_id)
if response.status == 200
hosts = response.body['hosts']
end
#delete the host record
response = Zerigo[:compute].delete_host( host_id)
if response.status == 200
puts "host record #{host_id} deleted from zone"
end
#delete the zone we created
response = Zerigo[:compute].delete_zone( zone_id)
if response.status == 200
puts "deleted zone #{zone_id}"
end
rescue
#opps, ran into a problem
puts $!.message
return false
end
end
######################################
# make sure Fog credentials file has been setup
@ -369,6 +384,6 @@ if RUN_SLICEHOST_SAMPLE and Fog::credentials[:slicehost_password]
show_slicehost_dns_usage
end
if RUN_ZERIGO_SAMPLE and Fog::credentials[:zerigo_user] and Fog::credentials[:zerigo_password]
if RUN_ZERIGO_SAMPLE and Fog::credentials[:zerigo_email] and Fog::credentials[:zerigo_password]
show_zerigo_dns_usage
end

View file

@ -11,7 +11,9 @@ module Fog
def end_element(name)
case name
when 'Id', 'Status', 'SubmittedAt'
when 'Id'
@response[name] = @value.sub('/change/', '')
when 'Status', 'SubmittedAt'
@response[name] = @value
end
end
@ -21,4 +23,4 @@ module Fog
end
end
end
end
end

View file

@ -11,7 +11,9 @@ module Fog
def end_element(name)
case name
when 'Id', 'Status', 'SubmittedAt'
when 'Id'
@response[name] = @value.sub('/change/', '')
when 'Status', 'SubmittedAt'
@response[name] = @value
end
end

View file

@ -32,21 +32,17 @@ module Fog
def create_hosted_zone( name, options = {})
optional_tags = ''
options.each { |option, value|
case option
when :caller_ref
optional_tags+= "<CallerReference>#{value}</CallerReference>"
when :comment
optional_tags+= "<HostedZoneConfig><Comment>#{value}</Comment></HostedZoneConfig>"
end
}
#make sure we have a unique call reference
if options[:caller_ref].nil?
if options[:caller_ref]
optional_tags+= "<CallerReference>#{options[:call_ref]}</CallerReference>"
else
#make sure we have a unique call reference
caller_ref = "ref-#{rand(1000000).to_s}"
optional_tags+= "<CallerReference>#{caller_ref}</CallerReference>"
end
if options[:comment]
optional_tags+= "<HostedZoneConfig><Comment>#{options[:comment]}</Comment></HostedZoneConfig>"
end
request({
:body => %Q{<?xml version="1.0" encoding="UTF-8"?><CreateHostedZoneRequest xmlns="https://route53.amazonaws.com/doc/2010-10-01/"><Name>#{name}</Name>#{optional_tags}</CreateHostedZoneRequest>},
:parser => Fog::Parsers::AWS::DNS::CreateHostedZone.new,

View file

@ -60,7 +60,7 @@ module Fog
when :axfr_ips
optional_tags+= "<axfr-ips>#{value}</axfr-ips>"
when :custom_nameservers
optional_tags+= "<custom_nameservers>#{value}</custom-nameservers>"
optional_tags+= "<custom-nameservers>#{value}</custom-nameservers>"
when :custom_ns
optional_tags+= "<custom-ns>#{value}</custom-ns>"
when :hostmaster

View file

@ -1,66 +1,278 @@
Shindo.tests('AWS::DNS | DNS requests', ['aws', 'dns']) do
@test_domain = 'sample53-domain.com'
@org_zone_count = 0
@zone_id = ''
@change_id = ''
@new_records =[]
# NOTE: can't use generate_unique_domain() as we do in other DNS provider
# test suites as AWS charges $1/mth for each domain, even if it exists
# on AWS for only the time that this test suite runs!!
# http://aws.amazon.com/route53/pricing/
@test_domain = 'test-343246324434.com'
tests( 'success') do
tests('#create_hosted_zones') {
test('see if test domain already exists') do
pending if Fog.mocking?
test('simple zone') {
pending if Fog.mocking?
response = AWS[:dns].create_hosted_zone( @test_domain)
if response.status == 201
zone_id = response.body['HostedZone']['Id']
response = AWS[:dns].delete_hosted_zone( zone_id)
(response.status == 200) ? true : false
@zone_id = nil
response = AWS[:dns].list_hosted_zones()
if response.status == 200
@hosted_zones = response.body['HostedZones']
end
#go through zones for this account
@hosted_zones.each { |zone|
domain = zone['Name']
if domain.chomp == @test_domain
@zone_id = zone['Id']
end
}
}
tests('#get_hosted_zones') {
}
tests('#delete_hosted_zones') {
@zone_id.nil?
end
test('get current zone count') do
pending if Fog.mocking?
@org_zone_count= 0
response = AWS[:dns].list_hosted_zones()
if response.status == 200
@hosted_zones = response.body['HostedZones']
@org_zone_count = @hosted_zones.count
end
response.status == 200
end
test('create simple zone') {
pending if Fog.mocking?
result = false
response = AWS[:dns].create_hosted_zone( @test_domain)
if response.status == 201
zone= response.body['HostedZone']
change_info = response.body['ChangeInfo']
ns_servers = response.body['NameServers']
if (zone and change_info and ns_servers)
@zone_id = zone['Id']
caller_ref = zone['CallerReference']
@change_id = change_info['Id']
status = change_info['Status']
ns_srv_count = ns_servers.count
if (@zone_id.length > 0) and (caller_ref.length > 0) and (@change_id.length > 0) and
(status.length > 0) and (ns_srv_count > 0)
result = true
end
end
end
result
}
tests('#list_hosted_zones') {
test("get status of change #{@change_id}") {
pending if Fog.mocking?
test( 'simple list') {
pending if Fog.mocking?
result = false
response = AWS[:dns].get_change(@change_id)
if response.status == 200
status = response.body['Status']
if (status == 'PENDING') or (status == 'INSYNC')
result= true
end
end
result
}
test("get info on hosted zone #{@zone_id}") {
pending if Fog.mocking?
response = AWS[:dns].list_hosted_zones()
response.status == 200
result = false
response = AWS[:dns].get_hosted_zone( @zone_id)
if response.status == 200
zone = response.body['HostedZone']
zone_id = zone['Id']
name = zone['Name']
caller_ref = zone['CallerReference']
ns_servers = response.body['NameServers']
# AWS returns domain with a dot at end - so when compare, remove dot
if (zone_id == @zone_id) and (name.chop == @test_domain) and (caller_ref.length > 0) and
(ns_servers.count > 0)
result = true
end
end
result
}
test('list zones') do
pending if Fog.mocking?
result = false
response = AWS[:dns].list_hosted_zones()
if response.status == 200
zones= response.body['HostedZones']
if (zones.count > 0)
zone= zones[0]
zone_id = zone['Id']
zone_name= zone['Name']
caller_ref = zone['CallerReference']
end
max_items = response.body['MaxItems']
if (zone_id.length > 0) and (zone_name.length > 0) and (caller_ref.length > 0) and
(max_items > 0)
result = true
end
end
result
end
test("add a A resource record") {
pending if Fog.mocking?
result = false
# create an A resource record
host = 'www.' + @test_domain
ip_addrs = ['1.2.3.4']
resource_record = { :name => host, :type => 'A', :ttl => 3600, :resource_records => ip_addrs }
resource_record_set = resource_record.merge( :action => 'CREATE')
change_batch = []
change_batch << resource_record_set
options = { :comment => 'add A record to domain'}
response = AWS[:dns].change_resource_record_sets( @zone_id, change_batch, options)
if response.status == 200
change_id = response.body['Id']
status = response.body['Status']
@new_records << resource_record
end
response.status == 200
}
test("add a CNAME resource record") {
pending if Fog.mocking?
result = false
# create a CNAME resource record
host = 'mail.' + @test_domain
value = ['www.' + @test_domain]
resource_record = { :name => host, :type => 'CNAME', :ttl => 3600, :resource_records => value }
resource_record_set = resource_record.merge( :action => 'CREATE')
change_batch = []
change_batch << resource_record_set
options = { :comment => 'add CNAME record to domain'}
response = AWS[:dns].change_resource_record_sets( @zone_id, change_batch, options)
if response.status == 200
change_id = response.body['Id']
status = response.body['Status']
@new_records << resource_record
end
response.status == 200
}
test("add a MX resource record") {
pending if Fog.mocking?
result = false
# create a MX resource record
host = @test_domain
value = ['7 mail.' + @test_domain]
resource_record = { :name => host, :type => 'MX', :ttl => 3600, :resource_records => value }
resource_record_set = resource_record.merge( :action => 'CREATE')
change_batch = []
change_batch << resource_record_set
options = { :comment => 'add MX record to domain'}
response = AWS[:dns].change_resource_record_sets( @zone_id, change_batch, options)
if response.status == 200
change_id = response.body['Id']
status = response.body['Status']
@new_records << resource_record
end
response.status == 200
}
test("list resource records") {
# get resource records for zone
response = AWS[:dns].list_resource_record_sets( @zone_id)
if response.status == 200
record_sets= response.body['ResourceRecordSets']
num_records= record_sets.count
end
response.status == 200
}
test("delete #{@new_records.count} resource records") {
pending if Fog.mocking?
result = true
change_batch = []
@new_records.each { |record|
resource_record_set = record.merge( :action => 'DELETE')
change_batch << resource_record_set
}
options = { :comment => 'remove records from domain'}
response = AWS[:dns].change_resource_record_sets( @zone_id, change_batch, options)
if response.status != 200
result == false
break
end
result
}
test("delete hosted zone #{@zone_id}") {
pending if Fog.mocking?
response = AWS[:dns].delete_hosted_zone( @zone_id)
response.status == 200
}
end
tests( 'failure') do
tests('#create_hosted_zone') do
tests('invalid domain name') {
pending if Fog.mocking?
raises( Excon::Errors::BadRequest) {
response = AWS[:dns].create_hosted_zone( 'invalid-domain')
}
tests( 'failure') do
tests('create hosted zone using invalid domain name') do
pending if Fog.mocking?
raises( Excon::Errors::BadRequest) {
response = AWS[:dns].create_hosted_zone( 'invalid-domain')
}
end
tests('#get_hosted_zone') do
tests('get hosted zone using invalid ID') do
pending if Fog.mocking?
tests('for invalid zone ID') do
pending if Fog.mocking?
raises(Excon::Errors::BadRequest) {
zone_id = 'dummy-id'
response = AWS[:dns].get_hosted_zone( zone_id)
}
end
raises(Excon::Errors::BadRequest) {
zone_id = 'dummy-id'
response = AWS[:dns].get_hosted_zone( zone_id)
}
end
end

View file

@ -1,9 +1,21 @@
Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
@test_domain = 'test-fog.com'
@domain = ''
@new_zones = []
@new_records =[]
def generate_unique_domain( with_trailing_dot = false)
#get time (with 1/100th of sec accuracy)
#want unique domain name and if provider is fast, this can be called more than once per second
time= (Time.now.to_f * 100).to_i
domain = 'test-' + time.to_s + '.com'
if with_trailing_dot
domain+= '.'
end
domain
end
tests( 'success') do
test('get current zone count') do
@ -23,8 +35,9 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
pending if Fog.mocking?
type = 'master'
options = { :SOA_email => "netops@#{@test_domain}", :description => "Sample-Domain Inc", :status => 0}
response = Linode[:compute].domain_create( @test_domain, type, options)
domain= generate_unique_domain
options = { :SOA_email => "netops@#{domain}", :description => "Sample-Domain Inc", :status => 0}
response = Linode[:compute].domain_create( domain, type, options)
if response.status == 200
@master_zone_id = response.body['DATA']['DomainID']
@new_zones << @master_zone_id
@ -37,10 +50,10 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
pending if Fog.mocking?
type = 'slave'
options = { :SOA_email => "netops@#{@test_domain}", :refresh_sec => 14400, :retry_sec => 3600,
@domain= generate_unique_domain
options = { :SOA_email => "netops@#{@domain}", :refresh_sec => 14400, :retry_sec => 3600,
:expire_sec => 604800, :ttl_sec => 28800, :status => 0, :master_ips => '1.2.3.4;2.3.4.5' }
domain= 'sub.' + @test_domain
response = Linode[:compute].domain_create( domain, type, options)
response = Linode[:compute].domain_create( @domain, type, options)
if response.status == 200
@slave_zone_id = response.body['DATA']['DomainID']
@new_zones << @slave_zone_id
@ -49,21 +62,20 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
response.status == 200
end
test("get zone #{@slave_zone_id} - check all parameters") do
test("get zone #{@slave_zone_id} - check all parameters for #{@domain}") do
pending if Fog.mocking?
result= false
domain= 'sub.' + @test_domain
response = Linode[:compute].domain_list( @slave_zone_id)
if response.status == 200
zones = response.body['DATA']
num_zones = zones.count
if num_zones == 1
zone= zones[0]
if (zone['SOA_EMAIL'] == "netops@#{@test_domain}") and (zone['REFRESH_SEC'] == 14400) and
if (zone['SOA_EMAIL'] == "netops@#{@domain}") and (zone['REFRESH_SEC'] == 14400) and
(zone['RETRY_SEC'] == 3600) and (zone['EXPIRE_SEC'] == 604800) and (zone['TTL_SEC'] == 28800) and
(zone['STATUS'] == 0) and (zone['DOMAIN'] == domain) and (zone['TYPE'] == 'slave')
(zone['STATUS'] == 0) and (zone['DOMAIN'] == @domain) and (zone['TYPE'] == 'slave')
(zone['MASTER_IPS'] == '1.2.3.4;2.3.4.5')
result= true
end
@ -110,8 +122,8 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
test('create record - simple A record') do
pending if Fog.mocking?
domain= 'www.' + @test_domain
options = { :name => domain, :target => '4.5.6.7', :ttl_sec => 3600 }
host= 'www.' + @domain
options = { :name => host, :target => '4.5.6.7', :ttl_sec => 3600 }
response = Linode[:compute].domain_resource_create( @master_zone_id, 'A', options)
if response.status == 200
record_id = response.body['DATA']['ResourceID']
@ -124,8 +136,8 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
test('create record - CNAME record') do
pending if Fog.mocking?
domain= 'mail'
options = { :name => domain, :target => 'www.' + @test_domain }
host= 'mail'
options = { :name => host, :target => 'www.' + @domain }
response = Linode[:compute].domain_resource_create( @master_zone_id, 'CNAME', options)
if response.status == 200
record_id = response.body['DATA']['ResourceID']
@ -138,7 +150,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
test('create record - NS record') do
pending if Fog.mocking?
options = { :name => @test_domain, :target => 'ns.' + @test_domain}
options = { :name => @domain, :target => 'ns.' + @domain}
response = Linode[:compute].domain_resource_create( @master_zone_id, 'NS', options)
if response.status == 200
record_id = response.body['DATA']['ResourceID']
@ -151,7 +163,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
test('create record - MX record') do
pending if Fog.mocking?
options = { :target => 'mail.' + @test_domain, :ttl_sec => 7200, :priority => 5 }
options = { :target => 'mail.' + @domain, :ttl_sec => 7200, :priority => 5 }
response = Linode[:compute].domain_resource_create( @master_zone_id, 'MX', options)
if response.status == 200
@record_id = response.body['DATA']['ResourceID']
@ -166,7 +178,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
result= false
domain= 'mail.' + @test_domain
domain= 'mail.' + @domain
response = Linode[:compute].domain_resource_list(@master_zone_id, @record_id)
if response.status == 200
@ -187,7 +199,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
test("update record #{@record_id} - change target") do
pending if Fog.mocking?
options = { :target => 'mail2.' + @test_domain }
options = { :target => 'mail2.' + @domain }
response = Linode[:compute].domain_resource_update( @master_zone_id, @record_id, options)
response.status == 200
@ -198,7 +210,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
result= false
domain= 'mail2.' + @test_domain
domain= 'mail2.' + @domain
response = Linode[:compute].domain_resource_list(@master_zone_id, @record_id)
if response.status == 200

View file

@ -1,9 +1,21 @@
Shindo.tests('Slicehost::Compute | DNS requests', ['slicehost', 'dns']) do
@test_domain = 'test-fog.com.'
@domain = ''
@new_zones = []
@new_records =[]
def generate_unique_domain( with_trailing_dot = false)
#get time (with 1/100th of sec accuracy)
#want unique domain name and if provider is fast, this can be called more than once per second
time= (Time.now.to_f * 100).to_i
domain = 'test-' + time.to_s + '.com'
if with_trailing_dot
domain+= '.'
end
domain
end
tests( 'success') do
test('get current zone count') do
@ -22,7 +34,8 @@ Shindo.tests('Slicehost::Compute | DNS requests', ['slicehost', 'dns']) do
test('create zone - simple') do
pending if Fog.mocking?
response = Slicehost[:compute].create_zone(@test_domain)
domain = generate_unique_domain( true)
response = Slicehost[:compute].create_zone(domain)
if response.status == 201
zone_id = response.body['id']
@new_zones << zone_id
@ -35,8 +48,8 @@ Shindo.tests('Slicehost::Compute | DNS requests', ['slicehost', 'dns']) do
pending if Fog.mocking?
options = { :ttl => 1800, :active => 'N' }
domain= 'sub.' + @test_domain
response = Slicehost[:compute].create_zone( domain, options)
@domain= generate_unique_domain( true)
response = Slicehost[:compute].create_zone( @domain, options)
if response.status == 201
@zone_id = response.body['id']
@new_zones << @zone_id
@ -45,16 +58,15 @@ Shindo.tests('Slicehost::Compute | DNS requests', ['slicehost', 'dns']) do
response.status == 201
end
test("get zone #{@zone_id} - check all parameters") do
test("get zone #{@zone_id} - check all parameters for #{@domain}") do
pending if Fog.mocking?
result= false
domain= 'sub.' + @test_domain
response = Slicehost[:compute].get_zone( @zone_id)
if response.status == 200
zone = response.body
if (zone['origin'] == 'sub.' + @test_domain) and (zone['ttl'] == 1800) and
if (zone['origin'] == @domain) and (zone['ttl'] == 1800) and
(zone['active'] == 'N')
result= true;
end
@ -89,7 +101,7 @@ Shindo.tests('Slicehost::Compute | DNS requests', ['slicehost', 'dns']) do
zones = response.body['zones']
zones.each { |zone|
if zone['id'] == @new_zones[1]
if (zone['origin'] == 'sub.' + @test_domain) and (zone['ttl'] == 1800) and
if (zone['origin'] == 'sub.' + @domain) and (zone['ttl'] == 1800) and
(zone['active'] == 'N')
result= true;
end
@ -106,9 +118,9 @@ Shindo.tests('Slicehost::Compute | DNS requests', ['slicehost', 'dns']) do
test('create record - simple A record') do
pending if Fog.mocking?
domain= 'sub.' + @test_domain
host= 'www.' + @domain
zone_id= @new_zones[1]
response = Slicehost[:compute].create_record( 'A', zone_id, domain, '1.2.3.4')
response = Slicehost[:compute].create_record( 'A', zone_id, host, '1.2.3.4')
if response.status == 201
record_id = response.body['id']
@new_records << record_id
@ -120,10 +132,10 @@ Shindo.tests('Slicehost::Compute | DNS requests', ['slicehost', 'dns']) do
test('create record - A record - all parameters set') do
pending if Fog.mocking?
domain= 'sub2.' + @test_domain
host= 'ftp.' + @domain
zone_id= @new_zones[1]
options = { :ttl => 3600, :active => 'N'}
response = Slicehost[:compute].create_record( 'A', zone_id, domain, '1.2.3.4', options)
response = Slicehost[:compute].create_record( 'A', zone_id, host, '1.2.3.4', options)
if response.status == 201
record_id = response.body['id']
@new_records << record_id
@ -135,9 +147,8 @@ Shindo.tests('Slicehost::Compute | DNS requests', ['slicehost', 'dns']) do
test('create record - CNAME record') do
pending if Fog.mocking?
domain= 'sub.' + @test_domain
zone_id= @new_zones[1]
response = Slicehost[:compute].create_record( 'CNAME', zone_id, 'www', domain)
response = Slicehost[:compute].create_record( 'CNAME', zone_id, 'mail', @domain)
if response.status == 201
record_id = response.body['id']
@new_records << record_id
@ -149,11 +160,10 @@ Shindo.tests('Slicehost::Compute | DNS requests', ['slicehost', 'dns']) do
test('create record - NS record') do
pending if Fog.mocking?
domain= 'sub.' + @test_domain
ns_domain = 'ns.' + @test_domain
ns_domain = 'ns.' + @domain
zone_id= @new_zones[1]
options = { :ttl => 3600, :active => 'N'}
response = Slicehost[:compute].create_record( 'NS', zone_id, domain, ns_domain, options)
response = Slicehost[:compute].create_record( 'NS', zone_id, @domain, ns_domain, options)
if response.status == 201
record_id = response.body['id']
@new_records << record_id
@ -165,11 +175,10 @@ Shindo.tests('Slicehost::Compute | DNS requests', ['slicehost', 'dns']) do
test('create record - MX record') do
pending if Fog.mocking?
domain= 'sub.' + @test_domain
mail_domain = 'mail.' + @test_domain
mail_domain = 'mail.' + @domain
zone_id= @new_zones[1]
options = { :ttl => 3600, :active => 'N', :aux => '10'}
response = Slicehost[:compute].create_record( 'MX', zone_id, domain, mail_domain, options)
response = Slicehost[:compute].create_record( 'MX', zone_id, @domain, mail_domain, options)
if response.status == 201
@record_id = response.body['id']
@new_records << @record_id
@ -185,10 +194,9 @@ Shindo.tests('Slicehost::Compute | DNS requests', ['slicehost', 'dns']) do
response = Slicehost[:compute].get_record(@record_id)
if response.status == 200
domain= 'sub.' + @test_domain
mail_domain = 'mail.' + @test_domain
mail_domain = 'mail.' + @domain
record = response.body['records'][0]
if (record['record-type'] == 'MX') and (record['name'] == domain) and
if (record['record-type'] == 'MX') and (record['name'] == @domain) and
(record['data'] == mail_domain) and (record['ttl'] == 3600) and (record['active'] == 'N') and
(record['aux'] == "10")
result= true
@ -211,9 +219,8 @@ Shindo.tests('Slicehost::Compute | DNS requests', ['slicehost', 'dns']) do
records.each {|record|
if record['record-type'] == 'MX'
domain= 'sub.' + @test_domain
mail_domain = 'mail.' + @test_domain
if (record['record-type'] == 'MX') and (record['name'] == domain) and
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
(record['aux'] == "10")
result= true

View file

@ -1,57 +1,374 @@
USERNAME=''
PASSWORD=''
TEST_DOMAIN = 'sample53-domain.com.'
Shindo.tests('Zerigo::Compute | DNS requests', ['zerigo', 'dns']) do
# tests assume have a free acccount - ie need to limit # of zones to max of 3
#connect to Zerigo
# options = { :zerigo_user => USERNAME, :zerigo_password => PASSWORD }
# @zerigo = Fog::Zerigo::Compute.new( options)
@domain = ''
@org_zone_count = 0
@new_zones = []
@new_records =[]
def generate_unique_domain( with_trailing_dot = false)
#get time (with 1/100th of sec accuracy)
#want unique domain name and if provider is fast, this can be called more than once per second
time= (Time.now.to_f * 100).to_i
domain = 'test-' + time.to_s + '.com'
if with_trailing_dot
domain+= '.'
end
domain
end
tests( 'success') do
tests('#count_hosts') do
test('get current zone count') do
pending if Fog.mocking?
@org_zone_count= 0
response = Zerigo[:compute].count_zones()
if response.status == 200
@org_zone_count = response.body['count']
end
response.status == 200
end
test('create zone - simple') do
pending if Fog.mocking?
options = { :nx_ttl => 1800 }
domain = generate_unique_domain
response = Zerigo[:compute].create_zone( domain, 3600, 'pri_sec', options)
if response.status == 201
zone_id = response.body['id']
#worked so can now delete
response = Zerigo[:compute].delete_zone( zone_id)
end
response.status == 200
end
test('create zone - set zerigo as slave') do
pending if Fog.mocking?
options = { :active => 'N', :ns1=> '2.3.4.5' }
domain= generate_unique_domain
response = Zerigo[:compute].create_zone( domain, 14400, 'sec', options )
if response.status == 201
zone_id = response.body['id']
#worked so can now delete
response = Zerigo[:compute].delete_zone( zone_id)
end
response.status == 200
end
test('create zone - set zerigo as master') do
pending if Fog.mocking?
domain= generate_unique_domain
options = { :active => 'N', :slave_nameservers=> "ns1.#{domain},ns2.#{domain}" }
response = Zerigo[:compute].create_zone( domain, 14400, 'pri', options )
if response.status == 201
zone_id = response.body['id']
#worked so can now delete
response = Zerigo[:compute].delete_zone( zone_id)
end
response.status == 200
end
tests('#count_zones') do
test('create zone - set all parameters') do
pending if Fog.mocking?
@domain = generate_unique_domain
options = { :nx_ttl => 1800, :active => 'N', :hostmaster => "netops@#{@domain}",
:notes => 'for client ABC', :tag_list=> 'sample-tag' }
response = Zerigo[:compute].create_zone( @domain, 14400, 'pri', options )
if response.status == 201
@zone_id = response.body['id']
@new_zones << @zone_id
end
response.status == 201
end
test("get zone #{@zone_id} for #{@domain}- check all parameters") do
pending if Fog.mocking?
result= false
response = Zerigo[:compute].get_zone( @zone_id)
if response.status == 200
zone = response.body
if (zone['ns-type'] == 'pri') and (zone['tag-list'] == 'sample-tag') and
(zone['default-ttl'] == 14400) and (zone['nx-ttl'] == 1800) and
(zone['updated-at'].length > 0) and (zone['created-at'].length > 0) and
(zone['domain'] == @domain) and (zone['notes'] == 'for client ABC') and
(zone['id'] == @zone_id)
result = true
end
result
end
end
tests('#create_host') do
test("update zone #{@zone_id} - set notes & tags") do
pending if Fog.mocking?
options = { :notes => 'for client XYZ', :tag_list=> 'testing-tag' }
response = Zerigo[:compute].update_zone( @zone_id, options )
response.status == 200
end
test("get zone #{@zone_id} - check updated parameters") do
pending if Fog.mocking?
result= false
response = Zerigo[:compute].get_zone( @zone_id)
if response.status == 200
zone = response.body
if (zone['tag-list'] == 'testing-tag') and (zone['notes'] == 'for client XYZ')
result = true
end
result
end
end
tests('#create_zone') do
test("get zone stats for #{@zone_id}") do
pending if Fog.mocking?
result= false
response = Zerigo[:compute].get_zone_stats( @zone_id)
if response.status == 200
zone = response.body
if (zone['domain'] == @domain) and (zone['id'] == @zone_id) and
(zone['period-begin'].length > 0) and (zone['period-end'].length > 0)
result= true
end
result
end
end
tests('#delete_host') do
end
test('list zones - make sure total count is correct') do
pending if Fog.mocking?
result= false
response = Zerigo[:compute].list_zones()
if response.status == 200
zones = response.body['zones']
if (@org_zone_count+1) == zones.count
result= true;
end
end
result
end
tests('#find_hosts') do
test('create record - simple A record') do
pending if Fog.mocking?
host= 'www'
options = { :hostname => host }
response = Zerigo[:compute].create_host( @zone_id, 'A', '1.2.3.4', options)
if response.status == 201
record_id = response.body['id']
@new_records << record_id
end
response.status == 201
end
tests('#get_host') do
test('create record - CNAME record') do
pending if Fog.mocking?
host = 'mail'
options = { :hostname => host }
response = Zerigo[:compute].create_host( @zone_id, 'CNAME', @domain, options)
if response.status == 201
record_id = response.body['id']
@new_records << record_id
end
response.status == 201
end
tests('#get_zone') do
test('create record - NS record') do
pending if Fog.mocking?
#note, when use create_host for a NS record, it needs to be a delation
#rather than a NS record for the main domain (those NS records are setup
#using the zone methods)
sub_domain = 'subdomain' # that we want to delete DNS for
ns_host = 'ns.' + @domain
options = { :hostname => sub_domain}
response = Zerigo[:compute].create_host( @zone_id, 'NS', ns_host, options)
if response.status == 201
record_id = response.body['id']
@new_records << record_id
end
response.status == 201
end
tests('#get_zone_stats') do
test('create record - MX record') do
pending if Fog.mocking?
mail_domain = 'mail.' + @domain
options = { :hostname => @domain, :ttl => 3600, :priority => '3'}
response = Zerigo[:compute].create_host( @zone_id, 'MX', mail_domain, options)
if response.status == 201
@record_id = response.body['id']
@new_records << @record_id
end
response.status == 201
end
tests('#list_hosts') do
test("get host #{@record_id}") do
pending if Fog.mocking?
result = false
response = Zerigo[:compute].get_host( @record_id)
if response.status == 200
host = response.body
if (host['id'] == @record_id) and (host['host-type'] == 'MX') and
(host['created-at'].length > 0) and (host['updated-at'].length > 0)
result = true
end
end
result
end
tests('#list_zones') do
test("update host #{@record_id}") do
pending if Fog.mocking?
result = false
options = { :priority => 7 }
response = Zerigo[:compute].update_host( @record_id, options)
if response.status == 200
response = Zerigo[:compute].get_host( @record_id)
if response.status == 200
host= response.body
if (host['priority'] == 7)
result = true
end
end
end
result
end
tests('#update_host') do
test('count host records') do
pending if Fog.mocking?
host_count = 0
response = Zerigo[:compute].count_hosts( @zone_id)
if response.status == 200
host_count = response.body['count']
end
host_count == 4
end
tests('#update_zone') do
test('list host records') do
pending if Fog.mocking?
result = false
response = Zerigo[:compute].list_hosts( @zone_id)
if response.status == 200
hosts = response.body['hosts']
if (hosts.count == 4)
hosts.each { |host|
if (host['id'] > 0) and (host['fqdn'].length > 0) and (host['host-type'].length > 0) and
(host['created-at'].length > 0) and (host['updated-at'].length > 0)
result = true
end
}
end
end
result
end
test("find host: mail.#{@domain}") do
pending if Fog.mocking?
result = false
host = 'mail.' + @domain
response = Zerigo[:compute].find_hosts( host)
if response.status == 200
hosts = response.body['hosts']
host_count = hosts.count
if (host_count == 1)
result = true
end
end
result
end
test("find host: mail.#{@domain} - method 2") do
pending if Fog.mocking?
result = false
host = 'mail.' + @domain
response = Zerigo[:compute].find_hosts( host, @zone_id)
if response.status == 200
hosts = response.body['hosts']
host_count = hosts.count
if (host_count == 1)
result = true
end
end
result
end
test("delete #{@new_records.count} records created") do
pending if Fog.mocking?
result= true
@new_records.each { |record_id|
response = Zerigo[:compute].delete_host( record_id)
if response.status != 200
result= false;
end
}
result
end
test("delete #{@new_zones.count} zones created") do
pending if Fog.mocking?
result= true
@new_zones.each { |zone_id|
response = Zerigo[:compute].delete_zone( zone_id)
if response.status != 200
result= false;
end
}
result
end
end
tests( 'failure') do
end
end