1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-13 13:17:39 +03:00

feature #788: delete unneeded test files

This commit is contained in:
Ruben S. Montero 2011-09-02 17:09:50 +02:00
parent 1d5dddfc91
commit 416940d5fa
7 changed files with 0 additions and 933 deletions

View File

@ -1,55 +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. #
#--------------------------------------------------------------------------- #
class ClientMock
def initialize(mock_data)
@mock_data=mock_data
end
def search_method(methods, args)
keys=methods.keys
if keys.include? args[0]
value=methods[args[0]]
if value.class != Hash
return value
elsif args.length>1
return search_method(value, args[1..-1])
else
nil
end
else
nil
end
end
def call(action, *args)
value=search_method(@mock_data, [action]+args.flatten)
if value
if value.class==Proc
value.call(action, args.flatten)
else
value
end
else
message="Action '#{action}(#{args.join(',')})' not defined"
STDERR.puts message
OpenNebula::Error.new(message)
end
end
end

View File

@ -1,25 +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 'rubygems'
require 'sequel'
def check_column(schema, column)
schema.find {|c| c[0] == column }.should_not == nil
end

View File

@ -1,551 +0,0 @@
vmpool.info:
0: "<VM_POOL>
<VM>
<ID>
0
</ID>
<UID>
0
</UID>
<USERNAME>
jfontan
</USERNAME>
<NAME>
test
</NAME>
<LAST_POLL>
0
</LAST_POLL>
<STATE>
1
</STATE>
<LCM_STATE>
0
</LCM_STATE>
<STIME>
1278433840
</STIME>
<ETIME>
0
</ETIME>
<DEPLOY_ID/>
<MEMORY>
0
</MEMORY>
<CPU>
0
</CPU>
<NET_TX>
0
</NET_TX>
<NET_RX>
0
</NET_RX>
</VM>
<VM>
<ID>
1
</ID>
<UID>
0
</UID>
<USERNAME>
jfontan
</USERNAME>
<NAME>
test
</NAME>
<LAST_POLL>
0
</LAST_POLL>
<STATE>
1
</STATE>
<LCM_STATE>
0
</LCM_STATE>
<STIME>
1278433841
</STIME>
<ETIME>
0
</ETIME>
<DEPLOY_ID/>
<MEMORY>
0
</MEMORY>
<CPU>
0
</CPU>
<NET_TX>
0
</NET_TX>
<NET_RX>
0
</NET_RX>
</VM>
</VM_POOL>"
1: "<VM_POOL>
<VM>
<ID>
2
</ID>
<UID>
1
</UID>
<USERNAME>
lero
</USERNAME>
<NAME>
test
</NAME>
<LAST_POLL>
0
</LAST_POLL>
<STATE>
1
</STATE>
<LCM_STATE>
0
</LCM_STATE>
<STIME>
1278433868
</STIME>
<ETIME>
0
</ETIME>
<DEPLOY_ID/>
<MEMORY>
0
</MEMORY>
<CPU>
0
</CPU>
<NET_TX>
0
</NET_TX>
<NET_RX>
0
</NET_RX>
</VM>
<VM>
<ID>
3
</ID>
<UID>
1
</UID>
<USERNAME>
lero
</USERNAME>
<NAME>
test
</NAME>
<LAST_POLL>
0
</LAST_POLL>
<STATE>
1
</STATE>
<LCM_STATE>
0
</LCM_STATE>
<STIME>
1278433869
</STIME>
<ETIME>
0
</ETIME>
<DEPLOY_ID/>
<MEMORY>
0
</MEMORY>
<CPU>
0
</CPU>
<NET_TX>
0
</NET_TX>
<NET_RX>
0
</NET_RX>
</VM>
</VM_POOL>"
vm.info:
0: "<VM>
<ID>
0
</ID>
<UID>
0
</UID>
<NAME>
test
</NAME>
<LAST_POLL>
0
</LAST_POLL>
<STATE>
1
</STATE>
<LCM_STATE>
0
</LCM_STATE>
<STIME>
1278433840
</STIME>
<ETIME>
0
</ETIME>
<DEPLOY_ID/>
<MEMORY>
0
</MEMORY>
<CPU>
0
</CPU>
<NET_TX>
0
</NET_TX>
<NET_RX>
0
</NET_RX>
<TEMPLATE>
<CPU>
<![CDATA[0.5]]>
</CPU>
<DISK>
<READONLY>
<![CDATA[no]]>
</READONLY>
<SOURCE>
<![CDATA[/local/xen/domains/etch/disk.img]]>
</SOURCE>
<TARGET>
<![CDATA[sda]]>
</TARGET>
</DISK>
<DISK>
<READONLY>
<![CDATA[no]]>
</READONLY>
<SIZE>
<![CDATA[1024]]>
</SIZE>
<TARGET>
<![CDATA[sdb]]>
</TARGET>
<TYPE>
<![CDATA[swap]]>
</TYPE>
</DISK>
<MEMORY>
<![CDATA[64]]>
</MEMORY>
<NAME>
<![CDATA[test]]>
</NAME>
<NIC>
<MAC>
<![CDATA[00:ff:72:17:20:27]]>
</MAC>
</NIC>
<OS>
<INITRD>
<![CDATA[/initrd.img]]>
</INITRD>
<KERNEL>
<![CDATA[/vmlinuz]]>
</KERNEL>
<ROOT>
<![CDATA[sda]]>
</ROOT>
</OS>
<VMID>
<![CDATA[0]]>
</VMID>
</TEMPLATE>
</VM>"
1: "<VM>
<ID>
1
</ID>
<UID>
0
</UID>
<NAME>
test
</NAME>
<LAST_POLL>
0
</LAST_POLL>
<STATE>
1
</STATE>
<LCM_STATE>
0
</LCM_STATE>
<STIME>
1278433841
</STIME>
<ETIME>
0
</ETIME>
<DEPLOY_ID/>
<MEMORY>
0
</MEMORY>
<CPU>
0
</CPU>
<NET_TX>
0
</NET_TX>
<NET_RX>
0
</NET_RX>
<TEMPLATE>
<CPU>
<![CDATA[1]]>
</CPU>
<DISK>
<READONLY>
<![CDATA[no]]>
</READONLY>
<SOURCE>
<![CDATA[/local/xen/domains/etch/disk.img]]>
</SOURCE>
<TARGET>
<![CDATA[sda]]>
</TARGET>
</DISK>
<DISK>
<READONLY>
<![CDATA[no]]>
</READONLY>
<SIZE>
<![CDATA[1024]]>
</SIZE>
<TARGET>
<![CDATA[sdb]]>
</TARGET>
<TYPE>
<![CDATA[swap]]>
</TYPE>
</DISK>
<MEMORY>
<![CDATA[256]]>
</MEMORY>
<NAME>
<![CDATA[test]]>
</NAME>
<NIC>
<MAC>
<![CDATA[00:ff:72:17:20:27]]>
</MAC>
</NIC>
<OS>
<INITRD>
<![CDATA[/initrd.img]]>
</INITRD>
<KERNEL>
<![CDATA[/vmlinuz]]>
</KERNEL>
<ROOT>
<![CDATA[sda]]>
</ROOT>
</OS>
<VMID>
<![CDATA[1]]>
</VMID>
</TEMPLATE>
</VM>"
2: "<VM>
<ID>
2
</ID>
<UID>
1
</UID>
<NAME>
test
</NAME>
<LAST_POLL>
0
</LAST_POLL>
<STATE>
1
</STATE>
<LCM_STATE>
0
</LCM_STATE>
<STIME>
1278433868
</STIME>
<ETIME>
0
</ETIME>
<DEPLOY_ID/>
<MEMORY>
0
</MEMORY>
<CPU>
0
</CPU>
<NET_TX>
0
</NET_TX>
<NET_RX>
0
</NET_RX>
<TEMPLATE>
<CPU>
<![CDATA[1.5]]>
</CPU>
<DISK>
<READONLY>
<![CDATA[no]]>
</READONLY>
<SOURCE>
<![CDATA[/local/xen/domains/etch/disk.img]]>
</SOURCE>
<TARGET>
<![CDATA[sda]]>
</TARGET>
</DISK>
<DISK>
<READONLY>
<![CDATA[no]]>
</READONLY>
<SIZE>
<![CDATA[1024]]>
</SIZE>
<TARGET>
<![CDATA[sdb]]>
</TARGET>
<TYPE>
<![CDATA[swap]]>
</TYPE>
</DISK>
<MEMORY>
<![CDATA[512]]>
</MEMORY>
<NAME>
<![CDATA[test]]>
</NAME>
<NIC>
<MAC>
<![CDATA[00:ff:72:17:20:27]]>
</MAC>
</NIC>
<OS>
<INITRD>
<![CDATA[/initrd.img]]>
</INITRD>
<KERNEL>
<![CDATA[/vmlinuz]]>
</KERNEL>
<ROOT>
<![CDATA[sda]]>
</ROOT>
</OS>
<VMID>
<![CDATA[2]]>
</VMID>
</TEMPLATE>
</VM>"
3: "<VM>
<ID>
3
</ID>
<UID>
1
</UID>
<NAME>
test
</NAME>
<LAST_POLL>
0
</LAST_POLL>
<STATE>
1
</STATE>
<LCM_STATE>
0
</LCM_STATE>
<STIME>
1278433869
</STIME>
<ETIME>
0
</ETIME>
<DEPLOY_ID/>
<MEMORY>
0
</MEMORY>
<CPU>
0
</CPU>
<NET_TX>
0
</NET_TX>
<NET_RX>
0
</NET_RX>
<TEMPLATE>
<CPU>
<![CDATA[2]]>
</CPU>
<DISK>
<READONLY>
<![CDATA[no]]>
</READONLY>
<SOURCE>
<![CDATA[/local/xen/domains/etch/disk.img]]>
</SOURCE>
<TARGET>
<![CDATA[sda]]>
</TARGET>
</DISK>
<DISK>
<READONLY>
<![CDATA[no]]>
</READONLY>
<SIZE>
<![CDATA[1024]]>
</SIZE>
<TARGET>
<![CDATA[sdb]]>
</TARGET>
<TYPE>
<![CDATA[swap]]>
</TYPE>
</DISK>
<MEMORY>
<![CDATA[1024]]>
</MEMORY>
<NAME>
<![CDATA[test]]>
</NAME>
<NIC>
<MAC>
<![CDATA[00:ff:72:17:20:27]]>
</MAC>
</NIC>
<OS>
<INITRD>
<![CDATA[/initrd.img]]>
</INITRD>
<KERNEL>
<![CDATA[/vmlinuz]]>
</KERNEL>
<ROOT>
<![CDATA[sda]]>
</ROOT>
</OS>
<VMID>
<![CDATA[3]]>
</VMID>
</TEMPLATE>
</VM>"

