mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
* Added Pool and StorageRepository models and collections Shindo tests
* Added missing attributes to Pool and StorageRepository models
This commit is contained in:
parent
df985aec67
commit
d480b3e3c6
7 changed files with 203 additions and 20 deletions
|
@ -10,21 +10,27 @@ module Fog
|
||||||
|
|
||||||
identity :reference
|
identity :reference
|
||||||
|
|
||||||
attribute :name_label
|
|
||||||
attribute :uuid
|
attribute :uuid
|
||||||
|
attribute :name, :aliases => :name_label
|
||||||
|
attribute :description, :aliases => :name_description
|
||||||
attribute :__default_sr, :aliases => :default_SR
|
attribute :__default_sr, :aliases => :default_SR
|
||||||
|
attribute :__master, :aliases => :master
|
||||||
def initialize(attributes={})
|
attribute :tags
|
||||||
@uuid ||= 0
|
attribute :restrictions
|
||||||
super
|
attribute :ha_enabled
|
||||||
end
|
attribute :vswitch_controller
|
||||||
|
|
||||||
|
|
||||||
def default_sr
|
def default_sr
|
||||||
connection.get_storage_repository_by_ref __default_sr
|
connection.storage_repositories.get __default_sr
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_storage_repository
|
def default_storage_repository
|
||||||
connection.get_storage_repository_by_ref __default_sr
|
default_sr
|
||||||
|
end
|
||||||
|
|
||||||
|
def master
|
||||||
|
connection.hosts.get __master
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,9 +21,9 @@ module Fog
|
||||||
def get( pool_ref )
|
def get( pool_ref )
|
||||||
if pool_ref && pool = connection.get_pool_by_ref( pool_ref )
|
if pool_ref && pool = connection.get_pool_by_ref( pool_ref )
|
||||||
new(pool)
|
new(pool)
|
||||||
|
else
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
rescue Fog::XenServer::NotFound
|
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,25 +10,29 @@ module Fog
|
||||||
|
|
||||||
identity :reference
|
identity :reference
|
||||||
|
|
||||||
attribute :name_label
|
attribute :name, :aliases => :name_label
|
||||||
|
attribute :description, :aliases => :name_description
|
||||||
attribute :uuid
|
attribute :uuid
|
||||||
attribute :allowed_operations
|
attribute :allowed_operations
|
||||||
|
attribute :current_operations
|
||||||
attribute :content_type
|
attribute :content_type
|
||||||
attribute :name_description
|
|
||||||
attribute :other_config
|
attribute :other_config
|
||||||
attribute :PBDs
|
attribute :__pbds, :aliases => :PBDs
|
||||||
attribute :shared
|
attribute :shared
|
||||||
attribute :type
|
attribute :type
|
||||||
attribute :VDIs
|
attribute :tags
|
||||||
|
attribute :__vdis, :aliases => :VDIs
|
||||||
|
attribute :physical_size
|
||||||
|
attribute :physical_utilisation
|
||||||
|
|
||||||
ignore_attributes :blobs, :current_operations, :physical_size, :physical_utilisation, :sm_config, :tags,
|
def vdis
|
||||||
:virtual_allocation
|
__vdis.collect { |vdi| connection.vdis.get vdi }
|
||||||
|
|
||||||
def initialize(attributes={})
|
|
||||||
@uuid ||= 0
|
|
||||||
super
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pbds
|
||||||
|
__pbds.collect { |pbd| connection.pbds.get pbd }
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
50
tests/xenserver/models/compute/pool_tests.rb
Normal file
50
tests/xenserver/models/compute/pool_tests.rb
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
Shindo.tests('Fog::Compute[:xenserver] | Pool model', ['Pool']) do
|
||||||
|
|
||||||
|
pools = Fog::Compute[:xenserver].pools
|
||||||
|
pool = pools.first
|
||||||
|
|
||||||
|
tests('The Pool model should') do
|
||||||
|
tests('have the action') do
|
||||||
|
test('reload') { pool.respond_to? 'reload' }
|
||||||
|
end
|
||||||
|
tests('have attributes') do
|
||||||
|
model_attribute_hash = pool.attributes
|
||||||
|
attributes = [
|
||||||
|
:reference,
|
||||||
|
:uuid,
|
||||||
|
:name,
|
||||||
|
:description,
|
||||||
|
:__default_sr,
|
||||||
|
:__master,
|
||||||
|
:tags,
|
||||||
|
:restrictions,
|
||||||
|
:ha_enabled,
|
||||||
|
:vswitch_controller
|
||||||
|
]
|
||||||
|
tests("The Pool model should respond to") do
|
||||||
|
attributes.each do |attribute|
|
||||||
|
test("#{attribute}") { pool.respond_to? attribute }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
tests("The attributes hash should have key") do
|
||||||
|
attributes.each do |attribute|
|
||||||
|
test("#{attribute}") { model_attribute_hash.has_key? attribute }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test('be a kind of Fog::Compute::XenServer::Pool') { pool.kind_of? Fog::Compute::XenServer::Pool}
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
tests("A real Pool should") do
|
||||||
|
tests("return a valid default_storage_repository") do
|
||||||
|
test("should be a Fog::Compute::XenServer::StorageRepository") { pool.default_storage_repository.kind_of? Fog::Compute::XenServer::StorageRepository }
|
||||||
|
end
|
||||||
|
tests("return valid Host as the master") do
|
||||||
|
test("should be a Fog::Compute::XenServer::Host") { pool.master.kind_of? Fog::Compute::XenServer::Host }
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
30
tests/xenserver/models/compute/pools_tests.rb
Normal file
30
tests/xenserver/models/compute/pools_tests.rb
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
Shindo.tests('Fog::Compute[:xenserver] | Pools collection', ['pools']) do
|
||||||
|
|
||||||
|
conn = Fog::Compute[:xenserver]
|
||||||
|
|
||||||
|
tests('The pools collection') do
|
||||||
|
pools = conn.pools.all
|
||||||
|
|
||||||
|
test('should not be empty') { !pools.empty? }
|
||||||
|
|
||||||
|
test('should be a kind of Fog::Compute::XenServer::Pools') { pools.kind_of? Fog::Compute::XenServer::Pools }
|
||||||
|
|
||||||
|
tests('should be an array of Fog::Compute::XenServer::Pool') do
|
||||||
|
pools.each do |p|
|
||||||
|
test("#{p.uuid} is a Fog::Compute::XenServer::Pool") {
|
||||||
|
p.is_a? Fog::Compute::XenServer::Pool
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('should be able to reload itself').succeeds { pools.reload }
|
||||||
|
|
||||||
|
tests('should be able to get a model') do
|
||||||
|
tests('by reference').succeeds {
|
||||||
|
pools.get(pools.first.reference).is_a? Fog::Compute::XenServer::Pool
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
30
tests/xenserver/models/compute/storage_repositories_tests.rb
Normal file
30
tests/xenserver/models/compute/storage_repositories_tests.rb
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
Shindo.tests('Fog::Compute[:xenserver] | StorageRepositories collection', ['storage_repositories']) do
|
||||||
|
|
||||||
|
conn = Fog::Compute[:xenserver]
|
||||||
|
|
||||||
|
tests('The storage_repositories collection') do
|
||||||
|
storage_repositories = conn.storage_repositories.all
|
||||||
|
|
||||||
|
test('should not be empty') { !storage_repositories.empty? }
|
||||||
|
|
||||||
|
test('should be a kind of Fog::Compute::XenServer::StorageRepositories') { storage_repositories.kind_of? Fog::Compute::XenServer::StorageRepositories }
|
||||||
|
|
||||||
|
tests('should be an array of Fog::Compute::XenServer::StorageRepository') do
|
||||||
|
storage_repositories.each do |p|
|
||||||
|
test("#{p.uuid} is a Fog::Compute::XenServer::StorageRepository") {
|
||||||
|
p.is_a? Fog::Compute::XenServer::StorageRepository
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('should be able to reload itself').succeeds { storage_repositories.reload }
|
||||||
|
|
||||||
|
tests('should be able to get a model') do
|
||||||
|
tests('by reference').succeeds {
|
||||||
|
storage_repositories.get(storage_repositories.first.reference).is_a? Fog::Compute::XenServer::StorageRepository
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
63
tests/xenserver/models/compute/storage_repository_tests.rb
Normal file
63
tests/xenserver/models/compute/storage_repository_tests.rb
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
Shindo.tests('Fog::Compute[:xenserver] | StorageRepository model', ['StorageRepository']) do
|
||||||
|
|
||||||
|
storage_repositories = Fog::Compute[:xenserver].storage_repositories
|
||||||
|
storage_repository = storage_repositories.first
|
||||||
|
|
||||||
|
tests('The StorageRepository model should') do
|
||||||
|
tests('have the action') do
|
||||||
|
test('reload') { storage_repository.respond_to? 'reload' }
|
||||||
|
end
|
||||||
|
tests('have attributes') do
|
||||||
|
model_attribute_hash = storage_repository.attributes
|
||||||
|
attributes = [
|
||||||
|
:reference,
|
||||||
|
:name,
|
||||||
|
:uuid,
|
||||||
|
:description,
|
||||||
|
:uuid,
|
||||||
|
:allowed_operations,
|
||||||
|
:current_operations,
|
||||||
|
:content_type,
|
||||||
|
:other_config,
|
||||||
|
:__pbds,
|
||||||
|
:shared,
|
||||||
|
:type,
|
||||||
|
:tags,
|
||||||
|
:__vdis,
|
||||||
|
:physical_size,
|
||||||
|
:physical_utilisation
|
||||||
|
]
|
||||||
|
tests("The StorageRepository model should respond to") do
|
||||||
|
attributes.each do |attribute|
|
||||||
|
test("#{attribute}") { storage_repository.respond_to? attribute }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
tests("The attributes hash should have key") do
|
||||||
|
attributes.each do |attribute|
|
||||||
|
test("#{attribute}") { model_attribute_hash.has_key? attribute }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test('be a kind of Fog::Compute::XenServer::StorageRepository') { storage_repository.kind_of? Fog::Compute::XenServer::StorageRepository }
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
tests("A real StorageRepository should") do
|
||||||
|
tests("return a valid list of VDIs") do
|
||||||
|
storage_repository.vdis.each do |vdi|
|
||||||
|
test("where #{vid.uuid} is a Fog::Compute::XenServer::VDI") {
|
||||||
|
p.is_a? Fog::Compute::XenServer::VDI
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
tests("return a valid list of PBDs") do
|
||||||
|
storage_repository.pbds.each do |pbd|
|
||||||
|
test("where #{pbd.uuid} is a Fog::Compute::XenServer::PBD") {
|
||||||
|
pbd.is_a? Fog::Compute::XenServer::PBD
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in a new issue