@@ -17,6 +17,8 @@ package misc
1717import (
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,27 @@ 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+ }[runtime .GOARCH ]
51+
2952func init () {
3053 register .RegisterTest (& register.Test {
3154 Run : varLibContainers ,
@@ -35,6 +58,15 @@ func init() {
3558 Distros : []string {"rhcos" , "fcos" },
3659 Platforms : []string {"qemu" },
3760 })
61+
62+ register .RegisterTest (& register.Test {
63+ Run : dpsUuidTest ,
64+ ClusterSize : 0 ,
65+ Name : "coreos.misc.disk.dpsUuid" ,
66+ Flags : []register.Flag {},
67+ Distros : []string {"rhcos" , "fcos" },
68+ Platforms : []string {"qemu" },
69+ })
3870}
3971
4072func varLibContainers (c cluster.TestCluster ) {
@@ -154,3 +186,104 @@ func varLibContainers(c cluster.TestCluster) {
154186 }
155187 c .MustSSH (m , "sudo podman build -t test -f Dockerfile ." )
156188}
189+
190+ type LSBLK struct {
191+ Blockdevices []BlockDevice `json:"blockdevices"`
192+ }
193+
194+ type BlockDevice struct {
195+ Name string `json:"name"`
196+ PartType * string `json:"parttype"`
197+ UUID * string `json:"uuid"`
198+ Mountpoint * string `json:"mountpoint"`
199+ PartTypeName * string `json:"parttypename"`
200+ Label * string `json:"label"`
201+ Children []BlockDevice `json:"children,omitempty"`
202+ }
203+
204+ func dpsFatalFail (c cluster.TestCluster , blockDev * BlockDevice , reqUuid string ) {
205+ c .Fatalf (
206+ "Partition '%s' does not have DPS UUID. Have: %s, Need: %s" ,
207+ blockDev .Name ,
208+ * blockDev .PartType ,
209+ reqUuid ,
210+ )
211+ }
212+
213+ func dpsUuidTest (c cluster.TestCluster ) {
214+ c .Platform ()
215+
216+ m , err := c .NewMachine (nil )
217+ if err != nil {
218+ c .Fatal (err )
219+ }
220+
221+ // find the partition
222+ devMajMin := strings .TrimSpace (string (c .MustSSH (m , "findmnt -no MAJ:MIN /sysroot" )))
223+
224+ // find the backing dev
225+ cmd := fmt .Sprintf ("basename $(dirname $(readlink -f /sys/dev/block/%s))" , devMajMin )
226+ device := strings .TrimSpace (string (c .MustSSH (m , cmd )))
227+
228+ cmd = fmt .Sprintf (
229+ "lsblk -oname,parttype,uuid,mountpoint,parttypename,label --json /dev/%s" ,
230+ device ,
231+ )
232+ lsblkOut := c .MustSSH (m , cmd )
233+
234+ lsblk := LSBLK {}
235+
236+ err = json .Unmarshal (lsblkOut , & lsblk )
237+ if err != nil {
238+ c .Fatal (err )
239+ }
240+
241+ if len (lsblk .Blockdevices ) != 1 {
242+ c .Fatalf ("More than one block device found for device no '%s'" , devMajMin )
243+ }
244+
245+ // NOTE: Not adding a check for whether we found the XBootldr
246+ // partition or not as there would be a few cases where it won't be used
247+ // Ex. In composefs-native UKI case
248+ var (
249+ rootFound = false
250+ espFound = false
251+ )
252+
253+ for _ , child := range lsblk .Blockdevices [0 ].Children {
254+ if child .Label == nil {
255+ continue
256+ }
257+
258+ if child .PartType == nil {
259+ c .Fatalf ("'%s' has no parttype" , child .Name )
260+ }
261+
262+ switch * child .Label {
263+ case "boot" :
264+ if strings .ToUpper (* child .PartType ) != XBootldr {
265+ dpsFatalFail (c , & child , XBootldr )
266+ }
267+
268+ case "root" :
269+ rootFound = true
270+ if strings .ToUpper (* child .PartType ) != RootPartition {
271+ dpsFatalFail (c , & child , RootPartition )
272+ }
273+
274+ case "EFI-SYSTEM" :
275+ espFound = true
276+ if strings .ToUpper (* child .PartType ) != ESP {
277+ dpsFatalFail (c , & child , ESP )
278+ }
279+ }
280+ }
281+
282+ if ! rootFound {
283+ c .Fatalf ("Root partition not found" )
284+ }
285+
286+ if ! espFound {
287+ c .Fatalf ("EFI partition not found" )
288+ }
289+ }
0 commit comments