1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

Feature #938: Move tests from ozones/Server/test to ozones/test

(cherry picked from commit f2e86d4b487ac4ceb20e57c35790eca10e1c1501)
This commit is contained in:
Hector Sanjuan 2012-03-06 12:17:01 +01:00 committed by Ruben S. Montero
parent a9bf2f05dc
commit 28e841c739
23 changed files with 228 additions and 354 deletions

View File

@ -1,9 +0,0 @@
require 'rake'
require 'spec/rake/spectask'
desc "Run all tests with RCov"
Spec::Rake::SpecTask.new('test_with_rcov') do |t|
t.spec_files = FileList['spec/*_spec.rb']
t.rcov = true
t.rcov_opts = ['--exclude', '/Library']
end

View File

@ -1,18 +0,0 @@
{
"vdcpool": {
"vdc": [
{
"hosts": "testhostvdc0n0,testhostvdc0n1,testhostvdc0n2",
"zones_id": 1,
"name": "testvdc0",
"id": 1
},
{
"hosts": "testhostvdc1n0",
"zones_id": 1,
"name": "testvdc1",
"id": 2
}
]
}
}

View File

@ -1,12 +0,0 @@
{
"vdcpool": {
"vdc": [
{
"hosts": "testhostvdc0n0,testhostvdc0n1,testhostvdc0n2",
"zones_id": 1,
"name": "testvdc0",
"id": 1
}
]
}
}

View File

@ -1,22 +0,0 @@
{
"zonepool": {
"zone": [
{
"onename": "oneadmin",
"onepass": "opennebula",
"endpoint": "http://localhost:2633/RPC2",
"numbervdcs": 2,
"name": "testzone0",
"id": 1
},
{
"onename": "testname",
"onepass": "testpass",
"endpoint": "http://remoteserver:2633/RPC2",
"numbervdcs": 0,
"name": "testzone1",
"id": 2
}
]
}
}

View File

@ -1,14 +0,0 @@
{
"zonepool": {
"zone": [
{
"onename": "oneadmin",
"onepass": "opennebula",
"endpoint": "http://localhost:2633/RPC2",
"numbervdcs": 2,
"name": "testzone0",
"id": 1
}
]
}
}

View File

@ -1,8 +0,0 @@
{
"vdc": {
"hosts": "5,7,9",
"zones_id": 1,
"name": "testvdc0",
"id": 1
}
}

View File

@ -1,5 +0,0 @@
NAME=testvdc0
ZONEID=1
HOSTS=5,7,9
VDCADMINNAME=adminname
VDCADMINPASS=adminpass

View File

@ -1,5 +0,0 @@
NAME=testvdc1
HOSTS=8
ZONEID=1
VDCADMINNAME=othername
VDCADMINPASS=otherpass

View File

@ -1,3 +0,0 @@
NAME=testvdcnozone
HOSTS=3,7
ZONEID=5

View File

@ -1,23 +0,0 @@
{
"zone": {
"onename": "oneadmin",
"onepass": "opennebula",
"endpoint": "http://localhost:2633/RPC2",
"name": "testzone0",
"id": 1,
"vdcs": [
{
"hosts": "testhostvdc0n0,testhostvdc0n1,testhostvdc0n2",
"zones_id": 1,
"name": "testvdc0",
"id": 1
},
{
"hosts": "testhostvdc1n0",
"zones_id": 1,
"name": "testvdc1",
"id": 2
}
]
}
}

View File

@ -1,4 +0,0 @@
NAME=testzone0
ENDPOINT=http://localhost:2633/RPC2
ONENAME=oneadmin
ONEPASS=opennebula

View File

@ -1,4 +0,0 @@
NAME=testzone1
ENDPOINT=http://remoteserver:2633/RPC2
ONENAME=testname
ONEPASS=testpass

View File

