mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace|dns] records requests
This commit is contained in:
parent
d6654e736c
commit
754947b98f
17 changed files with 409 additions and 148 deletions
|
@ -19,7 +19,7 @@ module Fog
|
|||
attribute :comment
|
||||
|
||||
def destroy
|
||||
response = connection.delete_domain(identity)
|
||||
response = connection.remove_domain(identity)
|
||||
wait_for_job response.body['jobId'], Fog.timeout
|
||||
true
|
||||
end
|
||||
|
@ -53,7 +53,7 @@ module Fog
|
|||
end
|
||||
|
||||
def create
|
||||
requires :domain
|
||||
requires :domain, :email
|
||||
|
||||
data = { :name => domain, :email => email }
|
||||
response = connection.create_domains([data])
|
||||
|
|
|
@ -16,15 +16,21 @@ module Fog
|
|||
collection :zones
|
||||
|
||||
request_path 'fog/dns/requests/rackspace'
|
||||
#TODO - Import/Export, modify multiple domains
|
||||
#TODO - Import/Export, modify multiple domains, modify multiple records
|
||||
request :callback
|
||||
request :list_domains
|
||||
request :list_domain_details
|
||||
request :modify_domain
|
||||
request :create_domains
|
||||
request :delete_domain
|
||||
request :delete_domains
|
||||
request :remove_domain
|
||||
request :remove_domains
|
||||
request :list_subdomains
|
||||
request :list_records
|
||||
request :list_record_details
|
||||
request :modify_record
|
||||
request :remove_record
|
||||
request :remove_records
|
||||
request :add_records
|
||||
|
||||
class Mock
|
||||
end
|
||||
|
@ -82,6 +88,12 @@ module Fog
|
|||
def array_to_query_string(arr)
|
||||
arr.collect {|k,v| "#{k}=#{v}" }.join('&')
|
||||
end
|
||||
|
||||
def validate_path_fragment(name, fragment)
|
||||
if fragment.nil? or fragment.to_s.empty?
|
||||
raise ArgumentError.new ("#{name} cannot be null or empty")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
34
lib/fog/dns/requests/rackspace/add_records.rb
Normal file
34
lib/fog/dns/requests/rackspace/add_records.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rackspace
|
||||
class Real
|
||||
def add_records(domain_id, records)
|
||||
|
||||
validate_path_fragment :domain_id, domain_id
|
||||
|
||||
data = {
|
||||
'records' => records.collect do |record|
|
||||
record_data = {
|
||||
'name' => record[:name],
|
||||
'type' => record[:type],
|
||||
'data' => record[:data]
|
||||
}
|
||||
|
||||
if record.has_key? :priority
|
||||
record_data['priority'] = record[:priority]
|
||||
end
|
||||
record_data
|
||||
end
|
||||
}
|
||||
|
||||
request(
|
||||
:expects => 202,
|
||||
:method => 'POST',
|
||||
:path => "domains/#{domain_id}/records",
|
||||
:body => MultiJson.encode(data)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,6 +3,9 @@ module Fog
|
|||
class Rackspace
|
||||
class Real
|
||||
def callback(job_id)
|
||||
|
||||
validate_path_fragment :job_id, job_id
|
||||
|
||||
request(
|
||||
:expects => [200, 202, 204],
|
||||
:method => 'GET',
|
||||
|
|
|
@ -4,6 +4,8 @@ module Fog
|
|||
class Real
|
||||
def list_domain_details(domain_id, options={})
|
||||
|
||||
validate_path_fragment :domain_id, domain_id
|
||||
|
||||
path = "domains/#{domain_id}"
|
||||
query_data = {}
|
||||
|
||||
|
|
21
lib/fog/dns/requests/rackspace/list_record_details.rb
Normal file
21
lib/fog/dns/requests/rackspace/list_record_details.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rackspace
|
||||
class Real
|
||||
def list_record_details(domain_id, record_id)
|
||||
|
||||
validate_path_fragment :domain_id, domain_id
|
||||
validate_path_fragment :record_id, record_id
|
||||
|
||||
path = "domains/#{domain_id}/records/#{record_id}"
|
||||
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => path
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/dns/requests/rackspace/list_records.rb
Normal file
23
lib/fog/dns/requests/rackspace/list_records.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rackspace
|
||||
class Real
|
||||
def list_records(domain_id, options={})
|
||||
|
||||
validate_path_fragment :domain_id, domain_id
|
||||
|
||||
path = "domains/#{domain_id}/records"
|
||||
if !options.empty?
|
||||
path = path + '?' + array_to_query_string(options)
|
||||
end
|
||||
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => path
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,6 +4,8 @@ module Fog
|
|||
class Real
|
||||
def list_subdomains(domain_id, options={})
|
||||
|
||||
validate_path_fragment :domain_id, domain_id
|
||||
|
||||
path = "domains/#{domain_id}/subdomains"
|
||||
if !options.empty?
|
||||
path = path + '?' + array_to_query_string(options)
|
||||
|
|
|
@ -4,6 +4,8 @@ module Fog
|
|||
class Real
|
||||
def modify_domain(domain_id, options={})
|
||||
|
||||
validate_path_fragment :domain_id, domain_id
|
||||
|
||||
path = "domains/#{domain_id}"
|
||||
data = {}
|
||||
|
||||
|
|
37
lib/fog/dns/requests/rackspace/modify_record.rb
Normal file
37
lib/fog/dns/requests/rackspace/modify_record.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rackspace
|
||||
class Real
|
||||
def modify_record(domain_id, record_id, options={})
|
||||
|
||||
validate_path_fragment :domain_id, domain_id
|
||||
validate_path_fragment :record_id, record_id
|
||||
|
||||
path = "domains/#{domain_id}/records/#{record_id}"
|
||||
data = {}
|
||||
|
||||
if options.has_key? :ttl
|
||||
data['ttl'] = options[:ttl]
|
||||
end
|
||||
if options.has_key? :name
|
||||
data['name'] = options[:name]
|
||||
end
|
||||
if options.has_key? :data
|
||||
data['data'] = options[:data]
|
||||
end
|
||||
|
||||
if data.empty?
|
||||
return
|
||||
end
|
||||
|
||||
request(
|
||||
:expects => [202, 204],
|
||||
:method => 'PUT',
|
||||
:path => path,
|
||||
:body => MultiJson.encode(data)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,7 +2,9 @@ module Fog
|
|||
module DNS
|
||||
class Rackspace
|
||||
class Real
|
||||
def delete_domain(domain_id, options={})
|
||||
def remove_domain(domain_id, options={})
|
||||
|
||||
validate_path_fragment :domain_id, domain_id
|
||||
|
||||
path = "domains/#{domain_id}"
|
||||
query_data = {}
|
|
@ -2,7 +2,7 @@ module Fog
|
|||
module DNS
|
||||
class Rackspace
|
||||
class Real
|
||||
def delete_domains(domain_ids, options={})
|
||||
def remove_domains(domain_ids, options={})
|
||||
|
||||
path = "domains?" + domain_ids.collect { |domain_id| "id=#{domain_id}" }.join('&')
|
||||
query_data = {}
|
21
lib/fog/dns/requests/rackspace/remove_record.rb
Normal file
21
lib/fog/dns/requests/rackspace/remove_record.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rackspace
|
||||
class Real
|
||||
def remove_record(domain_id, record_id)
|
||||
|
||||
validate_path_fragment :domain_id, domain_id
|
||||
validate_path_fragment :record_id, record_id
|
||||
|
||||
path = "domains/#{domain_id}/records/#{record_id}"
|
||||
|
||||
request(
|
||||
:expects => [202, 204],
|
||||
:method => 'DELETE',
|
||||
:path => path
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
20
lib/fog/dns/requests/rackspace/remove_records.rb
Normal file
20
lib/fog/dns/requests/rackspace/remove_records.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rackspace
|
||||
class Real
|
||||
def remove_records(domain_id, record_ids)
|
||||
|
||||
validate_path_fragment :domain_id, domain_id
|
||||
|
||||
path = "domains/#{domain_id}/records?" + record_ids.collect { |record_id| "id=#{record_id}" }.join('&')
|
||||
|
||||
request(
|
||||
:expects => [202, 204],
|
||||
:method => 'DELETE',
|
||||
:path => path
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,139 +2,8 @@ Shindo.tests('Fog::DNS[:rackspace] | DNS requests', ['rackspace', 'dns']) do
|
|||
|
||||
@service = Fog::DNS[:rackspace]
|
||||
|
||||
SUBDOMAIN_FORMAT = {
|
||||
'name' => String,
|
||||
'id' => Integer,
|
||||
'created' => String,
|
||||
'updated' => String
|
||||
}
|
||||
|
||||
LIST_SUBDOMAINS_FORMAT = {
|
||||
'domains' => [SUBDOMAIN_FORMAT],
|
||||
'totalEntries' => Integer
|
||||
}
|
||||
|
||||
LIST_DOMAIN_FORMAT = {
|
||||
'domains' => [
|
||||
{
|
||||
'name' => String,
|
||||
'id' => Integer,
|
||||
'accountId' => Integer,
|
||||
'updated' => String,
|
||||
'created' => String
|
||||
}
|
||||
],
|
||||
'totalEntries' => Integer,
|
||||
'links' => [
|
||||
{
|
||||
'rel' => String,
|
||||
'href' => String
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
RECORD_LIST_FORMAT = {
|
||||
'records' => [
|
||||
{
|
||||
'name' => String,
|
||||
'id' => String,
|
||||
'type' => String,
|
||||
'data' => String,
|
||||
'updated' => String,
|
||||
'created' => String,
|
||||
'ttl' => Integer,
|
||||
'priority' => Fog::Nullable::Integer
|
||||
}
|
||||
],
|
||||
#In some cases this is returned (domain details) and in some cases it isn't (create domain). Marking as nullable.
|
||||
'totalEntries' => Fog::Nullable::Integer
|
||||
}
|
||||
|
||||
NAME_SERVERS_FORMAT = [{
|
||||
'name' => String
|
||||
}]
|
||||
|
||||
BASIC_DOMAIN_DETAIL_FORMAT = {
|
||||
'name' => String,
|
||||
'id' => Integer,
|
||||
'accountId' => Integer,
|
||||
'updated' => String,
|
||||
'created' =>String,
|
||||
'ttl' => Integer,
|
||||
'emailAddress' => String,
|
||||
'nameservers' => NAME_SERVERS_FORMAT
|
||||
}
|
||||
|
||||
LIST_DOMAIN_DETAILS_WITH_RECORDS = BASIC_DOMAIN_DETAIL_FORMAT.merge({
|
||||
'recordsList' => RECORD_LIST_FORMAT
|
||||
})
|
||||
|
||||
LIST_DOMAIN_DETAILS_WITH_RECORDS_AND_SUBDOMAINS_FORMAT = BASIC_DOMAIN_DETAIL_FORMAT.merge({
|
||||
'recordsList' => RECORD_LIST_FORMAT,
|
||||
'subdomains' => [SUBDOMAIN_FORMAT]
|
||||
})
|
||||
|
||||
LIST_DOMAIN_DETAILS_WITHOUT_RECORDS_AND_SUBDOMAINS_FORMAT = BASIC_DOMAIN_DETAIL_FORMAT
|
||||
|
||||
CREATE_DOMAINS_FORMAT = {
|
||||
'domains' => [
|
||||
BASIC_DOMAIN_DETAIL_FORMAT.merge({
|
||||
'recordsList' => RECORD_LIST_FORMAT
|
||||
})
|
||||
]
|
||||
}
|
||||
|
||||
def wait_for(response)
|
||||
job_id = response.body['jobId']
|
||||
while true
|
||||
response = @service.callback(job_id)
|
||||
return response if response.status != 202
|
||||
sleep 5
|
||||
end
|
||||
end
|
||||
|
||||
def domain_tests(domain_attributes)
|
||||
tests("create_domains([#{domain_attributes}])").formats(CREATE_DOMAINS_FORMAT) do
|
||||
response = wait_for @service.create_domains([domain_attributes])
|
||||
@domain_details = response.body['domains']
|
||||
@domain_id = @domain_details[0]['id']
|
||||
response.body
|
||||
end
|
||||
|
||||
begin
|
||||
if block_given?
|
||||
yield
|
||||
end
|
||||
ensure
|
||||
tests("delete_domain('#{@domain_id}')").succeeds do
|
||||
wait_for @service.delete_domain @domain_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def domains_tests(domains_attributes, custom_delete = false)
|
||||
tests("create_domains(#{domains_attributes})").formats(CREATE_DOMAINS_FORMAT) do
|
||||
response = wait_for @service.create_domains(domains_attributes)
|
||||
@domain_details = response.body['domains']
|
||||
@domain_ids = @domain_details.collect { |domain| domain['id'] }
|
||||
response.body
|
||||
end
|
||||
|
||||
begin
|
||||
if block_given?
|
||||
yield
|
||||
end
|
||||
ensure
|
||||
if !custom_delete
|
||||
tests("deletes_domains(#{@domain_ids})").succeeds do
|
||||
wait_for @service.delete_domains @domain_ids
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
tests('success on simple domain') do
|
||||
domain_tests({:name => 'basictestdomain.com', :email => 'hostmaster@basictestdomain.com', :records => [{:ttl => 300, :name => 'basictestdomain.com', :type => 'A', :data => '192.168.1.1'}]}) do
|
||||
domain_tests(@service, {:name => 'basictestdomain.com', :email => 'hostmaster@basictestdomain.com', :records => [{:ttl => 300, :name => 'basictestdomain.com', :type => 'A', :data => '192.168.1.1'}]}) do
|
||||
|
||||
tests('list_domains').formats(LIST_DOMAIN_FORMAT) do
|
||||
@service.list_domains.body
|
||||
|
@ -150,13 +19,13 @@ Shindo.tests('Fog::DNS[:rackspace] | DNS requests', ['rackspace', 'dns']) do
|
|||
|
||||
tests("modify_domain('#{@domain_id}', :ttl => 500, :comment => 'woot', :email => 'randomemail@randomhost.com')").succeeds do
|
||||
response = @service.modify_domain @domain_id, :ttl => 500, :comment => 'woot', :email => 'randomemail@randomhost.com'
|
||||
wait_for response
|
||||
wait_for @service, response
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
tests('success for domain with multiple records') do
|
||||
domain_tests(
|
||||
domain_tests(@service,
|
||||
{
|
||||
:name => 'testdomainwithmultiplerecords.com',
|
||||
:email => 'hostmaster@testdomainwithmultiplerecords.com',
|
||||
|
@ -180,7 +49,7 @@ Shindo.tests('Fog::DNS[:rackspace] | DNS requests', ['rackspace', 'dns']) do
|
|||
end
|
||||
|
||||
tests('success for multiple domains') do
|
||||
domains_tests(
|
||||
domains_tests(@service,
|
||||
[
|
||||
{:name => 'basictestdomain1.com', :email => 'hostmaster@basictestdomain1.com', :records => [{:ttl => 300, :name =>'basictestdomain1.com', :type => 'A', :data => '192.168.1.1'}]},
|
||||
{:name => 'basictestdomain2.com', :email => 'hostmaster@basictestdomain2.com', :records => [{:ttl => 300, :name =>'basictestdomain2.com', :type => 'A', :data => '192.168.1.1'}]}
|
||||
|
@ -188,7 +57,7 @@ Shindo.tests('Fog::DNS[:rackspace] | DNS requests', ['rackspace', 'dns']) do
|
|||
end
|
||||
|
||||
tests('success for domain with subdomain') do
|
||||
domains_tests(
|
||||
domains_tests(@service,
|
||||
[
|
||||
{:name => 'basictestdomain.com', :email => 'hostmaster@basictestdomain.com', :records => [{:ttl => 300, :name =>'basictestdomain.com', :type => 'A', :data => '192.168.1.1'}]},
|
||||
{:name => 'subdomain.basictestdomain.com', :email => 'hostmaster@subdomain.basictestdomain.com', :records => [{:ttl => 300, :name =>'subdomain.basictestdomain.com', :type => 'A', :data => '192.168.1.1'}]}
|
||||
|
@ -216,8 +85,8 @@ Shindo.tests('Fog::DNS[:rackspace] | DNS requests', ['rackspace', 'dns']) do
|
|||
@service.list_subdomains(@root_domain_id).body
|
||||
end
|
||||
|
||||
tests("delete_domain('#{@root_domain_id}', :delete_subdomains => true)") do
|
||||
wait_for @service.delete_domain(@root_domain_id, :delete_subdomains => true)
|
||||
tests("remove_domain('#{@root_domain_id}', :delete_subdomains => true)") do
|
||||
wait_for @service, @service.remove_domain(@root_domain_id, :delete_subdomains => true)
|
||||
|
||||
test('domain and subdomains were really deleted') do
|
||||
(@service.list_domains.body['domains'].collect { |domain| domain['name'] } & ['basictestdomain.com', 'subdomain.basictestdomain.com']).empty?
|
||||
|
@ -229,7 +98,7 @@ Shindo.tests('Fog::DNS[:rackspace] | DNS requests', ['rackspace', 'dns']) do
|
|||
tests( 'failure') do
|
||||
|
||||
tests('create_domain(invalid)').raises(Fog::Rackspace::Errors::BadRequest) do
|
||||
wait_for @service.create_domains [{:name => 'badtestdomain.com', :email => '', :records => [{:ttl => 300, :name => 'badtestdomain.com', :type => 'A', :data => '192.168.1.1'}]}]
|
||||
wait_for @service, @service.create_domains([{:name => 'badtestdomain.com', :email => '', :records => [{:ttl => 300, :name => 'badtestdomain.com', :type => 'A', :data => '192.168.1.1'}]}])
|
||||
end
|
||||
|
||||
tests('list_domains :limit => 5, :offset => 8').raises(Fog::Rackspace::Errors::BadRequest) do
|
||||
|
@ -243,8 +112,8 @@ Shindo.tests('Fog::DNS[:rackspace] | DNS requests', ['rackspace', 'dns']) do
|
|||
#tests('create_domains(#{domains})').raises(Fog::Rackspace::Errors::Conflict) do
|
||||
# wait_for @service.create_domains(domains)
|
||||
#end
|
||||
#tests('delete_domain(34343435)').raises(Fog::DNS::Rackspace::DeleteFault) do
|
||||
# @service.delete_domain 34343435
|
||||
#tests('remove_domain(34343435)').raises(Fog::DNS::Rackspace::DeleteFault) do
|
||||
# @service.remove_domain 34343435
|
||||
#end
|
||||
end
|
||||
end
|
||||
|
|
132
tests/dns/requests/rackspace/helper.rb
Normal file
132
tests/dns/requests/rackspace/helper.rb
Normal file
|
@ -0,0 +1,132 @@
|
|||
SUBDOMAIN_FORMAT = {
|
||||
'name' => String,
|
||||
'id' => Integer,
|
||||
'created' => String,
|
||||
'updated' => String
|
||||
}
|
||||
|
||||
LIST_SUBDOMAINS_FORMAT = {
|
||||
'domains' => [SUBDOMAIN_FORMAT],
|
||||
'totalEntries' => Integer
|
||||
}
|
||||
|
||||
LIST_DOMAIN_FORMAT = {
|
||||
'domains' => [
|
||||
{
|
||||
'name' => String,
|
||||
'id' => Integer,
|
||||
'accountId' => Integer,
|
||||
'updated' => String,
|
||||
'created' => String
|
||||
}
|
||||
],
|
||||
'totalEntries' => Integer,
|
||||
'links' => [
|
||||
{
|
||||
'rel' => String,
|
||||
'href' => String
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
RECORD_FORMAT = {
|
||||
'name' => String,
|
||||
'id' => String,
|
||||
'type' => String,
|
||||
'data' => String,
|
||||
'updated' => String,
|
||||
'created' => String,
|
||||
'ttl' => Integer,
|
||||
'priority' => Fog::Nullable::Integer
|
||||
}
|
||||
|
||||
RECORD_LIST_FORMAT = {
|
||||
'records' => [RECORD_FORMAT],
|
||||
#In some cases this is returned (domain details) and in some cases it isn't (create domain). Marking as nullable.
|
||||
'totalEntries' => Fog::Nullable::Integer
|
||||
}
|
||||
|
||||
NAME_SERVERS_FORMAT = [{
|
||||
'name' => String
|
||||
}]
|
||||
|
||||
BASIC_DOMAIN_DETAIL_FORMAT = {
|
||||
'name' => String,
|
||||
'id' => Integer,
|
||||
'accountId' => Integer,
|
||||
'updated' => String,
|
||||
'created' =>String,
|
||||
'ttl' => Integer,
|
||||
'emailAddress' => String,
|
||||
'nameservers' => NAME_SERVERS_FORMAT
|
||||
}
|
||||
|
||||
LIST_DOMAIN_DETAILS_WITH_RECORDS = BASIC_DOMAIN_DETAIL_FORMAT.merge({
|
||||
'recordsList' => RECORD_LIST_FORMAT
|
||||
})
|
||||
|
||||
LIST_DOMAIN_DETAILS_WITH_RECORDS_AND_SUBDOMAINS_FORMAT = BASIC_DOMAIN_DETAIL_FORMAT.merge({
|
||||
'recordsList' => RECORD_LIST_FORMAT,
|
||||
'subdomains' => [SUBDOMAIN_FORMAT]
|
||||
})
|
||||
|
||||
LIST_DOMAIN_DETAILS_WITHOUT_RECORDS_AND_SUBDOMAINS_FORMAT = BASIC_DOMAIN_DETAIL_FORMAT
|
||||
|
||||
CREATE_DOMAINS_FORMAT = {
|
||||
'domains' => [
|
||||
BASIC_DOMAIN_DETAIL_FORMAT.merge({
|
||||
'recordsList' => RECORD_LIST_FORMAT
|
||||
})
|
||||
]
|
||||
}
|
||||
|
||||
def wait_for(service, response)
|
||||
job_id = response.body['jobId']
|
||||
while true
|
||||
response = service.callback(job_id)
|
||||
return response if response.status != 202
|
||||
sleep 5
|
||||
end
|
||||
end
|
||||
|
||||
def domain_tests(service, domain_attributes)
|
||||
tests("create_domains([#{domain_attributes}])").formats(CREATE_DOMAINS_FORMAT) do
|
||||
response = wait_for service, service.create_domains([domain_attributes])
|
||||
@domain_details = response.body['domains']
|
||||
@domain_id = @domain_details[0]['id']
|
||||
response.body
|
||||
end
|
||||
|
||||
begin
|
||||
if block_given?
|
||||
yield
|
||||
end
|
||||
ensure
|
||||
tests("remove_domain('#{@domain_id}')").succeeds do
|
||||
wait_for service, service.remove_domain(@domain_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def domains_tests(service, domains_attributes, custom_delete = false)
|
||||
tests("create_domains(#{domains_attributes})").formats(CREATE_DOMAINS_FORMAT) do
|
||||
response = wait_for service, service.create_domains(domains_attributes)
|
||||
@domain_details = response.body['domains']
|
||||
@domain_ids = @domain_details.collect { |domain| domain['id'] }
|
||||
response.body
|
||||
end
|
||||
|
||||
begin
|
||||
if block_given?
|
||||
yield
|
||||
end
|
||||
ensure
|
||||
if !custom_delete
|
||||
tests("remove_domains(#{@domain_ids})").succeeds do
|
||||
wait_for service, service.remove_domains(@domain_ids)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
81
tests/dns/requests/rackspace/records_tests.rb
Normal file
81
tests/dns/requests/rackspace/records_tests.rb
Normal file
|
@ -0,0 +1,81 @@
|
|||
Shindo.tests('Fog::DNS[:rackspace] | dns records requests', ['rackspace', 'dns']) do
|
||||
|
||||
@service = Fog::DNS[:rackspace]
|
||||
|
||||
domain_tests(@service, {:name => 'basictestdomain.com', :email => 'hostmaster@basictestdomain.com', :records => [{:ttl => 300, :name => 'basictestdomain.com', :type => 'A', :data => '192.168.1.1'}]}) do
|
||||
|
||||
tests('success on single record') do
|
||||
|
||||
tests("list_records(#{@domain_id})").formats(RECORD_LIST_FORMAT) do
|
||||
@service.list_records(@domain_id).body
|
||||
end
|
||||
|
||||
tests("add_records(#{@domain_id}, [{ :name => 'test1.basictestdomain.com', :type => 'A', :data => '192.168.2.1'}])").formats(RECORD_LIST_FORMAT) do
|
||||
response = wait_for @service, @service.add_records(@domain_id, [{ :name => 'test1.basictestdomain.com', :type => 'A', :data => '192.168.2.1'}])
|
||||
@record_id = response.body['records'].first['id']
|
||||
response.body
|
||||
end
|
||||
|
||||
tests("list_record_details(#{@domain_id}, #{@record_id})").formats(RECORD_FORMAT) do
|
||||
@service.list_record_details(@domain_id, @record_id).body
|
||||
end
|
||||
|
||||
tests("modify_record(#{@domain_id}, #{@record_id}, { :ttl => 500, :name => 'test2.basictestdomain.com', :data => '192.168.3.1' })").succeeds do
|
||||
wait_for @service, @service.modify_record(@domain_id, @record_id, { :ttl => 500, :name => 'test2.basictestdomain.com', :data => '192.168.3.1' })
|
||||
end
|
||||
|
||||
tests("remove_record(#{@domain_id}, #{@record_id})").succeeds do
|
||||
wait_for @service, @service.remove_record(@domain_id, @record_id)
|
||||
end
|
||||
end
|
||||
|
||||
tests('success on multiple records') do
|
||||
|
||||
records_attributes =
|
||||
[
|
||||
{ :name => 'test1.basictestdomain.com', :type => 'A', :data => '192.168.2.1'},
|
||||
{ :name => 'basictestdomain.com', :type => 'MX', :priority => 10, :data => 'mx.basictestdomain.com'}
|
||||
]
|
||||
|
||||
tests("add_records(#{@domain_id}, #{records_attributes})").formats(RECORD_LIST_FORMAT) do
|
||||
response = wait_for @service, @service.add_records(@domain_id, records_attributes)
|
||||
@record_ids = response.body['records'].collect { |record| record['id'] }
|
||||
response.body
|
||||
end
|
||||
|
||||
tests("remove_records(#{@domain_id}, #{@record_ids})").succeeds do
|
||||
wait_for @service, @service.remove_records(@domain_id, @record_ids)
|
||||
end
|
||||
end
|
||||
|
||||
tests( 'failure') do
|
||||
tests("list_records('')").raises(ArgumentError) do
|
||||
@service.list_records('')
|
||||
end
|
||||
|
||||
tests("list_records('abc')").raises(Fog::Rackspace::Errors::NotFound) do
|
||||
@service.list_records('abc')
|
||||
end
|
||||
|
||||
tests("list_record_details(#{@domain_id}, '')").raises(ArgumentError) do
|
||||
@service.list_record_details(@domain_id, '')
|
||||
end
|
||||
|
||||
tests("list_record_details(#{@domain_id}, 'abc')").raises(Fog::Rackspace::Errors::NotFound) do
|
||||
@service.list_record_details(@domain_id, 'abc')
|
||||
end
|
||||
|
||||
tests("remove_record(#{@domain_id}, '')").raises(ArgumentError) do
|
||||
@service.remove_record(@domain_id, '')
|
||||
end
|
||||
|
||||
tests("remove_record(#{@domain_id}, 'abc')").raises(Fog::Rackspace::Errors::NotFound) do
|
||||
@service.remove_record(@domain_id, 'abc')
|
||||
end
|
||||
|
||||
tests("add_record(#{@domain_id}, [{ :name => '', :type => '', :data => ''}])").raises(Fog::Rackspace::Errors::BadRequest) do
|
||||
@service.add_records(@domain_id, [{ :name => '', :type => '', :data => ''}])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue