[libVirt] added tests

This commit is contained in:
Amos Benari 2012-04-04 18:32:09 +03:00 committed by Ohad Levy
parent 0c7824bf49
commit ceeae011af
19 changed files with 336 additions and 5 deletions

View File

@ -13,7 +13,7 @@ module Fog
load(connection.list_interfaces(filter))
end
def get(key)
def get(name)
self.all(:name => name).first
end

View File

@ -72,9 +72,10 @@ module Fog
end
def start
return if active?
return true if active?
connection.vm_action(uuid, :create)
reload
true
end
def mac
@ -92,7 +93,7 @@ module Fog
end
def reboot
connection.vm_action :reboot
connection.vm_action(uuid, :reboot)
end
def poweroff

View File

@ -12,7 +12,7 @@ def array_differences(array_a, array_b)
end
# check to see which credentials are available and add others to the skipped tags list
all_providers = ['aws', 'bluebox', 'brightbox', 'dnsimple', 'dnsmadeeasy', 'dynect', 'ecloud', 'glesys', 'gogrid', 'google', 'ibm', 'joyent', 'linode', 'local', 'ninefold', 'baremetalcloud', 'openstack', 'ovirt', 'rackspace', 'slicehost', 'stormondemand', 'voxel', 'vsphere', 'zerigo']
all_providers = ['aws', 'bluebox', 'brightbox', 'dnsimple', 'dnsmadeeasy', 'dynect', 'ecloud', 'glesys', 'gogrid', 'google', 'ibm', 'joyent', 'libvirt', 'linode', 'local', 'ninefold', 'baremetalcloud', 'openstack', 'ovirt', 'rackspace', 'slicehost', 'stormondemand', 'voxel', 'vsphere', 'zerigo']
available_providers = Fog.available_providers.map {|provider| provider.downcase}
for provider in (all_providers - available_providers)
Formatador.display_line("[yellow]Skipping tests for [bold]#{provider}[/] [yellow]due to lacking credentials (add some to '~/.fog' to run them)[/]")

View File

@ -69,6 +69,9 @@ if Fog.mock?
:vsphere_server => 'virtualcenter.lan',
:vsphere_username => 'apiuser',
:vsphere_password => 'apipassword',
:vsphere_expected_pubkey_hash => 'abcdef1234567890'
:vsphere_expected_pubkey_hash => 'abcdef1234567890',
:libvirt_uri => 'qemu:///system',
:libvirt_username => 'root',
:libvirt_password => 'password'
}
end

View File

@ -0,0 +1,17 @@
Shindo.tests('Fog::Compute[:libvirt]', ['libvirt']) do
compute = Fog::Compute[:libvirt]
tests("Compute collections") do
%w{ servers interfaces networks nics nodes pools volumes}.each do |collection|
test("it should respond to #{collection}") { compute.respond_to? collection }
end
end
tests("Compute requests") do
%w{ create_domain create_volume define_domain define_pool destroy_interface destroy_network get_node_info list_domains
list_interfaces list_networks list_pools list_pool_volumes list_volumes pool_action vm_action volume_action }.each do |request|
test("it should respond to #{request}") { compute.respond_to? request }
end
end
end

View File

@ -0,0 +1,27 @@
Shindo.tests('Fog::Compute[:libvirt] | interface model', ['libvirt']) do
interfaces = Fog::Compute[:libvirt].interfaces
interface = interfaces.last
tests('The interface model should') do
tests('have the action') do
test('reload') { interface.respond_to? 'reload' }
end
tests('have attributes') do
model_attribute_hash = interface.attributes
attributes = [ :name, :mac, :active]
tests("The interface model should respond to") do
attributes.each do |attribute|
test("#{attribute}") { interface.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::Libvirt::Interface') { interface.kind_of? Fog::Compute::Libvirt::Interface }
end
end

View File

@ -0,0 +1,14 @@
Shindo.tests('Fog::Compute[:libvirt] | interfaces collection', ['libvirt']) do
interfaces = Fog::Compute[:libvirt].interfaces
tests('The interfaces collection') do
test('should not be empty') { not interfaces.empty? }
test('should be a kind of Fog::Compute::Libvirt::Interfaces') { interfaces.kind_of? Fog::Compute::Libvirt::Interfaces }
tests('should be able to reload itself').succeeds { interfaces.reload }
tests('should be able to get a model') do
tests('by instance name').succeeds { interfaces.get interfaces.first.name }
end
end
end

View File

@ -0,0 +1,27 @@
Shindo.tests('Fog::Compute[:libvirt] | network model', ['libvirt']) do
networks = Fog::Compute[:libvirt].networks
network = networks.last
tests('The network model should') do
tests('have the action') do
test('reload') { network.respond_to? 'reload' }
end
tests('have attributes') do
model_attribute_hash = network.attributes
attributes = [ :name, :uuid, :bridge_name]
tests("The network model should respond to") do
attributes.each do |attribute|
test("#{attribute}") { network.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::Libvirt::Network') { network.kind_of? Fog::Compute::Libvirt::Network }
end
end

View File

@ -0,0 +1,13 @@
Shindo.tests('Fog::Compute[:libvirt] | networks collection', ['libvirt']) do
networks = Fog::Compute[:libvirt].networks
tests('The networks collection') do
test('should be a kind of Fog::Compute::Libvirt::Networks') { networks.kind_of? Fog::Compute::Libvirt::Networks }
tests('should be able to reload itself').succeeds { networks.reload }
tests('should be able to get a model') do
tests('by instance id').succeeds { networks.get networks.first.uuid }
end
end
end

View File

@ -0,0 +1,31 @@
Shindo.tests('Fog::Compute[:libvirt] | nic model', ['libvirt']) do
nic = Fog::Compute[:libvirt].servers.all.select{|v| v.name =~ /^fog/}.first.nics.first
tests('The nic model should') do
tests('have the action') do
test('reload') { nic.respond_to? 'reload' }
end
tests('have attributes') do
model_attribute_hash = nic.attributes
attributes = [ :mac,
:model,
:type,
:network,
:bridge]
tests("The nic model should respond to") do
attributes.each do |attribute|
test("#{attribute}") { nic.respond_to? attribute }
end
end
tests("The attributes hash should have key") do
attributes.delete(:bridge)
attributes.each do |attribute|
test("#{attribute}") { model_attribute_hash.has_key? attribute }
end
end
end
test('be a kind of Fog::Compute::Libvirt::Nic') { nic.kind_of? Fog::Compute::Libvirt::Nic }
end
end

View File

@ -0,0 +1,10 @@
Shindo.tests('Fog::Compute[:libvirt] | nics collection', ['libvirt']) do
nics = Fog::Compute[:libvirt].servers.first.nics
tests('The nics collection') do
test('should not be empty') { not nics.empty? }
test('should be a kind of Array') { nics.kind_of? Array }
end
end

View File

@ -0,0 +1,27 @@
Shindo.tests('Fog::Compute[:libvirt] | interface model', ['libvirt']) do
pools = Fog::Compute[:libvirt].pools
pool = pools.last
tests('The interface 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 = [ :uuid, :name, :persistent, :active, :autostart, :allocation, :capacity, :num_of_volumes, :state]
tests("The interface 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::Libvirt::Pool') { pool.kind_of? Fog::Compute::Libvirt::Pool }
end
end

View File

@ -0,0 +1,13 @@
Shindo.tests('Fog::Compute[:libvirt] | pools request', ['libvirt']) do
pools = Fog::Compute[:libvirt].pools
tests('The pools collection') do
test('should not be empty') { not pools.empty? }
test('should be a kind of Fog::Compute::Libvirt::Pools') { pools.kind_of? Fog::Compute::Libvirt::Pools }
tests('should be able to reload itself').succeeds { pools.reload }
tests('should be able to get a model') do
tests('by instance id').succeeds { pools.get pools.first.uuid }
end
end
end

View File

@ -0,0 +1,58 @@
Shindo.tests('Fog::Compute[:libvirt] | server model', ['libvirt']) do
servers = Fog::Compute[:libvirt].servers
server = servers.all.select{|v| v.name =~ /^fog/}.last
tests('The server model should') do
tests('have the action') do
test('reload') { server.respond_to? 'reload' }
%w{ start stop destroy reboot suspend }.each do |action|
test(action) { server.respond_to? action }
end
%w{ start reboot suspend stop destroy}.each do |action|
test("#{action} returns successfully") {
begin
server.send(action.to_sym)
rescue Libvirt::Error
#libvirt error is acceptable for the above actions.
true
end
}
end
end
tests('have attributes') do
model_attribute_hash = server.attributes
attributes = [ :id,
:cpus,
:cputime,
:os_type,
:memory_size,
:max_memory_size,
:name,
:arch,
:persistent,
:domain_type,
:uuid,
:autostart,
:vnc_port,
:nics,
:volumes,
:active,
:boot_order,
:state]
tests("The server model should respond to") do
attributes.each do |attribute|
test("#{attribute}") { server.respond_to? attribute }
end
end
tests("The attributes hash should have key") do
attributes.delete(:volumes)
attributes.each do |attribute|
test("#{attribute}") { model_attribute_hash.has_key? attribute }
end
end
end
test('be a kind of Fog::Compute::Libvirt::Server') { server.kind_of? Fog::Compute::Libvirt::Server }
end
end

View File

@ -0,0 +1,14 @@
Shindo.tests('Fog::Compute[:libvirt] | servers collection', ['libvirt']) do
servers = Fog::Compute[:libvirt].servers
tests('The servers collection') do
test('should not be empty') { not servers.empty? }
test('should be a kind of Fog::Compute::Libvirt::Servers') { servers.kind_of? Fog::Compute::Libvirt::Servers }
tests('should be able to reload itself').succeeds { servers.reload }
tests('should be able to get a model') do
tests('by instance uuid').succeeds { servers.get servers.first.id }
end
end
end

View File

@ -0,0 +1,30 @@
Shindo.tests('Fog::Compute[:libvirt] | volume model', ['libvirt']) do
volume = Fog::Compute[:libvirt].servers.all.select{|v| v.name !~ /^fog/}.first.volumes.first
tests('The volume model should') do
tests('have attributes') do
model_attribute_hash = volume.attributes
attributes = [ :id,
:pool_name,
:key,
:name,
:path,
:capacity,
:allocation,
:format_type]
tests("The volume model should respond to") do
attributes.each do |attribute|
test("#{attribute}") { volume.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::Libvirt::Volume') { volume.kind_of? Fog::Compute::Libvirt::Volume }
end
end

View File

@ -0,0 +1,14 @@
Shindo.tests('Fog::Compute[:libvirt] | volumes collection', ['libvirt']) do
volumes = Fog::Compute[:libvirt].volumes
tests('The volumes collection') do
test('should not be empty') { not volumes.empty? }
test('should be a kind of Fog::Compute::Libvirt::Volumes') { volumes.kind_of? Fog::Compute::Libvirt::Volumes }
tests('should be able to reload itself').succeeds { volumes.reload }
tests('should be able to get a model') do
tests('by instance uuid').succeeds { volumes.get volumes.first.id }
end
end
end

View File

@ -0,0 +1,21 @@
Shindo.tests("Fog::Compute[:libvirt] | create_domain request", 'libvirt') do
compute = Fog::Compute[:libvirt]
xml = compute.servers.new( :nics => [{:bridge => "br180"}]).to_xml
tests("Create Domain") do
response = compute.create_domain(xml)
test("should be a kind of Libvirt::Domain") { response.kind_of? Libvirt::Domain}
end
tests("Fail Creating Domain") do
begin
response = compute.create_domain(xml)
test("should be a kind of Libvirt::Domain") { response.kind_of? Libvirt::Domain} #mock never raise exceptions
rescue => e
#should raise vm name already exist exception.
test("error should be a kind of Libvirt::Error") { e.kind_of? Libvirt::Error}
end
end
end

View File

@ -0,0 +1,11 @@
Shindo.tests("Fog::Compute[:libvirt] | define_domain request", 'libvirt') do
compute = Fog::Compute[:libvirt]
xml = compute.servers.new().to_xml
tests("Define Domain") do
response = compute.define_domain(xml)
test("should be a kind of Libvirt::Domain") { response.kind_of? Libvirt::Domain}
end
end