@ -1,133 +0,0 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
# Load libraries
require 'rubygems'
require 'spec'
require 'json'
require File.dirname(__FILE__) + "/../../../Client/lib/OZonesClient.rb"
EXAMPLES_PATH = File.dirname(__FILE__) + "/../examples/"
describe 'OZones Pool' do
before(:all) do
@client_launched = true
begin
@ozones_client = OZonesClient::Client.new("http://localhost:6121")
rescue Exception => e
@client_launched = false
end
@client_launched.should == true
rc = @ozones_client.post_resource(
"zone",EXAMPLES_PATH + '/zone/zone0.template')
rc.class.should_not eql(OZonesClient::Error)
rc = @ozones_client.post_resource(
"zone",EXAMPLES_PATH + '/zone/zone1.template')
rc.class.should_not eql(OZonesClient::Error)
rc = @ozones_client.post_resource(
"vdc",EXAMPLES_PATH + '/vdc/vdc0.template')
rc.class.should_not eql(OZonesClient::Error)
rc = @ozones_client.post_resource(
"vdc",EXAMPLES_PATH + '/vdc/vdc1.template')
rc.class.should_not eql(OZonesClient::Error)
end
it "should be able to retrieve the zone pool" do
zonepool = @ozones_client.get_pool("zone")
zonepool.class.should eql(Net::HTTPOK)
zonepool.body.should eql(
File.read(EXAMPLES_PATH+'/pool/zonepool0.json'))
end
it "should be able to retrieve the vdc pool" do
vdcpool = @ozones_client.get_pool("vdc")
vdcpool.class.should eql(Net::HTTPOK)
vdcpool.body.should eql(
File.read(EXAMPLES_PATH+'/pool/vdcpool0.json'))
end
it "should be able to retrieve a particular zone" do
zone0 = @ozones_client.get_resource("zone",1)
zone0.class.should eql(Net::HTTPOK)
zone0.body.should eql(
File.read(EXAMPLES_PATH+'/zone/zone0.json'))
end
it "should be able to retrieve a particular vdc" do
vdc0 = @ozones_client.get_resource("vdc",1)
vdc0.class.should eql(Net::HTTPOK)
vdc0.body.should eql(
File.read(EXAMPLES_PATH+'/vdc/vdc0.json'))
end
it "should fail on zone recreation (with the same name)" do
rc = @ozones_client.post_resource(
"zone",EXAMPLES_PATH + '/zone/zone0.template')
rc.class.should eql(OZonesClient::Error)
end
it "should fail on vdc recreation (with the same name)" do
rc = @ozones_client.post_resource(
"vdc",EXAMPLES_PATH + '/vdc/vdc0.template')
rc.class.should eql(OZonesClient::Error)
end
it "should fail on vdc creation with no existing zone" do
rc = @ozones_client.post_resource(
"vdc",EXAMPLES_PATH +
'/vdc/vdc2nozone.template')
rc.class.should eql(OZonesClient::Error)
end
it "should allow deleting a zone" do
rc = @ozones_client.delete_resource("zone",2)
rc.class.should eql(Net::HTTPOK)
# Zone pool shouldn't account for the deleted zone
zonepool = @ozones_client.get_pool("zone")
zonepool.class.should eql(Net::HTTPOK)
zonepool.body.should eql(
File.read(EXAMPLES_PATH+
'/pool/zonepool1deleted.json'))
end
it "should allow deleting a vdc" do
rc = @ozones_client.delete_resource("vdc",2)
rc.class.should eql(Net::HTTPOK)
# Zone pool shouldn't account for the deleted zone
vdcpool = @ozones_client.get_pool("vdc")
vdcpool.class.should eql(Net::HTTPOK)
vdcpool.body.should eql(
File.read(EXAMPLES_PATH+
'/pool/vdcpool1deleted.json'))
end
it "should fail on non existing zone deletion" do
rc = @ozones_client.delete_resource("zone",5)
rc.class.should eql(OZonesClient::Error)
end
it "should fail on non existing vdc deletion" do
rc = @ozones_client.delete_resource("vdc",5)
rc.class.should eql(OZonesClient::Error)
end
end

View File

