mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
commit
93a52e2c02
12 changed files with 389 additions and 13 deletions
|
@ -5,10 +5,22 @@ require 'fog/core/parser'
|
|||
|
||||
module Fog
|
||||
module Dynect
|
||||
|
||||
extend Fog::Provider
|
||||
|
||||
service(:dns, 'dynect/dns')
|
||||
|
||||
class Mock
|
||||
def self.job_id
|
||||
Fog::Mock.random_numbers(8).to_i
|
||||
end
|
||||
|
||||
def self.token
|
||||
Fog::Mock.random_hex(48)
|
||||
end
|
||||
|
||||
def self.version
|
||||
[Fog::Mock.random_numbers(1), Fog::Mock.random_numbers(1), Fog::Mock.random_numbers(1)].join('.')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,13 +27,33 @@ module Fog
|
|||
request :put_zone
|
||||
|
||||
class Mock
|
||||
|
||||
def initialize(options={})
|
||||
@dynect_customer = options[:dynect_customer]
|
||||
@dynect_username = options[:dynect_username]
|
||||
@dynect_password = options[:dynect_password]
|
||||
end
|
||||
|
||||
def self.data
|
||||
@data ||= {
|
||||
:zones => {}
|
||||
}
|
||||
end
|
||||
|
||||
def self.reset
|
||||
@data = nil
|
||||
end
|
||||
|
||||
def auth_token
|
||||
@auth_token ||= Fog::Dynect::Mock.token
|
||||
end
|
||||
|
||||
def data
|
||||
self.class.data
|
||||
end
|
||||
|
||||
def reset_data
|
||||
self.class.reset
|
||||
end
|
||||
end
|
||||
|
||||
class Real
|
||||
|
|
|
@ -19,6 +19,37 @@ module Fog
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def delete_record(type, zone, fqdn, record_id)
|
||||
raise Fog::DNS::Dynect::NotFound unless zone = self.data[:zones][zone]
|
||||
|
||||
raise Fog::DNS::Dynect::NotFound unless zone[:records][type].find { |record| record[:fqdn] == fqdn && record[:record_id] == record_id.to_i }
|
||||
|
||||
zone[:records_to_delete] << {
|
||||
:type => type,
|
||||
:fqdn => fqdn,
|
||||
:record_id => record_id.to_i
|
||||
}
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
response.body = {
|
||||
"status" => "success",
|
||||
"data" => {},
|
||||
"job_id" => Fog::Dynect::Mock.job_id,
|
||||
"msgs" => [{
|
||||
"INFO" => "delete: Record will be deleted on zone publish",
|
||||
"SOURCE" => "BLL",
|
||||
"ERR_CD" => nil,
|
||||
"LVL" => "INFO"
|
||||
}]
|
||||
}
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,6 +16,27 @@ module Fog
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def delete_zone(zone)
|
||||
self.data[:zones].delete(zone)
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
"status" => "success",
|
||||
"data" => {},
|
||||
"job_id" => Fog::Dynect::Mock.job_id,
|
||||
"msgs" => [{
|
||||
"ERR_CD" => '',
|
||||
"INFO" => '',
|
||||
"LVL" => '',
|
||||
"SOURCE" => ''
|
||||
}]
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,6 +18,37 @@ module Fog
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_node_list(zone, options = {})
|
||||
raise Fog::Dynect::DNS::NotFound unless zone = self.data[:zones][zone]
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
data = [zone[:zone]]
|
||||
|
||||
if fqdn = options[:fqdn]
|
||||
data = data | zone[:records].collect { |type, records| records.select { |record| record[:fqdn] == fqdn } }.flatten.compact
|
||||
else
|
||||
data = data | zone[:records].collect { |type, records| records.collect { |record| record[:fqdn] } }.flatten
|
||||
end
|
||||
|
||||
response.body = {
|
||||
"status" => "success",
|
||||
"data" => data,
|
||||
"job_id" => Fog::Dynect::Mock.job_id,
|
||||
"msgs" => [{
|
||||
"INFO" => "get_tree: Here is your zone tree",
|
||||
"SOURCE" => "BLL",
|
||||
"ERR_CD" => nil,
|
||||
"LVL" => "INFO"
|
||||
}]
|
||||
}
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,6 +20,60 @@ module Fog
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_record(type, zone, fqdn, options = {})
|
||||
raise ArgumentError unless [
|
||||
'AAAA', 'ANY', 'A', 'CNAME',
|
||||
'DHCID', 'DNAME', 'DNSKEY',
|
||||
'DS', 'KEY', 'LOC', 'MX',
|
||||
'NSA', 'NS', 'PTR', 'PX',
|
||||
'RP', 'SOA', 'SPF', 'SRV',
|
||||
'SSHFP', 'TXT'
|
||||
].include? type
|
||||
raise Fog::Dynect::DNS::NotFound unless zone = self.data[:zones][zone]
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
if record_id = options['record_id']
|
||||
raise Fog::Dynect::DNS::NotFound unless record = zone[:records][type].first { |record| record[:record_id] == record_id }
|
||||
response.body = {
|
||||
"status" => "success",
|
||||
"data" => {
|
||||
"zone" => record[:zone][:zone],
|
||||
"ttl" => record[:ttl],
|
||||
"fqdn" => record[:fqdn],
|
||||
"record_type" => type,
|
||||
"rdata" => record[:rdata],
|
||||
"record_id" => record[:record_id]
|
||||
},
|
||||
"job_id" => Fog::Dynect::Mock.job_id,
|
||||
"msgs" => [{
|
||||
"INFO" => "get: Found the record",
|
||||
"SOURCE" => "API-B",
|
||||
"ERR_CD" => nil,
|
||||
"LVL" => "INFO"
|
||||
}]
|
||||
}
|
||||
else
|
||||
records = zone[:records][type].select { |record| record[:fqdn] == fqdn }
|
||||
response.body = {
|
||||
"status" => "success",
|
||||
"data" => records.collect { |record| "/REST/ARecord/#{record[:zone]}/#{record[:fqdn]}/#{record[:record_id]}" },
|
||||
"job_id" => Fog::Dynect::Mock.job_id,
|
||||
"msgs" => [{
|
||||
"INFO" => "detail: Found #{records.size} record",
|
||||
"SOURCE" => "BLL",
|
||||
"ERR_CD" => nil,
|
||||
"LVL" => "INFO"
|
||||
}]
|
||||
}
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,6 +17,40 @@ module Fog
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_zone(options = {})
|
||||
if options['zone'] && zone = self.data[:zones][options['zone']]
|
||||
data = {
|
||||
"zone_type" => zone[:zone_type],
|
||||
"serial_style" => zone[:serial_style],
|
||||
"serial" => zone[:serial],
|
||||
"zone" => zone[:zone]
|
||||
}
|
||||
info = "get: Your zone, #{zone[:zone]}"
|
||||
else
|
||||
data = self.data[:zones].collect { |zone, data| "/REST/Zone/#{zone}/" }
|
||||
info = "get: Your #{data.size} zones"
|
||||
end
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
response.body = {
|
||||
"status" => "success",
|
||||
"data" => data,
|
||||
"job_id" => Fog::Dynect::Mock.job_id,
|
||||
"msgs" => [{
|
||||
"INFO" => info,
|
||||
"SOURCE" => "BLL",
|
||||
"ERR_CD" => nil,
|
||||
"LVL" => "INFO"
|
||||
}]
|
||||
}
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,6 +22,51 @@ module Fog
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def post_record(type, zone, fqdn, rdata, options = {})
|
||||
raise Fog::Dynect::DNS::NotFound unless zone = self.data[:zones][zone]
|
||||
|
||||
records = zone[:records]
|
||||
record_id = zone[:next_record_id]
|
||||
zone[:next_record_id] += 1
|
||||
|
||||
record = {
|
||||
:type => type,
|
||||
:zone => zone,
|
||||
:fqdn => fqdn,
|
||||
:rdata => rdata,
|
||||
:ttl => options[:ttl] || zone[:ttl],
|
||||
:record_id => record_id
|
||||
}
|
||||
|
||||
records[type] << record
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
response.body = {
|
||||
"status" => "success",
|
||||
"data" => {
|
||||
"zone" => record[:zone][:zone],
|
||||
"ttl" => record[:ttl],
|
||||
"fqdn" => record[:fqdn],
|
||||
"record_type" => record[:type],
|
||||
"rdata" => record[:rdata],
|
||||
"record_id" => record[:record_id]
|
||||
},
|
||||
"job_id" => Fog::Dynect::Mock.job_id,
|
||||
"msgs" => [{
|
||||
"INFO"=>"add: Record added",
|
||||
"SOURCE"=>"BLL",
|
||||
"ERR_CD"=>nil,
|
||||
"LVL"=>"INFO"
|
||||
}]
|
||||
}
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,19 +18,26 @@ module Fog
|
|||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def post_session
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'API-Version' => '2.3.1',
|
||||
'Auth-Token' => 'thetoken=='
|
||||
"status" => "success",
|
||||
"data" => {
|
||||
"token" => auth_token,
|
||||
"version" => Fog::Dynect::Mock.version
|
||||
},
|
||||
"job_id" => Fog::Dynect::Mock.job_id,
|
||||
"msgs"=>[{
|
||||
"INFO"=>"login: Login successful",
|
||||
"SOURCE"=>"BLL",
|
||||
"ERR_CD"=>nil,
|
||||
"LVL"=>"INFO"
|
||||
}]
|
||||
}
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,6 +27,45 @@ module Fog
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def post_zone(rname, ttl, zone, options = {})
|
||||
new_zone = self.data[:zones][zone] = {
|
||||
:next_record_id => 0,
|
||||
:records => Hash.new do |records_hash, type|
|
||||
records_hash[type] = []
|
||||
end,
|
||||
:records_to_delete => [],
|
||||
:rname => rname,
|
||||
:serial_style => options[:serial_style] || "increment",
|
||||
:serial => 0,
|
||||
:ttl => ttl,
|
||||
:zone => zone,
|
||||
:zone_type => "Primary"
|
||||
}
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
"status" => "success",
|
||||
"data" => {
|
||||
"zone_type" => new_zone[:zone_type],
|
||||
"serial_style" => new_zone[:serial_style],
|
||||
"serial" => new_zone[:serial],
|
||||
"zone" => zone
|
||||
},
|
||||
"job_id" => Fog::Dynect::Mock.job_id,
|
||||
"msgs" => [{
|
||||
"INFO" => "create: New zone #{zone} created. Publish it to put it on our server.",
|
||||
"SOURCE" => "BLL",
|
||||
"ERR_CD" => nil,
|
||||
"LVL" => "INFO"
|
||||
}]
|
||||
}
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,6 +21,56 @@ module Fog
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def put_zone(zone, options = {})
|
||||
raise Fog::Dynect::DNS::NotFound unless zone = self.data[:zones][zone]
|
||||
|
||||
raise ArgumentError unless options.size == 1
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
data = {}
|
||||
|
||||
if options['freeze']
|
||||
zone['frozen'] = true
|
||||
info = "freeze: Your zone is now frozen"
|
||||
elsif options['publish']
|
||||
zone[:changes] = {}
|
||||
zone[:records_to_delete].each do |record|
|
||||
zone[:records][record[:type]].delete_if { |r| r[:fqdn] == record[:fqdn] && r[:record_id] == record[:record_id] }
|
||||
end
|
||||
zone[:records_to_delete] = []
|
||||
data = {
|
||||
"zone_type" => zone[:zone_type],
|
||||
"serial_style" => zone[:serial_style],
|
||||
"serial" => zone[:serial] += 1,
|
||||
"zone" => zone[:zone]
|
||||
}
|
||||
info = "publish: #{zone[:zone]} published"
|
||||
elsif options['thaw']
|
||||
zone[:frozen] = false
|
||||
info = "thaw: Your zone is now thawed, you may edit normally"
|
||||
else
|
||||
raise ArgumentError
|
||||
end
|
||||
|
||||
response.body = {
|
||||
"status" => "success",
|
||||
"data" => data,
|
||||
"job_id" => Fog::Dynect::Mock.job_id,
|
||||
"msgs" => [{
|
||||
"INFO" => info,
|
||||
"SOURCE"=>"BLL",
|
||||
"ERR_CD"=>nil,
|
||||
"LVL"=>"INFO"
|
||||
}]
|
||||
}
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
Shindo.tests('Dynect::dns | DNS requests', ['dynect', 'dns']) do
|
||||
|
||||
pending if Fog.mocking?
|
||||
|
||||
shared_format = {
|
||||
'job_id' => Integer,
|
||||
'msgs' => [{
|
||||
|
@ -81,7 +79,7 @@ Shindo.tests('Dynect::dns | DNS requests', ['dynect', 'dns']) do
|
|||
@dns.post_record('A', @domain, @fqdn, {'address' => '1.2.3.4'}, {}).body
|
||||
end
|
||||
|
||||
put_zone_format = shared_format.merge({
|
||||
publish_zone_format = shared_format.merge({
|
||||
'data' => {
|
||||
'serial' => Integer,
|
||||
'serial_style' => String,
|
||||
|
@ -90,8 +88,24 @@ Shindo.tests('Dynect::dns | DNS requests', ['dynect', 'dns']) do
|
|||
}
|
||||
})
|
||||
|
||||
tests("put_zone('#{@domain}', :publish => true)").formats(put_zone_format) do
|
||||
@dns.put_zone(@domain, :publish => true).body
|
||||
tests("put_zone('#{@domain}', 'publish' => true)").formats(publish_zone_format) do
|
||||
@dns.put_zone(@domain, 'publish' => true).body
|
||||
end
|
||||
|
||||
freeze_zone_format = shared_format.merge({
|
||||
'data' => {}
|
||||
})
|
||||
|
||||
tests("put_zone('#{@domain}', 'freeze' => true)").formats(freeze_zone_format) do
|
||||
@dns.put_zone(@domain, 'freeze' => true).body
|
||||
end
|
||||
|
||||
thaw_zone_format = shared_format.merge({
|
||||
'data' => {}
|
||||
})
|
||||
|
||||
tests("put_zone('#{@domain}', 'thaw' => true)").formats(thaw_zone_format) do
|
||||
@dns.put_zone(@domain, 'thaw' => true).body
|
||||
end
|
||||
|
||||
get_node_list_format = shared_format.merge({
|
||||
|
@ -112,6 +126,23 @@ Shindo.tests('Dynect::dns | DNS requests', ['dynect', 'dns']) do
|
|||
data
|
||||
end
|
||||
|
||||
get_record_format = shared_format.merge({
|
||||
'data' => {
|
||||
'zone' => String,
|
||||
'ttl' => Integer,
|
||||
'fqdn' => String,
|
||||
'record_type' => String,
|
||||
'rdata' => {
|
||||
'address' => String
|
||||
},
|
||||
'record_id' => Integer
|
||||
}
|
||||
})
|
||||
|
||||
tests("get_record('A', '#{@domain}', '#{@fqdn}', 'record_id' => '#{@record_id}')").formats(get_record_format) do
|
||||
@dns.get_record('A', @domain, @fqdn, 'record_id' => @record_id).body
|
||||
end
|
||||
|
||||
delete_record_format = shared_format.merge({
|
||||
'data' => {}
|
||||
})
|
||||
|
@ -124,9 +155,10 @@ Shindo.tests('Dynect::dns | DNS requests', ['dynect', 'dns']) do
|
|||
'data' => {}
|
||||
})
|
||||
|
||||
sleep 3 unless Fog.mocking?
|
||||
|
||||
tests("delete_zone('#{@domain}')").formats(delete_zone_format) do
|
||||
@dns.delete_zone(@domain).body
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue