@@ -80,12 +80,11 @@ def testAppendLossFunctionWithDegradationPercent(self):
8080 FLAGS .maintenance_degradation_percent = 90
8181 vm_spec = mock .MagicMock (spec = benchmark_spec .BenchmarkSpec )
8282 self .trigger .trigger_time = datetime .datetime .fromtimestamp (2 )
83- self .trigger .disruption_events = []
84- self .enter_context (
85- mock .patch .object (
86- self .trigger , 'GetDisruptionEnds' , return_value = None , autospec = True
83+ self .trigger .disruption_events = [
84+ base_disruption_trigger .DisruptionEvent (
85+ start_time = 2 , end_time = 8 , total_time = 100
8786 )
88- )
87+ ]
8988 s = [
9089 sample .CreateTimeSeriesSample (
9190 [100 , 100 , 100 , 90 , 90 , 90 ],
@@ -111,6 +110,20 @@ def testAppendLossFunctionWithDegradationPercent(self):
111110 },
112111 timestamp = 0 ,
113112 ),
113+ sample .Sample (
114+ metric = 'LM Total Time' ,
115+ value = 100.0 ,
116+ unit = 'seconds' ,
117+ metadata = {
118+ 'values' : [100 , 100 , 100 , 90 , 90 , 90 ],
119+ 'timestamps' : [1000 , 2000 , 3000 , 4000 , 5000 , 6000 ],
120+ 'interval' : 1 ,
121+ 'LM_total_time' : 100 ,
122+ 'Host_maintenance_start' : 2 ,
123+ 'Host_maintenance_end' : 8 ,
124+ },
125+ timestamp = 0 ,
126+ ),
114127 sample .Sample (
115128 metric = 'seconds_dropped_below_0_percent' ,
116129 value = 0.0 ,
@@ -197,7 +210,7 @@ def testAppendLossFunctionWithDegradationPercent(self):
197210 ),
198211 sample .Sample (
199212 metric = 'total_missing_seconds' ,
200- value = 0 ,
213+ value = 0.0 ,
201214 unit = 's' ,
202215 metadata = {},
203216 timestamp = 0 ,
@@ -209,12 +222,11 @@ def testAppendLossFunctionWithDegradationPercent(self):
209222 def testAppendLossFunctionWithMissingTimeStampsWithRegression (self ):
210223 vm_spec = mock .MagicMock (spec = benchmark_spec .BenchmarkSpec )
211224 self .trigger .trigger_time = datetime .datetime .fromtimestamp (2 )
212- self .trigger .disruption_events = []
213- self .enter_context (
214- mock .patch .object (
215- self .trigger , 'GetDisruptionEnds' , return_value = None , autospec = True
225+ self .trigger .disruption_events = [
226+ base_disruption_trigger .DisruptionEvent (
227+ start_time = 2 , end_time = 8 , total_time = 100
216228 )
217- )
229+ ]
218230 s = [
219231 sample .CreateTimeSeriesSample (
220232 [100 , 100 , 20 , 100 ],
@@ -240,6 +252,20 @@ def testAppendLossFunctionWithMissingTimeStampsWithRegression(self):
240252 },
241253 timestamp = 0 ,
242254 ),
255+ sample .Sample (
256+ metric = 'LM Total Time' ,
257+ value = 100.0 ,
258+ unit = 'seconds' ,
259+ metadata = {
260+ 'values' : [100 , 100 , 20 , 100 ],
261+ 'timestamps' : [1000 , 2000 , 6000 , 7000 ],
262+ 'interval' : 1 ,
263+ 'LM_total_time' : 100 ,
264+ 'Host_maintenance_start' : 2 ,
265+ 'Host_maintenance_end' : 8 ,
266+ },
267+ timestamp = 0 ,
268+ ),
243269 sample .Sample (
244270 metric = 'seconds_dropped_below_0_percent' ,
245271 value = 0.0 ,
@@ -337,12 +363,11 @@ def testAppendLossFunctionWithMissingTimeStampsWithRegression(self):
337363 @mock .patch .object (time , 'time' , mock .MagicMock (return_value = 0 ))
338364 def testAppendLossFunctionWithMissingTimeStampsNoRegression (self ):
339365 self .trigger .trigger_time = datetime .datetime .fromtimestamp (2 )
340- self .trigger .disruption_events = []
341- self .enter_context (
342- mock .patch .object (
343- self .trigger , 'GetDisruptionEnds' , return_value = None , autospec = True
366+ self .trigger .disruption_events = [
367+ base_disruption_trigger .DisruptionEvent (
368+ start_time = 2 , end_time = 8 , total_time = 100
344369 )
345- )
370+ ]
346371 vm_spec = mock .MagicMock (spec = benchmark_spec .BenchmarkSpec )
347372 s = [
348373 sample .CreateTimeSeriesSample (
@@ -369,6 +394,20 @@ def testAppendLossFunctionWithMissingTimeStampsNoRegression(self):
369394 },
370395 timestamp = 0 ,
371396 ),
397+ sample .Sample (
398+ metric = 'LM Total Time' ,
399+ value = 100.0 ,
400+ unit = 'seconds' ,
401+ metadata = {
402+ 'values' : [1 , 1 , 4 , 1 ],
403+ 'timestamps' : [1000 , 2000 , 6000 , 7000 ],
404+ 'interval' : 1 ,
405+ 'LM_total_time' : 100 ,
406+ 'Host_maintenance_start' : 2 ,
407+ 'Host_maintenance_end' : 8 ,
408+ },
409+ timestamp = 0 ,
410+ ),
372411 sample .Sample (
373412 metric = 'seconds_dropped_below_0_percent' ,
374413 value = 0.0 ,
@@ -455,7 +494,7 @@ def testAppendLossFunctionWithMissingTimeStampsNoRegression(self):
455494 ),
456495 sample .Sample (
457496 metric = 'total_missing_seconds' ,
458- value = 3 ,
497+ value = 3.0 ,
459498 unit = 's' ,
460499 metadata = {},
461500 timestamp = 0 ,
@@ -466,12 +505,11 @@ def testAppendLossFunctionWithMissingTimeStampsNoRegression(self):
466505 @mock .patch .object (time , 'time' , mock .MagicMock (return_value = 0 ))
467506 def testAppendLossFunctionSamples (self ):
468507 vm_spec = mock .MagicMock (spec = benchmark_spec .BenchmarkSpec )
469- self .trigger .disruption_events = []
470- self .enter_context (
471- mock .patch .object (
472- self .trigger , 'GetDisruptionEnds' , return_value = None , autospec = True
508+ self .trigger .disruption_events = [
509+ base_disruption_trigger .DisruptionEvent (
510+ start_time = 5 , end_time = 8 , total_time = 100
473511 )
474- )
512+ ]
475513 self .trigger .vms = [mock .MagicMock ()]
476514 s = sample .CreateTimeSeriesSample (
477515 [1 , 1 , 1 , 1 , 0 , 0.1 , 0.2 , 0.3 ],
@@ -481,6 +519,7 @@ def testAppendLossFunctionSamples(self):
481519 1 ,
482520 )
483521 samples = [s ]
522+
484523 self .trigger .trigger_time = datetime .datetime .fromtimestamp (4 )
485524 self .trigger .AppendSamples (None , vm_spec , samples )
486525 self .assertEqual (
@@ -506,6 +545,29 @@ def testAppendLossFunctionSamples(self):
506545 },
507546 timestamp = 0 ,
508547 ),
548+ sample .Sample (
549+ metric = 'LM Total Time' ,
550+ value = 100.0 ,
551+ unit = 'seconds' ,
552+ metadata = {
553+ 'values' : [1 , 1 , 1 , 1 , 0 , 0.1 , 0.2 , 0.3 ],
554+ 'timestamps' : [
555+ 1000 ,
556+ 2000 ,
557+ 3000 ,
558+ 4000 ,
559+ 5000 ,
560+ 6000 ,
561+ 7000 ,
562+ 8000 ,
563+ ],
564+ 'interval' : 1 ,
565+ 'LM_total_time' : 100 ,
566+ 'Host_maintenance_start' : 5 ,
567+ 'Host_maintenance_end' : 8 ,
568+ },
569+ timestamp = 0 ,
570+ ),
509571 sample .Sample (
510572 metric = 'seconds_dropped_below_0_percent' ,
511573 value = 1.0 ,
@@ -592,7 +654,7 @@ def testAppendLossFunctionSamples(self):
592654 ),
593655 sample .Sample (
594656 metric = 'total_missing_seconds' ,
595- value = 0 ,
657+ value = 0.0 ,
596658 unit = 's' ,
597659 metadata = {},
598660 timestamp = 0 ,
0 commit comments