Merge branch 'ggoodale'

Conflicts:
	lib/fog/bin/bluebox.rb
	tests/helper.rb

Closes #156
This commit is contained in:
geemus 2011-02-23 11:14:44 -08:00
commit 8bcd078193
32 changed files with 1138 additions and 19 deletions

View File

@ -5,7 +5,9 @@ class Bluebox < Fog::Bin
case key
when :compute
Fog::Bluebox::Compute
else
when :dns
Fog::Bluebox::DNS
else
raise ArgumentError, "Unsupported #{self} service: #{key}"
end
end
@ -15,6 +17,8 @@ class Bluebox < Fog::Bin
hash[key] = case key
when :compute
Fog::Compute.new(:provider => 'Bluebox')
when :dns
Fog::DNS.new(:provider => 'Bluebox')
else
raise ArgumentError, "Unrecognized service: #{service}"
end

View File

@ -84,13 +84,14 @@ module Fog
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :flavor_id, :image_id
options = if !password && !public_key
raise(ArgumentError, "password or public_key is required for this operation")
elsif public_key
{'ssh_public_key' => public_key}
elsif @password
{'password' => password}
options = {}
if identity.nil? # new record
raise(ArgumentError, "password or public_key is required for this operation") if !password && !public_key
options['ssh_public_key'] = public_key if @public_key
options['password'] = password if @password
end
options['username'] = username
data = connection.create_block(flavor_id, image_id, options)
merge_attributes(data.body)

View File

@ -7,6 +7,9 @@ module Fog
when 'AWS'
require 'fog/dns/aws'
Fog::AWS::DNS.new(attributes)
when 'Bluebox'
require 'fog/dns/bluebox'
Fog::Bluebox::DNS.new(attributes)
when 'Linode'
require 'fog/dns/linode'
Fog::Linode::DNS.new(attributes)

110
lib/fog/dns/bluebox.rb Normal file
View File

@ -0,0 +1,110 @@
module Fog
module Bluebox
class DNS < Fog::Service
requires :bluebox_api_key, :bluebox_customer_id
recognizes :bluebox_host, :bluebox_port, :bluebox_scheme, :persistent
recognizes :provider # remove post deprecation
model_path 'fog/dns/models/bluebox'
model :record
collection :records
model :zone
collection :zones
request_path 'fog/dns/requests/bluebox'
request :create_record
request :update_record
request :delete_record
request :create_zone
request :update_zone
request :delete_zone
request :get_record
request :get_records
request :get_zone
request :get_zones
class Mock
def self.data
@data ||= Hash.new do |hash, key|
hash[key] = {}
end
end
def self.reset_data(keys=data.keys)
for key in [*keys]
data.delete(key)
end
end
def initialize(options={})
unless options.delete(:provider)
location = caller.first
warning = "[yellow][WARN] Fog::Bluebox::DNS.new is deprecated, use Fog::DNS.new(:provider => 'Bluebox') instead[/]"
warning << " [light_black](" << location << ")[/] "
Formatador.display_line(warning)
end
@bluebox_customer_id = options[:bluebox_customer_id]
@bluebox_api_key = options[:bluebox_api_key]
@data = self.class.data[@bluebox_customer_id]
@data = self.class.data[@bluebox_api_key]
end
end
class Real
def initialize(options ={})
unless options.delete(:provider)
location = caller.first
warning = "[yellow][WARN] Fog::Bluebox::DNS.new is deprecated, use Fog::DNS.new(:provider => 'Bluebox') instead[/]"
warning << " [light_black](" << location << ")[/] "
Formatador.display_line(warning)
end
@bluebox_customer_id = options[:bluebox_customer_id]
@bluebox_api_key = options[:bluebox_api_key]
@host = options[:bluebox_host] || "boxpanel.bluebox.net"
@port = options[:bluebox_port] || 443
@scheme = options[:bluebox_scheme] || 'https'
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
end
def reload
@connection.reset
end
def request(params)
params[:headers] ||= {}
params[:headers]['Authorization'] = "Basic #{auth_header}"
params[:headers]['Accept'] = 'application/xml'
case params[:method]
when 'POST', 'PUT'
params[:headers]['Content-Type'] = 'application/xml'
end
begin
response = @connection.request(params.merge!({:host => @host}))
rescue Excon::Errors::HTTPStatusError => error
raise case error
when Excon::Errors::NotFound
Fog::Bluebox::DNS::NotFound.slurp(error)
else
error
end
end
response
end
protected
def auth_header
@auth_header ||= Base64.encode64("#{@bluebox_customer_id}:#{@bluebox_api_key}").gsub("\n",'')
end
end
end
end
end

