1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-26 06:50:09 +03:00

feature #201 Unit tests for OCA Cluster

This commit is contained in:
Daniel Molina 2010-07-09 11:56:03 +02:00 committed by Ruben S. Montero
parent fb66cd4849
commit 39404a7a55
5 changed files with 361 additions and 0 deletions

View File

@ -0,0 +1,81 @@
$: << '../'
require 'OpenNebula'
require 'MockClient'
module OpenNebula
describe "Cluster using NOKOGIRI" do
before(:all) do
NOKOGIRI=true
client = MockClient.new()
@cluster_pool = ClusterPool.new(client)
end
it "should update the CLUSTER_POOL info" do
rc = @cluster_pool.info()
rc.nil?.should eql(true)
end
it "should iterate the USER_POOL elements and get info from them" do
rc = @cluster_pool.each{ |cluster|
cluster.class.to_s.should eql("OpenNebula::Cluster")
if cluster.id == 0
cluster.name.should eql('default')
elsif cluster.id == 1
cluster.name.should eql('Red')
elsif cluster.id == 2
cluster.name.should eql('Black')
end
}
end
it "should get a hash representation of the USER_POOL" do
cluster_hash = @cluster_pool.to_hash
cluster_hash['CLUSTER_POOL']['CLUSTER'][0]['ID'].should eql('0')
cluster_hash['CLUSTER_POOL']['CLUSTER'][0]['NAME'].should eql('default')
cluster_hash['CLUSTER_POOL']['CLUSTER'][1]['ID'].should eql('1')
cluster_hash['CLUSTER_POOL']['CLUSTER'][1]['NAME'].should eql('Red')
cluster_hash['CLUSTER_POOL']['CLUSTER'][2]['ID'].should eql('2')
cluster_hash['CLUSTER_POOL']['CLUSTER'][2]['NAME'].should eql('Black')
end
end
describe "Cluster using REXML" do
before(:all) do
NOKOGIRI=false
client = MockClient.new()
@cluster_pool = ClusterPool.new(client)
end
it "should update the CLUSTER_POOL info" do
rc = @cluster_pool.info()
rc.nil?.should eql(true)
end
it "should iterate the CLUSTER_POOL elements and get info from them" do
rc = @cluster_pool.each{ |cluster|
cluster.class.to_s.should eql("OpenNebula::Cluster")
if cluster.id == 0
cluster.name.should eql('default')
elsif cluster.id == 1
cluster.name.should eql('Red')
elsif cluster.id == 2
cluster.name.should eql('Black')
end
}
end
it "should get a hash representation of the CLUSTER_POOL" do
cluster_hash = @cluster_pool.to_hash
cluster_hash['CLUSTER_POOL']['CLUSTER'][0]['ID'].should eql('0')
cluster_hash['CLUSTER_POOL']['CLUSTER'][0]['NAME'].should eql('default')
cluster_hash['CLUSTER_POOL']['CLUSTER'][1]['ID'].should eql('1')
cluster_hash['CLUSTER_POOL']['CLUSTER'][1]['NAME'].should eql('Red')
cluster_hash['CLUSTER_POOL']['CLUSTER'][2]['ID'].should eql('2')
cluster_hash['CLUSTER_POOL']['CLUSTER'][2]['NAME'].should eql('Black')
end
end
end

View File

@ -0,0 +1,201 @@
$: << '../'
require 'OpenNebula'
require 'MockClient'
module OpenNebula
describe "Cluster using NOKOGIRI" do
before(:all) do
NOKOGIRI=true
@xml = Cluster.build_xml(5)
client = MockClient.new()
@cluster = Cluster.new(@xml,client)
end
it "should create a Nokogiri Node" do
@xml.class.to_s.should eql('Nokogiri::XML::NodeSet')
end
it "should allocate the new CLUSTER" do
@cluster.allocate(nil)
@cluster.id.should eql(5)
end
it "should update the CLUSTER info" do
@cluster.info()
@cluster.id.should eql(5)
@cluster.name.should eql('Production')
end
it "should delete the CLUSTER" do
rc = @cluster.delete()
rc.should eql(nil)
end
it "should add a host to the CLUSTER" do
rc = @cluster.add_host(nil)
rc.should eql(nil)
end
it "should remove a host from the CLUSTER" do
rc = @cluster.remove_host(nil)
rc.should eql(nil)
end
it "should access an attribute using []" do
@cluster['ID'].should eql('5')
@cluster['NAME'].should eql('Production')
end
it "should get a hash representation of the CLUSTER" do
cluster_hash = @cluster.to_hash
cluster_hash['CLUSTER']['ID'].should eql('5')
cluster_hash['CLUSTER']['NAME'].should eql('Production')
end
end
describe "Cluster using REXML" do
before(:all) do
NOKOGIRI=false
@xml = Cluster.build_xml(5)
client = MockClient.new()
@cluster = Cluster.new(@xml,client)
end
it "should create a REXML Element" do
@xml.class.to_s.should eql('REXML::Element')
end
it "should allocate the new CLUSTER" do
@cluster.allocate(nil)
@cluster.id.should eql(5)
end
it "should update the CLUSTER info" do
@cluster.info()
@cluster.id.should eql(5)
@cluster.name.should eql('Production')
end
it "should delete the CLUSTER" do
rc = @cluster.delete()
rc.should eql(nil)
end
it "should add a host to the CLUSTER" do
rc = @cluster.add_host(nil)
rc.should eql(nil)
end
it "should remove a host from the CLUSTER" do
rc = @cluster.remove_host(nil)
rc.should eql(nil)
end
it "should access an attribute using []" do
@cluster['ID'].should eql('5')
@cluster['NAME'].should eql('Production')
end
it "should get a hash representation of the CLUSTER" do
cluster_hash = @cluster.to_hash
cluster_hash['CLUSTER']['ID'].should eql('5')
cluster_hash['CLUSTER']['NAME'].should eql('Production')
end
end
describe "Cluster using NOKOGIRI without id" do
before(:all) do
NOKOGIRI=true
@xml = Cluster.build_xml()
client = MockClient.new()
@cluster = Cluster.new(@xml,client)
end
it "should create a Nokogiri Node" do
@xml.class.to_s.should eql('Nokogiri::XML::NodeSet')
end
it "should get Error getting info" do
rc = @cluster.info()
OpenNebula.is_error?(rc).should eql(true)
end
it "should get Error deleting the CLUSTER" do
rc = @cluster.delete()
OpenNebula.is_error?(rc).should eql(true)
end
it "should add a host to the CLUSTER" do
rc = @cluster.add_host(nil)
OpenNebula.is_error?(rc).should eql(true)
end
it "should remove a host from the CLUSTER" do
rc = @cluster.remove_host(nil)
OpenNebula.is_error?(rc).should eql(true)
end
end
describe "User using REXML without id" do
before(:all) do
NOKOGIRI=false
@xml = Cluster.build_xml()
client = MockClient.new()
@cluster = Cluster.new(@xml,client)
end
it "should create a REXML Element" do
@xml.class.to_s.should eql('REXML::Element')
end
it "should get Error getting info" do
rc = @cluster.info()
OpenNebula.is_error?(rc).should eql(true)
end
it "should get Error deleting the CLUSTER" do
rc = @cluster.delete()
OpenNebula.is_error?(rc).should eql(true)
end
it "should add a host to the CLUSTER" do
rc = @cluster.add_host(nil)
OpenNebula.is_error?(rc).should eql(true)
end
it "should remove a host from the CLUSTER" do
rc = @cluster.remove_host(nil)
OpenNebula.is_error?(rc).should eql(true)
end
end
end

View File

@ -0,0 +1,61 @@
class MockClient
def call(action, *args)
xmlrpc_action = "one."+action
case xmlrpc_action
when "one.vn.info"
return File.read("xml_test/vnet.xml")
when "one.vn.allocate"
return 3
when "one.vn.delete"
return nil
when "one.vm.info"
return File.read("xml_test/vm.xml")
when "one.vm.allocate"
return 6
when "one.vm.delete"
return nil
when "one.vm.action"
return nil
when "one.vm.deploy"
return nil
when "one.vm.migrate"
return nil
when "one.host.info"
return File.read("xml_test/host.xml")
when "one.host.allocate"
return 7
when "one.host.delete"
return nil
when "one.host.enable"
return nil
when "one.user.allocate"
return 3
when "one.user.info"
return File.read("xml_test/user.xml")
when "one.user.delete"
return nil
when "one.cluster.allocate"
return 5
when "one.cluster.info"
return File.read("xml_test/cluster.xml")
when "one.cluster.delete"
return nil
when "one.cluster.addhost"
return nil
when "one.cluster.removehost"
return nil
when "one.vnpool.info"
return File.read("xml_test/vnetpool.xml")
when "one.vmpool.info"
return File.read("xml_test/vmpool.xml")
when "one.hostpool.info"
return File.read("xml_test/hostpool.xml")
when "one.userpool.info"
return File.read("xml_test/userpool.xml")
when "one.clusterpool.info"
return File.read("xml_test/clusterpool.xml")
end
end
end

View File

@ -0,0 +1,4 @@
<CLUSTER>
<ID>5</ID>
<NAME>Production</NAME>
</CLUSTER>

View File

@ -0,0 +1,14 @@
<CLUSTER_POOL>
<CLUSTER>
<ID>0</ID>
<NAME>default</NAME>
</CLUSTER>
<CLUSTER>
<ID>1</ID>
<NAME>Red</NAME>
</CLUSTER>
<CLUSTER>
<ID>2</ID>
<NAME>Black</NAME>
</CLUSTER>
</CLUSTER_POOL>