diff --git a/lib/fog/xenserver/models/compute/vif.rb b/lib/fog/xenserver/models/compute/vif.rb index dda8a0043..36f14afc0 100644 --- a/lib/fog/xenserver/models/compute/vif.rb +++ b/lib/fog/xenserver/models/compute/vif.rb @@ -18,18 +18,20 @@ module Fog attribute :mac_autogenerated, :aliases => :MAC_autogenerated attribute :metrics attribute :mtu, :aliases => :MTU - attribute :network + attribute :__network, :aliases => :network attribute :status_code attribute :status_detail - attribute :vm, :aliases => :VM + attribute :__vm, :aliases => :VM - #ignore_attributes :current_operations, :qos_supported_algorithms, :qos_algorithm_params, :qos_algorithm_type, :other_config, - # :runtime_properties - - def initialize(attributes={}) - @uuid ||= 0 - super + + def network + connection.networks.get __network end + + def server + connection.servers.get __vm + end + end end diff --git a/tests/xenserver/models/compute/vif_tests.rb b/tests/xenserver/models/compute/vif_tests.rb new file mode 100644 index 000000000..b1d38c76f --- /dev/null +++ b/tests/xenserver/models/compute/vif_tests.rb @@ -0,0 +1,53 @@ +Shindo.tests('Fog::Compute[:xenserver] | VIF model', ['VIF']) do + + vifs = Fog::Compute[:xenserver].vifs + vif = vifs.first + + tests('The VIF model should') do + tests('have the action') do + test('reload') { vif.respond_to? 'reload' } + end + tests('have attributes') do + model_attribute_hash = vif.attributes + attributes = [ + :reference, + :mac, + :uuid, + :allowed_operations, + :currently_attached, + :device, + :mac_autogenerated, + :metrics, + :mtu, + :__network, + :status_code, + :status_detail, + :__vm + ] + tests("The VIF model should respond to") do + attributes.each do |attribute| + test("#{attribute}") { vif.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::VIF') { vif.kind_of? Fog::Compute::XenServer::VIF} + + end + + tests("A real VIF should") do + tests("return a valid network") do + test("should be a Fog::Compute::XenServer::Network") { vif.network.kind_of? Fog::Compute::XenServer::Network } + end + tests("return valid VIF") do + test("should be a Fog::Compute::XenServer::Server") { vif.server.kind_of? Fog::Compute::XenServer::Server } + end + + end + +end