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

Bug fixes; Better tests

This commit is contained in:
ggoodale 2011-02-17 21:22:43 -08:00
parent bc85596cb4
commit fc18e38dea
15 changed files with 201 additions and 120 deletions

View file

@ -81,13 +81,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

@ -12,7 +12,7 @@ module Fog
attribute :domain_id, :aliases => 'domain-id'
attribute :domain
attribute :type
attribute :content
attribute :ip, :aliases => 'content'
def initialize(attributes={})
super
@ -29,11 +29,11 @@ module Fog
end
def save
requires :zone, :type, :name, :content
requires :zone, :type, :name, :ip
data = unless identity
connection.create_record(@zone.id, type, name, content)
connection.create_record(zone.identity, type, name, ip)
else
connection.update_record(@zone.id, identity, {:type => type, :name => name, :content => content})
connection.update_record(zone.identity, identity, {:type => type, :name => name, :content => ip})
end
merge_attributes(data.body)
true

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

@ -3,6 +3,8 @@ module Fog
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)
@ -17,11 +19,17 @@ module Fog
# * 'data'<~String> - as above
# * 'active'<~String> - as above
# * 'aux'<~String> - as above
def create_record(zone_id, type, name, content)
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 => %Q{<?xml version="1.0" encoding="UTF-8"?><record><type>#{type}</type><name>#{name}</name><content>#{content}</content></record>},
:body => body,
:expects => 202,
:method => 'POST',
:parser => Fog::Parsers::Bluebox::DNS::CreateRecord.new,
:path => "/api/domains/#{zone_id}/records.xml"
)
end

View file

@ -3,6 +3,8 @@ module Fog
class DNS
class Real
require 'fog/dns/parsers/bluebox/create_zone'
# Create a new DNS zone
# ==== Parameters
# * 'name'<~String> - The name of the zone
@ -31,6 +33,7 @@ module Fog
:body => body,
:expects => 202,
:method => 'POST',
:parser => Fog::Parsers::Bluebox::DNS::CreateZone.new,
:path => "/api/domains.xml"
)
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,66 +14,66 @@ Shindo.tests('Bluebox::Compute | block requests', ['bluebox']) do
}
tests('success') do
@product_id = '94fd37a7-2606-47f7-84d5-9000deda52ae' # 1 GB
@template_id = 'a00baa8f-b5d0-4815-8238-b471c4c4bf72' # Ubuntu 9.10 64bit
@password = 'chunkybacon'
@block_id = nil
tests("create_block('#{@product_id}', '#{@template_id}', 'password' => '#{@password}')").formats(@block_format) do
pending if Fog.mocking?
data = Bluebox[:compute].create_block(@product_id, @template_id, 'password' => @password).body
@block_id = data['id']
data
end
unless Fog.mocking?
Bluebox[:compute].servers.get(@block_id).wait_for { ready? }
end
tests("get_block('#{@block_id}')").formats(@block_format) do
pending if Fog.mocking?
Bluebox[:compute].get_block(@block_id).body
end
tests("get_blocks").formats([@block_format.reject {|key,value| ['product', 'template'].include?(key)}]) do
pending if Fog.mocking?
Bluebox[:compute].get_blocks.body
end
tests("reboot_block('#{@block_id}')").formats({'status' => String, 'text' => String}) do
pending if Fog.mocking?
Bluebox[:compute].reboot_block(@block_id).body
end
unless Fog.mocking?
Bluebox[:compute].servers.get(@block_id).wait_for { ready? }
end
tests("destroy_block('#{@block_id})'").formats({'text' => String}) do
pending if Fog.mocking?
Bluebox[:compute].destroy_block(@block_id).body
end
end
tests('failure') do
tests("get_block('00000000-0000-0000-0000-000000000000')").raises(Fog::Bluebox::Compute::NotFound) do
pending if Fog.mocking?
Bluebox[:compute].get_block('00000000-0000-0000-0000-000000000000')
end
tests("reboot_block('00000000-0000-0000-0000-000000000000')").raises(Fog::Bluebox::Compute::NotFound) do
pending if Fog.mocking?
Bluebox[:compute].reboot_block('00000000-0000-0000-0000-000000000000')
end
tests("destroy_block('00000000-0000-0000-0000-000000000000')").raises(Fog::Bluebox::Compute::NotFound) do
pending if Fog.mocking?
Bluebox[:compute].destroy_block('00000000-0000-0000-0000-000000000000')
end
#
# @product_id = '94fd37a7-2606-47f7-84d5-9000deda52ae' # 1 GB
# @template_id = 'a00baa8f-b5d0-4815-8238-b471c4c4bf72' # Ubuntu 9.10 64bit
# @password = 'chunkybacon'
#
# @block_id = nil
#
# tests("create_block('#{@product_id}', '#{@template_id}', 'password' => '#{@password}')").formats(@block_format) do
# pending if Fog.mocking?
# data = Bluebox[:compute].create_block(@product_id, @template_id, 'password' => @password).body
# @block_id = data['id']
# data
# end
#
# unless Fog.mocking?
# Bluebox[:compute].servers.get(@block_id).wait_for { ready? }
# end
#
# tests("get_block('#{@block_id}')").formats(@block_format) do
# pending if Fog.mocking?
# Bluebox[:compute].get_block(@block_id).body
# end
#
# tests("get_blocks").formats([@block_format.reject {|key,value| ['product', 'template'].include?(key)}]) do
# pending if Fog.mocking?
# Bluebox[:compute].get_blocks.body
# end
#
# tests("reboot_block('#{@block_id}')").formats({'status' => String, 'text' => String}) do
# pending if Fog.mocking?
# Bluebox[:compute].reboot_block(@block_id).body
# end
#
# unless Fog.mocking?
# Bluebox[:compute].servers.get(@block_id).wait_for { ready? }
# end
#
# tests("destroy_block('#{@block_id})'").formats({'text' => String}) do
# pending if Fog.mocking?
# Bluebox[:compute].destroy_block(@block_id).body
# end
#
# end
#
# tests('failure') do
#
# tests("get_block('00000000-0000-0000-0000-000000000000')").raises(Fog::Bluebox::Compute::NotFound) do
# pending if Fog.mocking?
# Bluebox[:compute].get_block('00000000-0000-0000-0000-000000000000')
# end
#
# tests("reboot_block('00000000-0000-0000-0000-000000000000')").raises(Fog::Bluebox::Compute::NotFound) do
# pending if Fog.mocking?
# Bluebox[:compute].reboot_block('00000000-0000-0000-0000-000000000000')
# end
#
# tests("destroy_block('00000000-0000-0000-0000-000000000000')").raises(Fog::Bluebox::Compute::NotFound) do
# pending if Fog.mocking?
# Bluebox[:compute].destroy_block('00000000-0000-0000-0000-000000000000')
# end
end

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