View File

@ -1,77 +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 'spec_common'
require 'client_mock'
require 'one_usage'
describe "OneUsage" do
before(:all) do
mock_data=YAML::load(File.read('oca_vms.yaml'))
client=ClientMock.new(mock_data)
@one_usage=OneUsage.new(client)
end
it "should get information about vm users" do
@one_usage.update_user(0)
vms=@one_usage.vms(0)
vms.size.should == 2
vms[0].cpu.should == 0.5
vms[0].memory.should == 64
vms[1].cpu.should == 1.0
vms[1].memory.should == 256
usage=@one_usage.total(0)
usage.cpu.should == 1.5
usage.memory.should == 64+256
@one_usage.update_user(1)
vms=@one_usage.vms(1)
vms.size.should == 2
vms[2].cpu.should == 1.5
vms[2].memory.should == 512
vms[3].cpu.should == 2.0
vms[3].memory.should == 1024
usage=@one_usage.total(1)
usage.cpu.should == 3.5
usage.memory.should == 512+1024
end
it "should update information" do
vms=@one_usage.vms(1)
vms[4]=VmUsage.new(4.0, 2048)
usage=@one_usage.total(1)
usage.cpu.should == 1.5 + 2.0 + 4.0
usage.memory.should == 512+1024+2048
vms.delete(3)
usage=@one_usage.total(1)
usage.cpu.should == 1.5 + 4.0
usage.memory.should == 512+2048
@one_usage.update_user(1)
usage=@one_usage.total(1)
usage.cpu.should == 1.5 + 2.0
usage.memory.should == 512+1024
end
end

