mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-16 14:40:28 +00:00
fix reset not updating EFI files (#600)
This commit is contained in:
2082
internal/webui/public/package-lock.json
generated
2082
internal/webui/public/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -199,6 +199,16 @@ func (r ResetAction) Run() (err error) {
|
|||||||
// Create extra dirs in rootfs as afterwards this will be impossible due to RO system
|
// Create extra dirs in rootfs as afterwards this will be impossible due to RO system
|
||||||
createExtraDirsInRootfs(r.cfg, r.spec.ExtraDirsRootfs, r.spec.Active.MountPoint)
|
createExtraDirsInRootfs(r.cfg, r.spec.ExtraDirsRootfs, r.spec.Active.MountPoint)
|
||||||
|
|
||||||
|
// Mount EFI partition before installing grub as under EFI this copies stuff in there
|
||||||
|
if r.spec.Efi {
|
||||||
|
err = e.MountPartition(r.spec.Partitions.EFI)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cleanup.Push(func() error { return e.UnmountPartition(r.spec.Partitions.EFI) })
|
||||||
|
}
|
||||||
|
//TODO: does bios needs to be mounted here?
|
||||||
|
|
||||||
// install grub
|
// install grub
|
||||||
grub := utils.NewGrub(r.cfg)
|
grub := utils.NewGrub(r.cfg)
|
||||||
err = grub.Install(
|
err = grub.Install(
|
||||||
|
@@ -20,18 +20,15 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
|
||||||
"regexp"
|
|
||||||
|
|
||||||
"github.com/kairos-io/kairos-agent/v2/pkg/action"
|
"github.com/kairos-io/kairos-agent/v2/pkg/action"
|
||||||
agentConfig "github.com/kairos-io/kairos-agent/v2/pkg/config"
|
agentConfig "github.com/kairos-io/kairos-agent/v2/pkg/config"
|
||||||
"github.com/kairos-io/kairos-agent/v2/pkg/constants"
|
"github.com/kairos-io/kairos-agent/v2/pkg/constants"
|
||||||
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
|
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
|
||||||
"github.com/kairos-io/kairos-agent/v2/pkg/utils"
|
|
||||||
"github.com/kairos-io/kairos-agent/v2/pkg/utils/fs"
|
"github.com/kairos-io/kairos-agent/v2/pkg/utils/fs"
|
||||||
v1mock "github.com/kairos-io/kairos-agent/v2/tests/mocks"
|
v1mock "github.com/kairos-io/kairos-agent/v2/tests/mocks"
|
||||||
ghwMock "github.com/kairos-io/kairos-sdk/ghw/mocks"
|
ghwMock "github.com/kairos-io/kairos-sdk/ghw/mocks"
|
||||||
sdkTypes "github.com/kairos-io/kairos-sdk/types"
|
sdkTypes "github.com/kairos-io/kairos-sdk/types"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
@@ -159,76 +156,82 @@ var _ = Describe("Reset action tests", func() {
|
|||||||
_, err = fs.Create(grubCfg)
|
_, err = fs.Create(grubCfg)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
|
|
||||||
runner.SideEffect = func(cmd string, args ...string) ([]byte, error) {
|
// create the fake grub dir with modules, it needs an arch in the path
|
||||||
regexCmd := regexp.MustCompile(cmdFail)
|
Expect(fsutils.MkdirAll(fs, filepath.Join(spec.Active.MountPoint, constants.Archx86), constants.DirPerm)).ToNot(HaveOccurred())
|
||||||
if cmdFail != "" && regexCmd.MatchString(cmd) {
|
for _, mod := range constants.GetGrubModules() {
|
||||||
return []byte{}, errors.New("command failed")
|
_, err = fs.Create(filepath.Join(spec.Active.MountPoint, constants.Archx86, mod))
|
||||||
}
|
Expect(err).ToNot(HaveOccurred())
|
||||||
return []byte{}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create fake shim
|
||||||
|
Expect(fsutils.MkdirAll(fs, filepath.Join(spec.Active.MountPoint, "/usr/share/efi/x86_64/"), constants.DirPerm)).ToNot(HaveOccurred())
|
||||||
|
_, err = fs.Create(filepath.Join(spec.Active.MountPoint, "/usr/share/efi/x86_64/", "shim.efi"))
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
// create fake grub
|
||||||
|
Expect(fsutils.MkdirAll(fs, filepath.Join(spec.Active.MountPoint, "/usr/share/efi/x86_64/"), constants.DirPerm)).ToNot(HaveOccurred())
|
||||||
|
_, err = fs.Create(filepath.Join(spec.Active.MountPoint, "/usr/share/efi/x86_64/", "grub.efi"))
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
reset = action.NewResetAction(config, spec)
|
reset = action.NewResetAction(config, spec)
|
||||||
})
|
})
|
||||||
|
|
||||||
AfterEach(func() {
|
AfterEach(func() {
|
||||||
ghwTest.Clean()
|
ghwTest.Clean()
|
||||||
})
|
})
|
||||||
|
Describe("With EFI", func() {
|
||||||
|
It("Successfully resets on non-squashfs recovery", func() {
|
||||||
|
Expect(reset.Run()).To(BeNil())
|
||||||
|
})
|
||||||
|
It("Successfully resets on non-squashfs recovery including persistent data", func() {
|
||||||
|
spec.FormatPersistent = true
|
||||||
|
spec.FormatOEM = true
|
||||||
|
Expect(reset.Run()).To(BeNil())
|
||||||
|
})
|
||||||
|
It("Successfully resets from a squashfs recovery image", Label("channel"), func() {
|
||||||
|
err := fsutils.MkdirAll(config.Fs, constants.IsoBaseTree, constants.DirPerm)
|
||||||
|
Expect(err).ShouldNot(HaveOccurred())
|
||||||
|
spec.Active.Source = v1.NewDirSrc(constants.IsoBaseTree)
|
||||||
|
Expect(reset.Run()).To(BeNil())
|
||||||
|
})
|
||||||
|
It("Successfully resets despite having errors on hooks", func() {
|
||||||
|
cloudInit.Error = true
|
||||||
|
Expect(reset.Run()).To(BeNil())
|
||||||
|
})
|
||||||
|
It("Successfully resets from a docker image", Label("docker"), func() {
|
||||||
|
spec.Active.Source = v1.NewDockerSrc("my/image:latest")
|
||||||
|
Expect(reset.Run()).To(BeNil())
|
||||||
|
|
||||||
It("Successfully resets on non-squashfs recovery", func() {
|
})
|
||||||
Expect(reset.Run()).To(BeNil())
|
It("Fails formatting state partition", func() {
|
||||||
})
|
cmdFail = "mkfs.ext4"
|
||||||
It("Successfully resets on non-squashfs recovery including persistent data", func() {
|
Expect(reset.Run()).NotTo(BeNil())
|
||||||
spec.FormatPersistent = true
|
Expect(runner.IncludesCmds([][]string{{"mkfs.ext4"}}))
|
||||||
spec.FormatOEM = true
|
})
|
||||||
Expect(reset.Run()).To(BeNil())
|
It("Fails setting the active label on non-squashfs recovery", func() {
|
||||||
})
|
cmdFail = "tune2fs"
|
||||||
It("Successfully resets from a squashfs recovery image", Label("channel"), func() {
|
Expect(reset.Run()).NotTo(BeNil())
|
||||||
err := fsutils.MkdirAll(config.Fs, constants.IsoBaseTree, constants.DirPerm)
|
})
|
||||||
Expect(err).ShouldNot(HaveOccurred())
|
It("Fails setting the passive label on squashfs recovery", func() {
|
||||||
spec.Active.Source = v1.NewDirSrc(constants.IsoBaseTree)
|
cmdFail = "tune2fs"
|
||||||
Expect(reset.Run()).To(BeNil())
|
Expect(reset.Run()).NotTo(BeNil())
|
||||||
})
|
Expect(runner.IncludesCmds([][]string{{"tune2fs"}}))
|
||||||
It("Successfully resets despite having errors on hooks", func() {
|
})
|
||||||
cloudInit.Error = true
|
It("Fails mounting partitions", func() {
|
||||||
Expect(reset.Run()).To(BeNil())
|
mounter.ErrorOnMount = true
|
||||||
})
|
Expect(reset.Run()).NotTo(BeNil())
|
||||||
It("Successfully resets from a docker image", Label("docker"), func() {
|
})
|
||||||
spec.Active.Source = v1.NewDockerSrc("my/image:latest")
|
It("Fails unmounting partitions", func() {
|
||||||
Expect(reset.Run()).To(BeNil())
|
mounter.ErrorOnUnmount = true
|
||||||
|
Expect(reset.Run()).NotTo(BeNil())
|
||||||
})
|
})
|
||||||
It("Fails installing grub", func() {
|
It("Fails unpacking docker image ", func() {
|
||||||
cmdFail = utils.FindCommand("grub2-install", []string{"grub2-install", "grub-install"})
|
spec.Active.Source = v1.NewDockerSrc("my/image:latest")
|
||||||
Expect(reset.Run()).NotTo(BeNil())
|
extractor.SideEffect = func(imageRef, destination, platformRef string) error {
|
||||||
Expect(runner.IncludesCmds([][]string{{cmdFail}}))
|
return fmt.Errorf("error")
|
||||||
})
|
}
|
||||||
It("Fails formatting state partition", func() {
|
Expect(reset.Run()).NotTo(BeNil())
|
||||||
cmdFail = "mkfs.ext4"
|
})
|
||||||
Expect(reset.Run()).NotTo(BeNil())
|
|
||||||
Expect(runner.IncludesCmds([][]string{{"mkfs.ext4"}}))
|
|
||||||
})
|
|
||||||
It("Fails setting the active label on non-squashfs recovery", func() {
|
|
||||||
cmdFail = "tune2fs"
|
|
||||||
Expect(reset.Run()).NotTo(BeNil())
|
|
||||||
})
|
|
||||||
It("Fails setting the passive label on squashfs recovery", func() {
|
|
||||||
cmdFail = "tune2fs"
|
|
||||||
Expect(reset.Run()).NotTo(BeNil())
|
|
||||||
Expect(runner.IncludesCmds([][]string{{"tune2fs"}}))
|
|
||||||
})
|
|
||||||
It("Fails mounting partitions", func() {
|
|
||||||
mounter.ErrorOnMount = true
|
|
||||||
Expect(reset.Run()).NotTo(BeNil())
|
|
||||||
})
|
|
||||||
It("Fails unmounting partitions", func() {
|
|
||||||
mounter.ErrorOnUnmount = true
|
|
||||||
Expect(reset.Run()).NotTo(BeNil())
|
|
||||||
})
|
|
||||||
It("Fails unpacking docker image ", func() {
|
|
||||||
spec.Active.Source = v1.NewDockerSrc("my/image:latest")
|
|
||||||
extractor.SideEffect = func(imageRef, destination, platformRef string) error {
|
|
||||||
return fmt.Errorf("error")
|
|
||||||
}
|
|
||||||
Expect(reset.Run()).NotTo(BeNil())
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user