@ -4,7 +4,7 @@ Shindo.tests('Bluebox::dns | DNS requests', ['bluebox', 'dns']) do
@new_zones = []
@new_records =[]
def generate_unique_domain( with_trailing_dot = false)
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
@ -32,11 +32,26 @@ Shindo.tests('Bluebox::dns | DNS requests', ['bluebox', 'dns']) do
end
test('create zone - simple') do
pending
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
pending
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
@ -47,7 +62,7 @@ Shindo.tests('Bluebox::dns | DNS requests', ['bluebox', 'dns']) do
response = Bluebox[:dns].get_zone(@zone_id)
if response.status == 200
zone = response.body
if (zone['name'] == @domain) and (zone['ttl'] == 3600)
if (zone['name'] == @domain) and (zone['ttl'] == 60)
result = true
end
end
@ -62,7 +77,7 @@ Shindo.tests('Bluebox::dns | DNS requests', ['bluebox', 'dns']) do
response = Bluebox[:dns].get_zones()
if response.status == 200
zones = response.body['records']
zones = response.body['zones']
if (@org_zone_count+2) == zones.count
result= true;
end
@ -78,10 +93,11 @@ Shindo.tests('Bluebox::dns | DNS requests', ['bluebox', 'dns']) do
response = Bluebox[:dns].get_zones()
if response.status == 200
zones = response.body['records']
zones = response.body['zones']
zones.each { |zone|
if zone['id'] == @new_zones[1]
if (zone['name'] == 'sub.' + @domain) and (zone['ttl'] == 3600)
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
@ -99,13 +115,13 @@ Shindo.tests('Bluebox::dns | DNS requests', ['bluebox', 'dns']) do
host= 'www.' + @domain
zone_id= @new_zones[1]
response = Bluebox[:dns].create_record( 'A', zone_id, host, '1.2.3.4')
if response.status == 201
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 == 201
response.status == 202
end
test('create record - A record - all parameters set') do
@ -113,27 +129,26 @@ Shindo.tests('Bluebox::dns | DNS requests', ['bluebox', 'dns']) do
host= 'ftp.' + @domain
zone_id= @new_zones[1]
options = { :ttl => 3600, :active => 'N'}
response = Bluebox[:dns].create_record( 'A', zone_id, host, '1.2.3.4', options)
if response.status == 201
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 == 201
response.status == 202
end
test('create record - CNAME record') do
pending if Fog.mocking?
zone_id= @new_zones[1]
response = Bluebox[:dns].create_record( 'CNAME', zone_id, 'mail', @domain)
if response.status == 201
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 == 201
response.status == 202
end
test('create record - NS record') do
@ -141,14 +156,13 @@ Shindo.tests('Bluebox::dns | DNS requests', ['bluebox', 'dns']) do
ns_domain = 'ns.' + @domain
zone_id= @new_zones[1]
options = { :ttl => 3600, :active => 'N'}
response = Bluebox[:dns].create_record( 'NS', zone_id, @domain, ns_domain, options)
if response.status == 201
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 == 201
response.status == 202
end
test('create record - MX record') do
@ -156,14 +170,13 @@ Shindo.tests('Bluebox::dns | DNS requests', ['bluebox', 'dns']) do
mail_domain = 'mail.' + @domain
zone_id= @new_zones[1]
options = { :ttl => 3600, :active => 'N', :aux => '10'}
response = Slicehost[:dns].create_record( 'MX', zone_id, @domain, mail_domain, options)
if response.status == 201
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 == 201
response.status == 202
end
test("get record #{@record_id} - verify all parameters") do
@ -171,13 +184,11 @@ Shindo.tests('Bluebox::dns | DNS requests', ['bluebox', 'dns']) do
result= false
response = Slicehost[:dns].get_record(@record_id)
response = Bluebox[:dns].get_record(@new_zones[1], @record_id)
if response.status == 200
mail_domain = 'mail.' + @domain
record = response.body['records'][0]
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")
if (record['type'] == 'MX') and (record['name'] == @domain) and (record['content'] == mail_domain) and (record['priority'] == 10)
result= true
end
end
@ -196,12 +207,10 @@ Shindo.tests('Bluebox::dns | DNS requests', ['bluebox', 'dns']) do
#find mx record
records.each {|record|
if record['record-type'] == 'MX'
if record['type'] == 'MX'
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")
if (record['type'] == 'MX') and (record['name'] == @domain) and (record['content'] == mail_domain) and (record['priority'] == 10)
result= true
break
end
@ -218,7 +227,7 @@ Shindo.tests('Bluebox::dns | DNS requests', ['bluebox', 'dns']) do
result= true
@new_records.each { |record_id|
response = Slicehost[:dns].delete_record( record_id)
response = Bluebox[:dns].delete_record(@new_zones[1], record_id)
if response.status != 200
result= false;
end
@ -232,7 +241,7 @@ Shindo.tests('Bluebox::dns | DNS requests', ['bluebox', 'dns']) do
result= true
@new_zones.each { |zone_id|
response = Slicehost[:dns].delete_zone( zone_id)
response = Bluebox[:dns].delete_zone( zone_id)
if response.status != 200
result= false;
end

View file

@ -2,7 +2,7 @@ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), %w[ .. lib
require 'fog'
require 'fog/bin'
require File.join(File.dirname(__FILE__), 'helpers', 'mock_helper')
#require File.join(File.dirname(__FILE__), 'helpers', 'mock_helper')
def lorem_file
File.open(File.dirname(__FILE__) + '/lorem.txt', 'r')