sys-apps/ignition: fix OEM detection

In case the OEM partition was specified with the name "OEM",
the btrfs format was not forced because it only considered the name "oem".

Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
This commit is contained in:
Mathieu Tortuyaux 2022-11-10 12:01:24 +01:00
parent a8467c41ec
commit 3a9541cd7e
3 changed files with 162 additions and 0 deletions

View File

@ -0,0 +1,161 @@
From c2f82824e643a06b0663ab410ad28ecdd5c3d3be Mon Sep 17 00:00:00 2001
From: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
Date: Thu, 10 Nov 2022 11:58:49 +0100
Subject: [PATCH] translation: support OEM and oem
Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
---
config/v24tov31/v24tov31.go | 6 +-
config/v24tov31/v24tov31_test.go | 109 +++++++++++++++++++++++++++++++
2 files changed, 112 insertions(+), 3 deletions(-)
diff --git a/config/v24tov31/v24tov31.go b/config/v24tov31/v24tov31.go
index 46749385..68da4014 100644
--- a/config/v24tov31/v24tov31.go
+++ b/config/v24tov31/v24tov31.go
@@ -21,14 +21,14 @@ import (
"path"
"path/filepath"
"reflect"
+ "strings"
old "github.com/flatcar/ignition/config/v2_4/types"
oldValidate "github.com/flatcar/ignition/config/validate"
"github.com/flatcar/ignition/v2/config/merge"
+ "github.com/flatcar/ignition/v2/config/util"
"github.com/flatcar/ignition/v2/config/v3_1/types"
"github.com/flatcar/ignition/v2/config/validate"
- "github.com/flatcar/ignition/v2/config/util"
-
)
// Check2_4 returns if the config is translatable but does not do any translation.
@@ -474,7 +474,7 @@ func translateFilesystems(fss []old.Filesystem, m map[string]string) (ret []type
}
format := f.Mount.Format
- if f.Name == "oem" && (wipe == nil || !*wipe) {
+ if strings.ToLower(f.Name) == "oem" && (wipe == nil || !*wipe) {
format = "btrfs"
}
diff --git a/config/v24tov31/v24tov31_test.go b/config/v24tov31/v24tov31_test.go
index e81f6bed..68c07109 100644
--- a/config/v24tov31/v24tov31_test.go
+++ b/config/v24tov31/v24tov31_test.go
@@ -1690,3 +1690,112 @@ func TestDuplicateUnits(t *testing.T) {
assert.Equal(t, test.ign3, res)
}
}
+
+func TestOEMPartition(t *testing.T) {
+ tests := []struct {
+ ign types2_4.Config
+ fsFormat string
+ }{
+ {
+ ign: types2_4.Config{
+ Ignition: types2_4.Ignition{
+ Version: "2.4.0",
+ Config: types2_4.IgnitionConfig{},
+ Timeouts: types2_4.Timeouts{},
+ Security: types2_4.Security{},
+ Proxy: types2_4.Proxy{},
+ },
+ Storage: types2_4.Storage{
+ Filesystems: []types2_4.Filesystem{
+ {
+ Name: "OEM",
+ Mount: &types2_4.Mount{
+ Device: "/dev/disk/by-label/OEM",
+ Format: "ext4",
+ },
+ },
+ },
+ },
+ },
+ fsFormat: "btrfs",
+ },
+ {
+ ign: types2_4.Config{
+ Ignition: types2_4.Ignition{
+ Version: "2.4.0",
+ Config: types2_4.IgnitionConfig{},
+ Timeouts: types2_4.Timeouts{},
+ Security: types2_4.Security{},
+ Proxy: types2_4.Proxy{},
+ },
+ Storage: types2_4.Storage{
+ Filesystems: []types2_4.Filesystem{
+ {
+ Name: "oem",
+ Mount: &types2_4.Mount{
+ Device: "/dev/disk/by-label/OEM",
+ Format: "ext4",
+ },
+ },
+ },
+ },
+ },
+ fsFormat: "btrfs",
+ },
+ {
+ ign: types2_4.Config{
+ Ignition: types2_4.Ignition{
+ Version: "2.4.0",
+ Config: types2_4.IgnitionConfig{},
+ Timeouts: types2_4.Timeouts{},
+ Security: types2_4.Security{},
+ Proxy: types2_4.Proxy{},
+ },
+ Storage: types2_4.Storage{
+ Filesystems: []types2_4.Filesystem{
+ {
+ Name: "OEM",
+ Mount: &types2_4.Mount{
+ Device: "/dev/disk/by-label/OEM",
+ Format: "ext4",
+ WipeFilesystem: true,
+ },
+ },
+ },
+ },
+ },
+ fsFormat: "ext4",
+ },
+ {
+ ign: types2_4.Config{
+ Ignition: types2_4.Ignition{
+ Version: "2.4.0",
+ Config: types2_4.IgnitionConfig{},
+ Timeouts: types2_4.Timeouts{},
+ Security: types2_4.Security{},
+ Proxy: types2_4.Proxy{},
+ },
+ Storage: types2_4.Storage{
+ Filesystems: []types2_4.Filesystem{
+ {
+ Name: "oem",
+ Mount: &types2_4.Mount{
+ Device: "/dev/disk/by-label/OEM",
+ Format: "ext4",
+ WipeFilesystem: true,
+ },
+ },
+ },
+ },
+ },
+ fsFormat: "ext4",
+ },
+ }
+
+ for _, test := range tests {
+ res, err := v24tov31.Translate(test.ign, nil)
+
+ assert.Nil(t, err)
+ assert.Equal(t, test.fsFormat, *res.Storage.Filesystems[0].Format)
+ }
+}
--
2.35.1

View File

@ -58,6 +58,7 @@ PATCHES=(
"${FILESDIR}/0014-Revert-drop-OEM-URI-support.patch"
"${FILESDIR}/0015-internal-resource-url-support-btrfs-as-OEM-partition.patch"
"${FILESDIR}/0016-internal-exec-stages-disks-prevent-races-with-udev.patch"
"${FILESDIR}/0017-translation-support-OEM-and-oem.patch"
)
src_compile() {