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

Fix Sunstone tests

This commit is contained in:
Daniel Molina 2011-06-20 17:01:08 +02:00
parent 5275c4ea06
commit bed83ae478
6 changed files with 53 additions and 230 deletions

View File

@ -2,6 +2,6 @@
"image": {
"name": "second_image",
"type": "CDROM",
"size": "512"
"path": "/etc/hosts"
}
}
}

View File

@ -1,176 +0,0 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2011, 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. #
#--------------------------------------------------------------------------- #
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe 'Cluster tests' do
before(:all) do
basic_authorize('oneadmin','opennebula')
post '/login'
last_response.status.should eql(204)
@host0_s = File.read(EXAMPLES_PATH + '/host/host0.json')
post '/host', @host0_s
last_response.status.should eql(201)
@cluster1_s = File.read(EXAMPLES_PATH + '/cluster/cluster1.json')
@cluster1_h = JSON.parse(@cluster1_s)
@cluster2_s = File.read(EXAMPLES_PATH + '/cluster/cluster2.json')
@cluster2_h = JSON.parse(@cluster2_s)
@action_addhost = File.read(EXAMPLES_PATH + '/cluster/addhost.json')
@action_rmhost = File.read(EXAMPLES_PATH + '/cluster/rmhost.json')
@wrong_action = File.read(EXAMPLES_PATH + '/error/wrong_action.json')
end
it "should create a first cluster" do
post '/cluster', @cluster1_s
last_response.status.should eql(201)
json_response = JSON.parse(last_response.body)
json_response['CLUSTER']['ID'].should eql("1")
end
it "should create a second cluster" do
post '/cluster', @cluster2_s
last_response.status.should eql(201)
json_response = JSON.parse(last_response.body)
json_response['CLUSTER']['ID'].should eql("2")
end
it "should get Cluster 1 information" do
get '/cluster/1'
last_response.status.should eql(200)
json_response = JSON.parse(last_response.body)
json_response['CLUSTER']['NAME'].should eql(@cluster1_h['cluster']['name'])
end
it "should add Host 0 to Cluster 1" do
post '/cluster/1/action', @action_addhost
last_response.status.should eql(204)
end
it "should get Host 0 information after adding it to the Cluster 1" do
get '/host/0'
last_response.status.should eql(200)
json_response = JSON.parse(last_response.body)
json_response['HOST']['CLUSTER'].should eql("cluster_one")
end
it "should remove Host 0 from Cluster 1" do
post '/cluster/1/action', @action_rmhost
last_response.status.should eql(204)
end
it "should get Host 0 information after removing it from Cluster 1" do
get '/host/0'
last_response.status.should eql(200)
json_response = JSON.parse(last_response.body)
json_response['HOST']['CLUSTER'].should eql("default")
end
it "should get Cluster 2 information" do
get '/cluster/2'
last_response.status.should eql(200)
json_response = JSON.parse(last_response.body)
json_response['CLUSTER']['NAME'].should eql(@cluster2_h['cluster']['name'])
end
it "should get cluster_pool information" do
get '/cluster'
last_response.status.should eql(200)
json_response = JSON.parse(last_response.body)
json_response['CLUSTER_POOL']['CLUSTER'].size.should eql(3)
json_response['CLUSTER_POOL']['CLUSTER'].each do |cluster|
if cluster['ID'] == '1'
cluster['NAME'].should eql(@cluster1_h['cluster']['name'])
elsif cluster['ID'] == '2'
cluster['NAME'].should eql(@cluster2_h['cluster']['name'])
else
cluster['NAME'].should eql("default")
end
end
end
it "should try to get Cluster 3 information and check the error, because " <<
"it does not exist" do
get '/cluster/3'
last_response.status.should eql(404)
json_response = JSON.parse(last_response.body)
json_response['error']['message'].should_not eql(nil)
end
it "should try to add Host 0 to Cluster 3 and check the error, because " <<
"it does not exist" do
post '/cluster/3/action', @action_addhost
last_response.status.should eql(404)
json_response = JSON.parse(last_response.body)
json_response['error']['message'].should_not eql(nil)
end
it "should try to remove Host 0 from Cluster 3 and check the error, " <<
"because it does not exist" do
post '/cluster/3/action', @action_removehost
last_response.status.should eql(404)
json_response = JSON.parse(last_response.body)
json_response['error']['message'].should_not eql(nil)
end
it "should try to perform a wrong action and check the error" do
post '/cluster/0/action', @wrong_action
last_response.status.should eql(500)
json_response = JSON.parse(last_response.body)
json_response['error']['message'].should_not eql(nil)
end
it "should delete the Cluster 2" do
delete '/cluster/2'
last_response.status.should eql(204)
end
it "should try to get the deleted Cluster information and check the error" do
url = '/cluster/2'
get url
last_response.status.should eql(404)
json_response = JSON.parse(last_response.body)
json_response['error']['message'].should_not eql(nil)
end
end

