diff --git a/lib/fog/xenserver/models/compute/pool.rb b/lib/fog/xenserver/models/compute/pool.rb index e7aabbe03..d29829114 100644 --- a/lib/fog/xenserver/models/compute/pool.rb +++ b/lib/fog/xenserver/models/compute/pool.rb @@ -10,21 +10,27 @@ module Fog identity :reference - attribute :name_label attribute :uuid + attribute :name, :aliases => :name_label + attribute :description, :aliases => :name_description attribute :__default_sr, :aliases => :default_SR - - def initialize(attributes={}) - @uuid ||= 0 - super - end + attribute :__master, :aliases => :master + attribute :tags + attribute :restrictions + attribute :ha_enabled + attribute :vswitch_controller + def default_sr - connection.get_storage_repository_by_ref __default_sr + connection.storage_repositories.get __default_sr end def default_storage_repository - connection.get_storage_repository_by_ref __default_sr + default_sr + end + + def master + connection.hosts.get __master end end diff --git a/lib/fog/xenserver/models/compute/pools.rb b/lib/fog/xenserver/models/compute/pools.rb index e82ad3105..7cb39ac76 100644 --- a/lib/fog/xenserver/models/compute/pools.rb +++ b/lib/fog/xenserver/models/compute/pools.rb @@ -21,9 +21,9 @@ module Fog def get( pool_ref ) if pool_ref && pool = connection.get_pool_by_ref( pool_ref ) new(pool) + else + nil end - rescue Fog::XenServer::NotFound - nil end end diff --git a/lib/fog/xenserver/models/compute/storage_repository.rb b/lib/fog/xenserver/models/compute/storage_repository.rb index 43486038a..b58b816b8 100644 --- a/lib/fog/xenserver/models/compute/storage_repository.rb +++ b/lib/fog/xenserver/models/compute/storage_repository.rb @@ -10,25 +10,29 @@ module Fog identity :reference - attribute :name_label + attribute :name, :aliases => :name_label + attribute :description, :aliases => :name_description attribute :uuid attribute :allowed_operations + attribute :current_operations attribute :content_type - attribute :name_description attribute :other_config - attribute :PBDs + attribute :__pbds, :aliases => :PBDs attribute :shared 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, - :virtual_allocation - - def initialize(attributes={}) - @uuid ||= 0 - super + def vdis + __vdis.collect { |vdi| connection.vdis.get vdi } end + def pbds + __pbds.collect { |pbd| connection.pbds.get pbd } + end + end end diff --git a/tests/xenserver/models/compute/pool_tests.rb b/tests/xenserver/models/compute/pool_tests.rb new file mode 100644 index 000000000..61ecf6706 --- /dev/null +++ b/tests/xenserver/models/compute/pool_tests.rb @@ -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 diff --git a/tests/xenserver/models/compute/pools_tests.rb b/tests/xenserver/models/compute/pools_tests.rb new file mode 100644 index 000000000..c99c186af --- /dev/null +++ b/tests/xenserver/models/compute/pools_tests.rb @@ -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 diff --git a/tests/xenserver/models/compute/storage_repositories_tests.rb b/tests/xenserver/models/compute/storage_repositories_tests.rb new file mode 100644 index 000000000..7230ec218 --- /dev/null +++ b/tests/xenserver/models/compute/storage_repositories_tests.rb @@ -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 diff --git a/tests/xenserver/models/compute/storage_repository_tests.rb b/tests/xenserver/models/compute/storage_repository_tests.rb new file mode 100644 index 000000000..5f2c8f65c --- /dev/null +++ b/tests/xenserver/models/compute/storage_repository_tests.rb @@ -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