View File

@ -1,97 +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 'spec_common'
require 'client_mock'
require 'quota'
def check_quota(uid, cpu, memory, num_vms)
quota=@quota.get(uid)
quota.should_not == nil
quota[:cpu].should == cpu
quota[:memory].should == memory
quota[:num_vms].should == num_vms
end
describe 'Quota' do
before(:all) do
@db=Sequel.sqlite
mock_data=YAML::load(File.read('oca_vms.yaml'))
client=ClientMock.new(mock_data)
@quota=Quota.new(@db, client)
end
it 'should create table' do
@db.table_exists?(:quotas).should == true
schema=@db.schema(:quotas)
check_column(schema, :uid)
check_column(schema, :cpu)
check_column(schema, :memory)
check_column(schema, :num_vms)
end
it 'should let add and retrieve quotas' do
@quota.set(0, 10.0, 1024, 10)
@quota.set(1, 20.0, 2048, 20)
@quota.set(2, 40.0, 4096, 40)
check_quota(0, 10.0, 1024, 10)
check_quota(1, 20.0, 2048, 20)
check_quota(2, 40.0, 4096, 40)
@quota.get(3).should == @quota.defaults
end
it 'should check for quotas' do
@quota.update(0)
@quota.update(1)
@quota.check(0).should == false
@quota.check(1).should == false
vms=@quota.get_user(0)
vms[5]=VmUsage.new(40.0, 8192)
vms=@quota.get_user(1)
vms[6]=VmUsage.new(40.0, 8192)
@quota.check(0).class.should == String
@quota.check(1).class.should == String
@quota.update(0)
@quota.update(1)
@quota.check(0).should == false
@quota.check(1).should == false
end
it 'should let update limits' do
@quota.set(0, nil, nil, nil)
check_quota(0, nil, nil, nil)
end
it 'should understand unlimited quotas' do
vms=@quota.get_user(0)
vms[7]=VmUsage.new(9999999999.0, 99999999999)
@quota.check(0).should == false
@quota.check(0, VmUsage.new(999999999.0, 99999999)).should == false
end
end

View File

@ -1,101 +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 'spec_common'
require 'client_mock'
require 'simple_permissions'
CONF=<<EOT
:database: sqlite://auth.db
:authentication: simple
:quota:
:enabled: false
:defaults:
:cpu: 10.0
:memory: 1048576
EOT
def gen_tokens(user_, action_, options={})
user=user_.to_s
action=action_.to_s.upcase
options={
:vm => true,
:host => true
}.merge!(options)
pub=(options[:public] ? '1' : '0')
id=(options[:id] ? options[:id].to_s : '1')
#owner=(options[:owner] ? options[:owner].to_s : '1')
if action=='CREATE'
vmowner='-'
vmid='-'
else
vmowner=user
vmid=user
end
tokens=[]
tokens<<"VM:#{vmid}:#{action}:#{vmowner}:#{pub}" if options[:vm]
tokens+=[
"NET:#{id}:#{action}:#{user}:#{pub}",
"IMAGE:#{id}:#{action}:#{user}:#{pub}"
]
tokens<<"HOST:#{id}:#{action}:#{user}:#{pub}" if options[:host]
tokens
end
describe SimplePermissions do
before(:all) do
@db=Sequel.sqlite
mock_data=YAML::load(File.read('oca_vms.yaml'))
client=ClientMock.new(mock_data)
@perm=SimplePermissions.new(@db, client, YAML::load(CONF))
end
it 'should let root manage everything' do
@perm.auth(0, gen_tokens(1, :create)).should == true
@perm.auth(0, gen_tokens(1, :delete)).should == true
@perm.auth(0, gen_tokens(1, :manage)).should == true
@perm.auth(0, gen_tokens(1, :use)).should == true
end
it 'should let anyone use public objects' do
@perm.auth(2, gen_tokens(1, :delete, :public => true)).
should_not == true
@perm.auth(2, gen_tokens(1, :manage, :public => true)).
should_not == true
# take out vm create (the first token) as it can not be "used" by
# other users even if public
@perm.auth(2, gen_tokens(1, :use, :public => true, :vm => false)).
should == true
end
it 'should let users use their own objects' do
@perm.auth(1, gen_tokens(1, :create, :host => false)).should == true
@perm.auth(1, gen_tokens(1, :delete, :host => false)).should == true
@perm.auth(1, gen_tokens(1, :manage, :host => false)).should == true
@perm.auth(1, gen_tokens(1, :use)).should == true
end
end

View File

@ -1,27 +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 'pp'
$: << '../../oca/ruby'
$: << '..'
require 'db_helpers'