Skip to content

Commit

Permalink
Use same naming as in GRUB
Browse files Browse the repository at this point in the history
Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com>
  • Loading branch information
mauromorales committed Mar 29, 2024
1 parent 3029e9b commit 5b10043
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
14 changes: 7 additions & 7 deletions pkg/action/bootentries.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ func systemdConfToBootName(conf string) (string, error) {
return bootName, nil
}

if strings.HasPrefix(conf, "autoreset") {
bootName := "autoreset"
confName := strings.TrimPrefix(fileName, "autoreset")
if strings.HasPrefix(conf, "statereset") {
bootName := "statereset"
confName := strings.TrimPrefix(fileName, "statereset")

if confName != "" {
bootName = bootName + " " + strings.Trim(confName, "_")
Expand Down Expand Up @@ -248,11 +248,11 @@ func bootNameToSystemdConf(name string) (string, error) {
return "recovery" + differenciator + ".conf", nil
}

if strings.HasPrefix(name, "autoreset") {
if name != "autoreset" {
differenciator = "_" + strings.TrimPrefix(name, "autoreset ")
if strings.HasPrefix(name, "statereset") {
if name != "statereset" {
differenciator = "_" + strings.TrimPrefix(name, "statereset ")
}
return "autoreset" + differenciator + ".conf", nil
return "statereset" + differenciator + ".conf", nil

}

Expand Down
36 changes: 18 additions & 18 deletions pkg/action/bootentries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ var _ = Describe("Bootentries tests", Label("bootentry"), func() {
Expect(err).ToNot(HaveOccurred())
err = fs.WriteFile("/efi/loader/entries/recovery.conf", []byte("title kairos recovery\nefi /EFI/kairos/recovery.efi\n"), os.ModePerm)
Expect(err).ToNot(HaveOccurred())
err = fs.WriteFile("/efi/loader/entries/autoreset.conf", []byte("title kairos autoreset\nefi /EFI/kairos/autoreset.efi\n"), os.ModePerm)
err = fs.WriteFile("/efi/loader/entries/statereset.conf", []byte("title kairos state reset (auto)\nefi /EFI/kairos/statereset.efi\n"), os.ModePerm)
Expect(err).ToNot(HaveOccurred())

entries, err := listSystemdEntries(config, &v1.Partition{MountPoint: "/efi"})
Expand All @@ -123,7 +123,7 @@ var _ = Describe("Bootentries tests", Label("bootentry"), func() {
Expect(entries).To(ContainElement("cos"))
Expect(entries).To(ContainElement("fallback"))
Expect(entries).To(ContainElement("recovery"))
Expect(entries).To(ContainElement("autoreset"))
Expect(entries).To(ContainElement("statereset"))

})
It("list empty boot entries if there is none", func() {
Expand All @@ -146,7 +146,7 @@ var _ = Describe("Bootentries tests", Label("bootentry"), func() {
Expect(err).ToNot(HaveOccurred())
err = fs.WriteFile("/efi/loader/entries/recovery.conf", []byte("title kairos recovery\nefi /EFI/kairos/recovery.efi\n"), os.ModePerm)
Expect(err).ToNot(HaveOccurred())
err = fs.WriteFile("/efi/loader/entries/autoreset.conf", []byte("title kairos autoreset\nefi /EFI/kairos/autoreset.efi\n"), os.ModePerm)
err = fs.WriteFile("/efi/loader/entries/statereset.conf", []byte("title kairos state reset (auto)\nefi /EFI/kairos/statereset.efi\n"), os.ModePerm)
Expect(err).ToNot(HaveOccurred())
err = fs.WriteFile("/efi/loader/loader.conf", []byte(""), os.ModePerm)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -193,12 +193,12 @@ var _ = Describe("Bootentries tests", Label("bootentry"), func() {
syscall.MS_REMOUNT|syscall.MS_RDONLY,
"")).To(BeTrue())

err = SelectBootEntry(config, "autoreset")
err = SelectBootEntry(config, "statereset")
Expect(err).ToNot(HaveOccurred())
Expect(memLog.String()).To(ContainSubstring("Default boot entry set to autoreset"))
Expect(memLog.String()).To(ContainSubstring("Default boot entry set to statereset"))
reader, err = utils.SystemdBootConfReader(fs, "/efi/loader/loader.conf")
Expect(err).ToNot(HaveOccurred())
Expect(reader["default"]).To(Equal("autoreset.conf"))
Expect(reader["default"]).To(Equal("statereset.conf"))
// Should have called a remount to make it RW
Expect(syscallMock.WasMountCalledWith(
"",
Expand Down Expand Up @@ -265,7 +265,7 @@ var _ = Describe("Bootentries tests", Label("bootentry"), func() {
Expect(err).ToNot(HaveOccurred())
err = fs.WriteFile("/efi/loader/entries/recovery_install-mode_awesomeos.conf", []byte("title awesomeos recovery\nefi /EFI/kairos/recovery_install-mode_awesomeos.efi\n"), os.ModePerm)
Expect(err).ToNot(HaveOccurred())
err = fs.WriteFile("/efi/loader/entries/autoreset_install-mode_awesomeos.conf", []byte("title awesomeos autoreset\nefi /EFI/kairos/autoreset_install-mode_awesomeos.efi\n"), os.ModePerm)
err = fs.WriteFile("/efi/loader/entries/statereset_install-mode_awesomeos.conf", []byte("title awesomeos state reset (auto)\nefi /EFI/kairos/statereset_install-mode_awesomeos.efi\n"), os.ModePerm)
Expect(err).ToNot(HaveOccurred())
err = fs.WriteFile("/efi/loader/loader.conf", []byte(""), os.ModePerm)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -312,12 +312,12 @@ var _ = Describe("Bootentries tests", Label("bootentry"), func() {
syscall.MS_REMOUNT|syscall.MS_RDONLY,
"")).To(BeTrue())

err = SelectBootEntry(config, "autoreset")
err = SelectBootEntry(config, "statereset")
Expect(err).ToNot(HaveOccurred())
Expect(memLog.String()).To(ContainSubstring("Default boot entry set to autoreset"))
Expect(memLog.String()).To(ContainSubstring("Default boot entry set to statereset"))
reader, err = utils.SystemdBootConfReader(fs, "/efi/loader/loader.conf")
Expect(err).ToNot(HaveOccurred())
Expect(reader["default"]).To(Equal("autoreset_install-mode_awesomeos.conf"))
Expect(reader["default"]).To(Equal("statereset_install-mode_awesomeos.conf"))
// Should have called a remount to make it RW
Expect(syscallMock.WasMountCalledWith(
"",
Expand Down Expand Up @@ -390,9 +390,9 @@ var _ = Describe("Bootentries tests", Label("bootentry"), func() {
Expect(err).ToNot(HaveOccurred())
err = fs.WriteFile("/efi/loader/entries/recovery_foobar.conf", []byte("title Kairos recovery\nefi /EFI/kairos/recovery_foobar.efi\n"), os.ModePerm)
Expect(err).ToNot(HaveOccurred())
err = fs.WriteFile("/efi/loader/entries/autoreset.conf", []byte("title Kairos autoreset\nefi /EFI/kairos/autoreset.efi\n"), os.ModePerm)
err = fs.WriteFile("/efi/loader/entries/statereset.conf", []byte("title Kairos state reset (auto)\nefi /EFI/kairos/statereset.efi\n"), os.ModePerm)
Expect(err).ToNot(HaveOccurred())
err = fs.WriteFile("/efi/loader/entries/autoreset_foobar.conf", []byte("title Kairos autoreset\nefi /EFI/kairos/autoreset_foobar.efi\n"), os.ModePerm)
err = fs.WriteFile("/efi/loader/entries/statereset_foobar.conf", []byte("title Kairos state reset (auto)\nefi /EFI/kairos/state_reset_foobar.efi\n"), os.ModePerm)
Expect(err).ToNot(HaveOccurred())
err = fs.WriteFile("/efi/loader/loader.conf", []byte(""), os.ModePerm)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -481,12 +481,12 @@ var _ = Describe("Bootentries tests", Label("bootentry"), func() {
syscall.MS_REMOUNT|syscall.MS_RDONLY,
"")).To(BeTrue())

err = SelectBootEntry(config, "autoreset")
err = SelectBootEntry(config, "statereset")
Expect(err).ToNot(HaveOccurred())
Expect(memLog.String()).To(ContainSubstring("Default boot entry set to autoreset"))
Expect(memLog.String()).To(ContainSubstring("Default boot entry set to statereset"))
reader, err = utils.SystemdBootConfReader(fs, "/efi/loader/loader.conf")
Expect(err).ToNot(HaveOccurred())
Expect(reader["default"]).To(Equal("autoreset.conf"))
Expect(reader["default"]).To(Equal("statereset.conf"))
// Should have called a remount to make it RW
Expect(syscallMock.WasMountCalledWith(
"",
Expand All @@ -502,12 +502,12 @@ var _ = Describe("Bootentries tests", Label("bootentry"), func() {
syscall.MS_REMOUNT|syscall.MS_RDONLY,
"")).To(BeTrue())

err = SelectBootEntry(config, "autoreset foobar")
err = SelectBootEntry(config, "statereset foobar")
Expect(err).ToNot(HaveOccurred())
Expect(memLog.String()).To(ContainSubstring("Default boot entry set to autoreset foobar"))
Expect(memLog.String()).To(ContainSubstring("Default boot entry set to statereset foobar"))
reader, err = utils.SystemdBootConfReader(fs, "/efi/loader/loader.conf")
Expect(err).ToNot(HaveOccurred())
Expect(reader["default"]).To(Equal("autoreset_foobar.conf"))
Expect(reader["default"]).To(Equal("statereset_foobar.conf"))
// Should have called a remount to make it RW
Expect(syscallMock.WasMountCalledWith(
"",
Expand Down
17 changes: 9 additions & 8 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const (
ActiveImgName = "active"
PassiveImgName = "passive"
RecoveryImgName = "recovery"
AutoResetEntryName = "autoreset"
StateResetImgName = "statereset"
GPT = "gpt"
UsrLocalPath = "/usr/local"
OEMPath = "/oem"
Expand Down Expand Up @@ -117,12 +117,13 @@ const (
UkiMaxEntries = 3

// Boot labeling
PassiveBootSuffix = " (fallback)"
RecoveryBootSuffix = " recovery"
PassiveBootSuffix = " (fallback)"
RecoveryBootSuffix = " recovery"
StateResetBootSuffix = " state reset (auto)"
)

func UkiDefaultMenuEntries() []string {
return []string{"cos", "fallback", "recovery", "autoreset"}
return []string{"cos", "fallback", "recovery", "statereset"}
}

func UkiDefaultSkipEntries() []string {
Expand Down Expand Up @@ -177,8 +178,8 @@ func BaseBootTitle(title string) string {
return strings.TrimSuffix(title, RecoveryBootSuffix)
} else if strings.HasSuffix(title, PassiveBootSuffix) {
return strings.TrimSuffix(title, PassiveBootSuffix)
} else if strings.HasSuffix(title, AutoResetEntryName) {
return strings.TrimSuffix(title, AutoResetEntryName)
} else if strings.HasSuffix(title, StateResetBootSuffix) {
return strings.TrimSuffix(title, StateResetBootSuffix)
}
return title
}
Expand All @@ -191,8 +192,8 @@ func BootTitleForRole(role, title string) (string, error) {
return BaseBootTitle(title) + PassiveBootSuffix, nil
case RecoveryImgName:
return BaseBootTitle(title) + RecoveryBootSuffix, nil
case AutoResetEntryName:
return BaseBootTitle(title) + " " + AutoResetEntryName, nil
case StateResetImgName:
return BaseBootTitle(title) + StateResetBootSuffix, nil
default:
return "", errors.New("invalid role")
}
Expand Down

0 comments on commit 5b10043

Please sign in to comment.