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

Merge branch 'master' of git.opennebula.org:one

This commit is contained in:
Ruben S. Montero 2011-06-23 14:00:24 +02:00
commit 3a75615817
21 changed files with 165 additions and 274 deletions

View File

@ -73,7 +73,7 @@ while true ; do
-r) UNINSTALL="yes" ; shift ;;
-l) LINK="yes" ; shift ;;
-c) CLIENT="yes"; INSTALL_ETC="no" ; shift ;;
-s) SUNSTONE="yes"; INSTALL_ETC="no" ; shift ;;
-s) SUNSTONE="yes"; shift ;;
-u) ONEADMIN_USER="$2" ; shift 2;;
-g) ONEADMIN_GROUP="$2"; shift 2;;
-d) ROOT="$2" ; shift 2 ;;
@ -320,7 +320,6 @@ INSTALL_SUNSTONE_RUBY_FILES=(
INSTALL_SUNSTONE_FILES=(
SUNSTONE_FILES:$SUNSTONE_LOCATION
SUNSTONE_BIN_FILES:$BIN_LOCATION
SUNSTONE_ETC_FILES:$ETC_LOCATION
SUNSTONE_MODELS_FILES:$SUNSTONE_LOCATION/models
SUNSTONE_MODELS_JSON_FILES:$SUNSTONE_LOCATION/models/OpenNebulaJSON
SUNSTONE_TEMPLATE_FILES:$SUNSTONE_LOCATION/templates
@ -337,6 +336,10 @@ INSTALL_SUNSTONE_FILES=(
SUNSTONE_PUBLIC_IMAGES_FILES:$SUNSTONE_LOCATION/public/images
)
INSTALL_SUNSTONE_ETC_FILES=(
SUNSTONE_ETC_FILES:$ETC_LOCATION
)
INSTALL_ETC_FILES=(
ETC_FILES:$ETC_LOCATION
VMM_EC2_ETC_FILES:$ETC_LOCATION/vmm_ec2
@ -352,7 +355,6 @@ INSTALL_ETC_FILES=(
ECO_ETC_TEMPLATE_FILES:$ETC_LOCATION/ec2query_templates
OCCI_ETC_FILES:$ETC_LOCATION
OCCI_ETC_TEMPLATE_FILES:$ETC_LOCATION/occi_templates
SUNSTONE_ETC_FILES:$ETC_LOCATION
CLI_CONF_FILES:$ETC_LOCATION/cli
)
@ -951,7 +953,14 @@ for i in ${INSTALL_SET[@]}; do
done
if [ "$INSTALL_ETC" = "yes" ] ; then
for i in ${INSTALL_ETC_FILES[@]}; do
if [ "$SUNSTONE" = "yes" ]; then
INSTALL_ETC_SET="${INSTALL_SUNSTONE_ETC_FILES[@]}"
else
INSTALL_ETC_SET="${INSTALL_ETC_FILES[@]} \
${INSTALL_SUNSTONE_ETC_FILES[@]}"
fi
for i in ${INSTALL_ETC_SET[@]}; do
SRC=$`echo $i | cut -d: -f1`
DST=`echo $i | cut -d: -f2`

View File

@ -14,6 +14,8 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
$: << '../'
require 'spec_common'
require 'client_mock'
@ -21,7 +23,7 @@ require 'one_usage'
describe "OneUsage" do
before(:all) do
mock_data=YAML::load(File.read('spec/oca_vms.yaml'))
mock_data=YAML::load(File.read('oca_vms.yaml'))
client=ClientMock.new(mock_data)
@one_usage=OneUsage.new(client)
end

View File

@ -14,6 +14,8 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
$: << '../'
require 'spec_common'
require 'client_mock'
@ -30,7 +32,7 @@ end
describe 'Quota' do
before(:all) do
@db=Sequel.sqlite
mock_data=YAML::load(File.read('spec/oca_vms.yaml'))
mock_data=YAML::load(File.read('oca_vms.yaml'))
client=ClientMock.new(mock_data)
@quota=Quota.new(@db, client)
end

View File

@ -14,6 +14,8 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
$: << '../'
require 'spec_common'
require 'client_mock'
@ -64,7 +66,7 @@ end
describe SimplePermissions do
before(:all) do
@db=Sequel.sqlite
mock_data=YAML::load(File.read('spec/oca_vms.yaml'))
mock_data=YAML::load(File.read('oca_vms.yaml'))
client=ClientMock.new(mock_data)
@perm=SimplePermissions.new(@db, client, YAML::load(CONF))
end

View File

@ -16,10 +16,11 @@
require 'pp'
$: << '../../oca/ruby'
$: << '..'
require 'db_helpers'
$: << '../oca/ruby'
$: << './spec'

View File

@ -91,7 +91,20 @@ EOT
if options[:xml]
return 0, pool.to_xml(true)
else
format_pool(pool, options, top)
phash = pool.to_hash
rname = self.class.rname
if phash["#{rname}_POOL"] && phash["#{rname}_POOL"]["#{rname}"]
if phash["#{rname}_POOL"]["#{rname}"].instance_of?(Array)
phash = phash["#{rname}_POOL"]["#{rname}"]
else
phash = [phash["#{rname}_POOL"]["#{rname}"]]
end
else
phash = Array.new
end
format_pool(phash, options, top)
return 0
end
end
@ -138,11 +151,11 @@ EOT
########################################################################
# Id translation
########################################################################
def uid_to_str(uid, options)
def uid_to_str(uid, options={})
rid_to_str(:users, uid, options)
end
def gid_to_str(gid, options)
def gid_to_str(gid, options={})
rid_to_str(:groups, gid, options)
end

View File

@ -50,9 +50,10 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
puts str % ["NAME", group.name]
puts
CLIHelper.print_header(str_h1 % "USERS",false)
CLIHelper.print_header(str_h1 % "USERS", false)
CLIHelper.print_header("%-15s %-20s" % ["ID","NAME"])
group.user_ids.each do |uid|
puts str % ["ID", uid]
puts "%-15s %-20s" % [uid, self.uid_to_str(uid.to_s)]
end
end

View File

@ -25,6 +25,12 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
"onehost.yaml"
end
def self.state_to_str(id)
id = id.to_i
state_str = Host::HOST_STATES[id]
return Host::SHORT_HOST_STATES[state_str]
end
private
def factory(id=nil)
@ -83,38 +89,38 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
end
column :RVM, "Number of Virtual Machines running", :size=>6 do |d|
d["HOST_SHARE/RUNNING_VMS"]
d["HOST_SHARE"]["RUNNING_VMS"]
end
column :TCPU, "Total CPU percentage", :size=>6 do |d|
d["HOST_SHARE/MAX_CPU"]
d["HOST_SHARE"]["MAX_CPU"]
end
column :FCPU, "Free CPU percentage", :size=>6 do |d|
d["HOST_SHARE/MAX_CPU"].to_i-d["HOST_SHARE/USED_CPU"].to_i
d["HOST_SHARE"]["MAX_CPU"].to_i-d["HOST_SHARE"]["USED_CPU"].to_i
end
column :ACPU, "Available cpu percentage (not reserved by VMs)", :size=>6 do |d|
max_cpu=d["HOST_SHARE/MAX_CPU"].to_i
max_cpu=d["HOST_SHARE"]["MAX_CPU"].to_i
max_cpu=100 if max_cpu==0
max_cpu-d["HOST_SHARE/CPU_USAGE"].to_i
max_cpu-d["HOST_SHARE"]["CPU_USAGE"].to_i
end
column :TMEM, "Total Memory", :size=>6 do |d|
OpenNebulaHelper.unit_to_str(d["HOST_SHARE/MAX_MEM"].to_i,options)
OpenNebulaHelper.unit_to_str(d["HOST_SHARE"]["MAX_MEM"].to_i,options)
end
column :FMEM, "Free Memory", :size=>6 do |d|
OpenNebulaHelper.unit_to_str(d["HOST_SHARE/FREE_MEM"].to_i,options)
OpenNebulaHelper.unit_to_str(d["HOST_SHARE"]["FREE_MEM"].to_i,options)
end
column :AMEM, "Available Memory (not reserved by VMs)", :size=>6 do |d|
acpu=d["HOST_SHARE/MAX_MEM"].to_i-d["HOST_SHARE/MEM_USAGE"].to_i
acpu=d["HOST_SHARE"]["MAX_MEM"].to_i-d["HOST_SHARE"]["MEM_USAGE"].to_i
OpenNebulaHelper.unit_to_str(acpu,options)
end
column :STAT, "Host status", :size=>6 do |d|
d.short_state_str
OneHostHelper.state_to_str(d["STATE"])
end
default :ID, :NAME, :RVM, :TCPU, :FCPU, :ACPU, :TMEM, :FMEM, :AMEM, :STAT

View File

@ -25,6 +25,22 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
"oneimage.yaml"
end
def self.persistent_to_str(str)
str.to_i==1 ? "Yes" : "No"
end
def self.state_to_str(id)
id = id.to_i
state_str = Image::IMAGE_STATES[id]
return Image::SHORT_IMAGE_STATES[state_str]
end
def self.type_to_str(id)
id = id.to_i
type_str = Image::IMAGE_TYPES[id]
return Image::SHORT_IMAGE_TYPES[type_str]
end
private
def factory(id=nil)
@ -80,7 +96,7 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
end
column :TYPE, "Type of the Image", :size=>4 do |d,e|
d.short_type_str
OneImageHelper.type_to_str(d["TYPE"])
end
column :REGTIME, "Registration time of the Image", :size=>20 do |d|
@ -96,7 +112,7 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
end
column :STAT, "State of the Image", :size=>4 do |d|
d.short_state_str
OneImageHelper.state_to_str(d["STATE"])
end
column :RVMS, "Number of VMs currently running from this Image", :size=>5 do |d|
@ -112,10 +128,4 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
table.show(pool, options)
end
end
private
def self.persistent_to_str(str)
str.to_i==1 ? "Yes" : "No"
end
end

View File

@ -70,14 +70,15 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
CLIHelper.print_header(str_h1 % "USER #{user['ID']} INFORMATION")
puts str % ["ID", user.id.to_s]
puts str % ["NAME", user.name]
puts str % ["GROUP", user.gid]
puts str % ["MAIN_GROUP", user.gid]
puts str % ["PASSWORD", user['PASSWORD']]
puts str % ["ENABLED", user['ENABLED']]
puts
CLIHelper.print_header(str_h1 % "SECONDARY GROUPS",false)
CLIHelper.print_header(str_h1 % "GROUPS", false)
CLIHelper.print_header("%-15s %-20s" % ["ID","NAME"])
user.group_ids.each do |gid|
puts str % ["ID", uid]
puts "%-15s %-20s" % [gid, self.gid_to_str(gid.to_s)]
end
end

View File

@ -25,6 +25,20 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
"onevm.yaml"
end
def self.state_to_str(id, lcm_id)
id = id.to_i
state_str = VirtualMachine::VM_STATE[id]
short_state_str = VirtualMachine::SHORT_VM_STATES[state_str]
if short_state_str=="actv"
lcm_id = lcm_id.to_i
lcm_state_str = VirtualMachine::LCM_STATE[lcm_id]
return VirtualMachine::SHORT_LCM_STATES[lcm_state_str]
end
return short_state_str
end
private
def factory(id=nil)
@ -89,7 +103,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
end
column :STAT, "Actual status", :size=>4 do |d,e|
d.status
OneVMHelper.state_to_str(d["STATE"], d["LCM_STATE"])
end
column :CPU, "CPU percentage used by the VM", :size=>3 do |d|
@ -101,7 +115,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
end
column :HOSTNAME, "Host where the VM is running", :size=>15 do |d|
d["HISTORY/HOSTNAME"]
d["HISTORY"]["HOSTNAME"] if d["HISTORY"]
end
column :TIME, "Time since the VM was submitted", :size=>11 do |d|

View File

@ -25,6 +25,12 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
"onevnet.yaml"
end
def self.type_to_str(id)
id = id.to_i
type_str = VirtualNetwork::VN_TYPES[id]
return VirtualNetwork::SHORT_VN_TYPES[type_str]
end
private
def factory(id=nil)
@ -82,7 +88,7 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
end
column :TYPE, "Type of Virtual Network", :size=>6 do |d|
d.type_str
OneVNetHelper.type_to_str(d["TYPE"])
end
column :SIZE, "Size of the Virtual Network", :size=>6 do |d|

View File

@ -53,7 +53,7 @@ class InformationManagerDriver < OpenNebulaDriver
# Execute the run_probes in the remote host
def action_monitor(number, host, do_update)
if !action_is_local?(:monitor)
if !action_is_local?(:MONITOR)
if do_update == "1"
# Use SCP to sync:
sync_cmd = "scp -r #{@local_scripts_base_path}/. " \
@ -65,7 +65,7 @@ class InformationManagerDriver < OpenNebulaDriver
LocalCommand.run(sync_cmd, log_method(number))
end
end
do_action("#{@hypervisor}", number, host, :monitor,
do_action("#{@hypervisor}", number, host, :MONITOR,
:script_name => 'run_probes')
end
end

View File

@ -1,4 +1,5 @@
$: << '..'
require 'OpenNebulaDriver'
require 'test/MonkeyPatcher'
@ -26,7 +27,7 @@ class OpenNebulaDriver
def read_configuration
old_one_location=ENV['ONE_LOCATION']
ENV['ONE_LOCATION']=File.join(ENV['PWD'], 'test', 'fixtures')
ENV['ONE_LOCATION']=File.join(ENV['PWD'], 'fixtures')
result=read_configuration_old
ENV['ONE_LOCATION']=old_one_location
result

View File

@ -31,9 +31,9 @@ module OpenNebula
:chown => "vn.chown"
}
NETWORK_TYPES=%w{RANGED FIXED}
VN_TYPES=%w{RANGED FIXED}
SHORT_NETWORK_TYPES={
SHORT_VN_TYPES={
"RANGED" => "R",
"FIXED" => "F"
}
@ -144,12 +144,12 @@ module OpenNebula
# Returns the type of the Virtual Network (string value)
def type_str
NETWORK_TYPES[type]
VN_TYPES[type]
end
# Returns the state of the Virtual Network (string value)
def short_type_str
SHORT_NETWORK_TYPES[type_str]
SHORT_VN_TYPES[type_str]
end
private

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