Skip to content

Commit

Permalink
🐛 make the snapshot scan fs detection better (#3737)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeffrey authored Apr 9, 2024
1 parent 6be5466 commit ea61dae
Show file tree
Hide file tree
Showing 6 changed files with 433 additions and 1 deletion.
3 changes: 2 additions & 1 deletion providers/os/connection/snapshot/blockdevices.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
56 changes: 56 additions & 0 deletions providers/os/connection/snapshot/blockdevices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
111 changes: 111 additions & 0 deletions providers/os/connection/snapshot/testdata/another_alma_attached.json
Original file line number Diff line number Diff line change
@@ -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
]
}
]
}
]
}
92 changes: 92 additions & 0 deletions providers/os/connection/snapshot/testdata/aws_attached.json
Original file line number Diff line number Diff line change
@@ -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
]
}
]
}
]
}
80 changes: 80 additions & 0 deletions providers/os/connection/snapshot/testdata/oracle_attached.json
Original file line number Diff line number Diff line change
@@ -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
]
}
]
}
]
}
Loading

0 comments on commit ea61dae

Please sign in to comment.