Skip to content

Commit

Permalink
config/fcos: warn if the partition number for root isn't correct
Browse files Browse the repository at this point in the history
Fixes coreos#243

This change warns if the partition number for the root label is not
specified or wrongly mentioned.
  • Loading branch information
sohankunkerkar committed Sep 16, 2021
1 parent dcc128a commit f5a61be
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
3 changes: 3 additions & 0 deletions config/common/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ var (
ErrUnknownBootDeviceLayout = errors.New("layout must be one of: aarch64, ppc64le, x86_64")
ErrTooFewMirrorDevices = errors.New("mirroring requires at least two devices")

// partition
ErrWrongPartitionNumber = errors.New("incorrect partition number; a new partition will be created using reserved label")

// MachineConfigs
ErrFieldElided = errors.New("field ignored in raw mode")
ErrNameRequired = errors.New("metadata.name is required")
Expand Down
14 changes: 14 additions & 0 deletions config/fcos/v1_3/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ func (c Config) ToIgn3_2Unvalidated(options common.TranslateOptions) (types.Conf
return types.Config{}, translate.TranslationSet{}, r
}
r.Merge(c.processBootDevice(&ret, &ts, options))
for i, disk := range ret.Storage.Disks {
// In the boot_device.mirror case, nothing specifies partition numbers
// so match existing paritions only when `wipeTable` is false
if !*disk.WipeTable {
for j, partition := range disk.Partitions {
// check for default partlabels
if partition.Label != nil {
if (*partition.Label == "BIOS-BOOT" && partition.Number != 1) || (*partition.Label == "PowerPC-PReP-boot" && partition.Number != 1) || (*partition.Label == "EFI-SYSTEM" && partition.Number != 2) || (*partition.Label == "boot" && partition.Number != 3) || (*partition.Label == "root" && partition.Number != 4) {
r.AddOnWarn(path.New("json", "storage", "disks", i, "partitions", j, *partition.Label), common.ErrWrongPartitionNumber)
}
}
}
}
}
return ret, ts, r
}

Expand Down
14 changes: 14 additions & 0 deletions config/fcos/v1_4/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ func (c Config) ToIgn3_3Unvalidated(options common.TranslateOptions) (types.Conf
return types.Config{}, translate.TranslationSet{}, r
}
r.Merge(c.processBootDevice(&ret, &ts, options))
for i, disk := range ret.Storage.Disks {
// In the boot_device.mirror case, nothing specifies partition numbers
// so match existing paritions only when `wipeTable` is false
if !*disk.WipeTable {
for j, partition := range disk.Partitions {
// check for default partlabels
if partition.Label != nil {
if (*partition.Label == "BIOS-BOOT" && partition.Number != 1) || (*partition.Label == "PowerPC-PReP-boot" && partition.Number != 1) || (*partition.Label == "EFI-SYSTEM" && partition.Number != 2) || (*partition.Label == "boot" && partition.Number != 3) || (*partition.Label == "root" && partition.Number != 4) {
r.AddOnWarn(path.New("json", "storage", "disks", i, "partitions", j, *partition.Label), common.ErrWrongPartitionNumber)
}
}
}
}
}
return ret, ts, r
}

Expand Down
14 changes: 14 additions & 0 deletions config/fcos/v1_5_exp/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ func (c Config) ToIgn3_4Unvalidated(options common.TranslateOptions) (types.Conf
return types.Config{}, translate.TranslationSet{}, r
}
r.Merge(c.processBootDevice(&ret, &ts, options))
for i, disk := range ret.Storage.Disks {
// In the boot_device.mirror case, nothing specifies partition numbers
// so match existing paritions only when `wipeTable` is false
if !*disk.WipeTable {
for j, partition := range disk.Partitions {
// check for default partlabels
if partition.Label != nil {
if (*partition.Label == "BIOS-BOOT" && partition.Number != 1) || (*partition.Label == "PowerPC-PReP-boot" && partition.Number != 1) || (*partition.Label == "EFI-SYSTEM" && partition.Number != 2) || (*partition.Label == "boot" && partition.Number != 3) || (*partition.Label == "root" && partition.Number != 4) {
r.AddOnWarn(path.New("json", "storage", "disks", i, "partitions", j, *partition.Label), common.ErrWrongPartitionNumber)
}
}
}
}
}
return ret, ts, r
}

Expand Down
2 changes: 1 addition & 1 deletion config/fcos/v1_5_exp/translate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ func TestTranslateBootDevice(t *testing.T) {
for i, test := range tests {
actual, translations, r := test.in.ToIgn3_4Unvalidated(common.TranslateOptions{})
assert.Equal(t, test.out, actual, "#%d: translation mismatch", i)
assert.Equal(t, report.Report{}, r, "#%d: non-empty report", i)
assert.Equal(t, report.Report{}, r, "#%d: report mismatch", i)
baseutil.VerifyTranslations(t, translations, test.exceptions, "#%d", i)
assert.NoError(t, translations.DebugVerifyCoverage(actual), "#%d: incomplete TranslationSet coverage", i)
}
Expand Down

0 comments on commit f5a61be

Please sign in to comment.