@@ -51,7 +51,7 @@ func (a *AnalyzeHostBlockDevices) Analyze(getCollectedFileContents func(string)
5151 return & result , nil
5252 }
5353
54- isMatch , err := compareHostBlockDevicesConditionalToActual (outcome .Fail .When , devices )
54+ isMatch , err := compareHostBlockDevicesConditionalToActual (outcome .Fail .When , hostAnalyzer . MinimumAcceptableSize , hostAnalyzer . IncludeUnmountedPartitions , devices )
5555 if err != nil {
5656 return nil , errors .Wrapf (err , "failed to compare %s" , outcome .Fail .When )
5757 }
@@ -72,7 +72,7 @@ func (a *AnalyzeHostBlockDevices) Analyze(getCollectedFileContents func(string)
7272 return & result , nil
7373 }
7474
75- isMatch , err := compareHostBlockDevicesConditionalToActual (outcome .Warn .When , devices )
75+ isMatch , err := compareHostBlockDevicesConditionalToActual (outcome .Warn .When , hostAnalyzer . MinimumAcceptableSize , hostAnalyzer . IncludeUnmountedPartitions , devices )
7676 if err != nil {
7777 return nil , errors .Wrapf (err , "failed to compare %s" , outcome .Warn .When )
7878 }
@@ -93,7 +93,7 @@ func (a *AnalyzeHostBlockDevices) Analyze(getCollectedFileContents func(string)
9393 return & result , nil
9494 }
9595
96- isMatch , err := compareHostBlockDevicesConditionalToActual (outcome .Pass .When , devices )
96+ isMatch , err := compareHostBlockDevicesConditionalToActual (outcome .Pass .When , hostAnalyzer . MinimumAcceptableSize , hostAnalyzer . IncludeUnmountedPartitions , devices )
9797 if err != nil {
9898 return nil , errors .Wrapf (err , "failed to compare %s" , outcome .Pass .When )
9999 }
@@ -113,7 +113,7 @@ func (a *AnalyzeHostBlockDevices) Analyze(getCollectedFileContents func(string)
113113
114114// <regexp> <op> <count>
115115// example: sdb > 0
116- func compareHostBlockDevicesConditionalToActual (conditional string , devices []collect.BlockDeviceInfo ) (res bool , err error ) {
116+ func compareHostBlockDevicesConditionalToActual (conditional string , minimumAcceptableSize uint64 , includeUnmountedPartitions bool , devices []collect.BlockDeviceInfo ) (res bool , err error ) {
117117 parts := strings .Split (conditional , " " )
118118 if len (parts ) != 3 {
119119 return false , fmt .Errorf ("Expected exactly 3 parts, got %d" , len (parts ))
@@ -123,7 +123,7 @@ func compareHostBlockDevicesConditionalToActual(conditional string, devices []co
123123 if err != nil {
124124 return false , errors .Wrapf (err , "failed to compile regex %q" , parts [0 ])
125125 }
126- count := countEligibleBlockDevices (rx , devices )
126+ count := countEligibleBlockDevices (rx , minimumAcceptableSize , includeUnmountedPartitions , devices )
127127
128128 desiredInt , err := strconv .Atoi (parts [2 ])
129129 if err != nil {
@@ -146,25 +146,37 @@ func compareHostBlockDevicesConditionalToActual(conditional string, devices []co
146146 return false , fmt .Errorf ("Unexpected operator %q" , parts [1 ])
147147}
148148
149- func countEligibleBlockDevices (rx * regexp.Regexp , devices []collect.BlockDeviceInfo ) int {
149+ func countEligibleBlockDevices (rx * regexp.Regexp , minimumAcceptableSize uint64 , includeUnmountedPartitions bool , devices []collect.BlockDeviceInfo ) int {
150150 count := 0
151151
152152 for _ , device := range devices {
153- if isEligibleBlockDevice (rx , device , devices ) {
153+ if isEligibleBlockDevice (rx , minimumAcceptableSize , includeUnmountedPartitions , device , devices ) {
154154 count ++
155155 }
156156 }
157157
158158 return count
159159}
160160
161- func isEligibleBlockDevice (rx * regexp.Regexp , device collect.BlockDeviceInfo , devices []collect.BlockDeviceInfo ) bool {
161+ func isEligibleBlockDevice (rx * regexp.Regexp , minimumAcceptableSize uint64 , includeUnmountedPartitions bool , device collect.BlockDeviceInfo , devices []collect.BlockDeviceInfo ) bool {
162162 if ! rx .MatchString (device .Name ) {
163163 return false
164164 }
165165
166- if device .Type != "disk" {
167- return false
166+ if includeUnmountedPartitions {
167+ if device .Type != "disk" && device .Type != "part" {
168+ return false
169+ }
170+ } else {
171+ if device .Type != "disk" {
172+ return false
173+ }
174+ }
175+
176+ if minimumAcceptableSize != 0 {
177+ if device .Size < minimumAcceptableSize {
178+ return false
179+ }
168180 }
169181
170182 if device .Mountpoint != "" {
0 commit comments