@ -1,46 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
VAR_LOCATION="$PWD/var"
OZONES_LOCATION="$PWD/../"
mkdir -p $VAR_LOCATION
if [ "$(ls -A $VAR_LOCATION)" ]; then
echo "$VAR_LOCATION is not empty."
exit -1
fi
rm -rf coverage_server
rcov --exclude /Library --exclude /Users/tinova/.gem -o coverage_server `which rackup` -- $OZONES_LOCATION/config.ru -s thin -p 6121 -o localhost &> server.log &
RCOVPID=$!
sleep 5
rake test_with_rcov
CODE=$?
kill $RCOVPID
sleep 2s;
if [ $CODE != 0 ] ; then
exit 1
fi
find $VAR_LOCATION -mindepth 1 -delete

View File

@ -0,0 +1,36 @@
{
"VDC_POOL": {
"VDC": [
{
"ID": 1,
"ACLS": "2,3,4,5,6,7",
"HOSTS": "1,2,3",
"NAME": "vdcA",
"ZONES_ID": 1,
"GROUP_ID": 100,
"VDCADMINNAME": "vdcadminA",
"VDCADMIN_ID": 2
},
{
"ID": 2,
"ACLS": "2,3,4,5",
"HOSTS": "1",
"NAME": "vdcB",
"ZONES_ID": 2,
"GROUP_ID": 100,
"VDCADMINNAME": "vdcadminB",
"VDCADMIN_ID": 2
},
{
"ID": 3,
"ACLS": "8,9,10,11",
"HOSTS": "4",
"NAME": "vdcC",
"ZONES_ID": 1,
"GROUP_ID": 101,
"VDCADMINNAME": "vdcadminC",
"VDCADMIN_ID": 3
}
]
}
}

View File

@ -0,0 +1,26 @@
{
"VDC_POOL": {
"VDC": [
{
"ID": 1,
"ACLS": "2,3,4,5,6,7",
"HOSTS": "1,2,3",
"NAME": "vdcA",
"ZONES_ID": 1,
"GROUP_ID": 100,
"VDCADMINNAME": "vdcadminA",
"VDCADMIN_ID": 2
},
{
"ID": 2,
"ACLS": "2,3,4,5",
"HOSTS": "1",
"NAME": "vdcB",
"ZONES_ID": 2,
"GROUP_ID": 100,
"VDCADMINNAME": "vdcadminB",
"VDCADMIN_ID": 2
}
]
}
}

View File

@ -0,0 +1,26 @@
{
"ZONE_POOL": {
"ZONE": [
{
"ID": 1,
"ENDPOINT": "http://localhost:2666/RPC2",
"NUMBERVDCS": 0,
"SUNSENDPOINT": "http://localhost:9869",
"NAME": "zoneA",
"SELFENDPOINT": null,
"ONENAME": "oneadminA",
"ONEPASS": "OkqWM2aSqbM/nlrdHGv3OA=="
},
{
"ID": 2,
"ENDPOINT": "http://localhost:2667/RPC2",
"NUMBERVDCS": 0,
"SUNSENDPOINT": null,
"NAME": "zoneB",
"SELFENDPOINT": null,
"ONENAME": "oneadminB",
"ONEPASS": "8Si8vlo2P3qn5/SNxkMkDg=="
}
]
}
}

View File

@ -0,0 +1,16 @@
{
"ZONE_POOL": {
"ZONE": [
{
"ID": 1,
"ENDPOINT": "http://localhost:2666/RPC2",
"NUMBERVDCS": 0,
"SUNSENDPOINT": "http://localhost:9869",
"NAME": "zoneA",
"SELFENDPOINT": null,
"ONENAME": "oneadminA",
"ONEPASS": "OkqWM2aSqbM/nlrdHGv3OA=="
}
]
}
}

View File

@ -0,0 +1,12 @@
{
"VDC": {
"ID": 1,
"ACLS": "2,3,4,5,6,7",
"HOSTS": "1,2,3",
"NAME": "vdcA",
"ZONES_ID": 1,
"GROUP_ID": 100,
"VDCADMINNAME": "vdcadminA",
"VDCADMIN_ID": 2
}
}

View File

@ -0,0 +1,14 @@
{
"ZONE": {
"ID": 1,
"ENDPOINT": "http://localhost:2666/RPC2",
"SUNSENDPOINT": "http://localhost:9869",
"VDCS": [
],
"NAME": "zoneA",
"SELFENDPOINT": null,
"ONENAME": "oneadminA",
"ONEPASS": "OkqWM2aSqbM/nlrdHGv3OA=="
}
}