View File

@ -0,0 +1,52 @@
require 'fog/core/model'
module Fog
module Bluebox
class DNS
class Record < Fog::Model
identity :id
attribute :name
attribute :domain_id, :aliases => 'domain-id'
attribute :domain
attribute :type
attribute :ip, :aliases => 'content'
def initialize(attributes={})
super
end
def destroy
requires :identity
connection.delete_record(@zone.identity, identity)
true
end
def zone
@zone
end
def save
requires :zone, :type, :name, :ip
data = unless identity
connection.create_record(zone.identity, type, name, ip)
else
connection.update_record(zone.identity, identity, {:type => type, :name => name, :content => ip})
end
merge_attributes(data.body)
true
end
private
def zone=(new_zone)
@zone = new_zone
end
end
end
end
end

View File

@ -0,0 +1,36 @@
require 'fog/core/collection'
require 'fog/dns/models/bluebox/record'
module Fog
module Bluebox
class DNS
class Records < Fog::Collection
attribute :zone
model Fog::Bluebox::DNS::Record
def all
requires :zone
data = connection.get_records(zone.identity).body['records']
load(data)
end
def get(record_id)
data = connection.get_record(zone.identity, record_id).body
new(data)
rescue Fog::Service::NotFound
nil
end
def new(attributes = {})
requires :zone
super({ :zone => zone }.merge!(attributes))
end
end
end
end
end

View File

@ -0,0 +1,62 @@
require 'fog/core/model'
require 'fog/dns/models/bluebox/records'
module Fog
module Bluebox
class DNS
class Zone < Fog::Model
identity :id
attribute :name
attribute :serial
attribute :ttl
attribute :retry
attribute :expires
attribute :record_count, :aliases => 'record-count'
attribute :refresh
attribute :minimum
def initialize(attributes = {})
super(attributes)
end
def destroy
raise Fog::Errors::Error.new('Not implemented')
end
def records
@records ||= begin
Fog::Bluebox::DNS::Records.new(
:zone => self,
:connection => connection
)
end
end
def nameservers
[
'ns1.blueblxgrid.com',
'ns2.blueblxgrid.com',
'ns3.blueblxgrid.com'
]
end
def destroy
requires :identity
connection.delete_zone(identity)
true
end
def save
requires :name, :ttl
options = attributes.inject({}) {|h, kv| h[kv[0]] = kv[1]; h}
data = identity.nil? ? connection.create_zone(options) : connection.update_zone(identity, options)
merge_attributes(data.body)
true
end
end
end
end
end

View File

@ -0,0 +1,28 @@
require 'fog/core/collection'
require 'fog/dns/models/bluebox/zone'
module Fog
module Bluebox
class DNS
class Zones < Fog::Collection
model Fog::Bluebox::DNS::Zone
def all
data = connection.get_zones.body['zones']
load(data)
end
def get(zone_id)
data = connection.get_zone(zone_id).body
new(data)
rescue Fog::Service::NotFound
nil
end
end
end
end
end

View File

@ -0,0 +1,26 @@
module Fog
module Parsers
module Bluebox
module DNS
class CreateRecord < Fog::Parsers::Base
def reset
@response = {}
end
def end_element(name)
case name
when 'serial', 'ttl', 'retry', 'refresh', 'minimum', 'record-count', 'expires'
@response[name] = @value.to_i
when 'name', 'id'
@response[name] = @value
end
end
end
end
end
end
end

View File

@ -0,0 +1,26 @@
module Fog
module Parsers
module Bluebox
module DNS
class CreateZone < Fog::Parsers::Base
def reset
@response = {}
end
def end_element(name)
case name
when 'serial', 'ttl', 'retry', 'refresh', 'minimum', 'record-count', 'expires'
@response[name] = @value.to_i
when 'name', 'id'
@response[name] = @value
end
end
end
end
end
end
end

View File

@ -0,0 +1,21 @@
module Fog
module Parsers
module Bluebox
module DNS
class GetRecord < Fog::Parsers::Base
def reset
@response = { }
end
def end_element(name)
@response[name] = @value
end
end
end
end
end
end

View File

@ -0,0 +1,27 @@
module Fog
module Parsers
module Bluebox
module DNS
class GetRecords < Fog::Parsers::Base
def reset
@record = {}
@response = { 'records' => [] }
end
def end_element(name)
case name
when 'record'
@response['records'] << @record
@record = {}
else
@record[name] = @value
end
end
end
end
end
end
end

