From ea61daef41c902328a0a76ba7cb6f0b745276baf Mon Sep 17 00:00:00 2001 From: vjeffrey Date: Tue, 9 Apr 2024 12:40:50 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20make=20the=20snapshot=20scan=20f?= =?UTF-8?q?s=20detection=20better=20(#3737)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../os/connection/snapshot/blockdevices.go | 3 +- .../connection/snapshot/blockdevices_test.go | 56 +++++++++ .../testdata/another_alma_attached.json | 111 ++++++++++++++++++ .../snapshot/testdata/aws_attached.json | 92 +++++++++++++++ .../snapshot/testdata/oracle_attached.json | 80 +++++++++++++ .../snapshot/testdata/rhel_attached.json | 92 +++++++++++++++ 6 files changed, 433 insertions(+), 1 deletion(-) create mode 100644 providers/os/connection/snapshot/testdata/another_alma_attached.json create mode 100644 providers/os/connection/snapshot/testdata/aws_attached.json create mode 100644 providers/os/connection/snapshot/testdata/oracle_attached.json create mode 100644 providers/os/connection/snapshot/testdata/rhel_attached.json diff --git a/providers/os/connection/snapshot/blockdevices.go b/providers/os/connection/snapshot/blockdevices.go index 83603596f8..7a9b7f1c78 100644 --- a/providers/os/connection/snapshot/blockdevices.go +++ b/providers/os/connection/snapshot/blockdevices.go @@ -21,6 +21,7 @@ type blockDevice struct { Uuid string `json:"uuid,omitempty"` MountPoint string `json:"mountpoint,omitempty"` Children []blockDevice `json:"children,omitempty"` + FsUse string `json:"fsuse%,omitempty"` } type fsInfo struct { @@ -112,7 +113,7 @@ func (blockEntries blockDevices) GetUnmountedBlockEntry() (*fsInfo, error) { } func (entry blockDevice) IsNoBootVolume() bool { - return entry.Uuid != "" && entry.FsType != "" && entry.FsType != "vfat" && entry.Label != "EFI" && entry.Label != "boot" && entry.Label != "/" + return entry.Uuid != "" && entry.FsType != "" && entry.FsType != "vfat" && entry.Label != "EFI" && entry.Label != "boot" && entry.FsUse == "" } func (entry blockDevice) IsNoBootVolumeAndUnmounted() bool { diff --git a/providers/os/connection/snapshot/blockdevices_test.go b/providers/os/connection/snapshot/blockdevices_test.go index f634d24e60..1e883680bd 100644 --- a/providers/os/connection/snapshot/blockdevices_test.go +++ b/providers/os/connection/snapshot/blockdevices_test.go @@ -122,3 +122,59 @@ func TestAttachedBlockEntry(t *testing.T) { require.Equal(t, "xfs", info.fstype) require.True(t, strings.Contains(info.name, "xvdh")) } + +func TestAttachedBlockEntryAWS(t *testing.T) { + data, err := os.ReadFile("./testdata/aws_attached.json") + require.NoError(t, err) + + blockEntries := blockDevices{} + err = json.Unmarshal(data, &blockEntries) + require.NoError(t, err) + + info, err := blockEntries.GetUnnamedBlockEntry() + require.NoError(t, err) + require.Equal(t, "xfs", info.fstype) + require.True(t, strings.Contains(info.name, "xvdh")) +} + +func TestAnotherAttachedBlockEntryAlma(t *testing.T) { + data, err := os.ReadFile("./testdata/another_alma_attached.json") + require.NoError(t, err) + + blockEntries := blockDevices{} + err = json.Unmarshal(data, &blockEntries) + require.NoError(t, err) + + info, err := blockEntries.GetUnnamedBlockEntry() + require.NoError(t, err) + require.Equal(t, "xfs", info.fstype) + require.True(t, strings.Contains(info.name, "nvme1n1")) +} + +func TestAttachedBlockEntryOracle(t *testing.T) { + data, err := os.ReadFile("./testdata/oracle_attached.json") + require.NoError(t, err) + + blockEntries := blockDevices{} + err = json.Unmarshal(data, &blockEntries) + require.NoError(t, err) + + info, err := blockEntries.GetUnnamedBlockEntry() + require.NoError(t, err) + require.Equal(t, "ext4", info.fstype) + require.True(t, strings.Contains(info.name, "xvdb")) +} + +func TestAttachedBlockEntryRhel(t *testing.T) { + data, err := os.ReadFile("./testdata/rhel_attached.json") + require.NoError(t, err) + + blockEntries := blockDevices{} + err = json.Unmarshal(data, &blockEntries) + require.NoError(t, err) + + info, err := blockEntries.GetUnnamedBlockEntry() + require.NoError(t, err) + require.Equal(t, "xfs", info.fstype) + require.True(t, strings.Contains(info.name, "nvme1n1")) +} diff --git a/providers/os/connection/snapshot/testdata/another_alma_attached.json b/providers/os/connection/snapshot/testdata/another_alma_attached.json new file mode 100644 index 0000000000..846b23ee54 --- /dev/null +++ b/providers/os/connection/snapshot/testdata/another_alma_attached.json @@ -0,0 +1,111 @@ +{ + + "blockdevices": [ + { + "name": "zram0", + "fstype": null, + "fsver": null, + "label": null, + "uuid": null, + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + "[SWAP]" + ] + },{ + "name": "nvme0n1", + "fstype": null, + "fsver": null, + "label": null, + "uuid": null, + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + null + ], + "children": [ + { + "name": "nvme0n1p1", + "fstype": "xfs", + "fsver": null, + "label": "/", + "uuid": "ff20f197-ffa7-403f-b746-72395ee51a0d", + "fsavail": "6.2G", + "fsuse%": "21%", + "mountpoints": [ + "/" + ] + },{ + "name": "nvme0n1p128", + "fstype": "vfat", + "fsver": "FAT16", + "label": null, + "uuid": "0E68-4A00", + "fsavail": "8.6M", + "fsuse%": "14%", + "mountpoints": [ + "/boot/efi" + ] + } + ] + },{ + "name": "nvme1n1", + "fstype": null, + "fsver": null, + "label": null, + "uuid": null, + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + null + ], + "children": [ + { + "name": "nvme1n1p1", + "fstype": null, + "fsver": null, + "label": null, + "uuid": null, + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + null + ] + },{ + "name": "nvme1n1p2", + "fstype": "vfat", + "fsver": "FAT16", + "label": null, + "uuid": "C8BB-FC87", + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + null + ] + },{ + "name": "nvme1n1p3", + "fstype": "xfs", + "fsver": null, + "label": null, + "uuid": "31f80bf2-f73c-4350-bd3e-1dfe82e691f9", + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + null + ] + },{ + "name": "nvme1n1p4", + "fstype": "xfs", + "fsver": null, + "label": null, + "uuid": "b6b03ca5-4431-4db9-a1fb-f13c8566f779", + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + null + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/providers/os/connection/snapshot/testdata/aws_attached.json b/providers/os/connection/snapshot/testdata/aws_attached.json new file mode 100644 index 0000000000..cf0499079c --- /dev/null +++ b/providers/os/connection/snapshot/testdata/aws_attached.json @@ -0,0 +1,92 @@ +{ + "blockdevices": [ + { + "name": "xvda", + "fstype": null, + "fsver": null, + "label": null, + "uuid": null, + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + null + ], + "children": [ + { + "name": "xvda1", + "fstype": "xfs", + "fsver": null, + "label": "/", + "uuid": "3d668946-b9eb-4d6b-acbd-da437d796ee8", + "fsavail": "6.4G", + "fsuse%": "19%", + "mountpoints": [ + "/" + ] + }, + { + "name": "xvda127", + "fstype": null, + "fsver": null, + "label": null, + "uuid": null, + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + null + ] + }, + { + "name": "xvda128", + "fstype": "vfat", + "fsver": "FAT16", + "label": null, + "uuid": "1753-28B3", + "fsavail": "8.7M", + "fsuse%": "13%", + "mountpoints": [ + "/boot/efi" + ] + } + ] + }, + { + "name": "xvdh", + "fstype": null, + "fsver": null, + "label": null, + "uuid": null, + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + null + ], + "children": [ + { + "name": "xvdh1", + "fstype": "xfs", + "fsver": null, + "label": "/", + "uuid": "8912f503-0393-46e9-ac20-cf4907701485", + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + null + ] + }, + { + "name": "xvdh128", + "fstype": null, + "fsver": null, + "label": null, + "uuid": null, + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + null + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/providers/os/connection/snapshot/testdata/oracle_attached.json b/providers/os/connection/snapshot/testdata/oracle_attached.json new file mode 100644 index 0000000000..ce0c1e0d70 --- /dev/null +++ b/providers/os/connection/snapshot/testdata/oracle_attached.json @@ -0,0 +1,80 @@ +{ + "blockdevices": [ + { + "name": "xvda", + "fstype": null, + "fsver": null, + "label": null, + "uuid": null, + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + null + ], + "children": [ + { + "name": "xvda1", + "fstype": "xfs", + "fsver": null, + "label": "/", + "uuid": "3d668946-b9eb-4d6b-acbd-da437d796ee8", + "fsavail": "6.4G", + "fsuse%": "19%", + "mountpoints": [ + "/" + ] + }, + { + "name": "xvda127", + "fstype": null, + "fsver": null, + "label": null, + "uuid": null, + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + null + ] + }, + { + "name": "xvda128", + "fstype": "vfat", + "fsver": "FAT16", + "label": null, + "uuid": "1753-28B3", + "fsavail": "8.7M", + "fsuse%": "13%", + "mountpoints": [ + "/boot/efi" + ] + } + ] + }, + { + "name": "xvdb", + "fstype": null, + "fsver": null, + "label": null, + "uuid": null, + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + null + ], + "children": [ + { + "name": "xvdb1", + "fstype": "ext4", + "fsver": "1.0", + "label": "/", + "uuid": "d5388b06-35e3-435e-8eaf-09a08de83883", + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + null + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/providers/os/connection/snapshot/testdata/rhel_attached.json b/providers/os/connection/snapshot/testdata/rhel_attached.json new file mode 100644 index 0000000000..1b5c506f8d --- /dev/null +++ b/providers/os/connection/snapshot/testdata/rhel_attached.json @@ -0,0 +1,92 @@ +{ + "blockdevices": [ + { + "name": "zram0", + "fstype": null, + "fsver": null, + "label": null, + "uuid": null, + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + "[SWAP]" + ] + }, + { + "name": "nvme1n1", + "fstype": null, + "fsver": null, + "label": null, + "uuid": null, + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + null + ], + "children": [ + { + "name": "nvme1n1p1", + "fstype": null, + "fsver": null, + "label": null, + "uuid": null, + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + null + ] + }, + { + "name": "nvme1n1p2", + "fstype": "xfs", + "fsver": null, + "label": null, + "uuid": "87be522b-2b75-4150-879d-4ee109559f7e", + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + null + ] + } + ] + }, + { + "name": "nvme0n1", + "fstype": null, + "fsver": null, + "label": null, + "uuid": null, + "fsavail": null, + "fsuse%": null, + "mountpoints": [ + null + ], + "children": [ + { + "name": "nvme0n1p1", + "fstype": "xfs", + "fsver": null, + "label": "/", + "uuid": "ff20f197-ffa7-403f-b746-72395ee51a0d", + "fsavail": "6.2G", + "fsuse%": "21%", + "mountpoints": [ + "/" + ] + }, + { + "name": "nvme0n1p128", + "fstype": "vfat", + "fsver": "FAT16", + "label": null, + "uuid": "0E68-4A00", + "fsavail": "8.6M", + "fsuse%": "14%", + "mountpoints": [ + "/boot/efi" + ] + } + ] + } + ] +} \ No newline at end of file