View File

@ -29,6 +29,8 @@ require 'command_parser'
require 'ozones_helper/zones_helper.rb'
require 'ozones_helper/vdc_helper.rb'
TESTS_PATH = File.dirname(__FILE__)+"/../"
module OZones
describe "oZones server regarding VDCs" do
@ -39,12 +41,12 @@ module OZones
VDCHelper.new("vdc", "ozonesadmin","ozonespassword")
@clientA = OpenNebula::Client.new(File.read(
File.dirname(__FILE__)+"/../etc/one_auth_a"),
TESTS_PATH+"etc/one_auth_a"),
"http://localhost:2666/RPC2")
@clientB = OpenNebula::Client.new(File.read(
File.dirname(__FILE__)+"/../etc/one_auth_b"),
"http://localhost:2667/RPC2")
TESTS_PATH+"etc/one_auth_b"),
"http://localhost:2667/RPC2")
hostA=OpenNebula::Host.new(OpenNebula::Host.build_xml, @clientA)
hostA.allocate("hostA1","im_dummy","vmm_dummy","tm_dummy","dummy")
@ -59,15 +61,14 @@ module OZones
end
it "should be able to create a couple of zones" do
@zonehelper.create_resource(File.dirname(__FILE__)+
"/../templates/zoneA.template")[0].should eql(0)
@zonehelper.create_resource(File.dirname(__FILE__)+
"/../templates/zoneB.template")[0].should eql(0)
rc = @zonehelper.create_resource(TESTS_PATH+"templates/zoneA.template")
rc[0].should eql(0)
rc = @zonehelper.create_resource(TESTS_PATH+"templates/zoneB.template")
rc[0].should eql(0)
end
it "should be able to create one vdc with the apropiate ONE resources" do
@vdchelper.create_resource(File.dirname(__FILE__)+
"/../templates/vdcA.template",
it "should be able to create one vdc with apropiate ONE resources" do
@vdchelper.create_resource(TESTS_PATH+"templates/vdcA.template",
{:force => false})[0].should eql(0)
upool = OpenNebula::UserPool.new(@clientA)
@ -98,25 +99,46 @@ module OZones
end
it "should be able to create a couple of VDCs" do
@vdchelper.create_resource(File.dirname(__FILE__)+
"/../templates/vdcB.template",
@vdchelper.create_resource(TESTS_PATH+"templates/vdcB.template",
{:force => false})[0].should eql(0)
@vdchelper.create_resource(File.dirname(__FILE__)+
"/../templates/vdcC.template",
@vdchelper.create_resource(TESTS_PATH+"templates/vdcC.template",
{:force => false})[0].should eql(0)
end
it "should fail when creating an existing VDC" do
@vdchelper.create_resource(File.dirname(__FILE__)+
"/../templates/vdcA.template",
@vdchelper.create_resource(TESTS_PATH+"templates/vdcA.template",
{:force => false})[0].should eql(-1)
end
it "should fail when creating a VDC upon a non existing zone" do
@vdchelper.create_resource(File.dirname(__FILE__)+
"/../templates/vdc.no.zone.template",
@vdchelper.create_resource(TESTS_PATH+"templates/vdc.no.zone.template",
{:force => false})[0].should eql(-1)
end
it "should be able to retrieve the vdc pool" do
vdcpool = @vdchelper.list_pool({:json => true})
vdcpool[0].should eql(0)
vdcpool[1].should eql(File.read(TESTS_PATH+"examples/pool/vdcpool0.json"))
end
it "should be able to retrieve a particular vdc" do
vdc = @vdchelper.show_resource(1, {:json => true})
vdc[0].should eql(0)
vdc[1].should eql(File.read(TESTS_PATH+"examples/vdc/vdc0.json"))
end
it "should allow deleting a vdc" do
rc = @vdchelper.delete_resource(3, {})
rc[0].should eql(0)
rc = @vdchelper.list_pool({:json => true})
rc[0].should eql(0)
rc[1].should eql(File.read(TESTS_PATH+
"examples/pool/vdcpool_deleted.json"))
end
it "should fail on non-existing vdc deletion" do
rc = @vdchelper.delete_resource(7, {})
rc[0].should eql(-1)
end
end
end

View File

@ -28,36 +28,71 @@ $: << RUBY_LIB_LOCATION+"/cli"
require 'command_parser'
require 'ozones_helper/zones_helper.rb'
TESTS_PATH = File.dirname(__FILE__)+"/../"
module OZones
describe "oZones server regarding zones" do
before(:all) do
@helper = ZonesHelper.new("zone", "ozonesadmin","ozonespassword")
@badhelper = ZonesHelper.new("zone", "wronguser","wrongpassword")
@helper = ZonesHelper.new("zone", "ozonesadmin","ozonespassword")
@badhelper = ZonesHelper.new("zone", "wronguser","wrongpassword")
end
it "should be able to create a couple of zones" do
@helper.create_resource(File.dirname(__FILE__)+
"/../templates/zoneA.template")[0].should eql(0)
@helper.create_resource(File.dirname(__FILE__)+
"/../templates/zoneB.template")[0].should eql(0)
end
rc = @helper.create_resource(TESTS_PATH+"templates/zoneA.template")
rc[0].should eql(0)
@helper.create_resource(TESTS_PATH+"templates/zoneB.template")
rc[0].should eql(0)
end
it "should fail with wrong zones templates" do
@helper.create_resource(File.dirname(__FILE__)+
"/../templates/zone.wrong.credentials.template")[0].should eql(-1)
@helper.create_resource(File.dirname(__FILE__)+
"/../templates/zone.wrong.endpoint.template")[0].should eql(-1)
end
templ_path = "templates/zone.wrong.credentials.template"
rc = @helper.create_resource(TESTS_PATH+templ_path)
rc[0].should eql(-1)
templ_path = "templates/zone.wrong.endpoint.template"
rc = @helper.create_resource(TESTS_PATH+templ_path)
rc[0].should eql(-1)
end
it "should fail when creating zones with existing name" do
@helper.create_resource(File.dirname(__FILE__)+
"/../templates/zoneA.template")[0].should eql(-1)
end
rc = @helper.create_resource(TESTS_PATH+"templates/zoneA.template")
rc[0].should eql(-1)
end
it "should refuse unauthorized requests" do
@badhelper.create_resource(File.dirname(__FILE__)+
"/../templates/zoneA.template")[0].should eql(-1)
end
rc = @badhelper.create_resource(TESTS_PATH+
"templates/zoneA.template")
rc[0].should eql(-1)
end
it "should be able to retrieve the zone pool" do
zonepool = @helper.list_pool({:json => true})
zonepool[0].should eql(0)
zonepool[1].should eql(File.read(TESTS_PATH+
"examples/pool/zonepool0.json"))
end
it "should be able to retrieve a particular zone" do
zone = @helper.show_resource(1,{:json => true})
zone[0].should eql(0)
zone[1].should eql(File.read(TESTS_PATH+"examples/zone/zone0.json"))
end
it "should allow deleting a zone" do
rc = @helper.delete_resource(2, {})
rc[0].should eql(0)
rc = @helper.list_pool({:json => true})
rc[0].should eql(0)
rc[1].should eql(File.read(TESTS_PATH+
"examples/pool/zonepool_deleted.json"))
end
it "should fail on non existing zone deletion" do
rc = @helper.delete_resource(7, {})
rc[0].should eql(-1)
end
end
end
end

View File

@ -51,13 +51,6 @@ for j in `ls ./spec/*_spec.rb` ; do
done
if (($CODE == 0)); then
# Terminate ONEs
ONE_LOCATION=$ONE_LOCATION_A oneA/bin/one stop
ONE_LOCATION=$ONE_LOCATION_B oneB/bin/one stop
# Stop oZones
ONE_LOCATION=$ONE_LOCATION_A oneA/bin/ozones-server stop
# Delete directories
rm -rf oneA
rm -rf oneB