View File

@ -71,7 +71,6 @@ describe 'Host tests NOKOGIRI' do
json_response['HOST']['IM_MAD'].should eql(@host0_h['host']['im_mad'])
json_response['HOST']['VM_MAD'].should eql(@host0_h['host']['vm_mad'])
json_response['HOST']['TM_MAD'].should eql(@host0_h['host']['tm_mad'])
json_response['HOST']['CLUSTER'].should eql("default")
json_response['HOST']['STATE'].should eql("0")
end
@ -120,7 +119,6 @@ describe 'Host tests NOKOGIRI' do
json_response['HOST']['IM_MAD'].should eql(@host1_h['host']['im_mad'])
json_response['HOST']['VM_MAD'].should eql(@host1_h['host']['vm_mad'])
json_response['HOST']['TM_MAD'].should eql(@host1_h['host']['tm_mad'])
json_response['HOST']['CLUSTER'].should eql("default")
json_response['HOST']['STATE'].should eql("0")
end

View File

@ -186,55 +186,55 @@ describe 'Image tests' do
json_response['IMAGE']['STATE'].should eql("1")
end
############################################################################
# Update / Remove attr
############################################################################
it "should add a new attribute to Image 0" do
url = '/image/0/action'
post url, @action_update
last_response.status.should eql(204)
end
it "should get first Image information after adding a new attribute" do
url = '/image/0'
get url
last_response.status.should eql(200)
json_response = JSON.parse(last_response.body)
json_response['IMAGE']['TEMPLATE']['FOO'].should eql("mock")
end
it "should remove an attribute from Image 0" do
url = '/image/0/action'
post url, @action_removeattr
last_response.status.should eql(204)
end
it "should get Image 0 information after removing an attribute" do
url = '/image/0'
get url
last_response.status.should eql(200)
json_response = JSON.parse(last_response.body)
json_response['IMAGE']['TEMPLATE']['FOO'].should eql(nil)
end
it "should get Image 1 information" do
url = '/image/1'
get url
last_response.status.should eql(200)
json_response = JSON.parse(last_response.body)
json_response['IMAGE']['NAME'].should eql(@image1_h['image']['name'])
json_response['IMAGE']['TYPE'].should eql("1")
json_response['IMAGE']['TEMPLATE']['SIZE'].should eql(@image1_h['image']['size'])
end
# ############################################################################
# # Update / Remove attr
# ############################################################################
# it "should add a new attribute to Image 0" do
# url = '/image/0/action'
# post url, @action_update
#
# last_response.status.should eql(204)
# end
#
# it "should get first Image information after adding a new attribute" do
# url = '/image/0'
# get url
#
# last_response.status.should eql(200)
#
# json_response = JSON.parse(last_response.body)
# json_response['IMAGE']['TEMPLATE']['FOO'].should eql("mock")
# end
#
# it "should remove an attribute from Image 0" do
# url = '/image/0/action'
# post url, @action_removeattr
#
# last_response.status.should eql(204)
# end
#
# it "should get Image 0 information after removing an attribute" do
# url = '/image/0'
# get url
#
# last_response.status.should eql(200)
#
# json_response = JSON.parse(last_response.body)
# json_response['IMAGE']['TEMPLATE']['FOO'].should eql(nil)
# end
#
#
# it "should get Image 1 information" do
# url = '/image/1'
# get url
#
# last_response.status.should eql(200)
#
# json_response = JSON.parse(last_response.body)
# json_response['IMAGE']['NAME'].should eql(@image1_h['image']['name'])
# json_response['IMAGE']['TYPE'].should eql("1")
# json_response['IMAGE']['TEMPLATE']['SIZE'].should eql(@image1_h['image']['size'])
# end
############################################################################
# Pool
@ -317,6 +317,7 @@ describe 'Image tests' do
it "should try to get the deleted Image information and check the error" do
url = '/image/1'
sleep 2
get url
last_response.status.should eql(404)

View File

@ -25,7 +25,7 @@ require 'rack/test'
require 'json'
# Load the Sinatra app
require 'one-ui'
require 'sunstone-server'
# Make Rack::Test available to all spec contexts
Spec::Runner.configure do |conf|

0
src/sunstone/test/test.sh Normal file → Executable file
View File