Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

otk-gen-partition-table: add support for ppc64/s390x partition tables #963

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions cmd/otk-gen-partition-table/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type InputCreate struct {
// InputPartition represents a single user provided partition input
type InputPartition struct {
Name string `json:"name"`
Bootable bool `json:"bootable"`
Mountpoint string `json:"mountpoint"`
Label string `json:"label"`
Size string `json:"size"`
Expand Down Expand Up @@ -183,21 +184,25 @@ func makePartitionTableFromOtkInput(input *Input) (*disk.PartitionTable, error)
if err != nil {
return nil, err
}
pt.Partitions = append(pt.Partitions, disk.Partition{
Size: uintSize,
UUID: part.PartUUID,
Type: part.PartType,
// XXX: support lvm,luks here
Payload: &disk.Filesystem{
// XXX: support lvm,luks here
newPart := disk.Partition{
Size: uintSize,
UUID: part.PartUUID,
Type: part.PartType,
supakeen marked this conversation as resolved.
Show resolved Hide resolved
Bootable: part.Bootable,
}
if part.Type != "" {
newPart.Payload = &disk.Filesystem{
Label: part.Label,
Type: part.Type,
Mountpoint: part.Mountpoint,
UUID: part.FsUUID,
FSTabOptions: part.FSMntOps,
FSTabFreq: part.FSFreq,
FSTabPassNo: part.FSPassNo,
},
})
}
}
pt.Partitions = append(pt.Partitions, newPart)
}

return pt, nil
Expand Down
87 changes: 87 additions & 0 deletions cmd/otk-gen-partition-table/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
)

// see https://github.com/achilleas-k/images/pull/2#issuecomment-2136025471
// Note that this partition table contains all json keys for testing, some may
// contradict each other
var partInputsComplete = `
{
"properties": {
Expand All @@ -32,6 +34,7 @@ var partInputsComplete = `
"partitions": [
{
"name": "root",
"bootable": true,
"mountpoint": "/",
"label": "root",
"size": "7 GiB",
Expand Down Expand Up @@ -69,6 +72,7 @@ var expectedInput = &genpart.Input{
Partitions: []*genpart.InputPartition{
{
Name: "root",
Bootable: true,
Mountpoint: "/",
Label: "root",
Size: "7 GiB",
Expand Down Expand Up @@ -307,6 +311,89 @@ func TestIntegrationRealistic(t *testing.T) {
assert.Equal(t, expectedSimplePartOutput, outp.String())
}

func TestGenPartitionTableBootable(t *testing.T) {
inp := &genpart.Input{
Properties: genpart.InputProperties{
Type: "dos",
},
Partitions: []*genpart.InputPartition{
{
Bootable: true,
Mountpoint: "/",
Size: "10 GiB",
Type: "ext4",
},
},
}

output, err := genpart.GenPartitionTable(inp, rand.New(rand.NewSource(0))) /* #nosec G404 */
assert.NoError(t, err)
assert.Equal(t, true, output.Const.Internal.PartitionTable.Partitions[0].Bootable)
}

func TestGenPartitionTableIntegrationPPC(t *testing.T) {
inp := &genpart.Input{
Properties: genpart.InputProperties{
Type: "dos",
DefaultSize: "10 GiB",
UUID: "0x14fc63d2",
},
Partitions: []*genpart.InputPartition{
{
Name: "ppc-boot",
Bootable: true,
Size: "4 MiB",
PartType: "41",
PartUUID: "",
},
{
Name: "root",
Size: "10 GiB",
Type: "xfs",
Mountpoint: "/",
},
},
}
expectedOutput := &otkdisk.Data{
Const: otkdisk.Const{
KernelOptsList: []string{},
PartitionMap: map[string]otkdisk.Partition{
"root": {
UUID: "0194fdc2-fa2f-4cc0-81d3-ff12045b73c8",
},
},
Filename: "disk.img",
Internal: otkdisk.Internal{
PartitionTable: &disk.PartitionTable{
Size: 10742661120,
UUID: "0x14fc63d2",
Type: "dos",
Partitions: []disk.Partition{
{
Bootable: true,
Start: 1048576,
Size: 4194304,
Type: "41",
},
{
Start: 5242880,
Size: 10737418240,
Payload: &disk.Filesystem{
Type: "xfs",
UUID: "0194fdc2-fa2f-4cc0-81d3-ff12045b73c8",
Mountpoint: "/",
},
},
},
},
},
},
}
output, err := genpart.GenPartitionTable(inp, rand.New(rand.NewSource(0))) /* #nosec G404 */
assert.NoError(t, err)
assert.Equal(t, expectedOutput, output)
}

func TestGenPartitionTableMinimal(t *testing.T) {
// XXX: think about what the smalltest inputs can be and validate
// that it's complete and/or provide defaults (e.g. for "type" for
Expand Down
Loading