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

[linode] cleanup and tests

This commit is contained in:
geemus 2010-07-17 22:35:08 -05:00
parent 1b35b9d2ca
commit 5ae1a79040
10 changed files with 218 additions and 19 deletions

View file

@ -58,19 +58,19 @@ module Fog
params[:query] ||= {}
params[:query].merge!(:api_key => @linode_api_key)
begin
response = @connection.request(params.merge!({:host => @host}))
rescue Excon::Errors::Error => error
raise case error
when Excon::Errors::NotFound
Fog::Linode::NotFound.slurp(error)
else
error
end
end
response = @connection.request(params.merge!({:host => @host}))
unless response.body.empty?
response.body = JSON.parse(response.body)
if data = response.body['ERRORARRAY'].first
error = case data['ERRORCODE']
when 5
Fog::Linode::NotFound
else
Fog::Linode::Error
end
raise error.new(data['ERRORMESSAGE'])
end
end
response
end

View file

@ -5,14 +5,17 @@ module Fog
# Get available distributions
#
# ==== Parameters
# * options<~Hash>:
# * distributionId<~Integer>: id to limit results to
# * distributionId<~Integer>: id to limit results to
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def avail_distributions(options={})
def avail_distributions(distribution_id=nil)
options = {}
if distribution_id
options.merge!(:distributionId => distribution_id)
end
request(
:expects => 200,
:method => 'GET',

View file

@ -8,11 +8,15 @@ module Fog
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def avail_linodeplans
def avail_linodeplans(linodeplan_id=nil)
options = {}
if linodeplan_id
options.merge!(:planId => linodeplan_id)
end
request(
:expects => 200,
:method => 'GET',
:query => { :api_action => 'avail.linodeplans' }
:query => { :api_action => 'avail.linodeplans' }.merge!(options)
)
end

View file

@ -5,14 +5,17 @@ module Fog
# List all linodes user has access or delete to
#
# ==== Parameters
# * options<~Hash>:
# * linodeId<~Integer>: Limit the list to the specified LinodeID
# * linodeId<~Integer>: Limit the list to the specified LinodeID
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def linode_list(options={})
def linode_list(linode_id=nil)
options = {}
if linode_id
options.merge!(:linodeId => linode_id)
end
request(
:expects => 200,
:method => 'GET',

25
tests/linode/helper.rb Normal file
View file

@ -0,0 +1,25 @@
module Linode
def self.[](service)
@@connections ||= Hash.new do |hash, key|
credentials = Fog.credentials.reject do |k,v|
![:linode_api_key].include?(k)
end
hash[key] = case key
when :linode
Fog::Linode.new(credentials)
end
end
@@connections[service]
end
module Formats
BASIC = {
'ERRORARRAY' => [],
'ACTION' => String
}
end
end

View file

@ -0,0 +1,18 @@
Shindo.tests('Linode | datacenter requests', ['linode']) do
@datacenters_format = Linode::Formats::BASIC.merge({
'DATA' => [{
'DATACENTERID' => Integer,
'LOCATION' => String
}]
})
tests('success') do
tests('#avail_datacenters').formats(@datacenters_format) do
Linode[:linode].avail_datacenters.body
end
end
end

View file

@ -0,0 +1,30 @@
Shindo.tests('Linode | distribution requests', ['linode']) do
@distributions_format = Linode::Formats::BASIC.merge({
'DATA' => [{
'CREATE_DT' => String,
'DISTRIBUTIONID' => Integer,
'IS64BIT' => Integer,
'LABEL' => String,
'MINIMAGESIZE' => Integer,
'REQUIRESPVOPSKERNEL' => Integer
}]
})
tests('success') do
@distribution_id = nil
tests('#avail_distributions').formats(@distributions_format) do
data = Linode[:linode].avail_distributions.body
@distribution_id = data['DATA'].first['DISTRIBUTIONID']
data
end
tests("@avail_distributions(#{@distribution_id})").formats(@distributions_format) do
Linode[:linode].avail_distributions(@distribution_id).body
end
end
end

View file

@ -0,0 +1,79 @@
Shindo.tests('Linode | linode requests', ['linode']) do
@linode_format = Linode::Formats::BASIC.merge({
'DATA' => { 'LinodeID' => Integer }
})
@linodes_format = Linode::Formats::BASIC.merge({
'DATA' => [{
'ALERT_BWIN_ENABLED' => Integer,
'ALERT_CPU_THRESHOLD' => Integer,
'ALERT_BWOUT_ENABLED' => Integer,
'ALERT_BWOUT_THRESHOLD' => Integer,
'ALERT_BWQUOTA_ENABLED' => Integer,
'ALERT_BWQUOTA_THRESHOLD' => Integer,
'ALERT_BWIN_THRESHOLD' => Integer,
'ALERT_CPU_ENABLED' => Integer,
'ALERT_DISKIO_ENABLED' => Integer,
'ALERT_DISKIO_THRESHOLD' => Integer,
'BACKUPSENABLED' => Integer,
'BACKUPWEEKLYDAY' => Integer,
'BACKUPWINDOW' => Integer,
'DATACENTERID' => Integer,
'LABEL' => String,
'LINODEID' => Integer,
'LPM_DISPLAYGROUP' => String,
'STATUS' => Integer,
'TOTALHD' => Integer,
'TOTALRAM' => Integer,
'TOTALXFER' => Integer,
'WATCHDOG' => Integer,
}]
})
@reboot_format = Linode::Formats::BASIC.merge({
'DATA' => { 'JobID' => Integer }
})
tests('success') do
@linode_id = nil
# (2 => Dallas, TX, USA), (1 => 1 month), (1 => Linode 512)
tests('#linode_create(2, 1, 1)').formats(@linode_format) do
data = Linode[:linode].linode_create(2, 1, 1).body
@linode_id = data['DATA']['LinodeID']
data
end
tests("#linode_list(#{@linode_id})").formats(@linodes_format) do
Linode[:linode].linode_list(@linode_id).body
end
tests('#linode_list').formats(@linodes_format) do
Linode[:linode].linode_list.body
end
# tests("#linode_reboot(#{@linode_id})").formats(@reboot_format) do
# Linode[:linode].linode_reboot(@linode_id).body
# end
tests('#linode_delete(#{@linode_id})').succeeds do
Linode[:linode].linode_delete(@linode_id)
end
end
tests('failure') do
tests('#linode_reboot(0)').raises(Fog::Linode::NotFound) do
Linode[:linode].linode_reboot(0)
end
tests('#linode_delete(0)').raises(Fog::Linode::NotFound) do
Linode[:linode].linode_delete(0)
end
end
end

View file

@ -0,0 +1,37 @@
Shindo.tests('Linode | linodeplans requests', ['linode']) do
@linodeplans_format = Linode::Formats::BASIC.merge({
'DATA' => [{
'AVAIL' => {
'2' => Integer,
'3' => Integer,
'4' => Integer,
'6' => Integer,
'7' => Integer
},
'DISK' => Integer,
'PLANID' => Integer,
'PRICE' => Float,
'RAM' => Integer,
'LABEL' => String,
'XFER' => Integer
}]
})
tests('success') do
@linodeplan_id = nil
tests('#avail_linodeplans').formats(@linodeplans_format) do
data = Linode[:linode].avail_linodeplans.body
@linodeplan_id = data['DATA'].first['PLANID']
data
end
tests("#avail_linodeplans(#{@linodeplan_id})").formats(@linodeplans_format) do
Linode[:linode].avail_linodeplans(@linodeplan_id).body
end
end
end

View file

@ -54,7 +54,7 @@ Shindo.tests('Slicehost | slice requests', ['slicehost']) do
Slicehost[:slices].reboot_slice(0)
end
tests('delete_slice(0)').raises(Fog::Slicehost::NotFound) do
tests('#delete_slice(0)').raises(Fog::Slicehost::NotFound) do
Slicehost[:slices].delete_slice(0)
end