[opennebula] Added live/mock tests for group/s
This commit is contained in:
parent
ed19c56943
commit
1c767981b9
|
@ -38,7 +38,41 @@ module Fog
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
|
def list_groups(filter={})
|
||||||
|
groups = []
|
||||||
|
net1 = mock_group "1", 'net1'
|
||||||
|
net2 = mock_group "2", 'fogtest'
|
||||||
|
|
||||||
|
grouppool = [net1, net2]
|
||||||
|
grouppool.each do |group|
|
||||||
|
filter_missmatch = false
|
||||||
|
|
||||||
|
unless (filter.empty?)
|
||||||
|
filter.each do |k,v|
|
||||||
|
if group["#{k.to_s.upcase}"] && group["#{k.to_s.upcase}"] != v.to_s
|
||||||
|
filter_missmatch = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
next if filter_missmatch
|
||||||
|
end
|
||||||
|
groups << {:id => group["ID"], :name => group["NAME"]}
|
||||||
|
end
|
||||||
|
groups
|
||||||
|
end
|
||||||
|
|
||||||
|
def mock_group id, name
|
||||||
|
{
|
||||||
|
"ID" => id,
|
||||||
|
"NAME" => name,
|
||||||
|
"UID" => "5",
|
||||||
|
"GID" => "5",
|
||||||
|
"DESCRIPTION" => "netDescription",
|
||||||
|
"VLAN" => "5"
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
module Fog
|
|
||||||
module Compute
|
|
||||||
class OpenNebula
|
|
||||||
class Mock
|
|
||||||
def list_interfaces(filter = { })
|
|
||||||
data=[]
|
|
||||||
if filter.keys.empty?
|
|
||||||
active_networks = client.list_interfaces rescue []
|
|
||||||
defined_networks = client.list_defined_interfaces rescue []
|
|
||||||
(active_networks + defined_networks).each do |ifname|
|
|
||||||
data << interface_to_attributes(client.lookup_interface_by_name(ifname))
|
|
||||||
end
|
|
||||||
else
|
|
||||||
data = [interface_to_attributes(get_interface_by_filter(filter))]
|
|
||||||
end
|
|
||||||
data.compact
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
# Retrieve the interface by mac or by name
|
|
||||||
def get_interface_by_filter(filter)
|
|
||||||
case filter.keys.first
|
|
||||||
when :mac
|
|
||||||
client.lookup_interface_by_mac(filter[:mac])
|
|
||||||
when :name
|
|
||||||
client.lookup_interface_by_name(filter[:name])
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
def interface_to_attributes(net)
|
|
||||||
return if net.nil? || net.name == 'lo'
|
|
||||||
{
|
|
||||||
:mac => net.mac,
|
|
||||||
:name => net.name,
|
|
||||||
:active => net.active?
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
class Real
|
|
||||||
def list_interfaces(filters={ })
|
|
||||||
if1 = mock_interface 'if5'
|
|
||||||
if2 = mock_interface 'if2'
|
|
||||||
[if1, if2]
|
|
||||||
end
|
|
||||||
|
|
||||||
def mock_interface name
|
|
||||||
{
|
|
||||||
:mac => 'aa:bb:cc:dd:ee:ff',
|
|
||||||
:name => name,
|
|
||||||
:active => true
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -3,7 +3,7 @@ Shindo.tests('Fog::Compute[:opennebula]', ['opennebula']) do
|
||||||
compute = Fog::Compute[:opennebula]
|
compute = Fog::Compute[:opennebula]
|
||||||
|
|
||||||
tests("Compute collections") do
|
tests("Compute collections") do
|
||||||
%w{networks}.each do |collection|
|
%w{networks groups}.each do |collection|
|
||||||
test("it should respond to #{collection}") { compute.respond_to? collection }
|
test("it should respond to #{collection}") { compute.respond_to? collection }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
Shindo.tests('Fog::Compute[:opennebula] | group model', ['opennebula']) do
|
||||||
|
|
||||||
|
groups = Fog::Compute[:opennebula].groups
|
||||||
|
group = groups.last
|
||||||
|
|
||||||
|
tests('The group model should') do
|
||||||
|
tests('have the action') do
|
||||||
|
test('reload') { group.respond_to? 'reload' }
|
||||||
|
end
|
||||||
|
tests('have attributes') do
|
||||||
|
model_attribute_hash = group.attributes
|
||||||
|
attributes =
|
||||||
|
tests("The group model should respond to") do
|
||||||
|
[:name, :id, :to_label].each do |attribute|
|
||||||
|
test("#{attribute}") { group.respond_to? attribute }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
tests("The attributes hash should have key") do
|
||||||
|
[:name, :id].each do |attribute|
|
||||||
|
test("#{attribute}") { model_attribute_hash.has_key? attribute }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
test('be a kind of Fog::Compute::OpenNebula::Group') { group.kind_of? Fog::Compute::OpenNebula::Group }
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,16 @@
|
||||||
|
Shindo.tests('Fog::Compute[:opennebula] | groups collection', ['opennebula']) do
|
||||||
|
|
||||||
|
groups = Fog::Compute[:opennebula].groups
|
||||||
|
|
||||||
|
tests('The groups collection') do
|
||||||
|
test('should be a kind of Fog::Compute::OpenNebula::Groups') { groups.kind_of? Fog::Compute::OpenNebula::Groups }
|
||||||
|
tests('should be able to reload itself').succeeds { groups.reload }
|
||||||
|
tests('should be able to get a model by id') do
|
||||||
|
tests('by instance id').succeeds { groups.get groups.first.id }
|
||||||
|
end
|
||||||
|
tests('should be able to get a model by name') do
|
||||||
|
tests('by instance id').succeeds { groups.get_by_name "fogtest" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -2,7 +2,14 @@ Shindo.tests("Fog::Compute[:opennebula] | vm_create and destroy request", 'openn
|
||||||
|
|
||||||
compute = Fog::Compute[:opennebula]
|
compute = Fog::Compute[:opennebula]
|
||||||
name_base = Time.now.to_i
|
name_base = Time.now.to_i
|
||||||
f = compute.flavors.get_by_name("foglivetest").first
|
f = compute.flavors.get_by_name("fogtest")
|
||||||
|
|
||||||
|
tests("Get 'fogtest' flavor/template") do
|
||||||
|
test("could not get template with name 'fogtest'! This is required for live tests!") {f.kind_of? Array}
|
||||||
|
raise ArgumentError, "Could not get a template with the name 'fogtest'" unless f
|
||||||
|
end
|
||||||
|
|
||||||
|
f = f.first
|
||||||
response = {}
|
response = {}
|
||||||
|
|
||||||
tests("Allocate VM") do
|
tests("Allocate VM") do
|
||||||
|
|
Loading…
Reference in New Issue