mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
bug #716: Add monitoring tests
This commit is contained in:
parent
de0d8cba73
commit
aab42cee60
@ -1,3 +1,5 @@
|
||||
$: << '.'
|
||||
|
||||
require 'helper/test_helper.rb'
|
||||
|
||||
describe "1 Vm 1 History" do
|
||||
|
@ -1,3 +1,5 @@
|
||||
$: << '.'
|
||||
|
||||
require 'helper/test_helper.rb'
|
||||
|
||||
describe "1 Vm X History" do
|
||||
|
@ -1,3 +1,5 @@
|
||||
$: << '.'
|
||||
|
||||
require 'helper/test_helper.rb'
|
||||
|
||||
describe "X Vm 1 History" do
|
||||
|
@ -1,4 +1,7 @@
|
||||
$: << '.'
|
||||
|
||||
require 'helper/test_helper.rb'
|
||||
require 'watch_client'
|
||||
|
||||
describe "VmWatchClient tests" do
|
||||
before(:all) do
|
||||
@ -13,7 +16,7 @@ describe "VmWatchClient tests" do
|
||||
@db[:vms].count.should eql(0)
|
||||
end
|
||||
|
||||
it "1 VM, 1 timestamp. Check totals, sums and resource info" do
|
||||
it "Create a VM: uid=2 gid=4, timestamp=100" do
|
||||
@monitoring.set_mock_timestamp(100)
|
||||
|
||||
@monitoring.insert(create_vmpool_hash)
|
||||
@ -24,7 +27,7 @@ describe "VmWatchClient tests" do
|
||||
:memory => 128,
|
||||
:net_tx => 200,
|
||||
:net_rx => 400,
|
||||
:last_poll => 90,
|
||||
:last_poll => 100,
|
||||
:uid => 2,
|
||||
:gid => 4,
|
||||
:history => [
|
||||
@ -55,16 +58,16 @@ describe "VmWatchClient tests" do
|
||||
monitoring.keys.size.should eql(4)
|
||||
|
||||
monitoring[:cpu_usage].size.should eql(1)
|
||||
monitoring[:cpu_usage].first.should eql([90,1])
|
||||
monitoring[:cpu_usage].first.should eql([100,1])
|
||||
|
||||
monitoring[:mem_usage].size.should eql(1)
|
||||
monitoring[:mem_usage].first.should eql([90,128])
|
||||
monitoring[:mem_usage].first.should eql([100,128])
|
||||
|
||||
monitoring[:net_tx].size.should eql(1)
|
||||
monitoring[:net_tx].first.should eql([90,200])
|
||||
monitoring[:net_tx].first.should eql([100,200])
|
||||
|
||||
monitoring[:net_rx].size.should eql(1)
|
||||
monitoring[:net_rx].first.should eql([90,400])
|
||||
monitoring[:net_rx].first.should eql([100,400])
|
||||
end
|
||||
|
||||
it "should check all the monitoring resources are shown by default and filtered" do
|
||||
@ -78,16 +81,16 @@ describe "VmWatchClient tests" do
|
||||
monitoring.keys.size.should eql(4)
|
||||
|
||||
monitoring[:cpu_usage].size.should eql(1)
|
||||
monitoring[:cpu_usage].first.should eql([90,1])
|
||||
monitoring[:cpu_usage].first.should eql([100,1])
|
||||
|
||||
monitoring[:mem_usage].size.should eql(1)
|
||||
monitoring[:mem_usage].first.should eql([90,128])
|
||||
monitoring[:mem_usage].first.should eql([100,128])
|
||||
|
||||
monitoring[:net_tx].size.should eql(1)
|
||||
monitoring[:net_tx].first.should eql([90,200])
|
||||
monitoring[:net_tx].first.should eql([100,200])
|
||||
|
||||
monitoring[:net_rx].size.should eql(1)
|
||||
monitoring[:net_rx].first.should eql([90,400])
|
||||
monitoring[:net_rx].first.should eql([100,400])
|
||||
end
|
||||
|
||||
it "should check no info for non exisiting user" do
|
||||
@ -104,7 +107,7 @@ describe "VmWatchClient tests" do
|
||||
monitoring.keys.size.should eql(1)
|
||||
|
||||
monitoring[:net_tx].size.should eql(1)
|
||||
monitoring[:net_tx].first.should eql([90,200])
|
||||
monitoring[:net_tx].first.should eql([100,200])
|
||||
end
|
||||
|
||||
it "should check only two monitoring resources are shown if specified" do
|
||||
@ -115,10 +118,10 @@ describe "VmWatchClient tests" do
|
||||
monitoring.keys.size.should eql(2)
|
||||
|
||||
monitoring[:net_tx].size.should eql(1)
|
||||
monitoring[:net_tx].first.should eql([90,200])
|
||||
monitoring[:net_tx].first.should eql([100,200])
|
||||
|
||||
monitoring[:cpu_usage].size.should eql(1)
|
||||
monitoring[:cpu_usage].first.should eql([90,1])
|
||||
monitoring[:cpu_usage].first.should eql([100,1])
|
||||
end
|
||||
|
||||
it "should check all the total monitoring resources are shown by default" do
|
||||
@ -134,19 +137,20 @@ describe "VmWatchClient tests" do
|
||||
monitoring[:active].size.should eql(1)
|
||||
monitoring[:active].first.should eql([100,1])
|
||||
|
||||
monitoring[:error].size.should eql(0)
|
||||
monitoring[:error].size.should eql(1)
|
||||
monitoring[:error].first.should eql([100,0])
|
||||
|
||||
monitoring[:cpu_usage].size.should eql(1)
|
||||
monitoring[:cpu_usage].first.should eql([90,1])
|
||||
monitoring[:cpu_usage].first.should eql([100,1])
|
||||
|
||||
monitoring[:mem_usage].size.should eql(1)
|
||||
monitoring[:mem_usage].first.should eql([90,128])
|
||||
monitoring[:mem_usage].first.should eql([100,128])
|
||||
|
||||
monitoring[:net_tx].size.should eql(1)
|
||||
monitoring[:net_tx].first.should eql([90,200])
|
||||
monitoring[:net_tx].first.should eql([100,200])
|
||||
|
||||
monitoring[:net_rx].size.should eql(1)
|
||||
monitoring[:net_rx].first.should eql([90,400])
|
||||
monitoring[:net_rx].first.should eql([100,400])
|
||||
end
|
||||
|
||||
it "should check only one total monitoring resources is shown if specified" do
|
||||
@ -172,7 +176,7 @@ describe "VmWatchClient tests" do
|
||||
mon.should eql(nil)
|
||||
end
|
||||
|
||||
it "add a second VM" do
|
||||
it "Create a second VM: uid=2 gid=4, timestamp=200" do
|
||||
@monitoring.set_mock_timestamp(200)
|
||||
|
||||
values = {
|
||||
@ -180,7 +184,7 @@ describe "VmWatchClient tests" do
|
||||
:memory => 128,
|
||||
:net_tx => 200,
|
||||
:net_rx => 400,
|
||||
:last_poll => 90,
|
||||
:last_poll => 100,
|
||||
:uid => 2,
|
||||
:gid => 4,
|
||||
:history => [
|
||||
@ -211,16 +215,16 @@ describe "VmWatchClient tests" do
|
||||
monitoring.keys.size.should eql(4)
|
||||
|
||||
monitoring[:cpu_usage].size.should eql(2)
|
||||
monitoring[:cpu_usage].first.should eql([90,1])
|
||||
monitoring[:cpu_usage].first.should eql([100,1])
|
||||
|
||||
monitoring[:mem_usage].size.should eql(2)
|
||||
monitoring[:mem_usage].first.should eql([90,128])
|
||||
monitoring[:mem_usage].first.should eql([100,128])
|
||||
|
||||
monitoring[:net_tx].size.should eql(2)
|
||||
monitoring[:net_tx].first.should eql([90,200])
|
||||
monitoring[:net_tx].first.should eql([100,200])
|
||||
|
||||
monitoring[:net_rx].size.should eql(2)
|
||||
monitoring[:net_rx].first.should eql([90,400])
|
||||
monitoring[:net_rx].first.should eql([100,400])
|
||||
|
||||
mon = @watch_client.resource_monitoring(2)
|
||||
|
||||
@ -232,16 +236,16 @@ describe "VmWatchClient tests" do
|
||||
monitoring.keys.size.should eql(4)
|
||||
|
||||
monitoring[:cpu_usage].size.should eql(1)
|
||||
monitoring[:cpu_usage].first.should eql([90,1])
|
||||
monitoring[:cpu_usage].first.should eql([100,1])
|
||||
|
||||
monitoring[:mem_usage].size.should eql(1)
|
||||
monitoring[:mem_usage].first.should eql([90,128])
|
||||
monitoring[:mem_usage].first.should eql([100,128])
|
||||
|
||||
monitoring[:net_tx].size.should eql(1)
|
||||
monitoring[:net_tx].first.should eql([90,200])
|
||||
monitoring[:net_tx].first.should eql([100,200])
|
||||
|
||||
monitoring[:net_rx].size.should eql(1)
|
||||
monitoring[:net_rx].first.should eql([90,400])
|
||||
monitoring[:net_rx].first.should eql([100,400])
|
||||
end
|
||||
|
||||
it "should check all the total monitoring resources are shown by default" do
|
||||
@ -259,22 +263,28 @@ describe "VmWatchClient tests" do
|
||||
monitoring[:active].first.should eql([100,1])
|
||||
monitoring[:active][1].should eql([200,2])
|
||||
|
||||
monitoring[:error].size.should eql(0)
|
||||
monitoring[:error].size.should eql(2)
|
||||
monitoring[:error].first.should eql([100,0])
|
||||
monitoring[:error][1].should eql([200,0])
|
||||
|
||||
monitoring[:cpu_usage].size.should eql(1)
|
||||
monitoring[:cpu_usage].first.should eql([90,1*2])
|
||||
monitoring[:cpu_usage].size.should eql(2)
|
||||
monitoring[:cpu_usage].first.should eql([100,1])
|
||||
monitoring[:cpu_usage][1].should eql([200,1*2])
|
||||
|
||||
monitoring[:mem_usage].size.should eql(1)
|
||||
monitoring[:mem_usage].first.should eql([90,128*2])
|
||||
monitoring[:mem_usage].size.should eql(2)
|
||||
monitoring[:mem_usage].first.should eql([100,128])
|
||||
monitoring[:mem_usage][1].should eql([200,128*2])
|
||||
|
||||
monitoring[:net_tx].size.should eql(1)
|
||||
monitoring[:net_tx].first.should eql([90,200*2])
|
||||
monitoring[:net_tx].size.should eql(2)
|
||||
monitoring[:net_tx].first.should eql([100,200])
|
||||
monitoring[:net_tx][1].should eql([200,200*2])
|
||||
|
||||
monitoring[:net_rx].size.should eql(1)
|
||||
monitoring[:net_rx].first.should eql([90,400*2])
|
||||
monitoring[:net_rx].size.should eql(2)
|
||||
monitoring[:net_rx].first.should eql([100,400])
|
||||
monitoring[:net_rx][1].should eql([200,400*2])
|
||||
end
|
||||
|
||||
it "add a third VM" do
|
||||
it "Create a third VM: uid=3 gid=5, timestamp=300" do
|
||||
@monitoring.set_mock_timestamp(300)
|
||||
|
||||
values = {
|
||||
@ -282,7 +292,7 @@ describe "VmWatchClient tests" do
|
||||
:memory => 128,
|
||||
:net_tx => 200,
|
||||
:net_rx => 400,
|
||||
:last_poll => 90,
|
||||
:last_poll => 270,
|
||||
:uid => 3,
|
||||
:gid => 5,
|
||||
:history => [
|
||||
@ -302,63 +312,93 @@ describe "VmWatchClient tests" do
|
||||
@db[:vms].count.should eql(3)
|
||||
end
|
||||
|
||||
it "should check the total monitoring resources are filtered by user" do
|
||||
it "should check the total monitoring resources are filtered by uid(3)" do
|
||||
mon = @watch_client.total_monitoring(nil, :uid=>3)
|
||||
|
||||
mon[:resource].should eql("VM_POOL")
|
||||
|
||||
monitoring = mon[:monitoring]
|
||||
|
||||
monitoring[:total].size.should eql(1)
|
||||
monitoring[:total].first.should eql([300,1])
|
||||
monitoring[:total].size.should eql(3)
|
||||
monitoring[:total].first.should eql([100,0])
|
||||
monitoring[:total][1].should eql([200,0])
|
||||
monitoring[:total][2].should eql([300,1])
|
||||
|
||||
monitoring[:active].size.should eql(1)
|
||||
monitoring[:active].first.should eql([300,1])
|
||||
monitoring[:active].size.should eql(3)
|
||||
monitoring[:active].first.should eql([100,0])
|
||||
monitoring[:active][1].should eql([200,0])
|
||||
monitoring[:active][2].should eql([300,1])
|
||||
|
||||
monitoring[:error].size.should eql(0)
|
||||
monitoring[:error].size.should eql(3)
|
||||
monitoring[:error].first.should eql([100,0])
|
||||
monitoring[:error][1].should eql([200,0])
|
||||
monitoring[:error][2].should eql([300,0])
|
||||
|
||||
monitoring[:cpu_usage].size.should eql(1)
|
||||
monitoring[:cpu_usage].first.should eql([90,1])
|
||||
monitoring[:cpu_usage].size.should eql(3)
|
||||
monitoring[:cpu_usage].first.should eql([100,0])
|
||||
monitoring[:cpu_usage][1].should eql([200,0])
|
||||
monitoring[:cpu_usage][2].should eql([300,1])
|
||||
|
||||
monitoring[:mem_usage].size.should eql(1)
|
||||
monitoring[:mem_usage].first.should eql([90,128])
|
||||
monitoring[:mem_usage].size.should eql(3)
|
||||
monitoring[:mem_usage].first.should eql([100,0])
|
||||
monitoring[:mem_usage][1].should eql([200,0])
|
||||
monitoring[:mem_usage][2].should eql([300,128])
|
||||
|
||||
monitoring[:net_tx].size.should eql(1)
|
||||
monitoring[:net_tx].first.should eql([90,200])
|
||||
monitoring[:net_tx].size.should eql(3)
|
||||
monitoring[:net_tx].first.should eql([100,0])
|
||||
monitoring[:net_tx][1].should eql([200,0])
|
||||
monitoring[:net_tx][2].should eql([300,200])
|
||||
|
||||
monitoring[:net_rx].size.should eql(1)
|
||||
monitoring[:net_rx].first.should eql([90,400])
|
||||
monitoring[:net_rx].size.should eql(3)
|
||||
monitoring[:net_rx].first.should eql([100,0])
|
||||
monitoring[:net_rx][1].should eql([200,0])
|
||||
monitoring[:net_rx][2].should eql([300,400])
|
||||
end
|
||||
|
||||
it "should check the total monitoring resources are filtered by group" do
|
||||
it "should check the total monitoring resources are filtered by gid(5)" do
|
||||
mon = @watch_client.total_monitoring(nil, :gid=>5)
|
||||
|
||||
mon[:resource].should eql("VM_POOL")
|
||||
|
||||
monitoring = mon[:monitoring]
|
||||
|
||||
monitoring[:total].size.should eql(1)
|
||||
monitoring[:total].first.should eql([300,1])
|
||||
monitoring[:total].size.should eql(3)
|
||||
monitoring[:total].first.should eql([100,0])
|
||||
monitoring[:total][1].should eql([200,0])
|
||||
monitoring[:total][2].should eql([300,1])
|
||||
|
||||
monitoring[:active].size.should eql(1)
|
||||
monitoring[:active].first.should eql([300,1])
|
||||
monitoring[:active].size.should eql(3)
|
||||
monitoring[:active].first.should eql([100,0])
|
||||
monitoring[:active][1].should eql([200,0])
|
||||
monitoring[:active][2].should eql([300,1])
|
||||
|
||||
monitoring[:error].size.should eql(0)
|
||||
monitoring[:error].size.should eql(3)
|
||||
monitoring[:error].first.should eql([100,0])
|
||||
monitoring[:error][1].should eql([200,0])
|
||||
monitoring[:error][2].should eql([300,0])
|
||||
|
||||
monitoring[:cpu_usage].size.should eql(1)
|
||||
monitoring[:cpu_usage].first.should eql([90,1])
|
||||
monitoring[:cpu_usage].size.should eql(3)
|
||||
monitoring[:cpu_usage].first.should eql([100,0])
|
||||
monitoring[:cpu_usage][1].should eql([200,0])
|
||||
monitoring[:cpu_usage][2].should eql([300,1])
|
||||
|
||||
monitoring[:mem_usage].size.should eql(1)
|
||||
monitoring[:mem_usage].first.should eql([90,128])
|
||||
monitoring[:mem_usage].size.should eql(3)
|
||||
monitoring[:mem_usage].first.should eql([100,0])
|
||||
monitoring[:mem_usage][1].should eql([200,0])
|
||||
monitoring[:mem_usage][2].should eql([300,128])
|
||||
|
||||
monitoring[:net_tx].size.should eql(1)
|
||||
monitoring[:net_tx].first.should eql([90,200])
|
||||
monitoring[:net_tx].size.should eql(3)
|
||||
monitoring[:net_tx].first.should eql([100,0])
|
||||
monitoring[:net_tx][1].should eql([200,0])
|
||||
monitoring[:net_tx][2].should eql([300,200])
|
||||
|
||||
monitoring[:net_rx].size.should eql(1)
|
||||
monitoring[:net_rx].first.should eql([90,400])
|
||||
monitoring[:net_rx].size.should eql(3)
|
||||
monitoring[:net_rx].first.should eql([100,0])
|
||||
monitoring[:net_rx][1].should eql([200,0])
|
||||
monitoring[:net_rx][2].should eql([300,400])
|
||||
end
|
||||
|
||||
it "should check the total monitoring resources are filtered by user" do
|
||||
it "should check the total monitoring resources are filtered by uid(2)" do
|
||||
mon = @watch_client.total_monitoring(nil, :uid=>2)
|
||||
|
||||
mon[:resource].should eql("VM_POOL")
|
||||
@ -375,22 +415,33 @@ describe "VmWatchClient tests" do
|
||||
monitoring[:active][1].should eql([200,2])
|
||||
monitoring[:active].last.should eql([300,2])
|
||||
|
||||
monitoring[:error].size.should eql(0)
|
||||
monitoring[:error].size.should eql(3)
|
||||
monitoring[:error].first.should eql([100,0])
|
||||
monitoring[:error][1].should eql([200,0])
|
||||
monitoring[:error][2].should eql([300,0])
|
||||
|
||||
monitoring[:cpu_usage].size.should eql(1)
|
||||
monitoring[:cpu_usage].first.should eql([90,1*2])
|
||||
monitoring[:cpu_usage].size.should eql(3)
|
||||
monitoring[:cpu_usage].first.should eql([100,1])
|
||||
monitoring[:cpu_usage][1].should eql([200,2])
|
||||
monitoring[:cpu_usage][2].should eql([300,2])
|
||||
|
||||
monitoring[:mem_usage].size.should eql(1)
|
||||
monitoring[:mem_usage].first.should eql([90,128*2])
|
||||
monitoring[:mem_usage].size.should eql(3)
|
||||
monitoring[:mem_usage].first.should eql([100,128])
|
||||
monitoring[:mem_usage][1].should eql([200,256])
|
||||
monitoring[:mem_usage][2].should eql([300,256])
|
||||
|
||||
monitoring[:net_tx].size.should eql(1)
|
||||
monitoring[:net_tx].first.should eql([90,200*2])
|
||||
monitoring[:net_tx].size.should eql(3)
|
||||
monitoring[:net_tx].first.should eql([100,200])
|
||||
monitoring[:net_tx][1].should eql([200,400])
|
||||
monitoring[:net_tx][2].should eql([300,400])
|
||||
|
||||
monitoring[:net_rx].size.should eql(1)
|
||||
monitoring[:net_rx].first.should eql([90,400*2])
|
||||
monitoring[:net_rx].size.should eql(3)
|
||||
monitoring[:net_rx].first.should eql([100,400])
|
||||
monitoring[:net_rx][1].should eql([200,800])
|
||||
monitoring[:net_rx][2].should eql([300,800])
|
||||
end
|
||||
|
||||
it "should check the total monitoring resources are filtered by group" do
|
||||
it "should check the total monitoring resources are filtered by gid(4)" do
|
||||
mon = @watch_client.total_monitoring(nil, :gid=>4)
|
||||
|
||||
mon[:resource].should eql("VM_POOL")
|
||||
@ -400,26 +451,37 @@ describe "VmWatchClient tests" do
|
||||
monitoring[:total].size.should eql(3)
|
||||
monitoring[:total].first.should eql([100,1])
|
||||
monitoring[:total][1].should eql([200,2])
|
||||
monitoring[:active].last.should eql([300,2])
|
||||
monitoring[:total].last.should eql([300,2])
|
||||
|
||||
monitoring[:active].size.should eql(3)
|
||||
monitoring[:active].first.should eql([100,1])
|
||||
monitoring[:active][1].should eql([200,2])
|
||||
monitoring[:active].last.should eql([300,2])
|
||||
|
||||
monitoring[:error].size.should eql(0)
|
||||
monitoring[:error].size.should eql(3)
|
||||
monitoring[:error].first.should eql([100,0])
|
||||
monitoring[:error][1].should eql([200,0])
|
||||
monitoring[:error][2].should eql([300,0])
|
||||
|
||||
monitoring[:cpu_usage].size.should eql(1)
|
||||
monitoring[:cpu_usage].first.should eql([90,1*2])
|
||||
monitoring[:cpu_usage].size.should eql(3)
|
||||
monitoring[:cpu_usage].first.should eql([100,1])
|
||||
monitoring[:cpu_usage][1].should eql([200,2])
|
||||
monitoring[:cpu_usage][2].should eql([300,2])
|
||||
|
||||
monitoring[:mem_usage].size.should eql(1)
|
||||
monitoring[:mem_usage].first.should eql([90,128*2])
|
||||
monitoring[:mem_usage].size.should eql(3)
|
||||
monitoring[:mem_usage].first.should eql([100,128])
|
||||
monitoring[:mem_usage][1].should eql([200,256])
|
||||
monitoring[:mem_usage][2].should eql([300,256])
|
||||
|
||||
monitoring[:net_tx].size.should eql(1)
|
||||
monitoring[:net_tx].first.should eql([90,200*2])
|
||||
monitoring[:net_tx].size.should eql(3)
|
||||
monitoring[:net_tx].first.should eql([100,200])
|
||||
monitoring[:net_tx][1].should eql([200,400])
|
||||
monitoring[:net_tx][2].should eql([300,400])
|
||||
|
||||
monitoring[:net_rx].size.should eql(1)
|
||||
monitoring[:net_rx].first.should eql([90,400*2])
|
||||
monitoring[:net_rx].size.should eql(3)
|
||||
monitoring[:net_rx].first.should eql([100,400])
|
||||
monitoring[:net_rx][1].should eql([200,800])
|
||||
monitoring[:net_rx][2].should eql([300,800])
|
||||
end
|
||||
|
||||
it "should check no total info for non existing user" do
|
||||
@ -429,18 +491,39 @@ describe "VmWatchClient tests" do
|
||||
|
||||
monitoring = mon[:monitoring]
|
||||
|
||||
monitoring[:total].size.should eql(0)
|
||||
monitoring[:total].size.should eql(3)
|
||||
monitoring[:total].first.should eql([100,0])
|
||||
monitoring[:total][1].should eql([200,0])
|
||||
monitoring[:total].last.should eql([300,0])
|
||||
|
||||
monitoring[:active].size.should eql(0)
|
||||
monitoring[:active].size.should eql(3)
|
||||
monitoring[:active].first.should eql([100,0])
|
||||
monitoring[:active][1].should eql([200,0])
|
||||
monitoring[:active].last.should eql([300,0])
|
||||
|
||||
monitoring[:error].size.should eql(0)
|
||||
monitoring[:error].size.should eql(3)
|
||||
monitoring[:error].first.should eql([100,0])
|
||||
monitoring[:error][1].should eql([200,0])
|
||||
monitoring[:error][2].should eql([300,0])
|
||||
|
||||
monitoring[:cpu_usage].size.should eql(0)
|
||||
monitoring[:cpu_usage].size.should eql(3)
|
||||
monitoring[:cpu_usage].first.should eql([100,0])
|
||||
monitoring[:cpu_usage][1].should eql([200,0])
|
||||
monitoring[:cpu_usage][2].should eql([300,0])
|
||||
|
||||
monitoring[:mem_usage].size.should eql(0)
|
||||
monitoring[:mem_usage].size.should eql(3)
|
||||
monitoring[:mem_usage].first.should eql([100,0])
|
||||
monitoring[:mem_usage][1].should eql([200,0])
|
||||
monitoring[:mem_usage][2].should eql([300,0])
|
||||
|
||||
monitoring[:net_tx].size.should eql(0)
|
||||
monitoring[:net_tx].size.should eql(3)
|
||||
monitoring[:net_tx].first.should eql([100,0])
|
||||
monitoring[:net_tx][1].should eql([200,0])
|
||||
monitoring[:net_tx][2].should eql([300,0])
|
||||
|
||||
monitoring[:net_rx].size.should eql(0)
|
||||
monitoring[:net_rx].size.should eql(3)
|
||||
monitoring[:net_rx].first.should eql([100,0])
|
||||
monitoring[:net_rx][1].should eql([200,0])
|
||||
monitoring[:net_rx][2].should eql([300,0])
|
||||
end
|
||||
end
|
@ -18,7 +18,6 @@ $: << '..'
|
||||
|
||||
|
||||
require 'examples/acct_client'
|
||||
require 'watch_client'
|
||||
require 'mock_client'
|
||||
|
||||
require 'accounting'
|
||||
@ -58,6 +57,8 @@ def clean_db
|
||||
WatchHelper::VmDelta.destroy
|
||||
WatchHelper::VmSample.destroy
|
||||
WatchHelper::HostSample.destroy
|
||||
WatchHelper::VmTimestamp.destroy
|
||||
WatchHelper::HostTimestamp.destroy
|
||||
WatchHelper::Vm.destroy
|
||||
WatchHelper::Host.destroy
|
||||
rescue Exception => e
|
||||
|
@ -1,102 +0,0 @@
|
||||
require 'helper/test_helper.rb'
|
||||
|
||||
describe "1 Vm 1 10 steps" do
|
||||
before(:each) do
|
||||
clean_db
|
||||
|
||||
@mock_client = MockClient.new
|
||||
@monitoring = OneWatch::VmMonitoring.new
|
||||
|
||||
@watch_client = OneWatchClient::WatchClient.new
|
||||
|
||||
@db = WatchHelper::DB
|
||||
@db[:vms].count.should eql(0)
|
||||
end
|
||||
|
||||
it "CPU testing" do
|
||||
ts1 = 100
|
||||
@monitoring.set_mock_timestamp(ts1)
|
||||
|
||||
@monitoring.insert(create_vmpool_hash)
|
||||
@db[:vms].count.should eql(0)
|
||||
|
||||
10.times { |i|
|
||||
ts2 = 200+100*i
|
||||
@monitoring.set_mock_timestamp(ts2)
|
||||
|
||||
values = {
|
||||
:cpu => 80+i,
|
||||
:memory => 122+i,
|
||||
:net_tx => 200+i,
|
||||
:net_rx => 134+i,
|
||||
:last_poll => 1309275256+i,
|
||||
:uid => 2,
|
||||
:gid => 4,
|
||||
:history => [
|
||||
:hid => 7,
|
||||
:pstime => 150,
|
||||
:petime => 0,
|
||||
:rstime => 0,
|
||||
:retime => 0,
|
||||
:estime => 0,
|
||||
:eetime => 0,
|
||||
:reason => 0
|
||||
]
|
||||
}
|
||||
|
||||
@mock_client.add_vm(1, values)
|
||||
|
||||
@monitoring.insert(create_vmpool_hash)
|
||||
@db[:vms].count.should eql(1)
|
||||
@db[:vm_samples].count.should eql(1+i > 5 ? 5 : 1+i)
|
||||
|
||||
@watch_client.vm_monitoring(1, ['cpu', 'net_tx'])
|
||||
|
||||
@watch_client.vm_total
|
||||
}
|
||||
end
|
||||
|
||||
it "Total testing" do
|
||||
ts1 = 100
|
||||
@monitoring.set_mock_timestamp(ts1)
|
||||
|
||||
@monitoring.insert(create_vmpool_hash)
|
||||
@db[:vms].count.should eql(0)
|
||||
|
||||
10.times { |i|
|
||||
ts2 = 200+100*i
|
||||
@monitoring.set_mock_timestamp(ts2)
|
||||
|
||||
values = {
|
||||
:cpu => 80+i,
|
||||
:memory => 122+i,
|
||||
:net_tx => 200+i,
|
||||
:net_rx => 134+i,
|
||||
:state => 7,
|
||||
:last_poll => 1309275256+i,
|
||||
:uid => 2,
|
||||
:gid => 4,
|
||||
:history => [
|
||||
:hid => 7,
|
||||
:pstime => 150,
|
||||
:petime => 0,
|
||||
:rstime => 0,
|
||||
:retime => 0,
|
||||
:estime => 0,
|
||||
:eetime => 0,
|
||||
:reason => 0
|
||||
]
|
||||
}
|
||||
|
||||
values[:state] = 7
|
||||
@mock_client.add_vm(i+100, values)
|
||||
values[:state] = 3
|
||||
@mock_client.add_vm(i+10, values)
|
||||
|
||||
@monitoring.insert(create_vmpool_hash)
|
||||
|
||||
@db[:vm_samples].count
|
||||
total = @watch_client.vm_total([:total, :error, :active])
|
||||
}
|
||||
end
|
||||
end
|
299
src/acct/test/vm_monitoring_spec.rb
Normal file
299
src/acct/test/vm_monitoring_spec.rb
Normal file
@ -0,0 +1,299 @@
|
||||
$: << '.'
|
||||
|
||||
require 'helper/test_helper.rb'
|
||||
|
||||
describe "VM Monitoring tests" do
|
||||
before(:all) do
|
||||
clean_db
|
||||
|
||||
@mock_client = MockClient.new
|
||||
@monitoring = OneWatch::VmMonitoring.new
|
||||
|
||||
#@watch_client = OneWatchClient::WatchClient.new
|
||||
|
||||
@db = WatchHelper::DB
|
||||
@db[:vms].count.should eql(0)
|
||||
@db[:vm_samples].count.should eql(0)
|
||||
@db[:vm_timestamps].count.should eql(0)
|
||||
end
|
||||
|
||||
it "after monitoring an empty pool: 0 VMs, 0 Samples, 1 Timestamp" do
|
||||
ts1 = 100
|
||||
@monitoring.set_mock_timestamp(ts1)
|
||||
|
||||
@monitoring.insert(create_vmpool_hash)
|
||||
@db[:vms].count.should eql(0)
|
||||
@db[:vm_samples].count.should eql(0)
|
||||
@db[:vm_timestamps].count.should eql(1)
|
||||
end
|
||||
|
||||
it "after monitoring a pool of 1 VM: 1 VMs, 1 Samples, 2 Timestamp" do
|
||||
values = {
|
||||
:cpu => 80,
|
||||
:memory => 122,
|
||||
:net_tx => 200,
|
||||
:net_rx => 134,
|
||||
:last_poll => 1309275256,
|
||||
:uid => 2,
|
||||
:gid => 4,
|
||||
:history => [
|
||||
:hid => 7,
|
||||
:pstime => 150,
|
||||
:petime => 0,
|
||||
:rstime => 0,
|
||||
:retime => 0,
|
||||
:estime => 0,
|
||||
:eetime => 0,
|
||||
:reason => 0
|
||||
]
|
||||
}
|
||||
|
||||
@mock_client.add_vm(0, values)
|
||||
|
||||
ts2 = 200
|
||||
@monitoring.set_mock_timestamp(ts2)
|
||||
|
||||
@monitoring.insert(create_vmpool_hash)
|
||||
@db[:vms].count.should eql(1)
|
||||
@db[:vm_samples].count.should eql(1)
|
||||
@db[:vm_timestamps].count.should eql(2)
|
||||
end
|
||||
|
||||
it "after monitoring a pool of 1 VM: 1 VMs, 2 Samples, 3 Timestamp" do
|
||||
values = {
|
||||
:cpu => 80,
|
||||
:memory => 122,
|
||||
:net_tx => 200,
|
||||
:net_rx => 134,
|
||||
:last_poll => 1309275256,
|
||||
:uid => 2,
|
||||
:gid => 4,
|
||||
:history => [
|
||||
:hid => 7,
|
||||
:pstime => 150,
|
||||
:petime => 0,
|
||||
:rstime => 0,
|
||||
:retime => 0,
|
||||
:estime => 0,
|
||||
:eetime => 0,
|
||||
:reason => 0
|
||||
]
|
||||
}
|
||||
|
||||
@mock_client.add_vm(0, values)
|
||||
|
||||
ts = 300
|
||||
@monitoring.set_mock_timestamp(ts)
|
||||
|
||||
@monitoring.insert(create_vmpool_hash)
|
||||
@db[:vms].count.should eql(1)
|
||||
@db[:vm_samples].count.should eql(2)
|
||||
@db[:vm_timestamps].count.should eql(3)
|
||||
end
|
||||
|
||||
it "after monitoring a pool of 2 VM: 2 VMs, 4 Samples, 4 Timestamp" do
|
||||
values = {
|
||||
:cpu => 80,
|
||||
:memory => 122,
|
||||
:net_tx => 200,
|
||||
:net_rx => 134,
|
||||
:last_poll => 1309275256,
|
||||
:uid => 2,
|
||||
:gid => 4,
|
||||
:history => [
|
||||
:hid => 7,
|
||||
:pstime => 150,
|
||||
:petime => 0,
|
||||
:rstime => 0,
|
||||
:retime => 0,
|
||||
:estime => 0,
|
||||
:eetime => 0,
|
||||
:reason => 0
|
||||
]
|
||||
}
|
||||
|
||||
@mock_client.add_vm(1, values)
|
||||
|
||||
ts = 400
|
||||
@monitoring.set_mock_timestamp(ts)
|
||||
|
||||
@monitoring.insert(create_vmpool_hash)
|
||||
@db[:vms].count.should eql(2)
|
||||
@db[:vm_samples].count.should eql(4)
|
||||
@db[:vm_timestamps].count.should eql(4)
|
||||
end
|
||||
|
||||
it "after monitoring a pool of 2 VM: 2 VMs, 6 Samples, 5 Timestamp" do
|
||||
values = {
|
||||
:cpu => 80,
|
||||
:memory => 122,
|
||||
:net_tx => 200,
|
||||
:net_rx => 134,
|
||||
:last_poll => 1309275256,
|
||||
:uid => 2,
|
||||
:gid => 4,
|
||||
:history => [
|
||||
:hid => 7,
|
||||
:pstime => 150,
|
||||
:petime => 0,
|
||||
:rstime => 0,
|
||||
:retime => 0,
|
||||
:estime => 0,
|
||||
:eetime => 0,
|
||||
:reason => 0
|
||||
]
|
||||
}
|
||||
|
||||
@mock_client.add_vm(1, values)
|
||||
|
||||
ts = 500
|
||||
@monitoring.set_mock_timestamp(ts)
|
||||
|
||||
@monitoring.insert(create_vmpool_hash)
|
||||
@db[:vms].count.should eql(2)
|
||||
@db[:vm_samples].count.should eql(6)
|
||||
@db[:vm_timestamps].count.should eql(5)
|
||||
end
|
||||
|
||||
it "after monitoring a pool of 3 VM: 3 VMs, 9 Samples, 5 Timestamp" do
|
||||
values = {
|
||||
:cpu => 80,
|
||||
:memory => 122,
|
||||
:net_tx => 200,
|
||||
:net_rx => 134,
|
||||
:last_poll => 1309275256,
|
||||
:uid => 2,
|
||||
:gid => 4,
|
||||
:history => [
|
||||
:hid => 7,
|
||||
:pstime => 150,
|
||||
:petime => 0,
|
||||
:rstime => 0,
|
||||
:retime => 0,
|
||||
:estime => 0,
|
||||
:eetime => 0,
|
||||
:reason => 0
|
||||
]
|
||||
}
|
||||
|
||||
@mock_client.add_vm(2, values)
|
||||
|
||||
ts = 600
|
||||
@monitoring.set_mock_timestamp(ts)
|
||||
|
||||
@monitoring.insert(create_vmpool_hash)
|
||||
@db[:vms].count.should eql(3)
|
||||
@db[:vm_samples].count.should eql(9)
|
||||
@db[:vm_timestamps].count.should eql(5)
|
||||
end
|
||||
|
||||
it "after monitoring a pool of 3 VM: 3 VMs, 11 Samples, 5 Timestamp" do
|
||||
values = {
|
||||
:cpu => 80,
|
||||
:memory => 122,
|
||||
:net_tx => 200,
|
||||
:net_rx => 134,
|
||||
:last_poll => 1309275256,
|
||||
:uid => 2,
|
||||
:gid => 4,
|
||||
:history => [
|
||||
:hid => 7,
|
||||
:pstime => 150,
|
||||
:petime => 0,
|
||||
:rstime => 0,
|
||||
:retime => 0,
|
||||
:estime => 0,
|
||||
:eetime => 0,
|
||||
:reason => 0
|
||||
]
|
||||
}
|
||||
|
||||
@mock_client.add_vm(2, values)
|
||||
|
||||
ts = 700
|
||||
@monitoring.set_mock_timestamp(ts)
|
||||
|
||||
@monitoring.insert(create_vmpool_hash)
|
||||
@db[:vms].count.should eql(3)
|
||||
@db[:vm_samples].count.should eql(11)
|
||||
@db[:vm_timestamps].count.should eql(5)
|
||||
end
|
||||
|
||||
|
||||
it "after monitoring a pool of 3 VM: 3 VMs, 13 Samples, 5 Timestamp" do
|
||||
values = {
|
||||
:cpu => 80,
|
||||
:memory => 122,
|
||||
:net_tx => 200,
|
||||
:net_rx => 134,
|
||||
:last_poll => 1309275256,
|
||||
:uid => 2,
|
||||
:gid => 4,
|
||||
:history => [
|
||||
:hid => 7,
|
||||
:pstime => 150,
|
||||
:petime => 0,
|
||||
:rstime => 0,
|
||||
:retime => 0,
|
||||
:estime => 0,
|
||||
:eetime => 0,
|
||||
:reason => 0
|
||||
]
|
||||
}
|
||||
|
||||
@mock_client.add_vm(2, values)
|
||||
|
||||
ts = 800
|
||||
@monitoring.set_mock_timestamp(ts)
|
||||
|
||||
@monitoring.insert(create_vmpool_hash)
|
||||
@db[:vms].count.should eql(3)
|
||||
@db[:vm_samples].count.should eql(13)
|
||||
@db[:vm_timestamps].count.should eql(5)
|
||||
end
|
||||
|
||||
it "after monitoring a pool of 4 VM: 4 VMs, 16 Samples, 5 Timestamp" do
|
||||
values = {
|
||||
:cpu => 80,
|
||||
:memory => 122,
|
||||
:net_tx => 200,
|
||||
:net_rx => 134,
|
||||
:last_poll => 1309275256,
|
||||
:uid => 2,
|
||||
:gid => 4,
|
||||
:history => [
|
||||
:hid => 7,
|
||||
:pstime => 150,
|
||||
:petime => 0,
|
||||
:rstime => 0,
|
||||
:retime => 0,
|
||||
:estime => 0,
|
||||
:eetime => 0,
|
||||
:reason => 0
|
||||
]
|
||||
}
|
||||
|
||||
@mock_client.add_vm(3, values)
|
||||
|
||||
ts = 900
|
||||
@monitoring.set_mock_timestamp(ts)
|
||||
|
||||
@monitoring.insert(create_vmpool_hash)
|
||||
@db[:vms].count.should eql(4)
|
||||
@db[:vm_samples].count.should eql(15)
|
||||
@db[:vm_timestamps].count.should eql(5)
|
||||
end
|
||||
|
||||
it "after (10)monitoring a pool of 4 VM: 4 VMs, 20 Samples, 5 Timestamp" do
|
||||
10.times { |i|
|
||||
ts = 1000+i*100
|
||||
@monitoring.set_mock_timestamp(ts)
|
||||
|
||||
@monitoring.insert(create_vmpool_hash)
|
||||
}
|
||||
|
||||
@db[:vms].count.should eql(4)
|
||||
@db[:vm_samples].count.should eql(20)
|
||||
@db[:vm_timestamps].count.should eql(5)
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user