View File

@ -0,0 +1,23 @@
module Fog
module Parsers
module Bluebox
module DNS
class GetZone < Fog::Parsers::Base
def reset
@response = {}
end
def end_element(name)
case name
when 'serial', 'ttl', 'retry', 'expires', 'record-count', 'refresh', 'minimum'
@response[name] = @value.to_i
when 'name', 'id'
@response[name] = @value
end
end
end
end
end
end
end

View File

@ -0,0 +1,30 @@
module Fog
module Parsers
module Bluebox
module DNS
class GetZones < Fog::Parsers::Base
def reset
@zone = {}
@response = { 'zones' => [] }
end
def end_element(name)
case name
when 'serial', 'ttl', 'retry', 'expires', 'record-count', 'refresh', 'minimum'
@zone[name] = @value.to_i
when 'name', 'id'
@zone[name] = @value
when 'record'
@response['zones'] << @zone
@zone = {}
end
end
end
end
end
end
end

View File

@ -0,0 +1,48 @@
module Fog
module Bluebox
class DNS
class Real
require 'fog/dns/parsers/bluebox/create_record'
# Create a new record in a DNS zone
# ==== Parameters
# * type<~String> - type of DNS record to create (A, CNAME, etc)
# * name<~String> - host name this DNS record is for
# * content<~String> - data for the DNS record (ie for an A record, the IP address)
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'name'<~String> - as above
# * 'id'<~Integer> - Id of zone/domain - used in future API calls for this zone
# * 'ttl'<~Integer> - as above
# * 'data'<~String> - as above
# * 'active'<~String> - as above
# * 'aux'<~String> - as above
def create_record(zone_id, type, name, content, options={})
body = %Q{<?xml version="1.0" encoding="UTF-8"?><record><type>#{type}</type><name>#{name}</name><content>#{content}</content>}
options.each do |k,v|
body += %Q{<#{k}>#{v}</#{k}>}
end
body += %Q{</record>}
request(
:body => body,
:expects => 202,
:method => 'POST',
:parser => Fog::Parsers::Bluebox::DNS::CreateRecord.new,
:path => "/api/domains/#{zone_id}/records.xml"
)
end
end
class Mock
def create_record(zone_id, type, name, content)
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,52 @@
module Fog
module Bluebox
class DNS
class Real
require 'fog/dns/parsers/bluebox/create_zone'
# Create a new DNS zone
# ==== Parameters
# * 'name'<~String> - The name of the zone
# * 'ttl'<~Integer> - TimeToLive (ttl) for the domain, in seconds
# * 'retry'<~Integer> - Retry interval for the domain, in seconds
# * 'refresh'<~Integer> - Refresh interval for the zone
# * 'minimum'<~Integer> - Minimum refresh interval for the zone
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'name'<~String> - The name of the zone
# * 'serial'<~Integer> - Serial number of the zone
# * 'ttl'<~Integer> - TimeToLive (ttl) for the domain, in seconds
# * 'retry'<~Integer> - Retry interval for the domain, in seconds
# * 'record-count'<~Integer> - Number of records in the zone
# * 'id'<~String> - Id for the zone
# * 'refresh'<~Integer> - Refresh interval for the zone
# * 'minimum'<~Integer> - Minimum refresh interval for the zone
def create_zone(options)
body = %Q{<?xml version="1.0" encoding="UTF-8"?><domain><name>#{options[:name]}</name><ttl>#{options[:ttl]}</ttl>}
body += %Q{<retry>#{options[:retry]}</retry>} if options[:retry]
body += %Q{<refresh>#{options[:retry]}</refresh>} if options[:refresh]
body += %Q{<minimum>#{options[:minimum]}</minimum>} if options[:minimum]
body += %Q{</domain>}
request(
:body => body,
:expects => 202,
:method => 'POST',
:parser => Fog::Parsers::Bluebox::DNS::CreateZone.new,
:path => "/api/domains.xml"
)
end
end
class Mock
def create_zone(options)
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,31 @@
module Fog
module Bluebox
class DNS
class Real
# Delete a record from the specified DNS zone
# ==== Parameters
# * record_id<~Integer> - Id of DNS record to delete
#
# ==== Returns
# * response<~Excon::Response>: - HTTP status code will be result
def delete_record(zone_id, record_id)
request(
:expects => 200,
:method => 'DELETE',
:path => "/api/domains/#{zone_id}/records/#{record_id}.xml"
)
end
end
class Mock
def delete_record(zone_id, record_id)
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,31 @@
module Fog
module Bluebox
class DNS
class Real
# Delete a zone from DNS
# ==== Parameters
# * zone_id<~Integer> - Id of zone to delete
#
# ==== Returns
# * response<~Excon::Response>: - HTTP status code will be result
def delete_zone(zone_id)
request(
:expects => 200,
:method => 'DELETE',
:path => "/api/domains/#{zone_id}.xml"
)
end
end
class Mock
def delete_zone(zone_id)
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,40 @@
module Fog
module Bluebox
class DNS
class Real
require 'fog/dns/parsers/bluebox/get_record'
# Get an individual DNS record from the specified zone
#
# ==== Returns
# * response<~Excon::Response>:
# * hash<~Hash>:
# * 'id'<~String> - The id of this record
# * 'type'<~String> - type of DNS record to create (A, CNAME, etc)
# * 'domain-id'<~Integer> - ID of the zone
# * 'name'<~String> - empty?
# * 'domain'<~String> - The domain name
# * 'type'<~String> - The type of DNS record (e.g. A, MX, NS, etc.)
# * 'content'<~String> - data for the DNS record (ie for an A record, the IP address)
def get_record(zone_id, record_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Bluebox::DNS::GetRecord.new,
:path => "/api/domains/#{zone_id}/records/#{record_id}.xml"
)
end
end
class Mock
def get_record(record_id)
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,41 @@
module Fog
module Bluebox
class DNS
class Real
require 'fog/dns/parsers/bluebox/get_records'
# Get all the DNS records across all the DNS zones for this account
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# * 'addresses'<~Array> - Ip addresses for the slice
# * 'backup-id'<~Integer> - Id of backup slice was booted from
# * 'flavor_id'<~Integer> - Id of flavor slice was booted from
# * 'id'<~Integer> - Id of the slice
# * 'image-id'<~Integer> - Id of image slice was booted from
# * 'name'<~String> - Name of the slice
# * 'progress'<~Integer> - Progress of current action, in percentage
# * 'status'<~String> - Current status of the slice
def get_records(zone_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Bluebox::DNS::GetRecords.new,
:path => "/api/domains/#{zone_id}/records.xml"
)
end
end
class Mock
def get_records
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,44 @@
module Fog
module Bluebox
class DNS
class Real
require 'fog/dns/parsers/bluebox/get_zone'
# Get details of a DNS zone
#
# ==== Parameters
# * zone_id<~Integer> - Id of zone to lookup
#
# ==== Returns
# * response<~Excon::Response>:
# * hash<~Hash>:
# * 'name'<~String> - The name of the zone
# * 'serial'<~Integer> - Serial number of the zone
# * 'ttl'<~Integer> - TimeToLive (ttl) for the domain, in seconds
# * 'retry'<~Integer> - Retry interval for the domain, in seconds
# * 'record-count'<~Integer> - Number of records in the zone
# * 'id'<~String> - Id for the zone
# * 'refresh'<~Integer> - Refresh interval for the zone
# * 'minimum'<~Integer> - Minimum refresh interval for the zone
def get_zone(zone_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Bluebox::DNS::GetZone.new,
:path => "/api/domains/#{zone_id}.xml"
)
end
end
class Mock
def get_zone(zone_id)
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,43 @@
module Fog
module Bluebox
class DNS
class Real
require 'fog/dns/parsers/bluebox/get_zones'
# Get list of all DNS zones hosted on Bluebox (for this account)
#
# ==== Returns
# * response<~Excon::Response>:
# * 'records'<~Array>
# * 'record'
# * 'name'<~String> - name of the zone
# * 'serial'<~Integer> - Serial # for the zone
# * 'ttl'<~Integer> - TTL for the zone record in seconds
# * 'retry'<~Integer> - Retry interval for the zone record in seconds
# * 'expires'<~Integer> - Expiration interval for the zone record in seconds
# * 'record-count'<~Integer> - # of records in this zone
# * 'id'<~String> - Id for the zone record
# * 'refresh'<~Integer> - default refresh interval for this zone, in seconds
# * 'minimum'<~Integer> - minimum value for intervals for this zone, in seconds
def get_zones
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Bluebox::DNS::GetZones.new,
:path => '/api/domains.xml'
)
end
end
class Mock
def get_zones
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,34 @@
module Fog
module Bluebox
class DNS
class Real
# Updates an existing record in a DNS zone
# ==== Parameters
# * type<~String> - type of DNS record (A, CNAME, etc)
# * name<~String> - host name for this DNS record
# * content<~String> - data for the DNS record (ie for an A record, the IP address)
def update_record(zone_id, record_id, options)
body = %Q{<?xml version="1.0" encoding="UTF-8"?><record>}
options.each {|k,v| body += "<#{k}>#{v}</#{k}>"}
body += "</record>"
request(
:body => body,
:expects => 202,
:method => 'PUT',
:path => "/api/domains/#{zone_id}/records/#{record_id}.xml"
)
end
end
class Mock
def create_record(zone_id, type, domain, content)
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,30 @@
module Fog
module Bluebox
class DNS
class Real
# Updates an existing DNS zone
def update_zone(zone_id, options)
body = %Q{<?xml version="1.0" encoding="UTF-8"?><domain>}
options.each {|k,v| body += "<#{k}>#{v}</#{k}>"}
body += "</domain>"
request(
:body => body,
:expects => 202,
:method => 'PUT',
:path => "/api/domains/#{zone_id}.xml"
)
end
end
class Mock
def create_record(zone_id, type, domain, content)
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -6,6 +6,7 @@ module Fog
extend Fog::Provider
service(:compute, 'compute/bluebox')
service(:dns, 'dns/bluebox')
end
end

View File

@ -6,12 +6,13 @@ def compute_providers
},
:mocked => true
},
Bluebox => {
:server_attributes => {
:image_id => 'a00baa8f-b5d0-4815-8238-b471c4c4bf72' # Ubuntu 9.10 64bit
},
:mocked => false
},
# Bluebox => {
# :server_attributes => {
# :image_id => 'a00baa8f-b5d0-4815-8238-b471c4c4bf72',
# :password => 'chunkybacon' # Ubuntu 9.10 64bit
# },
# :mocked => false
# },
Brightbox => {
:server_attributes => {
:image_id => 'img-9vxqi' # image img-9vxqi = Ubuntu Maverick 10.10 server

View File

@ -14,6 +14,12 @@ def dns_providers
},
Zerigo => {
:mocked => false
},
Bluebox => {
:mocked => false,
:zone_attributes => {
:ttl => 60
}
}
}
end
end

View File

@ -10,11 +10,11 @@ for provider, config in dns_providers
if !Fog.mocking? || config[:mocked]
zone_attributes = {
:domain => 'fogrecordtests.com'
:name => 'fogrecordtests.com',
:ttl => 60
}.merge(config[:zone_attributes] || {})
@zone = provider[:dns].zones.create(zone_attributes)
model_tests(@zone.records, record_attributes, config[:mocked])
@zone.destroy

View File

@ -10,7 +10,7 @@ for provider, config in dns_providers
if !Fog.mocking? || config[:mocked]
zone_attributes = {
:domain => 'fogrecordstests.com'
:name => 'fogrecordstests.com'
}.merge(config[:zone_attributes] || {})
@zone = provider[:dns].zones.create(zone_attributes)

View File

@ -3,7 +3,7 @@ for provider, config in dns_providers
Shindo.tests("#{provider}::DNS | zone", [provider.to_s.downcase]) do
zone_attributes = {
:domain => 'fogzonetests.com'
:name => 'fogzonetests.com'
}.merge!(config[:zone_attributes] || {})
model_tests(provider[:dns].zones, zone_attributes, config[:mocked])

View File

@ -3,7 +3,8 @@ for provider, config in dns_providers
Shindo.tests("#{provider}::DNS | zones", [provider.to_s.downcase]) do
zone_attributes = {
:domain => 'fogzonestests.com'
:name => 'fogzonestests.com',
:ttl => 60
}.merge!(config[:zone_attributes] || {})
collection_tests(provider[:dns].zones, zone_attributes, config[:mocked])

View File

@ -0,0 +1,267 @@
Shindo.tests('Bluebox::dns | DNS requests', ['bluebox', 'dns']) do
@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
pending if Fog.mocking?
@org_zone_count= 0
response = Bluebox[:dns].get_zones()
if response.status == 200
zones = response.body['zones']
@org_zone_count = zones.count
end
response.status == 200
end
test('create zone - simple') do
domain = generate_unique_domain
response = Bluebox[:dns].create_zone(:name => domain, :ttl => 360)
if response.status == 202
zone_id = response.body['id']
@new_zones << zone_id
end
response.status == 202
end
test('create zone - set all parameters') do
options = { :ttl => 60, :retry => 3600, :refresh => 1800, :minimum => 30 }
@domain= generate_unique_domain
response = Bluebox[:dns].create_zone(options.merge(:name => @domain))
if response.status == 202
@zone_id = response.body['id']
@new_zones << @zone_id
end
response.status == 202
end
test("get zone #{@zone_id} - check all parameters for #{@domain}") do
pending if Fog.mocking?
result = false
response = Bluebox[:dns].get_zone(@zone_id)
if response.status == 200
zone = response.body
if (zone['name'] == @domain) and (zone['ttl'] == 60)
result = true
end
end
result
end
test('get zones - make sure total count is correct') do
pending if Fog.mocking?
result = false
response = Bluebox[:dns].get_zones()
if response.status == 200
zones = response.body['zones']
if (@org_zone_count+2) == zones.count
result= true;
end
end
result
end
test('get zones - check all parameters for a zone') do
pending if Fog.mocking?
result= false
response = Bluebox[:dns].get_zones()
if response.status == 200
zones = response.body['zones']
zones.each { |zone|
if zone['id'] == @new_zones[1]
options = { :ttl => 60, :retry => 3600, :refresh => 1800, :minimum => 30 }
if (zone['name'] == @domain) and (zone['ttl'] == 60) and (zone['retry'] == 3600) and (zone['refresh'] == 1800) and (zone['minimum'] == 30)
result = true;
end
end
}
if (@org_zone_count+2) == zones.count
result = true;
end
end
result
end
test('create record - simple A record') do
pending if Fog.mocking?
host= 'www.' + @domain
zone_id= @new_zones[1]
response = Bluebox[:dns].create_record(zone_id, 'A', host, '1.2.3.4')
if response.status == 202
record_id = response.body['id']
@new_records << record_id
end
response.status == 202
end
test('create record - A record - all parameters set') do
pending if Fog.mocking?
host= 'ftp.' + @domain
zone_id= @new_zones[1]
response = Bluebox[:dns].create_record( zone_id, 'A', host, '1.2.3.4')
if response.status == 202
record_id = response.body['id']
@new_records << record_id
end
response.status == 202
end
test('create record - CNAME record') do
pending if Fog.mocking?
zone_id= @new_zones[1]
response = Bluebox[:dns].create_record( zone_id, 'CNAME', 'mail', @domain)
if response.status == 202
record_id = response.body['id']
@new_records << record_id
end
response.status == 202
end
test('create record - NS record') do
pending if Fog.mocking?
ns_domain = 'ns.' + @domain
zone_id= @new_zones[1]
response = Bluebox[:dns].create_record( zone_id, 'NS', @domain, ns_domain)
if response.status == 202
record_id = response.body['id']
@new_records << record_id
end
response.status == 202
end
test('create record - MX record') do
pending if Fog.mocking?
mail_domain = 'mail.' + @domain
zone_id= @new_zones[1]
response = Bluebox[:dns].create_record( zone_id, 'MX', @domain, mail_domain, :priority => 10)
if response.status == 202
@record_id = response.body['id']
@new_records << @record_id
end
response.status == 202
end
test("get record #{@record_id} - verify all parameters") do
pending if Fog.mocking?
result= false
response = Bluebox[:dns].get_record(@new_zones[1], @record_id)
if response.status == 200
mail_domain = 'mail.' + @domain + "."
record = response.body
if (record['type'] == 'MX') and (record['name'] == @domain) and (record['content'] == mail_domain) and (record['priority'] == '10')
result= true
end
end
result
end
test('get records - verify all parameters for one record') do
pending if Fog.mocking?
result= false
response = Bluebox[:dns].get_records(@new_zones[1])
if response.status == 200
records = response.body['records']
#find mx record
records.each {|record|
if record['type'] == 'MX'
mail_domain = 'mail.' + @domain + "."
if (record['type'] == 'MX') and (record['name'] == @domain) and (record['content'] == mail_domain) and (record['priority'] == '10')
result= true
break
end
end
}
end
result
end
test("delete #{@new_records.count} records created") do
pending if Fog.mocking?
result= true
@new_records.each { |record_id|
response = Bluebox[:dns].delete_record(@new_zones[1], 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 = Bluebox[:dns].delete_zone( zone_id)
if response.status != 200
result= false;
end
}
result
end
end
tests( 'failure') do
#create a zone with invalid parameters
#get zonfo info with invalid zone id
#delete a zone with an invalid zone id
tests('#create_zone') do
end
end
end