Skip to content

Commit 6493064

Browse files
authored
Revert "feat: Add partition type info to block device collector" (#1121)
Revert "feat: Add partition type info to block device collector (#1063)" This reverts commit 6eb9c70.
1 parent 00a46b9 commit 6493064

File tree

3 files changed

+24
-36
lines changed

3 files changed

+24
-36
lines changed

pkg/analyze/host_block_devices.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (a *AnalyzeHostBlockDevices) Analyze(getCollectedFileContents func(string)
116116
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 {
119-
return false, fmt.Errorf("expected exactly 3 parts, got %d", len(parts))
119+
return false, fmt.Errorf("Expected exactly 3 parts, got %d", len(parts))
120120
}
121121

122122
rx, err := regexp.Compile(parts[0])
@@ -143,7 +143,7 @@ func compareHostBlockDevicesConditionalToActual(conditional string, minimumAccep
143143
return count == desiredInt, nil
144144
}
145145

146-
return false, fmt.Errorf("unexpected operator %q", parts[1])
146+
return false, fmt.Errorf("Unexpected operator %q", parts[1])
147147
}
148148

149149
func countEligibleBlockDevices(rx *regexp.Regexp, minimumAcceptableSize uint64, includeUnmountedPartitions bool, devices []collect.BlockDeviceInfo) int {

pkg/analyze/host_block_devices_test.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func TestAnalyzeBlockDevices(t *testing.T) {
158158
},
159159
},
160160
{
161-
name: ".* == 1, pass with unmounted partition",
161+
name: ".* > 1, pass with unmounted partition",
162162
devices: []collect.BlockDeviceInfo{
163163
{
164164
Name: "sdb",
@@ -175,21 +175,13 @@ func TestAnalyzeBlockDevices(t *testing.T) {
175175
Major: 8,
176176
Minor: 1,
177177
},
178-
{
179-
Name: "sdb2",
180-
KernelName: "sdb2",
181-
ParentKernelName: "sdb",
182-
Type: "crypto_LUKS",
183-
Major: 8,
184-
Size: 1024 * 1024 * 1024 * 5,
185-
},
186178
},
187179
hostAnalyzer: &troubleshootv1beta2.BlockDevicesAnalyze{
188180
IncludeUnmountedPartitions: true,
189181
Outcomes: []*troubleshootv1beta2.Outcome{
190182
{
191183
Pass: &troubleshootv1beta2.SingleOutcome{
192-
When: ".* == 1",
184+
When: ".* >= 1",
193185
Message: "Block device or partition available",
194186
},
195187
},
@@ -263,18 +255,21 @@ func TestAnalyzeBlockDevices(t *testing.T) {
263255
}
264256
for _, test := range tests {
265257
t.Run(test.name, func(t *testing.T) {
258+
req := require.New(t)
266259
b, err := json.Marshal(test.devices)
267-
require.NoError(t, err)
260+
if err != nil {
261+
t.Fatal(err)
262+
}
268263

269264
getCollectedFileContents := func(filename string) ([]byte, error) {
270265
return b, nil
271266
}
272267

273268
result, err := (&AnalyzeHostBlockDevices{test.hostAnalyzer}).Analyze(getCollectedFileContents)
274269
if test.expectErr {
275-
assert.Error(t, err)
270+
req.Error(err)
276271
} else {
277-
assert.NoError(t, err)
272+
req.NoError(err)
278273
}
279274

280275
assert.Equal(t, test.result, result)

pkg/collect/host_block_device.go

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,22 @@ import (
1313
)
1414

1515
type BlockDeviceInfo struct {
16-
Name string `json:"name"`
17-
KernelName string `json:"kernel_name"`
18-
ParentKernelName string `json:"parent_kernel_name"`
19-
Type string `json:"type"`
20-
Major int `json:"major"`
21-
Minor int `json:"minor"`
22-
Size uint64 `json:"size"`
23-
FilesystemType string `json:"filesystem_type"`
24-
Mountpoint string `json:"mountpoint"`
25-
Serial string `json:"serial"`
26-
ReadOnly bool `json:"read_only"`
27-
Removable bool `json:"removable"`
28-
PartitionTableType string `json:"partition_table_type"`
16+
Name string `json:"name"`
17+
KernelName string `json:"kernel_name"`
18+
ParentKernelName string `json:"parent_kernel_name"`
19+
Type string `json:"type"`
20+
Major int `json:"major"`
21+
Minor int `json:"minor"`
22+
Size uint64 `json:"size"`
23+
FilesystemType string `json:"filesystem_type"`
24+
Mountpoint string `json:"mountpoint"`
25+
Serial string `json:"serial"`
26+
ReadOnly bool `json:"read_only"`
27+
Removable bool `json:"removable"`
2928
}
3029

31-
const lsblkColumns = "NAME,KNAME,PKNAME,TYPE,MAJ:MIN,SIZE,FSTYPE,MOUNTPOINT,SERIAL,RO,RM,PTTYPE"
32-
const lsblkFormat = `NAME=%q KNAME=%q PKNAME=%q TYPE=%q MAJ:MIN="%d:%d" SIZE="%d" FSTYPE=%q MOUNTPOINT=%q SERIAL=%q RO="%d" RM="%d0" PTTYPE=%q`
30+
const lsblkColumns = "NAME,KNAME,PKNAME,TYPE,MAJ:MIN,SIZE,FSTYPE,MOUNTPOINT,SERIAL,RO,RM"
31+
const lsblkFormat = `NAME=%q KNAME=%q PKNAME=%q TYPE=%q MAJ:MIN="%d:%d" SIZE="%d" FSTYPE=%q MOUNTPOINT=%q SERIAL=%q RO="%d" RM="%d0"`
3332
const HostBlockDevicesPath = `host-collectors/system/block_devices.json`
3433

3534
type CollectHostBlockDevices struct {
@@ -46,11 +45,6 @@ func (c *CollectHostBlockDevices) IsExcluded() (bool, error) {
4645
}
4746

4847
func (c *CollectHostBlockDevices) Collect(progressChan chan<- interface{}) (map[string][]byte, error) {
49-
// TODO: Consider using lsblk --json --output <columns> instead.
50-
// This simplifies the parsing logic and also represents a parent/child relationship
51-
// between devices when there are partitions.
52-
// NOTE: Remember to validate the output of lsblk json
53-
// NOTE: Check what version of lsblk --json was introduced.
5448
cmd := exec.Command("lsblk", "--noheadings", "--bytes", "--pairs", "-o", lsblkColumns)
5549
stdout, err := cmd.Output()
5650
if err != nil {
@@ -101,7 +95,6 @@ func parseLsblkOutput(output []byte) ([]BlockDeviceInfo, error) {
10195
&bdi.Serial,
10296
&ro,
10397
&rm,
104-
&bdi.PartitionTableType,
10598
)
10699
bdi.ReadOnly = ro == 1
107100
bdi.Removable = rm == 1

0 commit comments

Comments
 (0)