forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup_spec.rb
699 lines (596 loc) · 29 KB
/
rollup_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
describe Metric::CiMixin::Rollup do
before do
MiqRegion.seed
@zone = EvmSpecHelper.local_miq_server.zone
end
describe ".perf_rollup" do
context "with enabled and disabled targets", :with_enabled_disabled_vmware do
context "executing perf_capture_timer" do
before do
@expected_targets = all_targets
stub_settings_merge(:performance => {:history => {:initial_capture_days => 7}})
Metric::Capture.perf_capture_timer(@ems_vmware.id)
end
context "executing capture_ems_targets for realtime targets with parent objects" do
before do
@expected_targets = Metric::Targets.capture_ems_targets(@ems_vmware)
end
it "should create tasks and queue callbacks for perf_capture_timer" do
# stub_settings_merge(:performance => {:history => {:initial_capture_days => 7}})
# Metric::Capture.perf_capture_timer(@ems_vmware.id)
@vmware_clusters.each do |cluster|
expected_hosts = cluster.hosts.select { |h| @expected_targets.include?(h) }
next if expected_hosts.empty?
task = MiqTask.find_by(:name => "Performance rollup for EmsCluster:#{cluster.id}")
expect(task).not_to be_nil
expect(task.context_data[:targets]).to match_array(cluster.hosts.collect { |h| "ManageIQ::Providers::Vmware::InfraManager::Host:#{h.id}" })
expected_hosts.each do |host|
messages = MiqQueue.where(:class_name => 'ManageIQ::Providers::Vmware::InfraManager::Host',
:instance_id => host.id,
:method_name => "perf_capture_realtime")
expect(messages.size).to eq(1)
messages.each do |m|
expect(m.miq_callback).not_to be_nil
expect(m.miq_callback[:method_name]).to eq(:perf_capture_callback)
expect(m.miq_callback[:args]).to eq([[task.id]])
m.delivered("ok", "Message delivered successfully", nil)
end
end
task.reload
expect(task.state).to eq("Finished")
message = MiqQueue.find_by(:method_name => "perf_rollup_range", :class_name => "EmsCluster", :instance_id => cluster.id)
expect(message).not_to be_nil
expect(message.args).to eq([task.context_data[:start], task.context_data[:end], task.context_data[:interval], nil])
end
end
it "calling perf_capture_timer when existing capture messages are on the queue should merge messages and append new task id to cb args" do
# stub_settings_merge(:performance => {:history => {:initial_capture_days => 7}})
# Metric::Capture.perf_capture_timer(@ems_vmware.id)
Metric::Capture.perf_capture_timer(@ems_vmware.id)
@vmware_clusters.each do |cluster|
expected_hosts = cluster.hosts.select { |h| @expected_targets.include?(h) }
next if expected_hosts.empty?
tasks = MiqTask.where(:name => "Performance rollup for EmsCluster:#{cluster.id}").order("id DESC")
expect(tasks.length).to eq(2)
tasks.each do |task|
expect(task.context_data[:targets]).to match_array(cluster.hosts.collect { |h| "ManageIQ::Providers::Vmware::InfraManager::Host:#{h.id}" })
end
task_ids = tasks.collect(&:id)
expected_hosts.each do |host|
messages = MiqQueue.where(:class_name => 'ManageIQ::Providers::Vmware::InfraManager::Host',
:instance_id => host.id,
:method_name => "perf_capture_realtime")
expect(messages.size).to eq(1)
host.update_attribute(:last_perf_capture_on, 1.minute.from_now.utc)
messages.each do |m|
next if m.miq_callback[:args].blank?
expect(m.miq_callback).not_to be_nil
expect(m.miq_callback[:method_name]).to eq(:perf_capture_callback)
expect(m.miq_callback[:args].first.sort).to eq(task_ids.sort)
status, message, result = m.deliver
m.delivered(status, message, result)
end
end
tasks.each do |task|
task.reload
expect(task.state).to eq("Finished")
end
end
end
it "calling perf_capture_timer a second time should create another task with the correct time window" do
# Metric::Capture.perf_capture_timer(@ems_vmware.id)
Metric::Capture.perf_capture_timer(@ems_vmware.id)
@vmware_clusters.each do |cluster|
expected_hosts = cluster.hosts.select { |h| @expected_targets.include?(h) }
next if expected_hosts.empty?
tasks = MiqTask.where(:name => "Performance rollup for EmsCluster:#{cluster.id}").order("id")
expect(tasks.length).to eq(2)
t1, t2 = tasks
expect(t2.context_data[:start]).to eq(t1.context_data[:end])
end
end
end
end
end
context "with Vm realtime performances", :with_small_vmware do
before do
cases = {
"2010-04-14T20:52:30Z" => 100.0,
"2010-04-14T21:51:10Z" => 1.0,
"2010-04-14T21:51:30Z" => 2.0,
"2010-04-14T21:51:50Z" => 4.0,
"2010-04-14T21:52:10Z" => 8.0,
"2010-04-14T21:52:30Z" => 15.0,
"2010-04-14T22:52:30Z" => 100.0,
}
cases.each 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
)
end
end
## MetricRollup ci/rollup.perf_rollup
context "calling perf_rollup to hourly on the Vm" do
before do
@vm1.perf_rollup("2010-04-14T21:00:00Z", 'hourly')
end
it "should rollup Vm realtime into Vm hourly rows correctly" do
expect(MetricRollup.hourly.count).to eq(1)
perf = MetricRollup.hourly.first
expect(perf.resource_type).to eq('VmOrTemplate')
expect(perf.resource_id).to eq(@vm1.id)
expect(perf.capture_interval_name).to eq('hourly')
expect(perf.timestamp.iso8601).to eq("2010-04-14T21:00:00Z")
expect(perf.cpu_usage_rate_average).to eq(6.0)
expect(perf.cpu_ready_delta_summation).to eq(30_000.0)
expect(perf.v_pct_cpu_ready_delta_summation).to eq(30.0)
expect(perf.sys_uptime_absolute_latest).to eq(15.0)
expect(perf.abs_max_cpu_usage_rate_average_value).to eq(15.0)
expect(perf.abs_max_cpu_usage_rate_average_timestamp.utc.iso8601).to eq("2010-04-14T21:52:30Z")
expect(perf.abs_min_cpu_usage_rate_average_value).to eq(1.0)
expect(perf.abs_min_cpu_usage_rate_average_timestamp.utc.iso8601).to eq("2010-04-14T21:51:10Z")
end
end
end
context "with Vm hourly performances", :with_small_vmware do
before do
cases = {
"2010-04-13T21:00:00Z" => 100.0,
"2010-04-14T18:00:00Z" => 1.0,
"2010-04-14T19:00:00Z" => 2.0,
"2010-04-14T20:00:00Z" => 4.0,
"2010-04-14T21:00:00Z" => 8.0,
"2010-04-14T22:00:00Z" => 15.0,
"2010-04-15T21:00:00Z" => 100.0,
}
cases.each do |t, v|
@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
context "calling perf_rollup to daily on the Vm" do
before do
@vm1.perf_rollup("2010-04-14T00:00:00Z", 'daily', @time_profile.id)
end
it "should rollup Vm hourly into Vm daily rows correctly" do
expect(MetricRollup.daily.count).to eq(1)
perf = MetricRollup.daily.first
expect(perf.resource_type).to eq('VmOrTemplate')
expect(perf.resource_id).to eq(@vm1.id)
expect(perf.capture_interval_name).to eq('daily')
expect(perf.timestamp.iso8601).to eq("2010-04-14T00:00:00Z")
expect(perf.time_profile_id).to eq(@time_profile.id)
expect(perf.cpu_usage_rate_average).to eq(6.0)
expect(perf.cpu_ready_delta_summation).to eq(60_000.0) # actually uses average
expect(perf.v_pct_cpu_ready_delta_summation).to eq(1.7)
expect(perf.sys_uptime_absolute_latest).to eq(6.0) # actually uses average
expect(perf.max_cpu_usage_rate_average).to eq(15.0)
expect(perf.abs_max_cpu_usage_rate_average_value).to eq(15.0)
expect(perf.abs_max_cpu_usage_rate_average_timestamp.utc.iso8601).to eq("2010-04-14T22:00:20Z")
expect(perf.min_cpu_usage_rate_average).to eq(1.0)
expect(perf.abs_min_cpu_usage_rate_average_value).to eq(1.0)
expect(perf.abs_min_cpu_usage_rate_average_timestamp.utc.iso8601).to eq("2010-04-14T18:00:40Z")
end
it "will have created an operating range" do
vpors = @vm1.vim_performance_operating_ranges
expect(vpors.size).to eq(1)
expect(vpors.first.time_profile).to eq(@time_profile)
end
end
context "calling perf_rollup_range to daily on the Vm" do
before do
@vm1.perf_rollup_range("2010-04-13T00:00:00Z", "2010-04-15T00:00:00Z", 'daily', @time_profile.id)
end
it "should rollup Vm hourly into Vm daily rows correctly" do
perfs = MetricRollup.daily
expect(perfs.length).to eq(3)
expect(perfs.collect { |r| r.timestamp.iso8601 }).to match_array(["2010-04-13T00:00:00Z", "2010-04-14T00:00:00Z", "2010-04-15T00:00:00Z"])
end
end
context "and Host realtime performances" do
before do
cases = {
"2010-04-14T20:52:40Z" => 100.0,
"2010-04-14T21:51:20Z" => 2.0,
"2010-04-14T21:51:40Z" => 4.0,
"2010-04-14T21:52:00Z" => 8.0,
"2010-04-14T21:52:20Z" => 16.0,
"2010-04-14T21:52:40Z" => 30.0,
"2010-04-14T22:52:40Z" => 100.0,
}
cases.each do |t, v|
@host1.metrics << FactoryBot.create(
:metric_host_rt,
:timestamp => t,
:cpu_usage_rate_average => v,
:cpu_usagemhz_rate_average => v,
:sys_uptime_absolute_latest => v
)
end
cases = {
"2010-04-14T20:52:40Z" => 200.0,
"2010-04-14T21:51:20Z" => 3.0,
"2010-04-14T21:51:40Z" => 8.0,
"2010-04-14T21:52:00Z" => 16.0,
"2010-04-14T21:52:20Z" => 32.0,
"2010-04-14T21:52:40Z" => 60.0,
"2010-04-14T22:52:40Z" => 200.0,
}
cases.each do |t, v|
@host2.metrics << FactoryBot.create(
:metric_host_rt,
:timestamp => t,
:cpu_usage_rate_average => v,
:cpu_usagemhz_rate_average => v,
:sys_uptime_absolute_latest => v
)
end
end
context "calling perf_rollup to hourly on the Host" do
before do
@host1.perf_rollup("2010-04-14T21:00:00Z", 'hourly')
end
it "should rollup Host realtime and Vm hourly into Host hourly rows correctly" do
expect(MetricRollup.hourly.where(:resource_type => 'Host', :resource_id => @host1.id).count).to eq(1)
perf = MetricRollup.hourly.where(:resource_type => 'Host', :resource_id => @host1.id).first
expect(perf.resource_type).to eq('Host')
expect(perf.resource_id).to eq(@host1.id)
expect(perf.capture_interval_name).to eq('hourly')
expect(perf.timestamp.iso8601).to eq("2010-04-14T21:00:00Z")
expect(perf.cpu_usage_rate_average).to eq(12.0) # pulled from Host realtime
expect(perf.cpu_ready_delta_summation).to eq(80_000.0) # pulled from Vm hourly
expect(perf.v_pct_cpu_ready_delta_summation).to eq(2.2)
expect(perf.sys_uptime_absolute_latest).to eq(30.0) # pulled from Host realtime
# NOTE: min / max / burst are only pulled in from Vm realtime.
end
end
context "calling perf_rollup_range to realtime on the parent Cluster" do
before do
@ems_cluster.perf_rollup_range("2010-04-14T21:51:20Z", "2010-04-14T21:52:40Z", 'realtime')
end
it "should rollup Host realtime Cluster realtime rows correctly" do
expect(Metric.where(:resource_type => 'EmsCluster', :resource_id => @ems_cluster.id).count).to eq(5)
perfs = Metric.where(:resource_type => 'EmsCluster', :resource_id => @ems_cluster.id).order("timestamp")
expect(perfs[0].resource_type).to eq('EmsCluster')
expect(perfs[0].resource_id).to eq(@ems_cluster.id)
expect(perfs[0].capture_interval_name).to eq('realtime')
expect(perfs[0].timestamp.iso8601).to eq("2010-04-14T21:51:20Z")
expect(perfs[0].cpu_usage_rate_average).to eq(2.5) # pulled from Host realtime
expect(perfs[0].cpu_usagemhz_rate_average).to eq(5.0) # pulled from Host realtime
expect(perfs[0].sys_uptime_absolute_latest).to eq(3.0) # pulled from Host realtime
expect(perfs[0].derived_cpu_available).to eq(19_152)
expect(perfs[2].cpu_usage_rate_average).to eq(12.0) # pulled from Host realtime
expect(perfs[2].cpu_usagemhz_rate_average).to eq(24.0) # pulled from Host realtime
expect(perfs[2].sys_uptime_absolute_latest).to eq(16.0) # pulled from Host realtime
expect(perfs[2].derived_cpu_available).to eq(19_152)
expect(perfs[3].cpu_usage_rate_average).to eq(24.0) # pulled from Host realtime
expect(perfs[3].cpu_usagemhz_rate_average).to eq(48.0) # pulled from Host realtime
expect(perfs[3].sys_uptime_absolute_latest).to eq(32.0) # pulled from Host realtime
expect(perfs[3].derived_cpu_available).to eq(19_152)
end
end
end
end
end
describe "perf_rollup_gap" do
context "with a small environment and time_profile" do
before do
@vm1 = FactoryBot.create(:vm_vmware)
@vm2 = FactoryBot.create(:vm_vmware, :hardware => FactoryBot.create(:hardware, :cpu1x2, :memory_mb => 4096))
@host1 = FactoryBot.create(:host, :hardware => FactoryBot.create(:hardware, :memory_mb => 8124, :cpu_total_cores => 1, :cpu_speed => 9576), :vms => [@vm1])
@host2 = FactoryBot.create(:host, :hardware => FactoryBot.create(:hardware, :memory_mb => 8124, :cpu_total_cores => 1, :cpu_speed => 9576))
@ems_cluster = FactoryBot.create(:ems_cluster, :ext_management_system => @ems_vmware)
@ems_cluster.hosts << @host1
@ems_cluster.hosts << @host2
@time_profile = FactoryBot.create(:time_profile_utc)
MiqQueue.delete_all
end
context "with Vm hourly performances" do
before do
cases = {
"2010-04-13T21:00:00Z" => 100.0,
"2010-04-14T18:00:00Z" => 1.0,
"2010-04-14T19:00:00Z" => 2.0,
"2010-04-14T20:00:00Z" => 4.0,
"2010-04-14T21:00:00Z" => 8.0,
"2010-04-14T22:00:00Z" => 15.0,
"2010-04-15T21:00:00Z" => 100.0,
}
cases.each do |t, v|
@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
context "and Host realtime performances" do
before do
cases = {
"2010-04-14T20:52:40Z" => 100.0,
"2010-04-14T21:51:20Z" => 2.0,
"2010-04-14T21:51:40Z" => 4.0,
"2010-04-14T21:52:00Z" => 8.0,
"2010-04-14T21:52:20Z" => 16.0,
"2010-04-14T21:52:40Z" => 30.0,
"2010-04-14T22:52:40Z" => 100.0,
}
cases.each do |t, v|
@host1.metrics << FactoryBot.create(
:metric_host_rt,
:timestamp => t,
:cpu_usage_rate_average => v,
:cpu_usagemhz_rate_average => v,
:sys_uptime_absolute_latest => v
)
end
cases = [
"2010-04-14T20:52:40Z", 200.0,
"2010-04-14T21:51:20Z", 3.0,
"2010-04-14T21:51:40Z", 8.0,
"2010-04-14T21:52:00Z", 16.0,
"2010-04-14T21:52:20Z", 32.0,
"2010-04-14T21:52:40Z", 60.0,
"2010-04-14T22:52:40Z", 200.0,
]
cases.each_slice(2) do |t, v|
@host2.metrics << FactoryBot.create(
:metric_host_rt,
:timestamp => t,
:cpu_usage_rate_average => v,
:cpu_usagemhz_rate_average => v,
:sys_uptime_absolute_latest => v
)
end
end
context "executing perf_rollup_gap_queue" do
before do
@args = [2.days.ago.utc, Time.now.utc, 'daily', @time_profile.id]
Metric::Rollup.perf_rollup_gap_queue(*@args)
end
it "should queue up perf_rollup_gap" do
q_all = MiqQueue.order(:class_name)
expect(q_all.length).to eq(1)
expected = {
:args => @args,
:class_name => "Metric::Rollup",
:method_name => "perf_rollup_gap",
:role => nil
}
expect(q_all[0]).to have_attributes(expected)
end
end
context "executing perf_rollup_gap" do
before do
@args = [2.days.ago.utc, Time.now.utc, 'daily', @time_profile.id]
Metric::Rollup.perf_rollup_gap(*@args)
end
it "should queue up the rollups" do
expect(MiqQueue.count).to eq(3)
[@host1, @host2, @vm1].each do |ci|
message = MiqQueue.where(:class_name => ci.class.name, :instance_id => ci.id).first
expect(message).to have_attributes(:method_name => "perf_rollup_range", :args => @args)
end
end
end
end
end
end
end
describe ".perf_rollup_to_parents" do
context "as vmware" do
before do
@ems_vmware = FactoryBot.create(:ems_vmware, :zone => @zone)
@vm = FactoryBot.create(:vm_perf, :ext_management_system => @ems_vmware)
end
it "should have queued rollups for vm hourly" do
MiqQueue.delete_all
@vm.perf_rollup_to_parents("realtime", "2010-04-14T21:51:10Z", "2010-04-14T22:50:50Z")
q_all = MiqQueue.order(:id)
expect(q_all.length).to eq(2)
assert_queue_items_are_hourly_rollups(q_all, "2010-04-14T21:00:00Z", @vm.id, "ManageIQ::Providers::Vmware::InfraManager::Vm")
end
it "should have one set of queued rollups when rolled up twice" do
MiqQueue.delete_all
@vm.perf_rollup_to_parents("realtime", "2010-04-14T21:51:10Z", "2010-04-14T22:50:50Z")
@vm.perf_rollup_to_parents("realtime", "2010-04-14T21:51:10Z", "2010-04-14T22:50:50Z")
q_all = MiqQueue.order(:id)
expect(q_all.length).to eq(2)
assert_queue_items_are_hourly_rollups(q_all, "2010-04-14T21:00:00Z", @vm.id, "ManageIQ::Providers::Vmware::InfraManager::Vm")
end
it "queues service rollups" do
service = FactoryBot.create(:service)
service.add_resource(@vm)
service.save
MiqQueue.delete_all
@vm.perf_rollup_to_parents("hourly", "2010-04-14T21:51:10Z", "2010-04-14T22:50:50Z")
expect(MiqQueue.all.pluck(:class_name).uniq).to eq(%w[Service])
end
end
context "with a full vmware rollup chain and time profile" do
before do
@ems_vmware = FactoryBot.create(:ems_vmware, :zone => @zone)
@host = FactoryBot.create(:host, :ext_management_system => @ems_vmware)
@vm = FactoryBot.create(:vm_vmware, :ext_management_system => @ems_vmware, :host => @host)
@ems_cluster = FactoryBot.create(:ems_cluster, :ext_management_system => @ems_vmware)
@ems_cluster.hosts << @host
@time_profile = FactoryBot.create(:time_profile_utc)
MiqQueue.delete_all
end
it "should queue up from Vm realtime to Vm hourly" do
@vm.perf_rollup_to_parents('realtime', rollup_chain_timestamp)
q_all = MiqQueue.order(:id)
expect(q_all.length).to eq(1)
assert_queue_item_rollup_chain(q_all[0], @vm, 'hourly')
end
it "should queue up from Host realtime to Host hourly" do
@host.perf_rollup_to_parents('realtime', rollup_chain_timestamp)
q_all = MiqQueue.order(:id)
expect(q_all.length).to eq(1)
assert_queue_item_rollup_chain(q_all[0], @host, 'hourly')
end
it "should queue up from Vm hourly to Host hourly and Vm daily" do
@vm.perf_rollup_to_parents('hourly', rollup_chain_timestamp)
q_all = MiqQueue.order(:id)
expect(q_all.length).to eq(2)
assert_queue_item_rollup_chain(q_all[0], @host, 'hourly')
assert_queue_item_rollup_chain(q_all[1], @vm, 'daily', @time_profile)
end
it "should queue up from Host hourly to EmsCluster hourly and Host daily" do
@host.perf_rollup_to_parents('hourly', rollup_chain_timestamp)
q_all = MiqQueue.order(:id)
expect(q_all.length).to eq(2)
assert_queue_item_rollup_chain(q_all[0], @ems_cluster, 'hourly')
assert_queue_item_rollup_chain(q_all[1], @host, 'daily', @time_profile)
end
it "should queue up from EmsCluster hourly to EMS hourly and EmsCluster daily" do
@ems_cluster.perf_rollup_to_parents('hourly', rollup_chain_timestamp)
q_all = MiqQueue.order(:id)
expect(q_all.length).to eq(2)
assert_queue_item_rollup_chain(q_all[0], @ems_vmware, 'hourly')
assert_queue_item_rollup_chain(q_all[1], @ems_cluster, 'daily', @time_profile)
end
it "should queue up from Vm daily to nothing" do
@vm.perf_rollup_to_parents('daily', rollup_chain_timestamp)
expect(MiqQueue.count).to eq(0)
end
it "should queue up from Host daily to nothing" do
@host.perf_rollup_to_parents('daily', rollup_chain_timestamp)
expect(MiqQueue.count).to eq(0)
end
it "should queue up from EmsCluster daily to nothing" do
@ems_cluster.perf_rollup_to_parents('daily', rollup_chain_timestamp)
expect(MiqQueue.count).to eq(0)
end
it "should queue up from EMS daily to nothing" do
@ems_vmware.perf_rollup_to_parents('daily', rollup_chain_timestamp)
expect(MiqQueue.count).to eq(0)
end
end
context "as openstack" do
before do
@ems_openstack = FactoryBot.create(:ems_openstack, :zone => @zone)
@vm = FactoryBot.create(:vm_perf_openstack, :ext_management_system => @ems_openstack)
end
context "queueing up realtime rollups to parent" do
before do
MiqQueue.delete_all
@vm.perf_rollup_to_parents("realtime", "2010-04-14T21:51:10Z", "2010-04-14T22:50:50Z")
end
it "should have queued rollups for vm hourly" do
q_all = MiqQueue.order(:id)
expect(q_all.length).to eq(2)
assert_queue_items_are_hourly_rollups(q_all, "2010-04-14T21:00:00Z", @vm.id, "ManageIQ::Providers::Openstack::CloudManager::Vm")
end
context "twice" do
before do
@vm.perf_rollup_to_parents("realtime", "2010-04-14T21:51:10Z", "2010-04-14T22:50:50Z")
end
it "should have one set of queued rollups" do
q_all = MiqQueue.order(:id)
expect(q_all.length).to eq(2)
assert_queue_items_are_hourly_rollups(q_all, "2010-04-14T21:00:00Z", @vm.id, "ManageIQ::Providers::Openstack::CloudManager::Vm")
end
end
end
end
context "with a full openstack rollup chain and time profile" do
before do
@ems_openstack = FactoryBot.create(:ems_openstack, :zone => @zone)
@availability_zone = FactoryBot.create(:availability_zone, :ext_management_system => @ems_openstack)
@vm = FactoryBot.create(:vm_openstack, :ext_management_system => @ems_openstack, :availability_zone => @availability_zone)
@time_profile = FactoryBot.create(:time_profile_utc)
MiqQueue.delete_all
end
it "should queue up from Vm realtime to Vm hourly" do
@vm.perf_rollup_to_parents('realtime', rollup_chain_timestamp)
q_all = MiqQueue.order(:id)
expect(q_all.length).to eq(1)
assert_queue_item_rollup_chain(q_all[0], @vm, 'hourly')
end
it "should queue up from AvailabilityZone realtime to AvailabilityZone hourly" do
@availability_zone.perf_rollup_to_parents('realtime', rollup_chain_timestamp)
q_all = MiqQueue.order(:id)
expect(q_all.length).to eq(1)
assert_queue_item_rollup_chain(q_all[0], @availability_zone, 'hourly')
end
it "should queue up from Vm hourly to AvailabilityZone hourly and Vm daily" do
@vm.perf_rollup_to_parents('hourly', rollup_chain_timestamp)
q_all = MiqQueue.order(:id)
expect(q_all.length).to eq(2)
assert_queue_item_rollup_chain(q_all[0], @availability_zone, 'hourly')
assert_queue_item_rollup_chain(q_all[1], @vm, 'daily', @time_profile)
end
it "should queue up from AvailabilityZone hourly to EMS hourly and AvailabilityZone daily" do
@availability_zone.perf_rollup_to_parents('hourly', rollup_chain_timestamp)
q_all = MiqQueue.order(:id)
expect(q_all.length).to eq(2)
assert_queue_item_rollup_chain(q_all[0], @ems_openstack, 'hourly')
assert_queue_item_rollup_chain(q_all[1], @availability_zone, 'daily', @time_profile)
end
it "should queue up from Vm daily to nothing" do
@vm.perf_rollup_to_parents('daily', rollup_chain_timestamp)
expect(MiqQueue.count).to eq(0)
end
it "should queue up from AvailabilityZone daily to nothing" do
@availability_zone.perf_rollup_to_parents('daily', rollup_chain_timestamp)
expect(MiqQueue.count).to eq(0)
end
it "should queue up from EMS daily to nothing" do
@ems_openstack.perf_rollup_to_parents('daily', rollup_chain_timestamp)
expect(MiqQueue.count).to eq(0)
end
end
end
private
def assert_queued_rollup(q_item, instance_id, class_name, args, deliver_on, method = "perf_rollup")
deliver_on = Time.parse(deliver_on).utc if deliver_on.kind_of?(String)
expect(q_item.method_name).to eq(method)
expect(q_item.instance_id).to eq(instance_id)
expect(q_item.class_name).to eq(class_name)
expect(q_item.args).to eq(args)
expect(q_item.deliver_on.utc).to eq(deliver_on) unless deliver_on.nil?
end
def assert_queue_items_are_hourly_rollups(q_items, first_time, instance_id, class_name)
ts = first_time.kind_of?(Time) ? first_time.utc.iso8601 : first_time
q_items.each do |q|
assert_queued_rollup(q, instance_id, class_name, [ts, "hourly"], Time.parse(ts).utc + 1.hour)
ts = (Time.parse(ts).utc + 1.hour).iso8601
end
end
let(:rollup_chain_timestamp) { "2011-08-12T20:33:20Z" }
def assert_queue_item_rollup_chain(q_item, obj, interval_name, time_profile = nil)
case interval_name
when 'realtime'
values = [["2011-08-12T20:33:20Z", nil, 'realtime', nil], nil, "perf_rollup_range"]
when 'hourly'
values = [["2011-08-12T20:00:00Z", 'hourly'], "2011-08-12T21:00:00Z"]
when 'daily'
values = [["2011-08-12T00:00:00Z", 'daily', time_profile.id], "2011-08-13T00:00:00Z"]
end
assert_queued_rollup(q_item, obj.id, obj.class.name, *values)
end
end