mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-06 11:30:34 +00:00
Track active/passive boot for upgrade workflow (#133)
* Track active/passive boot for upgrade workflow Track what are we booting from during upgrade in order to not backup active into passive if we are booting from passive. If we are booting from active or recovery the workflow keeps as it was, backup active into passive, and then move the transition image into active. Signed-off-by: Itxaka <itxaka@kairos.io>
This commit is contained in:
@@ -149,6 +149,13 @@ var _ = Describe("Runtime Actions", func() {
|
||||
err = fsutils.MkdirAll(config.Fs, filepath.Join(spec.Active.MountPoint, "etc"), constants.DirPerm)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
|
||||
err = fsutils.MkdirAll(config.Fs, "/proc", constants.DirPerm)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
|
||||
// Write proc/cmdline so we can detect what we booted from
|
||||
err = fs.WriteFile("/proc/cmdline", []byte(constants.ActiveLabel), constants.FilePerm)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
|
||||
err = fs.WriteFile(
|
||||
filepath.Join(spec.Active.MountPoint, "etc", "os-release"),
|
||||
[]byte("GRUB_ENTRY_NAME=TESTOS"),
|
||||
@@ -161,9 +168,6 @@ var _ = Describe("Runtime Actions", func() {
|
||||
spec.Recovery.Size = 10
|
||||
|
||||
runner.SideEffect = func(command string, args ...string) ([]byte, error) {
|
||||
if command == "cat" && args[0] == "/proc/cmdline" {
|
||||
return []byte(constants.ActiveLabel), nil
|
||||
}
|
||||
if command == "mv" && args[0] == "-f" && args[1] == activeImg && args[2] == passiveImg {
|
||||
// we doing backup, do the "move"
|
||||
source, _ := fs.ReadFile(activeImg)
|
||||
@@ -359,6 +363,13 @@ var _ = Describe("Runtime Actions", func() {
|
||||
)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
|
||||
err = fsutils.MkdirAll(config.Fs, "/proc", constants.DirPerm)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
|
||||
// Write proc/cmdline so we can detect what we booted from
|
||||
err = fs.WriteFile("/proc/cmdline", []byte(constants.PassiveLabel), constants.FilePerm)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
|
||||
spec.Active.Size = 10
|
||||
spec.Passive.Size = 10
|
||||
spec.Recovery.Size = 10
|
||||
@@ -373,6 +384,10 @@ var _ = Describe("Runtime Actions", func() {
|
||||
_ = fs.WriteFile(activeImg, source, constants.FilePerm)
|
||||
_ = fs.RemoveAll(spec.Active.File)
|
||||
}
|
||||
if command == "mv" && args[0] == "-f" && args[1] == activeImg && args[2] == passiveImg {
|
||||
// If this command was called then its a complete failure as it tried to copy active into passive
|
||||
StopTrying("Passive was overwritten").Now()
|
||||
}
|
||||
return []byte{}, nil
|
||||
}
|
||||
config.Runner = runner
|
||||
@@ -436,6 +451,13 @@ var _ = Describe("Runtime Actions", func() {
|
||||
|
||||
spec.RecoveryUpgrade = true
|
||||
|
||||
err = fsutils.MkdirAll(config.Fs, "/proc", constants.DirPerm)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
|
||||
// Write proc/cmdline so we can detect what we booted from
|
||||
err = fs.WriteFile("/proc/cmdline", []byte(constants.RecoveryLabel), constants.FilePerm)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
|
||||
runner.SideEffect = func(command string, args ...string) ([]byte, error) {
|
||||
if command == "cat" && args[0] == "/proc/cmdline" {
|
||||
return []byte(constants.RecoveryLabel), nil
|
||||
@@ -522,6 +544,13 @@ var _ = Describe("Runtime Actions", func() {
|
||||
|
||||
spec.RecoveryUpgrade = true
|
||||
|
||||
err = fsutils.MkdirAll(config.Fs, "/proc", constants.DirPerm)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
|
||||
// Write proc/cmdline so we can detect what we booted from
|
||||
err = fs.WriteFile("/proc/cmdline", []byte(constants.RecoveryLabel), constants.FilePerm)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
|
||||
runner.SideEffect = func(command string, args ...string) ([]byte, error) {
|
||||
if command == "cat" && args[0] == "/proc/cmdline" {
|
||||
return []byte(constants.RecoveryLabel), nil
|
||||
|
Reference in New Issue
Block a user