Skip to content

Commit

Permalink
spec c&u cop fixin
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Nov 5, 2019
1 parent dd20bd4 commit f511115
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 230 deletions.
17 changes: 8 additions & 9 deletions spec/models/metric/capture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
context "with enabled and disabled vmware targets", :with_enabled_disabled_vmware do
let(:expected_queue_items) do
{
%w(ManageIQ::Providers::Vmware::InfraManager::Host perf_capture_realtime) => 3,
%w(ManageIQ::Providers::Vmware::InfraManager::Host perf_capture_historical) => 24,
%w(Storage perf_capture_hourly) => 1,
%w(ManageIQ::Providers::Vmware::InfraManager::Vm perf_capture_realtime) => 2,
%w(ManageIQ::Providers::Vmware::InfraManager::Vm perf_capture_historical) => 16,
%w(MiqTask destroy_older_by_condition) => 1
%w[ManageIQ::Providers::Vmware::InfraManager::Host perf_capture_realtime] => 3,
%w[ManageIQ::Providers::Vmware::InfraManager::Host perf_capture_historical] => 24,
%w[Storage perf_capture_hourly] => 1,
%w[ManageIQ::Providers::Vmware::InfraManager::Vm perf_capture_realtime] => 2,
%w[ManageIQ::Providers::Vmware::InfraManager::Vm perf_capture_historical] => 16,
%w[MiqTask destroy_older_by_condition] => 1
}
end

Expand Down Expand Up @@ -114,8 +114,7 @@
end

it "produces default with class not found" do
stub_performance_settings(:capture_threshold => {:vm => "4.minutes",
:default => "10.minutes"})
stub_performance_settings(:capture_threshold => {:vm => "4.minutes", :default => "10.minutes"})
Timecop.freeze(Time.now.utc) do
expect(described_class.standard_capture_threshold(host)).to eq 10.minutes.ago.utc
end
Expand Down Expand Up @@ -143,7 +142,7 @@
describe ".perf_capture_now" do
context "with enabled and disabled targets" do
before do
@ems_vmware = FactoryBot.create(:ems_vmware, :zone => @zone)
@ems_vmware = FactoryBot.create(:ems_vmware, :zone => @zone)
storages = FactoryBot.create_list(:storage_target_vmware, 2)
@vmware_clusters = FactoryBot.create_list(:cluster_target, 2)
@ems_vmware.ems_clusters = @vmware_clusters
Expand Down
322 changes: 162 additions & 160 deletions spec/models/metric/ci_mixin/rollup_spec.rb

Large diffs are not rendered by default.

46 changes: 24 additions & 22 deletions spec/models/metric/finders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,19 @@
"2010-04-15T21:00:00Z", 100.0,
]
cases.each_slice(2) do |t, v|
@vm1.metric_rollups << FactoryBot.create(:metric_rollup_vm_hr,
:timestamp => t,
:cpu_usage_rate_average => v,
:cpu_ready_delta_summation => v * 10000,
:sys_uptime_absolute_latest => v,
:min_max => {
:abs_max_cpu_usage_rate_average_value => v,
:abs_max_cpu_usage_rate_average_timestamp => Time.parse(t) + 20.seconds,
:abs_min_cpu_usage_rate_average_value => v,
:abs_min_cpu_usage_rate_average_timestamp => Time.parse(t) + 40.seconds,
}
)
@vm1.metric_rollups << FactoryBot.create(
:metric_rollup_vm_hr,
:timestamp => t,
:cpu_usage_rate_average => v,
:cpu_ready_delta_summation => v * 10_000,
:sys_uptime_absolute_latest => v,
:min_max => {
:abs_max_cpu_usage_rate_average_value => v,
:abs_max_cpu_usage_rate_average_timestamp => Time.parse(t).utc + 20.seconds,
:abs_min_cpu_usage_rate_average_value => v,
:abs_min_cpu_usage_rate_average_timestamp => Time.parse(t).utc + 40.seconds,
}
)
end
end

Expand All @@ -64,10 +65,10 @@

it "should find multiple resource types" do
@host1.metric_rollups << FactoryBot.create(:metric_rollup_host_hr,
:resource => @host1,
:timestamp => "2010-04-14T22:00:00Z")
:resource => @host1,
:timestamp => "2010-04-14T22:00:00Z")
metrics = Metric::Finders.find_all_by_day([@vm1, @host1], "2010-04-14T00:00:00Z", 'hourly', @time_profile)
expect(metrics.collect(&:resource_type).uniq).to match_array(%w(VmOrTemplate Host))
expect(metrics.collect(&:resource_type).uniq).to match_array(%w[VmOrTemplate Host])
end
end

Expand All @@ -83,12 +84,13 @@
"2010-04-14T22:52:30Z", 100.0,
]
cases.each_slice(2) do |t, v|
@vm1.metrics << FactoryBot.create(:metric_vm_rt,
:timestamp => t,
:cpu_usage_rate_average => v,
:cpu_ready_delta_summation => v * 1000, # Multiply by a factor of 1000 to maake it more realistic and enable testing virtual col v_pct_cpu_ready_delta_summation
:sys_uptime_absolute_latest => v
)
@vm1.metrics << FactoryBot.create(
:metric_vm_rt,
:timestamp => t,
:cpu_usage_rate_average => v,
:cpu_ready_delta_summation => v * 1000, # Multiply by a factor of 1000 to make it more realistic and enable testing virtual col v_pct_cpu_ready_delta_summation
:sys_uptime_absolute_latest => v
)
end
end

Expand All @@ -99,7 +101,7 @@
end

describe ".hour_to_range" do
it "works" do
it "determines range for hour" do
expect(Metric::Finders.hour_to_range("2010-04-14T21:00:00Z")).to eq(["2010-04-14T21:00:00Z", "2010-04-14T21:59:59Z"])
end
end
Expand Down
33 changes: 20 additions & 13 deletions spec/models/metric/helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
describe ".find_for_interval_name" do
before do
@time_profile = FactoryBot.create(:time_profile_utc)
@perf = FactoryBot.create(:metric_rollup_vm_daily,
:timestamp => "2010-04-14T00:00:00Z",
:time_profile => @time_profile
)
@perf = FactoryBot.create(
:metric_rollup_vm_daily,
:timestamp => "2010-04-14T00:00:00Z",
:time_profile => @time_profile
)
end
it "VimPerformanceDaily.find should return existing daily performances when a time_profile is passed" do
rec = Metric::Helper.find_for_interval_name("daily", @time_profile)
Expand All @@ -52,22 +53,28 @@
describe ".remove_duplicate_timestamps" do
let(:host) { FactoryBot.create(:host) }
let(:metric_rollup_1) do
FactoryBot.create(:metric_rollup,
:resource => host,
:timestamp => Time.zone.parse("2016-01-12T00:00:00.00000000"))
FactoryBot.create(
:metric_rollup,
:resource => host,
:timestamp => Time.zone.parse("2016-01-12T00:00:00.00000000")
)
end

# duplicate of metric_rollup_1
let(:metric_rollup_2) do
FactoryBot.create(:metric_rollup,
:resource => host,
:timestamp => Time.zone.parse("2016-01-12T00:00:00.00000000"))
FactoryBot.create(
:metric_rollup,
:resource => host,
:timestamp => Time.zone.parse("2016-01-12T00:00:00.00000000")
)
end

let(:metric_rollup_3) do
FactoryBot.create(:metric_rollup,
:resource => host,
:timestamp => Time.zone.parse("2016-01-12T01:00:00.00000000"))
FactoryBot.create(
:metric_rollup,
:resource => host,
:timestamp => Time.zone.parse("2016-01-12T01:00:00.00000000")
)
end

it "returns only unique records" do
Expand Down
6 changes: 3 additions & 3 deletions spec/models/metric/targets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
context "with vmware", :with_enabled_disabled_vmware do
it "finds enabled targets" do
targets = Metric::Targets.capture_ems_targets(@ems_vmware)
assert_infra_targets_enabled targets, %w(ManageIQ::Providers::Vmware::InfraManager::Vm ManageIQ::Providers::Vmware::InfraManager::Host ManageIQ::Providers::Vmware::InfraManager::Host ManageIQ::Providers::Vmware::InfraManager::Vm ManageIQ::Providers::Vmware::InfraManager::Host Storage)
assert_infra_targets_enabled targets, %w[ManageIQ::Providers::Vmware::InfraManager::Vm ManageIQ::Providers::Vmware::InfraManager::Host ManageIQ::Providers::Vmware::InfraManager::Host ManageIQ::Providers::Vmware::InfraManager::Vm ManageIQ::Providers::Vmware::InfraManager::Host Storage]
end

it "finds enabled targets excluding storages" do
targets = Metric::Targets.capture_ems_targets(@ems_vmware, :exclude_storages => true)
assert_infra_targets_enabled targets, %w(ManageIQ::Providers::Vmware::InfraManager::Vm ManageIQ::Providers::Vmware::InfraManager::Host ManageIQ::Providers::Vmware::InfraManager::Host ManageIQ::Providers::Vmware::InfraManager::Vm ManageIQ::Providers::Vmware::InfraManager::Host)
assert_infra_targets_enabled targets, %w[ManageIQ::Providers::Vmware::InfraManager::Vm ManageIQ::Providers::Vmware::InfraManager::Host ManageIQ::Providers::Vmware::InfraManager::Host ManageIQ::Providers::Vmware::InfraManager::Vm ManageIQ::Providers::Vmware::InfraManager::Host]
end
end

context "with openstack", :with_openstack_and_availability_zones do
it "finds enabled targets" do
targets = Metric::Targets.capture_ems_targets(@ems_openstack)
assert_cloud_targets_enabled targets, %w(ManageIQ::Providers::Openstack::CloudManager::Vm ManageIQ::Providers::Openstack::CloudManager::Vm ManageIQ::Providers::Openstack::CloudManager::Vm ManageIQ::Providers::Openstack::CloudManager::Vm ManageIQ::Providers::Openstack::CloudManager::Vm)
assert_cloud_targets_enabled targets, %w[ManageIQ::Providers::Openstack::CloudManager::Vm ManageIQ::Providers::Openstack::CloudManager::Vm ManageIQ::Providers::Openstack::CloudManager::Vm ManageIQ::Providers::Openstack::CloudManager::Vm ManageIQ::Providers::Openstack::CloudManager::Vm]
end
end
end
Expand Down
40 changes: 20 additions & 20 deletions spec/models/metric_rollup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
# TODO: A fix in ActiveRecord will make this test pass
expect do
MetricRollup.where(:id => 1)
.includes(:resource => {}, :time_profile => {})
.references(:time_profile => {}).last
.includes(:resource => {}, :time_profile => {})
.references(:time_profile => {}).last
end.not_to raise_error

# TODO: Also, there is a bug that exists in only the manageiq repo and not rails
Expand Down Expand Up @@ -69,9 +69,9 @@
:resource_type => "VmOrTemplate",
:capture_interval_name => "hourly",
:intervals_in_rollup => 180,
:cpu_ready_delta_summation => 10604.0,
:cpu_used_delta_summation => 401296.0,
:cpu_wait_delta_summation => 6709070.0,
:cpu_ready_delta_summation => 10_604.0,
:cpu_used_delta_summation => 401_296.0,
:cpu_wait_delta_summation => 6_709_070.0,
}
perf = MetricRollup.new(pdata)

Expand All @@ -85,9 +85,9 @@
:resource_type => "VmOrTemplate",
:capture_interval_name => "daily",
:intervals_in_rollup => 24,
:cpu_ready_delta_summation => 10868.0833333333,
:cpu_used_delta_summation => 131611.583333333,
:cpu_wait_delta_summation => 6772579.45833333,
:cpu_ready_delta_summation => 10_868.0833333333,
:cpu_used_delta_summation => 131_611.583333333,
:cpu_wait_delta_summation => 6_772_579.45833333,
}
perf = MetricRollup.new(pdata)

Expand All @@ -102,9 +102,9 @@
:capture_interval_name => "hourly",
:intervals_in_rollup => 179,
:derived_vm_count_on => 6,
:cpu_ready_delta_summation => 54281.0,
:cpu_used_delta_summation => 2324833.0,
:cpu_wait_delta_summation => 36722174.0,
:cpu_ready_delta_summation => 54_281.0,
:cpu_used_delta_summation => 2_324_833.0,
:cpu_wait_delta_summation => 36_722_174.0,
}
perf = MetricRollup.new(pdata)

Expand All @@ -131,9 +131,9 @@
:capture_interval_name => "daily",
:intervals_in_rollup => 24,
:derived_vm_count_on => 6,
:cpu_ready_delta_summation => 50579.1666666667,
:cpu_used_delta_summation => 2180869.375,
:cpu_wait_delta_summation => 36918805.4166667,
:cpu_ready_delta_summation => 50_579.1666666667,
:cpu_used_delta_summation => 2_180_869.375,
:cpu_wait_delta_summation => 36_918_805.4166667,
}
perf = MetricRollup.new(pdata)

Expand All @@ -160,9 +160,9 @@
:capture_interval_name => "hourly",
:intervals_in_rollup => nil,
:derived_vm_count_on => 10,
:cpu_ready_delta_summation => 58783.0,
:cpu_used_delta_summation => 3668409.0,
:cpu_wait_delta_summation => 60426340.0,
:cpu_ready_delta_summation => 58_783.0,
:cpu_used_delta_summation => 3_668_409.0,
:cpu_wait_delta_summation => 60_426_340.0,
}
perf = MetricRollup.new(pdata)

Expand All @@ -189,9 +189,9 @@
:capture_interval_name => "daily",
:intervals_in_rollup => 24,
:derived_vm_count_on => 10,
:cpu_ready_delta_summation => 54120.0833333333,
:cpu_used_delta_summation => 3209660.54166667,
:cpu_wait_delta_summation => 60868270.1666667,
:cpu_ready_delta_summation => 54_120.0833333333,
:cpu_used_delta_summation => 3_209_660.54166667,
:cpu_wait_delta_summation => 60_868_270.1666667,
}
perf = MetricRollup.new(pdata)

Expand Down
6 changes: 3 additions & 3 deletions spec/support/metric_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def assert_metric_targets(expected_targets)
t.kind_of?(Storage) ? [[t, "hourly"]] : [[t, "realtime"]] + [[t, "historical"]] * 8
end
selected = queue_intervals(
MiqQueue.where(:method_name => %w(perf_capture_hourly perf_capture_realtime perf_capture_historical)))
MiqQueue.where(:method_name => %w[perf_capture_hourly perf_capture_realtime perf_capture_historical])
)

expect(selected).to match_array(expected)
end
Expand All @@ -25,8 +26,7 @@ def queue_intervals(items)
end
end


# expecting to have setup:
# These contexts expect the following setup:
#
# before do
# MiqRegion.seed
Expand Down

0 comments on commit f511115

Please sign in to comment.