Adding Tests and Mocks
Adding several test cases for flavors and updating network tests to support new attributes.
This commit is contained in:
parent
2702f22e33
commit
83ed0422d1
|
@ -8,7 +8,7 @@ module Fog
|
||||||
model Fog::Compute::OpenNebula::Network
|
model Fog::Compute::OpenNebula::Network
|
||||||
|
|
||||||
def all(filter={})
|
def all(filter={})
|
||||||
load(service.list_networks(filter))
|
self.get_by_filter(filter)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(id)
|
def get(id)
|
||||||
|
@ -16,7 +16,7 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_by_filter(filter)
|
def get_by_filter(filter)
|
||||||
self.all(filter)
|
load(service.list_networks(filter))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,10 +33,11 @@ module Fog
|
||||||
def network_to_attributes(net)
|
def network_to_attributes(net)
|
||||||
return if net.nil?
|
return if net.nil?
|
||||||
h = {
|
h = {
|
||||||
:id => net["VNET"]["ID"],
|
:id => net["VNET"]["ID"],
|
||||||
:name => net["VNET"]["NAME"],
|
:name => net["VNET"]["NAME"],
|
||||||
:uid => net["VNET"]["UID"],
|
:uid => net["VNET"]["UID"],
|
||||||
:gid => net["VNET"]["GID"],
|
:uname => net["VNET"]["UNAME"],
|
||||||
|
:gid => net["VNET"]["GID"],
|
||||||
}
|
}
|
||||||
|
|
||||||
h[:description] = net["VNET"]["TEMPLATE"]["DESCRIPTION"] unless net["VNET"]["TEMPLATE"]["DESCRIPTION"].nil?
|
h[:description] = net["VNET"]["TEMPLATE"]["DESCRIPTION"] unless net["VNET"]["TEMPLATE"]["DESCRIPTION"].nil?
|
||||||
|
@ -59,6 +60,7 @@ module Fog
|
||||||
:id => "5",
|
:id => "5",
|
||||||
:name => name,
|
:name => name,
|
||||||
:uid => "5",
|
:uid => "5",
|
||||||
|
:uname => "mock",
|
||||||
:gid => "5",
|
:gid => "5",
|
||||||
:description => "netDescription",
|
:description => "netDescription",
|
||||||
:vlan => "5"
|
:vlan => "5"
|
||||||
|
|
|
@ -53,7 +53,8 @@ module Fog
|
||||||
h = Hash[
|
h = Hash[
|
||||||
:id => t.to_hash["VMTEMPLATE"]["ID"],
|
:id => t.to_hash["VMTEMPLATE"]["ID"],
|
||||||
:name => t.to_hash["VMTEMPLATE"]["NAME"],
|
:name => t.to_hash["VMTEMPLATE"]["NAME"],
|
||||||
:content => t.template_str
|
:content => t.template_str,
|
||||||
|
:USER_VARIABLES => "" # Default if not set in template
|
||||||
]
|
]
|
||||||
h.merge! t.to_hash["VMTEMPLATE"]["TEMPLATE"]
|
h.merge! t.to_hash["VMTEMPLATE"]["TEMPLATE"]
|
||||||
|
|
||||||
|
@ -99,7 +100,34 @@ module Fog
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
def template_pool(filter = { })
|
def template_pool(filter = { })
|
||||||
[ {}, {} ]
|
[
|
||||||
|
{
|
||||||
|
:content => %Q{
|
||||||
|
NAME = mock-vm
|
||||||
|
MEMORY = 512
|
||||||
|
VCPU = 1
|
||||||
|
CPU = 1
|
||||||
|
},
|
||||||
|
:id => 1,
|
||||||
|
:name => 'mock',
|
||||||
|
:cpu => 1,
|
||||||
|
:vcpu => 1,
|
||||||
|
:memory => 512,
|
||||||
|
:sched_requirements => 'CPUSPEED > 1000',
|
||||||
|
:sched_rank => 'FREECPU',
|
||||||
|
:sched_ds_requirements => "NAME=mock",
|
||||||
|
:sched_ds_rank => "FREE_MB",
|
||||||
|
:disk => {},
|
||||||
|
:nic => {},
|
||||||
|
:os => {
|
||||||
|
'ARCH' => 'x86_64'
|
||||||
|
},
|
||||||
|
:graphics => {},
|
||||||
|
:raw => {},
|
||||||
|
:context => {},
|
||||||
|
:user_variables => {}
|
||||||
|
}
|
||||||
|
]
|
||||||
end
|
end
|
||||||
end #class Mock
|
end #class Mock
|
||||||
end #class OpenNebula
|
end #class OpenNebula
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
Shindo.tests('Fog::Compute[:opennebula] | flavor model', ['opennebula']) do
|
||||||
|
|
||||||
|
flavors = Fog::Compute[:opennebula].flavors
|
||||||
|
flavor = flavors.last
|
||||||
|
|
||||||
|
tests('The flavor model should') do
|
||||||
|
tests('have the action') do
|
||||||
|
test('reload') { flavor.respond_to? 'reload' }
|
||||||
|
end
|
||||||
|
tests('have attributes') do
|
||||||
|
model_attribute_hash = flavor.attributes
|
||||||
|
attributes =
|
||||||
|
tests("The flavor model should respond to") do
|
||||||
|
[:name, :id, :to_label, :to_s, :get_cpu, :get_vcpu, :get_memory, :get_raw, :get_disk, :get_os,
|
||||||
|
:get_graphics, :get_nic, :get_sched_ds_requirements, :get_sched_ds_rank, :get_sched_requirements,
|
||||||
|
:get_sched_rank, :get_context, :get_user_variables].each do |attribute|
|
||||||
|
test("#{attribute}") { flavor.respond_to? attribute }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
tests("The attributes hash should have key") do
|
||||||
|
[:name, :id, :content, :cpu, :vcpu, :memory, :os, :graphics, :raw, :context, :user_variables ].each do |attribute|
|
||||||
|
test("#{attribute}") { model_attribute_hash.has_key? attribute }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
test('be a kind of Fog::Compute::OpenNebula::Flavor') { flavor.kind_of? Fog::Compute::OpenNebula::Flavor }
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,17 @@
|
||||||
|
Shindo.tests('Fog::Compute[:opennebula] | flavors collection', ['opennebula']) do
|
||||||
|
|
||||||
|
flavors = Fog::Compute[:opennebula].flavors
|
||||||
|
|
||||||
|
tests('The flavors collection should') do
|
||||||
|
test('should be a kind of Fog::Compute::OpenNebula::Flavors') { flavors.kind_of? Fog::Compute::OpenNebula::Flavors }
|
||||||
|
tests('should be able to reload itself').succeeds { flavors.reload }
|
||||||
|
|
||||||
|
tests('should be able to get models') do
|
||||||
|
tests('all').succeeds { flavors.all }
|
||||||
|
tests('by instance id').succeeds { flavors.get flavors.first.id }
|
||||||
|
tests('by name').succeeds { flavors.get_by_name "fogtest" }
|
||||||
|
tests('by filter').succeeds { flavors.get_by_filter ({:name => "fogtest", :id => flavors.first.id }) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -11,12 +11,12 @@ Shindo.tests('Fog::Compute[:opennebula] | network model', ['opennebula']) do
|
||||||
model_attribute_hash = network.attributes
|
model_attribute_hash = network.attributes
|
||||||
attributes =
|
attributes =
|
||||||
tests("The network model should respond to") do
|
tests("The network model should respond to") do
|
||||||
[:name, :id, :vlan, :uid, :gid, :description].each do |attribute|
|
[:name, :id, :vlan, :uid, :uname, :gid, :description].each do |attribute|
|
||||||
test("#{attribute}") { network.respond_to? attribute }
|
test("#{attribute}") { network.respond_to? attribute }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
tests("The attributes hash should have key") do
|
tests("The attributes hash should have key") do
|
||||||
[:name, :id, :uid, :gid].each do |attribute|
|
[:name, :id, :uid, :uname, :gid ].each do |attribute|
|
||||||
test("#{attribute}") { model_attribute_hash.has_key? attribute }
|
test("#{attribute}") { model_attribute_hash.has_key? attribute }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,9 @@ Shindo.tests('Fog::Compute[:opennebula] | networks collection', ['opennebula'])
|
||||||
test('should be a kind of Fog::Compute::OpenNebula::Networks') { networks.kind_of? Fog::Compute::OpenNebula::Networks }
|
test('should be a kind of Fog::Compute::OpenNebula::Networks') { networks.kind_of? Fog::Compute::OpenNebula::Networks }
|
||||||
tests('should be able to reload itself').succeeds { networks.reload }
|
tests('should be able to reload itself').succeeds { networks.reload }
|
||||||
tests('should be able to get a model') do
|
tests('should be able to get a model') do
|
||||||
|
tests('all').succeeds { networks.all }
|
||||||
tests('by instance id').succeeds { networks.get networks.first.id }
|
tests('by instance id').succeeds { networks.get networks.first.id }
|
||||||
|
tests('by filter').succeeds { networks.get_by_filter ({ :id => networks.first.id }) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue