diff --git a/src/cli/onehost b/src/cli/onehost index cb784c9f07..7ad6da8cf6 100755 --- a/src/cli/onehost +++ b/src/cli/onehost @@ -278,7 +278,7 @@ when "show" puts host.template_str else - puts host.to_xml + puts host.to_xml(true) end when "delete" @@ -316,7 +316,7 @@ when "list" else hostpool=OpenNebula::HostPool.new(get_one_client) hostpool.info - puts hostpool.to_xml + puts hostpool.to_xml(true) end when "top" diff --git a/src/cli/oneuser b/src/cli/oneuser index 5e07c9d46a..bf7ded78c1 100755 --- a/src/cli/oneuser +++ b/src/cli/oneuser @@ -214,7 +214,7 @@ when "list" else userpool=OpenNebula::UserPool.new(get_one_client) userpool.info - puts userpool.to_xml + puts userpool.to_xml(true) end else diff --git a/src/cli/onevm b/src/cli/onevm index 735e111e3e..b868b960e5 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -633,7 +633,7 @@ when "list" vmpool=OpenNebula::VirtualMachinePool.new(get_one_client, ops[:filter_user].to_i) vmpool.info - puts vmpool.to_xml + puts vmpool.to_xml(true) end when "top" @@ -718,7 +718,7 @@ when "show" puts vm.template_str else - puts vm.to_xml + puts vm.to_xml(true) end end else diff --git a/src/cli/onevnet b/src/cli/onevnet index 55171dcbd6..8baa6bed24 100755 --- a/src/cli/onevnet +++ b/src/cli/onevnet @@ -236,7 +236,7 @@ when "show" puts leases_str end else - puts vn.to_xml + puts vn.to_xml(true) end else puts "Error: "+result.message @@ -286,7 +286,7 @@ when "list" vnpool=OpenNebula::VirtualNetworkPool.new(get_one_client, filter_flag.to_i) vnpool.info - puts vnpool.to_xml + puts vnpool.to_xml(true) end else diff --git a/src/oca/ruby/OpenNebula/XMLUtils.rb b/src/oca/ruby/OpenNebula/XMLUtils.rb index 2ed93c1765..6ee470d0f3 100644 --- a/src/oca/ruby/OpenNebula/XMLUtils.rb +++ b/src/oca/ruby/OpenNebula/XMLUtils.rb @@ -41,6 +41,9 @@ module OpenNebula def [](key) if NOKOGIRI element=@xml.xpath(key.to_s.upcase) + if element.size == 0 + return nil + end else element=@xml.elements[key.to_s.upcase] end @@ -95,18 +98,22 @@ module OpenNebula end def to_hash - if !@hash + if !@hash && @xml @hash=Crack::XML.parse(to_xml) end return @hash end - def to_xml + def to_xml(pretty=false) if NOKOGIRI @xml.to_xml else str = "" - REXML::Formatters::Pretty.new(1).write(@xml,str) + if pretty + REXML::Formatters::Pretty.new(1).write(@xml,str) + else + REXML::Formatters::Default.new.write(@xml,str) + end str end end @@ -146,18 +153,22 @@ module OpenNebula end end - def to_xml + def to_xml(pretty=false) if NOKOGIRI @xml.to_xml else str = "" - REXML::Formatters::Pretty.new(1).write(@xml,str) + if pretty + REXML::Formatters::Pretty.new(1).write(@xml,str) + else + REXML::Formatters::Default.new.write(@xml,str) + end str end end def to_hash - if !@hash + if !@hash && @xml @hash=Crack::XML.parse(to_xml) end return @hash diff --git a/src/oca/ruby/test/HostPool_spec.rb b/src/oca/ruby/test/HostPool_spec.rb new file mode 100644 index 0000000000..171e38cccd --- /dev/null +++ b/src/oca/ruby/test/HostPool_spec.rb @@ -0,0 +1,97 @@ +$: << '../' + +require 'OpenNebula' +require 'MockClient' + +module OpenNebula + + describe "Host using NOKOGIRI" do + before(:all) do + NOKOGIRI=true + + client = MockClient.new() + @host_pool = HostPool.new(client) + end + + it "should update the HOST_POOL info" do + rc = @host_pool.info() + rc.nil?.should eql(true) + end + + it "should iterate the HOST_POOL elements and get info from them" do + rc = @host_pool.each{ |host| + host.class.to_s.should eql("OpenNebula::Host") + if host.id == 0 + host.name.should eql('dummyhost') + elsif host.id == 1 + host.name.should eql('thost') + end + } + end + + it "should get a hash representation of the HOST_POOL" do + host_hash = @host_pool.to_hash + host_hash['HOST_POOL']['HOST'][0]['ID'].should eql('0') + host_hash['HOST_POOL']['HOST'][0]['NAME'].should eql('dummyhost') + host_hash['HOST_POOL']['HOST'][0]['STATE'].should eql('2') + host_hash['HOST_POOL']['HOST'][0]['IM_MAD'].should eql('im_dummy') + host_hash['HOST_POOL']['HOST'][0]['HOST_SHARE']['MEM_USAGE'].should eql('1572864') + host_hash['HOST_POOL']['HOST'][0]['HOST_SHARE']['CPU_USAGE'].should eql('300') + host_hash['HOST_POOL']['HOST'][0]['HOST_SHARE']['FREE_MEM'].should eql('16777216') + host_hash['HOST_POOL']['HOST'][0]['HOST_SHARE']['RUNNING_VMS'].should eql('3') + host_hash['HOST_POOL']['HOST'][1]['ID'].should eql('1') + host_hash['HOST_POOL']['HOST'][1]['NAME'].should eql('thost') + host_hash['HOST_POOL']['HOST'][1]['STATE'].should eql('2') + host_hash['HOST_POOL']['HOST'][1]['IM_MAD'].should eql('im_dummy') + host_hash['HOST_POOL']['HOST'][1]['HOST_SHARE']['MEM_USAGE'].should eql('0') + host_hash['HOST_POOL']['HOST'][1]['HOST_SHARE']['CPU_USAGE'].should eql('0') + host_hash['HOST_POOL']['HOST'][1]['HOST_SHARE']['FREE_MEM'].should eql('16777216') + host_hash['HOST_POOL']['HOST'][1]['HOST_SHARE']['RUNNING_VMS'].should eql('0') + end + end + + describe "Host using REXML" do + before(:all) do + NOKOGIRI=false + + client = MockClient.new() + @host_pool = HostPool.new(client) + end + + it "should update the HOST_POOL info" do + rc = @host_pool.info() + rc.nil?.should eql(true) + end + + it "should iterate the HOST_POOL elements and get info from them" do + rc = @host_pool.each{ |host| + host.class.to_s.should eql("OpenNebula::Host") + if host.id == 0 + host.name.should eql('dummyhost') + elsif host.id == 1 + host.name.should eql('thost') + end + } + end + + it "should get a hash representation of the HOST_POOL" do + host_hash = @host_pool.to_hash + host_hash['HOST_POOL']['HOST'][0]['ID'].should eql('0') + host_hash['HOST_POOL']['HOST'][0]['NAME'].should eql('dummyhost') + host_hash['HOST_POOL']['HOST'][0]['STATE'].should eql('2') + host_hash['HOST_POOL']['HOST'][0]['IM_MAD'].should eql('im_dummy') + host_hash['HOST_POOL']['HOST'][0]['HOST_SHARE']['MEM_USAGE'].should eql('1572864') + host_hash['HOST_POOL']['HOST'][0]['HOST_SHARE']['CPU_USAGE'].should eql('300') + host_hash['HOST_POOL']['HOST'][0]['HOST_SHARE']['FREE_MEM'].should eql('16777216') + host_hash['HOST_POOL']['HOST'][0]['HOST_SHARE']['RUNNING_VMS'].should eql('3') + host_hash['HOST_POOL']['HOST'][1]['ID'].should eql('1') + host_hash['HOST_POOL']['HOST'][1]['NAME'].should eql('thost') + host_hash['HOST_POOL']['HOST'][1]['STATE'].should eql('2') + host_hash['HOST_POOL']['HOST'][1]['IM_MAD'].should eql('im_dummy') + host_hash['HOST_POOL']['HOST'][1]['HOST_SHARE']['MEM_USAGE'].should eql('0') + host_hash['HOST_POOL']['HOST'][1]['HOST_SHARE']['CPU_USAGE'].should eql('0') + host_hash['HOST_POOL']['HOST'][1]['HOST_SHARE']['FREE_MEM'].should eql('16777216') + host_hash['HOST_POOL']['HOST'][1]['HOST_SHARE']['RUNNING_VMS'].should eql('0') + end + end +end \ No newline at end of file diff --git a/src/oca/ruby/test/Host_spec.rb b/src/oca/ruby/test/Host_spec.rb new file mode 100644 index 0000000000..224656f99a --- /dev/null +++ b/src/oca/ruby/test/Host_spec.rb @@ -0,0 +1,251 @@ +$: << '../' + +require 'OpenNebula' +require 'MockClient' + +module OpenNebula + + describe "Host using NOKOGIRI" do + before(:all) do + NOKOGIRI=true + + @xml = Host.build_xml(7) + + client = MockClient.new() + @host = Host.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 HOST" do + @host.allocate(nil,nil,nil,nil) + + @host.id.should eql(7) + end + + it "should update the HOST info" do + @host.info() + + @host.id.should eql(7) + @host.name.should eql('dummyhost') + @host.state.should eql(2) + @host.state_str.should eql('MONITORED') + @host.short_state_str.should eql('on') + end + + it "should enable the HOST" do + rc = @host.enable() + + rc.should eql(nil) + end + + it "should disable the HOST" do + rc = @host.disable() + + rc.should eql(nil) + end + + it "should delete the HOST" do + rc = @host.delete() + + rc.should eql(nil) + end + + it "should access an attribute using []" do + @host['ID'].should eql('7') + @host['NAME'].should eql('dummyhost') + @host['STATE'].should eql('2') + @host['IM_MAD'].should eql('im_dummy') + @host['LAST_MON_TIME'].should eql('1277733596') + @host['HOST_SHARE/MEM_USAGE'].should eql('1572864') + @host['HOST_SHARE/CPU_USAGE'].should eql('300') + @host['HOST_SHARE/FREE_CPU'].should eql('800') + @host['HOST_SHARE/RUNNING_VMS'].should eql('3') + @host['TEMPLATE/CPUSPEED'].should eql('2.2GHz') + @host['TEMPLATE/HYPERVISOR'].should eql('dummy') + @host['TEMPLATE/TOTALMEMORY'].should eql('16777216') + end + + it "should get a hash representation of the HOST" do + host_hash = @host.to_hash + host_hash['HOST']['ID'].should eql('7') + host_hash['HOST']['NAME'].should eql('dummyhost') + host_hash['HOST']['STATE'].should eql('2') + host_hash['HOST']['IM_MAD'].should eql('im_dummy') + host_hash['HOST']['LAST_MON_TIME'].should eql('1277733596') + host_hash['HOST']['HOST_SHARE']['MEM_USAGE'].should eql('1572864') + host_hash['HOST']['HOST_SHARE']['CPU_USAGE'].should eql('300') + host_hash['HOST']['HOST_SHARE']['FREE_CPU'].should eql('800') + host_hash['HOST']['HOST_SHARE']['RUNNING_VMS'].should eql('3') + host_hash['HOST']['TEMPLATE']['CPUSPEED'].should eql('2.2GHz') + host_hash['HOST']['TEMPLATE']['HYPERVISOR'].should eql('dummy') + host_hash['HOST']['TEMPLATE']['TOTALMEMORY'].should eql('16777216') + end + end + + describe "Host using REXML" do + before(:all) do + NOKOGIRI=false + + @xml = Host.build_xml(7) + + client = MockClient.new() + @host = Host.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 HOST" do + @host.allocate(nil,nil,nil,nil) + + @host.id.should eql(7) + end + + it "should update the HOST info" do + @host.info() + + @host.id.should eql(7) + @host.name.should eql('dummyhost') + @host.state.should eql(2) + @host.state_str.should eql('MONITORED') + @host.short_state_str.should eql('on') + end + + it "should enable the HOST" do + rc = @host.enable() + + rc.should eql(nil) + end + + it "should disable the HOST" do + rc = @host.disable() + + rc.should eql(nil) + end + + it "should delete the HOST" do + rc = @host.delete() + + rc.should eql(nil) + end + + it "should access an attribute using []" do + @host['ID'].should eql('7') + @host['NAME'].should eql('dummyhost') + @host['STATE'].should eql('2') + @host['IM_MAD'].should eql('im_dummy') + @host['LAST_MON_TIME'].should eql('1277733596') + @host['HOST_SHARE/MEM_USAGE'].should eql('1572864') + @host['HOST_SHARE/CPU_USAGE'].should eql('300') + @host['HOST_SHARE/FREE_CPU'].should eql('800') + @host['HOST_SHARE/RUNNING_VMS'].should eql('3') + @host['TEMPLATE/CPUSPEED'].should eql('2.2GHz') + @host['TEMPLATE/HYPERVISOR'].should eql('dummy') + @host['TEMPLATE/TOTALMEMORY'].should eql('16777216') + end + + it "should get a hash representation of the HOST" do + host_hash = @host.to_hash + host_hash['HOST']['ID'].should eql('7') + host_hash['HOST']['NAME'].should eql('dummyhost') + host_hash['HOST']['STATE'].should eql('2') + host_hash['HOST']['IM_MAD'].should eql('im_dummy') + host_hash['HOST']['LAST_MON_TIME'].should eql('1277733596') + host_hash['HOST']['HOST_SHARE']['MEM_USAGE'].should eql('1572864') + host_hash['HOST']['HOST_SHARE']['CPU_USAGE'].should eql('300') + host_hash['HOST']['HOST_SHARE']['FREE_CPU'].should eql('800') + host_hash['HOST']['HOST_SHARE']['RUNNING_VMS'].should eql('3') + host_hash['HOST']['TEMPLATE']['CPUSPEED'].should eql('2.2GHz') + host_hash['HOST']['TEMPLATE']['HYPERVISOR'].should eql('dummy') + host_hash['HOST']['TEMPLATE']['TOTALMEMORY'].should eql('16777216') + end + end + + + describe "Host using NOKOGIRI without id" do + before(:all) do + NOKOGIRI=true + + @xml = Host.build_xml() + + client = MockClient.new() + @host = Host.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 = @host.info() + + OpenNebula.is_error?(rc).should eql(true) + @host.id.should eql(nil) + @host.name.should eql(nil) + end + + it "should enable the HOST" do + rc = @host.enable() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should disable the HOST" do + rc = @host.disable() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should get Error deleting the HOST" do + rc = @host.delete() + + OpenNebula.is_error?(rc).should eql(true) + end + end + + describe "Host using REXML without id" do + before(:all) do + NOKOGIRI=false + + @xml = Host.build_xml() + + client = MockClient.new() + @host = Host.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 = @host.info() + + OpenNebula.is_error?(rc).should eql(true) + @host.id.should eql(nil) + @host.name.should eql(nil) + end + + it "should enable the HOST" do + rc = @host.enable() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should disable the HOST" do + rc = @host.disable() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should get Error deleting the HOST" do + rc = @host.delete() + + OpenNebula.is_error?(rc).should eql(true) + end + end + +end \ No newline at end of file diff --git a/src/oca/ruby/test/MockClient.rb b/src/oca/ruby/test/MockClient.rb new file mode 100644 index 0000000000..9ec22687ff --- /dev/null +++ b/src/oca/ruby/test/MockClient.rb @@ -0,0 +1,49 @@ +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.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") + end + end +end \ No newline at end of file diff --git a/src/oca/ruby/test/UserPool_spec.rb b/src/oca/ruby/test/UserPool_spec.rb new file mode 100644 index 0000000000..38acf157eb --- /dev/null +++ b/src/oca/ruby/test/UserPool_spec.rb @@ -0,0 +1,81 @@ +$: << '../' + +require 'OpenNebula' +require 'MockClient' + +module OpenNebula + + describe "User using NOKOGIRI" do + before(:all) do + NOKOGIRI=true + + client = MockClient.new() + @user_pool = UserPool.new(client) + end + + it "should update the USER_POOL info" do + rc = @user_pool.info() + rc.nil?.should eql(true) + end + + it "should iterate the USER_POOL elements and get info from them" do + rc = @user_pool.each{ |user| + user.class.to_s.should eql("OpenNebula::User") + if user.id == 0 + user.name.should eql('oneadmin') + elsif user.id == 1 + user.name.should eql('dan') + end + } + end + + it "should get a hash representation of the USER_POOL" do + user_hash = @user_pool.to_hash + user_hash['USER_POOL']['USER'][0]['ID'].should eql('0') + user_hash['USER_POOL']['USER'][0]['NAME'].should eql('oneadmin') + user_hash['USER_POOL']['USER'][0]['PASSWORD'].should eql('f13a1234833436f71ab846572d251c0d40391e72') + user_hash['USER_POOL']['USER'][0]['ENABLED'].should eql('True') + user_hash['USER_POOL']['USER'][1]['ID'].should eql('1') + user_hash['USER_POOL']['USER'][1]['NAME'].should eql('dan') + user_hash['USER_POOL']['USER'][1]['PASSWORD'].should eql('d22a12348334v33f71ba846572d25250d40701e72') + user_hash['USER_POOL']['USER'][1]['ENABLED'].should eql('False') + end + end + + describe "User using REXML" do + before(:all) do + NOKOGIRI=false + + client = MockClient.new() + @user_pool = UserPool.new(client) + end + + it "should update the USER_POOL info" do + rc = @user_pool.info() + rc.nil?.should eql(true) + end + + it "should iterate the USER_POOL elements and get info from them" do + rc = @user_pool.each{ |user| + user.class.to_s.should eql("OpenNebula::User") + if user.id == 0 + user.name.should eql('oneadmin') + elsif user.id == 1 + user.name.should eql('dan') + end + } + end + + it "should get a hash representation of the USER_POOL" do + user_hash = @user_pool.to_hash + user_hash['USER_POOL']['USER'][0]['ID'].should eql('0') + user_hash['USER_POOL']['USER'][0]['NAME'].should eql('oneadmin') + user_hash['USER_POOL']['USER'][0]['PASSWORD'].should eql('f13a1234833436f71ab846572d251c0d40391e72') + user_hash['USER_POOL']['USER'][0]['ENABLED'].should eql('True') + user_hash['USER_POOL']['USER'][1]['ID'].should eql('1') + user_hash['USER_POOL']['USER'][1]['NAME'].should eql('dan') + user_hash['USER_POOL']['USER'][1]['PASSWORD'].should eql('d22a12348334v33f71ba846572d25250d40701e72') + user_hash['USER_POOL']['USER'][1]['ENABLED'].should eql('False') + end + end +end \ No newline at end of file diff --git a/src/oca/ruby/test/User_spec.rb b/src/oca/ruby/test/User_spec.rb new file mode 100644 index 0000000000..c889991271 --- /dev/null +++ b/src/oca/ruby/test/User_spec.rb @@ -0,0 +1,161 @@ +$: << '../' + +require 'OpenNebula' +require 'MockClient' + +module OpenNebula + + describe "User using NOKOGIRI" do + before(:all) do + NOKOGIRI=true + + @xml = User.build_xml(3) + + client = MockClient.new() + @user = User.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 USER" do + @user.allocate(nil,nil) + + @user.id.should eql(3) + end + + it "should update the USER info" do + @user.info() + + @user.id.should eql(3) + @user.name.should eql('dan') + end + + it "should delete the USER" do + rc = @user.delete() + + rc.should eql(nil) + end + + it "should access an attribute using []" do + @user['ID'].should eql('3') + @user['NAME'].should eql('dan') + @user['PASSWORD'].should eql('d22a12348334v33f71ba846572d25250d40701e72') + @user['ENABLED'].should eql('False') + end + + it "should get a hash representation of the USER" do + user_hash = @user.to_hash + user_hash['USER']['ID'].should eql('3') + user_hash['USER']['NAME'].should eql('dan') + user_hash['USER']['PASSWORD'].should eql('d22a12348334v33f71ba846572d25250d40701e72') + user_hash['USER']['ENABLED'].should eql('False') + end + end + + describe "User using REXML" do + before(:all) do + NOKOGIRI=false + + @xml = User.build_xml(3) + + client = MockClient.new() + @user = User.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 USER" do + @user.allocate(nil,nil) + + @user.id.should eql(3) + end + + it "should update the USER info" do + @user.info() + + @user.id.should eql(3) + @user.name.should eql('dan') + end + + it "should delete the USER" do + rc = @user.delete() + + rc.should eql(nil) + end + + it "should access an attribute using []" do + @user['ID'].should eql('3') + @user['NAME'].should eql('dan') + @user['PASSWORD'].should eql('d22a12348334v33f71ba846572d25250d40701e72') + @user['ENABLED'].should eql('False') + end + + it "should get a hash representation of the USER" do + user_hash = @user.to_hash + user_hash['USER']['ID'].should eql('3') + user_hash['USER']['NAME'].should eql('dan') + user_hash['USER']['PASSWORD'].should eql('d22a12348334v33f71ba846572d25250d40701e72') + user_hash['USER']['ENABLED'].should eql('False') + end + end + + + describe "User using NOKOGIRI without id" do + before(:all) do + NOKOGIRI=true + + @xml = User.build_xml() + + client = MockClient.new() + @user = User.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 = @user.info() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should get Error deleting the USER" do + rc = @user.delete() + + OpenNebula.is_error?(rc).should eql(true) + end + end + + describe "User using REXML without id" do + before(:all) do + NOKOGIRI=false + + @xml = User.build_xml() + + client = MockClient.new() + @user = User.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 = @user.info() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should get Error deleting the USER" do + rc = @user.delete() + + OpenNebula.is_error?(rc).should eql(true) + end + end + +end \ No newline at end of file diff --git a/src/oca/ruby/test/VirtualMachinePool_spec.rb b/src/oca/ruby/test/VirtualMachinePool_spec.rb new file mode 100644 index 0000000000..f8d66d0e62 --- /dev/null +++ b/src/oca/ruby/test/VirtualMachinePool_spec.rb @@ -0,0 +1,105 @@ +$: << '../' + +require 'OpenNebula' +require 'MockClient' + +module OpenNebula + + describe "VirtualMachinePool using NOKOGIRI" do + before(:all) do + NOKOGIRI=true + + client = MockClient.new() + @vm_pool = VirtualMachinePool.new(client) + end + + it "should update the VM_POOL info" do + rc = @vm_pool.info() + rc.nil?.should eql(true) + end + + it "should iterate the VM_POOL elements and get info from them" do + rc = @vm_pool.each{ |vm| + vm.class.to_s.should eql("OpenNebula::VirtualMachine") + if vm.id == 6 + vm.name.should eql('vm-example') + vm.state.should eql(3) + vm.state_str.should eql('ACTIVE') + elsif vm.id == 8 + vm.name.should eql('vmext') + vm.state.should eql(4) + vm.state_str.should eql('STOPPED') + end + } + end + + it "should get a hash representation of the VM_POOL" do + vm_hash = @vm_pool.to_hash + vm_hash['VM_POOL']['VM'][0]['ID'].should eql('6') + vm_hash['VM_POOL']['VM'][0]['UID'].should eql('0') + vm_hash['VM_POOL']['VM'][0]['USERNAME'].should eql('oneadmin') + vm_hash['VM_POOL']['VM'][0]['NAME'].should eql('vm-example') + vm_hash['VM_POOL']['VM'][0]['LAST_POLL'].should eql('1277910006') + vm_hash['VM_POOL']['VM'][0]['HISTORY']['HOSTNAME'].should eql('dummyhost') + vm_hash['VM_POOL']['VM'][0]['HISTORY']['STIME'].should eql('1277375186') + vm_hash['VM_POOL']['VM'][0]['HISTORY']['REASON'].should eql('0') + vm_hash['VM_POOL']['VM'][2]['ID'].should eql('8') + vm_hash['VM_POOL']['VM'][2]['UID'].should eql('0') + vm_hash['VM_POOL']['VM'][2]['USERNAME'].should eql('oneadmin') + vm_hash['VM_POOL']['VM'][2]['NAME'].should eql('vmext') + vm_hash['VM_POOL']['VM'][2]['LAST_POLL'].should eql('1277910006') + vm_hash['VM_POOL']['VM'][2]['HISTORY']['HOSTNAME'].should eql('thost') + vm_hash['VM_POOL']['VM'][2]['HISTORY']['STIME'].should eql('1277377556') + vm_hash['VM_POOL']['VM'][2]['HISTORY']['REASON'].should eql('0') + end + end + + describe "VirtualMachinePool using REXML" do + before(:all) do + NOKOGIRI=false + + client = MockClient.new() + @vm_pool = VirtualMachinePool.new(client) + end + + it "should update the VM_POOL info" do + rc = @vm_pool.info() + rc.nil?.should eql(true) + end + + it "should iterate the VM_POOL elements and get info from them" do + rc = @vm_pool.each{ |vm| + vm.class.to_s.should eql("OpenNebula::VirtualMachine") + if vm.id == 6 + vm.name.should eql('vm-example') + vm.state.should eql(3) + vm.state_str.should eql('ACTIVE') + elsif vm.id == 8 + vm.name.should eql('vmext') + vm.state.should eql(4) + vm.state_str.should eql('STOPPED') + end + } + end + + it "should get a hash representation of the VM_POOL" do + vm_hash = @vm_pool.to_hash + vm_hash['VM_POOL']['VM'][0]['ID'].should eql('6') + vm_hash['VM_POOL']['VM'][0]['UID'].should eql('0') + vm_hash['VM_POOL']['VM'][0]['USERNAME'].should eql('oneadmin') + vm_hash['VM_POOL']['VM'][0]['NAME'].should eql('vm-example') + vm_hash['VM_POOL']['VM'][0]['LAST_POLL'].should eql('1277910006') + vm_hash['VM_POOL']['VM'][0]['HISTORY']['HOSTNAME'].should eql('dummyhost') + vm_hash['VM_POOL']['VM'][0]['HISTORY']['STIME'].should eql('1277375186') + vm_hash['VM_POOL']['VM'][0]['HISTORY']['REASON'].should eql('0') + vm_hash['VM_POOL']['VM'][2]['ID'].should eql('8') + vm_hash['VM_POOL']['VM'][2]['UID'].should eql('0') + vm_hash['VM_POOL']['VM'][2]['USERNAME'].should eql('oneadmin') + vm_hash['VM_POOL']['VM'][2]['NAME'].should eql('vmext') + vm_hash['VM_POOL']['VM'][2]['LAST_POLL'].should eql('1277910006') + vm_hash['VM_POOL']['VM'][2]['HISTORY']['HOSTNAME'].should eql('thost') + vm_hash['VM_POOL']['VM'][2]['HISTORY']['STIME'].should eql('1277377556') + vm_hash['VM_POOL']['VM'][2]['HISTORY']['REASON'].should eql('0') + end + end +end \ No newline at end of file diff --git a/src/oca/ruby/test/VirtualMachine_spec.rb b/src/oca/ruby/test/VirtualMachine_spec.rb new file mode 100644 index 0000000000..2cd35489e9 --- /dev/null +++ b/src/oca/ruby/test/VirtualMachine_spec.rb @@ -0,0 +1,464 @@ +$: << '../' + +require 'OpenNebula' +require 'MockClient' + +module OpenNebula + + describe "VirtualMachine using NOKOGIRI" do + before(:all) do + NOKOGIRI=true + + @xml = VirtualMachine.build_xml(6) + + client = MockClient.new() + @vm = VirtualMachine.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 VM" do + @vm.allocate(nil) + + @vm.id.should eql(6) + end + + it "should update the VM info" do + @vm.info() + + @vm.id.should eql(6) + @vm.name.should eql('vm-example') + @vm.state.should eql(3) + @vm.state_str.should eql('ACTIVE') + @vm.lcm_state.should eql(3) + @vm.lcm_state_str.should eql('RUNNING') + @vm.status.should eql('runn') + end + + it "should deploy the VNET" do + rc = @vm.deploy(nil) + + rc.should eql(nil) + end + + it "should migrate the VNET" do + rc = @vm.migrate(nil) + + rc.should eql(nil) + end + + it "should live_migrate the VNET" do + rc = @vm.live_migrate(nil) + + rc.should eql(nil) + end + + it "should shutdown the VNET" do + rc = @vm.shutdown() + + rc.should eql(nil) + end + + it "should cancel the VNET" do + rc = @vm.cancel() + + rc.should eql(nil) + end + + it "should hold the VNET" do + rc = @vm.hold() + + rc.should eql(nil) + end + + it "should release the VNET" do + rc = @vm.release() + + rc.should eql(nil) + end + + it "should stop the VNET" do + rc = @vm.stop() + + rc.should eql(nil) + end + + it "should suspend the VNET" do + rc = @vm.suspend() + + rc.should eql(nil) + end + + it "should resume the VNET" do + rc = @vm.resume() + + rc.should eql(nil) + end + + it "should finalize the VNET" do + rc = @vm.finalize() + + rc.should eql(nil) + end + + it "should restart the VNET" do + rc = @vm.restart() + + rc.should eql(nil) + end + + it "should access an attribute using []" do + @vm['NAME'].should eql('vm-example') + @vm['DEPLOY_ID'].should eql('dummy') + @vm['TEMPLATE/MEMORY'].should eql('512') + @vm['ID'].should eql('6') + @vm['NAME'].should eql('vm-example') + @vm['LCM_STATE'].should eql('3') + @vm['DEPLOY_ID'].should eql('dummy') + @vm['TEMPLATE/MEMORY'].should eql('512') + @vm['TEMPLATE/CONTEXT/DNS'].should eql('192.169.1.4') + @vm['TEMPLATE/DISK/SIZE'].should eql('1024') + @vm['HISTORY/HOSTNAME'].should eql('dummyhost') + @vm['HISTORY/PSTIME'].should eql('1277375186') + end + + it "should get a hash representation of the VM" do + vm_hash = @vm.to_hash + vm_hash['VM']['ID'].should eql('6') + vm_hash['VM']['NAME'].should eql('vm-example') + vm_hash['VM']['LCM_STATE'].should eql('3') + vm_hash['VM']['DEPLOY_ID'].should eql('dummy') + vm_hash['VM']['TEMPLATE']['MEMORY'].should eql('512') + vm_hash['VM']['TEMPLATE']['CONTEXT']['DNS'].should eql('192.169.1.4') + vm_hash['VM']['TEMPLATE']['DISK'][0]['TARGET'].should eql('sda') + vm_hash['VM']['HISTORY']['HOSTNAME'].should eql('dummyhost') + vm_hash['VM']['HISTORY']['PSTIME'].should eql('1277375186') + end + end + + describe "VirtualMachine using REXML" do + before(:all) do + NOKOGIRI=false + + @xml = VirtualMachine.build_xml(6) + + client = MockClient.new() + @vm = VirtualMachine.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 VM" do + @vm.allocate(nil) + + @vm.id.should eql(6) + end + + it "should update the VM info" do + @vm.info() + + @vm.id.should eql(6) + @vm.name.should eql('vm-example') + @vm.state.should eql(3) + @vm.state_str.should eql('ACTIVE') + @vm.lcm_state.should eql(3) + @vm.lcm_state_str.should eql('RUNNING') + @vm.status.should eql('runn') + end + + it "should deploy the VNET" do + rc = @vm.deploy(nil) + + rc.should eql(nil) + end + + it "should migrate the VNET" do + rc = @vm.migrate(nil) + + rc.should eql(nil) + end + + it "should live_migrate the VNET" do + rc = @vm.live_migrate(nil) + + rc.should eql(nil) + end + + it "should shutdown the VNET" do + rc = @vm.shutdown() + + rc.should eql(nil) + end + + it "should cancel the VNET" do + rc = @vm.cancel() + + rc.should eql(nil) + end + + it "should hold the VNET" do + rc = @vm.hold() + + rc.should eql(nil) + end + + it "should release the VNET" do + rc = @vm.release() + + rc.should eql(nil) + end + + it "should stop the VNET" do + rc = @vm.stop() + + rc.should eql(nil) + end + + it "should suspend the VNET" do + rc = @vm.suspend() + + rc.should eql(nil) + end + + it "should resume the VNET" do + rc = @vm.resume() + + rc.should eql(nil) + end + + it "should finalize the VNET" do + rc = @vm.finalize() + + rc.should eql(nil) + end + + it "should restart the VNET" do + rc = @vm.restart() + + rc.should eql(nil) + end + + it "should access an attribute using []" do + @vm['NAME'].should eql('vm-example') + @vm['DEPLOY_ID'].should eql('dummy') + @vm['TEMPLATE/MEMORY'].should eql('512') + @vm['ID'].should eql('6') + @vm['NAME'].should eql('vm-example') + @vm['LCM_STATE'].should eql('3') + @vm['DEPLOY_ID'].should eql('dummy') + @vm['TEMPLATE/MEMORY'].should eql('512') + @vm['TEMPLATE/CONTEXT/DNS'].should eql('192.169.1.4') + @vm['TEMPLATE/DISK/SIZE'].should eql('1024') + @vm['HISTORY/HOSTNAME'].should eql('dummyhost') + @vm['HISTORY/PSTIME'].should eql('1277375186') + end + + it "should get a hash representation of the VM" do + vm_hash = @vm.to_hash + vm_hash['VM']['ID'].should eql('6') + vm_hash['VM']['NAME'].should eql('vm-example') + vm_hash['VM']['LCM_STATE'].should eql('3') + vm_hash['VM']['DEPLOY_ID'].should eql('dummy') + vm_hash['VM']['TEMPLATE']['MEMORY'].should eql('512') + vm_hash['VM']['TEMPLATE']['CONTEXT']['DNS'].should eql('192.169.1.4') + vm_hash['VM']['TEMPLATE']['DISK'][0]['TARGET'].should eql('sda') + vm_hash['VM']['HISTORY']['HOSTNAME'].should eql('dummyhost') + vm_hash['VM']['HISTORY']['PSTIME'].should eql('1277375186') + end + end + + + describe "VirtualMachine using NOKOGIRI without id" do + before(:all) do + NOKOGIRI=true + + @xml = VirtualMachine.build_xml() + + client = MockClient.new() + @vm = VirtualMachine.new(@xml,client) + end + + it "should create a Nokogiri Node" do + @xml.class.to_s.should eql('Nokogiri::XML::NodeSet') + end + + it "should deploy the VNET" do + rc = @vm.deploy(nil) + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should migrate the VNET" do + rc = @vm.migrate(nil) + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should live_migrate the VNET" do + rc = @vm.live_migrate(nil) + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should shutdown the VNET" do + rc = @vm.shutdown() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should cancel the VNET" do + rc = @vm.cancel() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should hold the VNET" do + rc = @vm.hold() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should release the VNET" do + rc = @vm.release() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should stop the VNET" do + rc = @vm.stop() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should suspend the VNET" do + rc = @vm.suspend() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should resume the VNET" do + rc = @vm.resume() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should finalize the VNET" do + rc = @vm.finalize() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should restart the VNET" do + rc = @vm.restart() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should get Error getting info" do + rc = @vm.info() + + OpenNebula.is_error?(rc).should eql(true) + @vm.id.should eql(nil) + @vm.name.should eql(nil) + end + end + + describe "VirtualMachine using REXML without id" do + before(:all) do + NOKOGIRI=false + + @xml = VirtualMachine.build_xml() + + client = MockClient.new() + @vm = VirtualMachine.new(@xml,client) + end + + it "should create a REXML Element" do + @xml.class.to_s.should eql('REXML::Element') + end + + it "should deploy the VNET" do + rc = @vm.deploy(nil) + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should migrate the VNET" do + rc = @vm.migrate(nil) + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should live_migrate the VNET" do + rc = @vm.live_migrate(nil) + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should shutdown the VNET" do + rc = @vm.shutdown() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should cancel the VNET" do + rc = @vm.cancel() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should hold the VNET" do + rc = @vm.hold() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should release the VNET" do + rc = @vm.release() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should stop the VNET" do + rc = @vm.stop() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should suspend the VNET" do + rc = @vm.suspend() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should resume the VNET" do + rc = @vm.resume() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should finalize the VNET" do + rc = @vm.finalize() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should restart the VNET" do + rc = @vm.restart() + + OpenNebula.is_error?(rc).should eql(true) + end + + it "should get Error getting info" do + rc = @vm.info() + + OpenNebula.is_error?(rc).should eql(true) + @vm.id.should eql(nil) + @vm.name.should eql(nil) + end + end +end \ No newline at end of file diff --git a/src/oca/ruby/test/VirtualNetworkPool_spec.rb b/src/oca/ruby/test/VirtualNetworkPool_spec.rb new file mode 100644 index 0000000000..bd373e488d --- /dev/null +++ b/src/oca/ruby/test/VirtualNetworkPool_spec.rb @@ -0,0 +1,103 @@ +$: << '../' + +require 'OpenNebula' +require 'MockClient' + +module OpenNebula + + describe "VirtualNetwork using NOKOGIRI" do + before(:all) do + NOKOGIRI=true + + client = MockClient.new() + @vnet_pool = VirtualNetworkPool.new(client) + end + + #it "should get nil, trying to get a hash, if the info method was not called before" do + # vnet_hash = @vnet_pool.to_hash + # vnet_hash.nil?.should eql(true) + #end + + it "should update the VNET_POOL info" do + rc = @vnet_pool.info() + rc.nil?.should eql(true) + end + + it "should iterate the VNET_POOL elements and get info from them" do + rc = @vnet_pool.each{ |vn| + vn.class.to_s.should eql("OpenNebula::VirtualNetwork") + if vn.id == 4 + vn.name.should eql('Red LAN') + elsif vn.id == 5 + vn.name.should eql('Public') + end + } + end + + it "should get a hash representation of the VNET_POOL" do + vnet_hash = @vnet_pool.to_hash + vnet_hash['VNET_POOL']['VNET'][0]['ID'].should eql('4') + vnet_hash['VNET_POOL']['VNET'][0]['UID'].should eql('0') + vnet_hash['VNET_POOL']['VNET'][0]['USERNAME'].should eql('oneadmin') + vnet_hash['VNET_POOL']['VNET'][0]['NAME'].should eql('Red LAN') + vnet_hash['VNET_POOL']['VNET'][0]['TYPE'].should eql('0') + vnet_hash['VNET_POOL']['VNET'][0]['BRIDGE'].should eql('vbr0') + vnet_hash['VNET_POOL']['VNET'][0]['TOTAL_LEASES'].should eql('0') + vnet_hash['VNET_POOL']['VNET'][1]['ID'].should eql('5') + vnet_hash['VNET_POOL']['VNET'][1]['UID'].should eql('0') + vnet_hash['VNET_POOL']['VNET'][1]['USERNAME'].should eql('oneadmin') + vnet_hash['VNET_POOL']['VNET'][1]['NAME'].should eql('Public') + vnet_hash['VNET_POOL']['VNET'][1]['TYPE'].should eql('0') + vnet_hash['VNET_POOL']['VNET'][1]['BRIDGE'].should eql('vbr0') + vnet_hash['VNET_POOL']['VNET'][1]['TOTAL_LEASES'].should eql('1') + end + end + + describe "VirtualNetwork using REXML" do + before(:all) do + NOKOGIRI=false + + client = MockClient.new() + @vnet_pool = VirtualNetworkPool.new(client) + end + + #it "should get nil, trying to get a hash, if the info method was not called before" do + # vnet_hash = @vnet_pool.to_hash + # vnet_hash.nil?.should eql(true) + #end + + it "should update the VNET_POOL info" do + rc = @vnet_pool.info() + rc.nil?.should eql(true) + end + + it "should iterate the VNET_POOL elements and get info from them" do + rc = @vnet_pool.each{ |vn| + vn.class.to_s.should eql("OpenNebula::VirtualNetwork") + if vn.id == 4 + vn.name.should eql('Red LAN') + elsif vn.id == 5 + vn.name.should eql('Public') + end + } + end + + it "should get a hash representation of the VNET_POOL" do + vnet_hash = @vnet_pool.to_hash + vnet_hash['VNET_POOL']['VNET'][0]['ID'].should eql('4') + vnet_hash['VNET_POOL']['VNET'][0]['UID'].should eql('0') + vnet_hash['VNET_POOL']['VNET'][0]['USERNAME'].should eql('oneadmin') + vnet_hash['VNET_POOL']['VNET'][0]['NAME'].should eql('Red LAN') + vnet_hash['VNET_POOL']['VNET'][0]['TYPE'].should eql('0') + vnet_hash['VNET_POOL']['VNET'][0]['BRIDGE'].should eql('vbr0') + vnet_hash['VNET_POOL']['VNET'][0]['TOTAL_LEASES'].should eql('0') + vnet_hash['VNET_POOL']['VNET'][1]['ID'].should eql('5') + vnet_hash['VNET_POOL']['VNET'][1]['UID'].should eql('0') + vnet_hash['VNET_POOL']['VNET'][1]['USERNAME'].should eql('oneadmin') + vnet_hash['VNET_POOL']['VNET'][1]['NAME'].should eql('Public') + vnet_hash['VNET_POOL']['VNET'][1]['TYPE'].should eql('0') + vnet_hash['VNET_POOL']['VNET'][1]['BRIDGE'].should eql('vbr0') + vnet_hash['VNET_POOL']['VNET'][1]['TOTAL_LEASES'].should eql('1') + end + end +end \ No newline at end of file diff --git a/src/oca/ruby/test/VirtualNetwork_spec.rb b/src/oca/ruby/test/VirtualNetwork_spec.rb new file mode 100644 index 0000000000..89682e28df --- /dev/null +++ b/src/oca/ruby/test/VirtualNetwork_spec.rb @@ -0,0 +1,183 @@ +$: << '../' + +require 'OpenNebula' +require 'MockClient' + +module OpenNebula + + describe "VirtualNetwork using NOKOGIRI" do + before(:all) do + NOKOGIRI=true + + @xml = VirtualNetwork.build_xml(3) + + client = MockClient.new() + @vnet = VirtualNetwork.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 VNET" do + @vnet.allocate(nil) + + @vnet.id.should eql(3) + end + + it "should update the VNET info" do + @vnet.info() + + @vnet.id.should eql(3) + @vnet.name.should eql('Red LAN') + end + + it "should delete the VNET" do + rc = @vnet.delete() + + rc.should eql(nil) + end + + it "should access an attribute using []" do + @vnet['ID'].should eql('3') + @vnet['NAME'].should eql('Red LAN') + @vnet['BRIDGE'].should eql('vbr0') + @vnet['TEMPLATE/NETWORK_ADDRESS'].should eql('192.168.0.0') + @vnet['TEMPLATE/TYPE'].should eql('RANGED') + @vnet['LEASES/LEASE/IP'].should eql('192.168.0.1') + @vnet['LEASES/LEASE/USED'].should eql('1') + end + + it "should get a hash representation of the VNET" do + vnet_hash = @vnet.to_hash + vnet_hash['VNET']['NAME'].should eql('Red LAN') + vnet_hash['VNET']['BRIDGE'].should eql('vbr0') + vnet_hash['VNET']['TEMPLATE']['NETWORK_ADDRESS'].should eql('192.168.0.0') + vnet_hash['VNET']['ID'].should eql('3') + vnet_hash['VNET']['NAME'].should eql('Red LAN') + vnet_hash['VNET']['BRIDGE'].should eql('vbr0') + vnet_hash['VNET']['TEMPLATE']['NETWORK_ADDRESS'].should eql('192.168.0.0') + vnet_hash['VNET']['TEMPLATE']['TYPE'].should eql('RANGED') + vnet_hash['VNET']['LEASES']['LEASE']['IP'].should eql('192.168.0.1') + vnet_hash['VNET']['LEASES']['LEASE']['USED'].should eql('1') + end + end + + describe "VirtualNetwork using REXML" do + before(:all) do + NOKOGIRI=false + + @xml = VirtualNetwork.build_xml(3) + + client = MockClient.new() + @vnet = VirtualNetwork.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 VNET" do + @vnet.allocate(nil) + + @vnet.id.should eql(3) + end + + it "should update the VNET info" do + @vnet.info() + + @vnet.id.should eql(3) + @vnet.name.should eql('Red LAN') + end + + it "should delete the VNET" do + rc = @vnet.delete() + + rc.should eql(nil) + end + + it "should access an attribute using []" do + @vnet['ID'].should eql('3') + @vnet['NAME'].should eql('Red LAN') + @vnet['BRIDGE'].should eql('vbr0') + @vnet['TEMPLATE/NETWORK_ADDRESS'].should eql('192.168.0.0') + @vnet['TEMPLATE/TYPE'].should eql('RANGED') + @vnet['LEASES/LEASE/IP'].should eql('192.168.0.1') + @vnet['LEASES/LEASE/USED'].should eql('1') + end + + it "should get a hash representation of the VNET" do + vnet_hash = @vnet.to_hash + vnet_hash['VNET']['NAME'].should eql('Red LAN') + vnet_hash['VNET']['BRIDGE'].should eql('vbr0') + vnet_hash['VNET']['TEMPLATE']['NETWORK_ADDRESS'].should eql('192.168.0.0') + vnet_hash['VNET']['ID'].should eql('3') + vnet_hash['VNET']['NAME'].should eql('Red LAN') + vnet_hash['VNET']['BRIDGE'].should eql('vbr0') + vnet_hash['VNET']['TEMPLATE']['NETWORK_ADDRESS'].should eql('192.168.0.0') + vnet_hash['VNET']['TEMPLATE']['TYPE'].should eql('RANGED') + vnet_hash['VNET']['LEASES']['LEASE']['IP'].should eql('192.168.0.1') + vnet_hash['VNET']['LEASES']['LEASE']['USED'].should eql('1') + end + end + + + describe "VirtualNetwork using NOKOGIRI without id" do + before(:all) do + NOKOGIRI=true + + @xml = VirtualNetwork.build_xml() + + client = MockClient.new() + @vnet = VirtualNetwork.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 = @vnet.info() + + OpenNebula.is_error?(rc).should eql(true) + @vnet.id.should eql(nil) + @vnet.name.should eql(nil) + end + + it "should get Error deleting the VNET" do + rc = @vnet.delete() + + OpenNebula.is_error?(rc).should eql(true) + end + end + + describe "VirtualNetwork using REXML without id" do + before(:all) do + NOKOGIRI=false + + @xml = VirtualNetwork.build_xml() + + client = MockClient.new() + @vnet = VirtualNetwork.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 = @vnet.info() + + OpenNebula.is_error?(rc).should eql(true) + @vnet.id.should eql(nil) + @vnet.name.should eql(nil) + end + + it "should get Error deleting the VNET" do + rc = @vnet.delete() + + OpenNebula.is_error?(rc).should eql(true) + end + end + +end \ No newline at end of file diff --git a/src/oca/ruby/test/xml_test/host.xml b/src/oca/ruby/test/xml_test/host.xml new file mode 100644 index 0000000000..55710fe305 --- /dev/null +++ b/src/oca/ruby/test/xml_test/host.xml @@ -0,0 +1,38 @@ + + 7 + dummyhost + 2 + im_dummy + vmm_dummy + tm_dummy + 1277733596 + + 0 + 0 + 1572864 + 300 + 0 + 16777216 + 800 + 0 + 16777216 + 800 + 0 + 0 + 0 + 3 + + + \ No newline at end of file diff --git a/src/oca/ruby/test/xml_test/hostpool.xml b/src/oca/ruby/test/xml_test/hostpool.xml new file mode 100644 index 0000000000..50fe5fc2b6 --- /dev/null +++ b/src/oca/ruby/test/xml_test/hostpool.xml @@ -0,0 +1,52 @@ + + + 0 + dummyhost + 2 + im_dummy + vmm_dummy + tm_dummy + 1277912461 + + 0 + 0 + 1572864 + 300 + 0 + 16777216 + 800 + 0 + 16777216 + 800 + 0 + 0 + 0 + 3 + + + + 1 + thost + 2 + im_dummy + vmm_dummy + tm_dummy + 1277912461 + + 1 + 0 + 0 + 0 + 0 + 16777216 + 800 + 0 + 16777216 + 800 + 0 + 0 + 0 + 0 + + + \ No newline at end of file diff --git a/src/oca/ruby/test/xml_test/user.xml b/src/oca/ruby/test/xml_test/user.xml new file mode 100644 index 0000000000..eab4482685 --- /dev/null +++ b/src/oca/ruby/test/xml_test/user.xml @@ -0,0 +1,6 @@ + + 3 + dan + d22a12348334v33f71ba846572d25250d40701e72 + False + \ No newline at end of file diff --git a/src/oca/ruby/test/xml_test/userpool.xml b/src/oca/ruby/test/xml_test/userpool.xml new file mode 100644 index 0000000000..d6d5565131 --- /dev/null +++ b/src/oca/ruby/test/xml_test/userpool.xml @@ -0,0 +1,14 @@ + + + 0 + oneadmin + f13a1234833436f71ab846572d251c0d40391e72 + True + + + 1 + dan + d22a12348334v33f71ba846572d25250d40701e72 + False + + \ No newline at end of file diff --git a/src/oca/ruby/test/xml_test/vm.xml b/src/oca/ruby/test/xml_test/vm.xml new file mode 100644 index 0000000000..9b5f2a1b20 --- /dev/null +++ b/src/oca/ruby/test/xml_test/vm.xml @@ -0,0 +1,59 @@ + + 6 + 0 + vm-example + 1277729095 + 3 + 3 + 1277375180 + 0 + dummy + 512 + 1 + 12345 + 0 + + + 0 + dummyhost + 0 + 1277375186 + 0 + 1277375186 + 1277375186 + 1277375186 + 0 + 0 + 0 + 0 + + \ No newline at end of file diff --git a/src/oca/ruby/test/xml_test/vmpool.xml b/src/oca/ruby/test/xml_test/vmpool.xml new file mode 100644 index 0000000000..7811116fd8 --- /dev/null +++ b/src/oca/ruby/test/xml_test/vmpool.xml @@ -0,0 +1,92 @@ + + + 6 + 0 + oneadmin + vm-example + 1277910006 + 3 + 3 + 1277375180 + 0 + dummy + 512 + 1 + 12345 + 0 + + 0 + dummyhost + 0 + 1277375186 + 0 + 1277375186 + 1277375186 + 1277375186 + 0 + 0 + 0 + 0 + + + + 7 + 0 + oneadmin + vm-in + 1277910006 + 3 + 3 + 1277377464 + 0 + dummy + 1024 + 2 + 12345 + 0 + + 0 + thost + 0 + 1277377466 + 0 + 1277377466 + 1277377466 + 1277377466 + 0 + 0 + 0 + 0 + + + + 8 + 0 + oneadmin + vmext + 1277910006 + 4 + 5 + 1277377533 + 0 + thost + 256 + 1 + 12345 + 0 + + 0 + thost + 0 + 1277377556 + 0 + 1277377556 + 1277377556 + 1277377556 + 0 + 0 + 0 + 0 + + + \ No newline at end of file diff --git a/src/oca/ruby/test/xml_test/vnet.xml b/src/oca/ruby/test/xml_test/vnet.xml new file mode 100644 index 0000000000..8df0c43070 --- /dev/null +++ b/src/oca/ruby/test/xml_test/vnet.xml @@ -0,0 +1,23 @@ + + 3 + 0 + Red LAN + 0 + vbr0 + + + + 192.168.0.1 + 00:03:c0:a8:00:01 + 1 + 18 + + + \ No newline at end of file diff --git a/src/oca/ruby/test/xml_test/vnetpool.xml b/src/oca/ruby/test/xml_test/vnetpool.xml new file mode 100644 index 0000000000..bc77abac40 --- /dev/null +++ b/src/oca/ruby/test/xml_test/vnetpool.xml @@ -0,0 +1,20 @@ + + + 4 + 0 + oneadmin + Red LAN + 0 + vbr0 + 0 + + + 5 + 0 + oneadmin + Public + 0 + vbr0 + 1 + + \ No newline at end of file