Skip to content

Commit 074ee50

Browse files
mantle/kola/qemu: Add test for DPS UUID
#4380 makes sure that partitions are created according to the Discoverable Partition Specification. This adds test for the same Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 23e1d90 commit 074ee50

File tree

1 file changed

+135
-0
lines changed

1 file changed

+135
-0
lines changed

mantle/kola/tests/misc/disk.go

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ package misc
1717
import (
1818
"encoding/json"
1919
"fmt"
20+
"runtime"
21+
"strings"
2022

2123
"github.com/coreos/coreos-assembler/mantle/kola/cluster"
2224
"github.com/coreos/coreos-assembler/mantle/kola/register"
@@ -26,6 +28,29 @@ import (
2628
ignv3types "github.com/coreos/ignition/v2/config/v3_0/types"
2729
)
2830

31+
const (
32+
// Extended Boot Loader Partition
33+
XBootldr = "BC13C2FF-59E6-4262-A352-B275FD6F7172"
34+
35+
// EFI System Partition (ESP) for UEFI boot
36+
ESP = "C12A7328-F81F-11D2-BA4B-00A0C93EC93B"
37+
)
38+
39+
var RootPartition = map[string]string{
40+
// Root partition for 64-bit x86/AMD64
41+
"amd64": "4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709",
42+
// Root partition for 64-bit ARM/AArch64 architecture
43+
"arm64": "B921B045-1DF0-41C3-AF44-4C6F280D3FAE",
44+
// Root partition for 64-bit PowerPC Big Endian
45+
"ppc64": "912ADE1D-A839-4913-8964-A10EEE08FBD2",
46+
// Root partition for 64-bit PowerPC Little Endian
47+
"ppc64le": "C31C45E6-3F39-412E-80FB-4809C4980599",
48+
// Root partition for s390x architecture
49+
"s390x": "5EEAD9A9-FE09-4A1E-A1D7-520D00531306",
50+
// Root partition for 64-bit RISC-V
51+
"riscv64": "72EC70A6-CF74-40E6-BD49-4BDA08E8F224",
52+
}[runtime.GOARCH]
53+
2954
func init() {
3055
register.RegisterTest(&register.Test{
3156
Run: varLibContainers,
@@ -35,6 +60,15 @@ func init() {
3560
Distros: []string{"rhcos", "fcos"},
3661
Platforms: []string{"qemu"},
3762
})
63+
64+
register.RegisterTest(&register.Test{
65+
Run: dpsUuidTest,
66+
ClusterSize: 0,
67+
Name: "coreos.misc.disk.dpsUuid",
68+
Flags: []register.Flag{},
69+
Distros: []string{"rhcos", "fcos"},
70+
Platforms: []string{"qemu"},
71+
})
3872
}
3973

4074
func varLibContainers(c cluster.TestCluster) {
@@ -154,3 +188,104 @@ func varLibContainers(c cluster.TestCluster) {
154188
}
155189
c.MustSSH(m, "sudo podman build -t test -f Dockerfile .")
156190
}
191+
192+
type LSBLK struct {
193+
Blockdevices []BlockDevice `json:"blockdevices"`
194+
}
195+
196+
type BlockDevice struct {
197+
Name string `json:"name"`
198+
PartType *string `json:"parttype"`
199+
UUID *string `json:"uuid"`
200+
Mountpoint *string `json:"mountpoint"`
201+
PartTypeName *string `json:"parttypename"`
202+
Label *string `json:"label"`
203+
Children []BlockDevice `json:"children,omitempty"`
204+
}
205+
206+
func dpsFatalFail(c cluster.TestCluster, blockDev *BlockDevice, reqUuid string) {
207+
c.Fatalf(
208+
"Partition '%s' does not have DPS UUID. Have: %s, Need: %s",
209+
blockDev.Name,
210+
*blockDev.PartType,
211+
reqUuid,
212+
)
213+
}
214+
215+
func dpsUuidTest(c cluster.TestCluster) {
216+
c.Platform()
217+
218+
m, err := c.NewMachine(nil)
219+
if err != nil {
220+
c.Fatal(err)
221+
}
222+
223+
// find the partition
224+
devMajMin := strings.TrimSpace(string(c.MustSSH(m, "findmnt -no MAJ:MIN /sysroot")))
225+
226+
// find the backing dev
227+
cmd := fmt.Sprintf("basename $(dirname $(readlink -f /sys/dev/block/%s))", devMajMin)
228+
device := strings.TrimSpace(string(c.MustSSH(m, cmd)))
229+
230+
cmd = fmt.Sprintf(
231+
"lsblk -oname,parttype,uuid,mountpoint,parttypename,label --json /dev/%s",
232+
device,
233+
)
234+
lsblkOut := c.MustSSH(m, cmd)
235+
236+
lsblk := LSBLK{}
237+
238+
err = json.Unmarshal(lsblkOut, &lsblk)
239+
if err != nil {
240+
c.Fatal(err)
241+
}
242+
243+
if len(lsblk.Blockdevices) != 1 {
244+
c.Fatalf("More than one block device found for device no '%s'", devMajMin)
245+
}
246+
247+
// NOTE: Not adding a check for whether we found the XBootldr
248+
// partition or not as there would be a few cases where it won't be used
249+
// Ex. In composefs-native UKI case
250+
var (
251+
rootFound = false
252+
espFound = false
253+
)
254+
255+
for _, child := range lsblk.Blockdevices[0].Children {
256+
if child.Label == nil {
257+
continue
258+
}
259+
260+
if child.PartType == nil {
261+
c.Fatalf("'%s' has no parttype", child.Name)
262+
}
263+
264+
switch *child.Label {
265+
case "boot":
266+
if strings.ToUpper(*child.PartType) != XBootldr {
267+
dpsFatalFail(c, &child, XBootldr)
268+
}
269+
270+
case "root":
271+
rootFound = true
272+
if strings.ToUpper(*child.PartType) != RootPartition {
273+
dpsFatalFail(c, &child, RootPartition)
274+
}
275+
276+
case "EFI-SYSTEM":
277+
espFound = true
278+
if strings.ToUpper(*child.PartType) != ESP {
279+
dpsFatalFail(c, &child, ESP)
280+
}
281+
}
282+
}
283+
284+
if !rootFound {
285+
c.Fatalf("Root partition not found")
286+
}
287+
288+
if !espFound {
289+
c.Fatalf("EFI partition not found")
290+
}
291+
}

0 commit comments

Comments
 (0)