mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[voxel|compute] fleshing out testing
This commit is contained in:
parent
138ea7cd94
commit
bf4ca3621d
11 changed files with 174 additions and 52 deletions
|
@ -13,12 +13,11 @@ module Fog
|
|||
attribute :name
|
||||
attribute :processing_cores
|
||||
attribute :image_id
|
||||
#attribute :ip
|
||||
attribute :status
|
||||
attribute :facility
|
||||
attribute :disk_size
|
||||
attribute :addresses
|
||||
attribute :password
|
||||
attribute :addresses
|
||||
attribute :password
|
||||
|
||||
def initialize(attributes={})
|
||||
super
|
||||
|
@ -36,7 +35,11 @@ module Fog
|
|||
end
|
||||
|
||||
def ready?
|
||||
status == 'SUCCEEDED'
|
||||
status == 'SUCCEEDED'
|
||||
end
|
||||
|
||||
def status
|
||||
connection.voxcloud_status(id).first[:status]
|
||||
end
|
||||
|
||||
def save
|
||||
|
|
|
@ -10,12 +10,6 @@ module Fog
|
|||
|
||||
def all
|
||||
data = connection.devices_list
|
||||
statuses = connection.voxcloud_status
|
||||
|
||||
data.each_index do |i|
|
||||
data[i][:status] = statuses.select { |s| s[:id] == data[i][:id] }.first[:status]
|
||||
end
|
||||
|
||||
load(data)
|
||||
end
|
||||
|
||||
|
@ -31,8 +25,6 @@ module Fog
|
|||
if server.empty?
|
||||
nil
|
||||
else
|
||||
status = connection.voxcloud_status(device_id)
|
||||
server.first[:status] = status.first[:status]
|
||||
new(server.first)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ module Fog
|
|||
data = request("voxel.devices.list", options)
|
||||
|
||||
if data['stat'] == 'fail'
|
||||
[]
|
||||
raise Fog::Voxel::Compute::NotFound
|
||||
elsif data['devices'].empty?
|
||||
[]
|
||||
else
|
||||
|
@ -22,15 +22,16 @@ module Fog
|
|||
|
||||
## TODO find both voxserver and voxcloud devices
|
||||
devices.select { |d| d['type']['id'] == '3' }.map do |device|
|
||||
{ :id => device['id'],
|
||||
{ :id => device['id'].to_i,
|
||||
:name => device['label'],
|
||||
:addresses => {
|
||||
:public => device['ipassignments']['ipassignment'].select { |i| i['type'] == "frontend" }.first['content'],
|
||||
:private => device['ipassignments']['ipassignment'].select { |i| i['type'] == "backend" }.first['content'] },
|
||||
:image_id => 0,
|
||||
:addresses => {
|
||||
:public => device['ipassignments']['ipassignment'].select { |i| i['type'] == "frontend" }.first['content'],
|
||||
:private => device['ipassignments']['ipassignment'].select { |i| i['type'] == "backend" }.first['content'] },
|
||||
:processing_cores => device['processor']['cores'].to_i,
|
||||
:facility => device['location']['facility']['code'],
|
||||
:disk_size => device['storage']['drive']['size'].to_i,
|
||||
:password => device['accessmethods']['accessmethod'].select { |am| am['type'] == 'admin' }.first['password'] }
|
||||
:password => device['accessmethods']['accessmethod'].select { |am| am['type'] == 'admin' }.first['password'] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -38,20 +39,16 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def devices_list( device_id = nil)
|
||||
devices = [
|
||||
{ :id => '12345', :name => "device1.test", :processing_cores => 1, :facility => 'LDJ1', :disk_size => 10,
|
||||
:addresses => { :public => "192.168.1.10", :private => "172.16.0.10" }, :password => 'foo' },
|
||||
{ :id => '67890', :name => "device2.test", :processing_cores => 5, :facility => 'AMS2', :disk_size => 100,
|
||||
:addresses => { :public => "192.168.2.10", :private => "172.16.1.10" }, :password => 'bar' },
|
||||
{ :id => '54321', :name => "device3.test", :processing_cores => 11, :facility => 'LGA7', :disk_size => 500,
|
||||
:addresses => { :public => "192.168.3.10", :private => "172.16.2.10" }, :password => 'blee' },
|
||||
{ :id => '10986', :name => "device4.test", :processing_cores => 2, :facility => 'SIN1', :disk_size => 15,
|
||||
:addresses => { :public => "192.168.4.10", :private => "172.16.3.10" }, :password => 'blah' } ]
|
||||
|
||||
if device_id.nil?
|
||||
devices
|
||||
@data[:servers]
|
||||
else
|
||||
devices.select { |d| d[:id] == device_id }
|
||||
result = @data[:servers].select { |d| d[:id] == device_id }
|
||||
|
||||
if result.empty?
|
||||
raise Fog::Voxel::Compute::NotFound
|
||||
else
|
||||
result
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,21 +16,25 @@ module Fog
|
|||
images = data['images']['image']
|
||||
images = [ images ] if images.is_a?(Hash)
|
||||
|
||||
images.map { |i| { :id => i['id'], :name => i['summary'] } }
|
||||
images.map { |i| { :id => i['id'].to_i, :name => i['summary'] } }
|
||||
else
|
||||
[]
|
||||
raise Fog::Voxel::Compute::NotFound
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def images_list( image_id = nil )
|
||||
images = [ { :id => 1, :name => "CentOS 5 x64" }, { :id => 2, :name => "Ubuntu 10.04 LTS x64" } ]
|
||||
|
||||
if image_id.nil?
|
||||
images
|
||||
@data[:images]
|
||||
else
|
||||
images.select { |i| i[:id] == image_id }
|
||||
selected = @data[:images].select { |i| i[:id] == image_id }
|
||||
|
||||
if selected.empty?
|
||||
raise Fog::Voxel::Compute::NotFound
|
||||
else
|
||||
selected
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,7 +15,16 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def voxcloud_create( options )
|
||||
devices_list(12345)
|
||||
device_id = Fog::Mock.random_numbers(7).to_i
|
||||
@data[:last_modified][:servers][device_id] = Time.now
|
||||
@data[:last_modified][:statuses][device_id] = Time.now
|
||||
@data[:statuses][device_id] = "QUEUED"
|
||||
@data[:servers].push( options.merge( {
|
||||
:password => "CHANGEME",
|
||||
:id => device_id,
|
||||
:addresses => { :private => '0.0.0.0', :public => '0.0.0.0' }
|
||||
} ) )
|
||||
devices_list(device_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,13 +16,15 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def voxcloud_delete( device_id )
|
||||
device = devices_list.select { |d| d[:id] == device_id }
|
||||
device = @data[:devices].select { |d| d[:id] == device_id }
|
||||
|
||||
if device.empty?
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
if device.empty?
|
||||
raise Fog::Voxel::Compute::NotFound
|
||||
else
|
||||
@data[:devices] = @data[:devices].select { |d| d[:id] != device_id }
|
||||
@data[:statuses].delete(device_id)
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ module Fog
|
|||
data = request("voxel.voxcloud.status", options)
|
||||
|
||||
if data['stat'] == 'fail'
|
||||
[]
|
||||
raise Fog::Voxel::Compute::NotFound
|
||||
else
|
||||
if data['devices']['device'].is_a?(Hash)
|
||||
devices = [ data['devices']['device'] ]
|
||||
|
@ -27,16 +27,27 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def voxcloud_status( device_id = nil )
|
||||
devices = [
|
||||
{ :id => '12345', :status => "QEUEUED" },
|
||||
{ :id => '67890', :status => "FAILED" },
|
||||
{ :id => '54321', :status => "IN_PROGRESS" },
|
||||
{ :id => '10986', :status => "SUCCEEDED" } ]
|
||||
@data[:statuses].each_pair do |id, status|
|
||||
if Time.now - @data[:last_modified][:statuses][id] > 2
|
||||
case status
|
||||
when "QUEUED"
|
||||
@data[:statuses][id] = "IN_PROGRESS"
|
||||
@data[:last_modified][:statuses][id] = Time.now
|
||||
when "IN_PROGRESS"
|
||||
@data[:statuses][id] = "SUCCEEDED"
|
||||
@data[:last_modified][:statuses][id] = Time.now
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if device_id.nil?
|
||||
devices
|
||||
if device_id.nil?
|
||||
@data[:statuses].map { |status| { :id => status[0], :status => status[1] } }
|
||||
else
|
||||
devices.select { |d| d[:id] == device_id }
|
||||
if @data[:statuses].has_key?(device_id)
|
||||
[ { :id => device_id, :status => @data[:statuses][device_id] } ]
|
||||
else
|
||||
raise Fog::Voxel::Compute::NotFound
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,6 +19,27 @@ module Fog
|
|||
|
||||
class Mock
|
||||
include Collections
|
||||
|
||||
def self.data
|
||||
@data ||= {
|
||||
:last_modified => { :servers => {}, :statuses => {}, :images => {} },
|
||||
:servers => [],
|
||||
:statuses => {},
|
||||
:images => [
|
||||
{ :id => 1, :name => "CentOS 5 x64" },
|
||||
{ :id => 2, :name => "Ubuntu 10.04 LTS x64" } ]
|
||||
}
|
||||
end
|
||||
|
||||
def self.reset_data(keys=data.keys)
|
||||
for key in [*keys]
|
||||
data.delete(key)
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(options={})
|
||||
@data = self.class.data
|
||||
end
|
||||
end
|
||||
|
||||
class Real
|
||||
|
|
24
tests/compute/requests/voxel/image_tests.rb
Normal file
24
tests/compute/requests/voxel/image_tests.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
Shindo.tests('Voxel::Compute | image requests', ['voxel']) do
|
||||
|
||||
@image_format = {
|
||||
:id => Integer,
|
||||
:name => String
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
tests('#images_list').formats([ @image_format ]) do
|
||||
Voxel[:compute].images_list
|
||||
end
|
||||
|
||||
tests('#images_list(1)').formats([ @image_format ]) do
|
||||
Voxel[:compute].images_list(1)
|
||||
end
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
tests('#images_list(0)').raises(Fog::Voxel::Compute::NotFound) do
|
||||
Voxel[:compute].images_list(0)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
57
tests/compute/requests/voxel/server_tests.rb
Normal file
57
tests/compute/requests/voxel/server_tests.rb
Normal file
|
@ -0,0 +1,57 @@
|
|||
Shindo.tests('Voxel::Compute | server requests', ['voxel']) do
|
||||
|
||||
@server_format = {
|
||||
:id => Integer,
|
||||
:name => String,
|
||||
:processing_cores => Integer,
|
||||
:image_id => Integer,
|
||||
:facility => String,
|
||||
:disk_size => Integer,
|
||||
:addresses => {
|
||||
:private => String,
|
||||
:public => String
|
||||
},
|
||||
:password => String
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
@server_id = nil
|
||||
|
||||
tests('#voxcloud_create( :name => "fog.test", :disk_size => 10, :processing_cores => 1, :image_id => 16, :facility => "LDJ1" )').formats([@server_format]) do
|
||||
data = Voxel[:compute].voxcloud_create( :name => "fog.test", :disk_size => 10, :processing_cores => 1, :image_id => 16, :facility => "LDJ1" )
|
||||
@server_id = data.first[:id]
|
||||
data
|
||||
end
|
||||
|
||||
Voxel[:compute].servers.get(@server_id).wait_for { ready? }
|
||||
|
||||
tests('#devices_list').formats([ @server_format ]) do
|
||||
Voxel[:compute].devices_list
|
||||
end
|
||||
|
||||
tests('#devices_list(@server_id)').formats([ @server_format ]) do
|
||||
Voxel[:compute].devices_list(@server_id)
|
||||
end
|
||||
|
||||
tests("#voxcloud_delete(#{@server_id})").succeeds do
|
||||
Voxel[:compute].voxcloud_delete(@server_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
tests('#voxcloud_delete(0)').raises(Fog::Voxel::Compute::NotFound) do
|
||||
Voxel[:compute].voxcloud_delete(0)
|
||||
end
|
||||
|
||||
tests('#voxcloud_status(0)').raises(Fog::Voxel::Compute::NotFound) do
|
||||
Voxel[:compute].voxcloud_status(0)
|
||||
end
|
||||
|
||||
tests('#devices_list(0)').raises(Fog::Voxel::Compute::NotFound) do
|
||||
Voxel[:compute].devices_list(0)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -28,6 +28,8 @@ if Fog.mock?
|
|||
:rackspace_api_key => 'rackspace_api_key',
|
||||
:rackspace_username => 'rackspace_username',
|
||||
:slicehost_password => 'slicehost_password',
|
||||
:voxel_api_key => 'voxel_api_key',
|
||||
:voxel_api_secret => 'voxel_api_secret',
|
||||
:zerigo_email => 'zerigo_email',
|
||||
:zerigo_token => 'zerigo_token'
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue