From 416940d5fa0e4265c690aaf3a69050469ffc8395 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 2 Sep 2011 17:09:50 +0200 Subject: [PATCH] feature #788: delete unneeded test files --- src/authm_mad/test/client_mock.rb | 55 -- src/authm_mad/test/db_helpers.rb | 25 - src/authm_mad/test/oca_vms.yaml | 551 ------------------ src/authm_mad/test/one_usage_spec.rb | 77 --- src/authm_mad/test/quota_spec.rb | 97 --- src/authm_mad/test/simple_permissions_spec.rb | 101 ---- src/authm_mad/test/spec_common.rb | 27 - 7 files changed, 933 deletions(-) delete mode 100644 src/authm_mad/test/client_mock.rb delete mode 100644 src/authm_mad/test/db_helpers.rb delete mode 100644 src/authm_mad/test/oca_vms.yaml delete mode 100644 src/authm_mad/test/one_usage_spec.rb delete mode 100644 src/authm_mad/test/quota_spec.rb delete mode 100644 src/authm_mad/test/simple_permissions_spec.rb delete mode 100644 src/authm_mad/test/spec_common.rb diff --git a/src/authm_mad/test/client_mock.rb b/src/authm_mad/test/client_mock.rb deleted file mode 100644 index cbd23b66e2..0000000000 --- a/src/authm_mad/test/client_mock.rb +++ /dev/null @@ -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 - - diff --git a/src/authm_mad/test/db_helpers.rb b/src/authm_mad/test/db_helpers.rb deleted file mode 100644 index 1abdf1ae8d..0000000000 --- a/src/authm_mad/test/db_helpers.rb +++ /dev/null @@ -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 - - - diff --git a/src/authm_mad/test/oca_vms.yaml b/src/authm_mad/test/oca_vms.yaml deleted file mode 100644 index b69377b77a..0000000000 --- a/src/authm_mad/test/oca_vms.yaml +++ /dev/null @@ -1,551 +0,0 @@ - -vmpool.info: - 0: " - - - 0 - - - 0 - - - jfontan - - - test - - - 0 - - - 1 - - - 0 - - - 1278433840 - - - 0 - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 1 - - - 0 - - - jfontan - - - test - - - 0 - - - 1 - - - 0 - - - 1278433841 - - - 0 - - - - 0 - - - 0 - - - 0 - - - 0 - - - " - 1: " - - - 2 - - - 1 - - - lero - - - test - - - 0 - - - 1 - - - 0 - - - 1278433868 - - - 0 - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 3 - - - 1 - - - lero - - - test - - - 0 - - - 1 - - - 0 - - - 1278433869 - - - 0 - - - - 0 - - - 0 - - - 0 - - - 0 - - - " -vm.info: - 0: " - - 0 - - - 0 - - - test - - - 0 - - - 1 - - - 0 - - - 1278433840 - - - 0 - - - - 0 - - - 0 - - - 0 - - - 0 - - - " - 1: " - - 1 - - - 0 - - - test - - - 0 - - - 1 - - - 0 - - - 1278433841 - - - 0 - - - - 0 - - - 0 - - - 0 - - - 0 - - - " - 2: " - - 2 - - - 1 - - - test - - - 0 - - - 1 - - - 0 - - - 1278433868 - - - 0 - - - - 0 - - - 0 - - - 0 - - - 0 - - - " - 3: " - - 3 - - - 1 - - - test - - - 0 - - - 1 - - - 0 - - - 1278433869 - - - 0 - - - - 0 - - - 0 - - - 0 - - - 0 - - - " \ No newline at end of file diff --git a/src/authm_mad/test/one_usage_spec.rb b/src/authm_mad/test/one_usage_spec.rb deleted file mode 100644 index 1a68229128..0000000000 --- a/src/authm_mad/test/one_usage_spec.rb +++ /dev/null @@ -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 diff --git a/src/authm_mad/test/quota_spec.rb b/src/authm_mad/test/quota_spec.rb deleted file mode 100644 index 7743e45622..0000000000 --- a/src/authm_mad/test/quota_spec.rb +++ /dev/null @@ -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 - - diff --git a/src/authm_mad/test/simple_permissions_spec.rb b/src/authm_mad/test/simple_permissions_spec.rb deleted file mode 100644 index 75a63bf2b6..0000000000 --- a/src/authm_mad/test/simple_permissions_spec.rb +++ /dev/null @@ -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=< 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 - - diff --git a/src/authm_mad/test/spec_common.rb b/src/authm_mad/test/spec_common.rb deleted file mode 100644 index 80850db4fd..0000000000 --- a/src/authm_mad/test/spec_common.rb +++ /dev/null @@ -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' - - - - -