@@ -736,12 +736,12 @@ public void testHostNetworkWriteRuleDoesNotFireBelowThreshold() {
736736
737737 private ResourceAlertRuleVO volumeSizeRule (double thresholdGb ) {
738738 return new ResourceAlertRuleVO ("vol" , ResourceAlertRule .ResourceType .Volume ,
739- VOLUME_ID , 1L , 1L , "VOLUME_SIZE_GB " , AlertCondition .GT , thresholdGb ,
739+ VOLUME_ID , 1L , 1L , "VOLUME_USED_GB " , AlertCondition .GT , thresholdGb ,
740740 AlertSeverity .MEDIUM , null , false , 600 );
741741 }
742742
743743 @ Test
744- public void testVolumeSizeRuleUsesPhysicalSizeByPath () {
744+ public void testVolumeUsedRuleUsesPhysicalSizeByPath () {
745745 when (ruleDao .listActive ()).thenReturn (Collections .singletonList (volumeSizeRule (10.0 )));
746746 VolumeVO vol = mock (VolumeVO .class );
747747 when (vol .getFormat ()).thenReturn (Storage .ImageFormat .QCOW2 );
@@ -759,7 +759,29 @@ public void testVolumeSizeRuleUsesPhysicalSizeByPath() {
759759 }
760760
761761 @ Test
762- public void testVolumeSizeRuleUsesChainInfoForOva () {
762+ public void testVolumeUtilizationIsUsedOverDiskSize () {
763+ ResourceAlertRuleVO rule = new ResourceAlertRuleVO ("vol-pct" , ResourceAlertRule .ResourceType .Volume ,
764+ VOLUME_ID , 1L , 1L , "VOLUME_UTILIZATION" , AlertCondition .GT , 50.0 ,
765+ AlertSeverity .MEDIUM , null , false , 600 );
766+ when (ruleDao .listActive ()).thenReturn (Collections .singletonList (rule ));
767+ VolumeVO vol = mock (VolumeVO .class );
768+ when (vol .getFormat ()).thenReturn (Storage .ImageFormat .QCOW2 );
769+ when (vol .getState ()).thenReturn (Volume .State .Ready );
770+ when (vol .getPath ()).thenReturn ("vol-path" );
771+ when (volumeDao .findById (VOLUME_ID )).thenReturn (vol );
772+ VolumeStats stats = mock (VolumeStats .class );
773+ when (stats .getPhysicalSize ()).thenReturn (6L * 1024 * 1024 * 1024 );
774+ when (stats .getVirtualSize ()).thenReturn (8L * 1024 * 1024 * 1024 );
775+ when (statsCollector .getVolumeStats ("vol-path" )).thenReturn (stats );
776+
777+ manager .evaluateRules ();
778+
779+ verify (alertDao ).persist (alertCaptor .capture ());
780+ assertEquals (75.0 , alertCaptor .getValue ().getMetricValue (), 0.001 );
781+ }
782+
783+ @ Test
784+ public void testVolumeUsedRuleUsesChainInfoForOva () {
763785 when (ruleDao .listActive ()).thenReturn (Collections .singletonList (volumeSizeRule (10.0 )));
764786 VolumeVO vol = mock (VolumeVO .class );
765787 when (vol .getFormat ()).thenReturn (Storage .ImageFormat .OVA );
@@ -847,7 +869,7 @@ public void testGenericRuleScopeForUserIsOwnAccount() {
847869 @ Test
848870 public void testGenericVolumeRuleForRootAdminListsReadyVolumesCloudWide () {
849871 ResourceAlertRuleVO rule = new ResourceAlertRuleVO ("vol" , ResourceAlertRule .ResourceType .Volume ,
850- null , 1L , 1L , "VOLUME_SIZE_GB " , AlertCondition .GT , 10.0 , AlertSeverity .LOW , null , false , 600 );
872+ null , 1L , 1L , "VOLUME_USED_GB " , AlertCondition .GT , 10.0 , AlertSeverity .LOW , null , false , 600 );
851873 when (ruleDao .listActive ()).thenReturn (Collections .singletonList (rule ));
852874 stubOwner (Account .Type .ADMIN );
853875
0 commit comments