mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-06 03:20:25 +00:00
Respect user defined/default sizes on upgrade (#587)
This commit is contained in:
@@ -18,22 +18,17 @@ package action_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/kairos-io/kairos-agent/v2/internal/agent"
|
||||
"github.com/kairos-io/kairos-agent/v2/pkg/action"
|
||||
agentConfig "github.com/kairos-io/kairos-agent/v2/pkg/config"
|
||||
"github.com/kairos-io/kairos-agent/v2/pkg/constants"
|
||||
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
|
||||
fsutils "github.com/kairos-io/kairos-agent/v2/pkg/utils/fs"
|
||||
v1mock "github.com/kairos-io/kairos-agent/v2/tests/mocks"
|
||||
"github.com/kairos-io/kairos-sdk/collector"
|
||||
ghwMock "github.com/kairos-io/kairos-sdk/ghw/mocks"
|
||||
sdkTypes "github.com/kairos-io/kairos-sdk/types"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
@@ -55,10 +50,8 @@ var _ = Describe("Upgrade Actions test", func() {
|
||||
var ghwTest ghwMock.GhwMock
|
||||
var extractor *v1mock.FakeImageExtractor
|
||||
var dummySourceFile string
|
||||
var dummySourceSizeMb int64
|
||||
|
||||
BeforeEach(func() {
|
||||
dummySourceSizeMb = 20
|
||||
runner = v1mock.NewFakeRunner()
|
||||
syscall = &v1mock.FakeSyscall{}
|
||||
mounter = v1mock.NewErrorMounter()
|
||||
@@ -153,34 +146,6 @@ var _ = Describe("Upgrade Actions test", func() {
|
||||
AfterEach(func() {
|
||||
ghwTest.Clean()
|
||||
})
|
||||
It("calculates the recovery source size correctly", func() {
|
||||
dummySourceFile = createDummyFile(fs, dummySourceSizeMb)
|
||||
upgradeConfig := agent.ExtraConfigUpgrade{}
|
||||
upgradeConfig.Upgrade.Entry = constants.BootEntryRecovery
|
||||
upgradeConfig.Upgrade.RecoverySystem.URI = fmt.Sprintf("file:%s", dummySourceFile)
|
||||
d, err := json.Marshal(upgradeConfig)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
cliConfig := string(d)
|
||||
|
||||
config, err := agentConfig.Scan(collector.Readers(strings.NewReader(cliConfig)))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
agentConfig.WithFs(fs)(config)
|
||||
agentConfig.WithRunner(runner)(config)
|
||||
agentConfig.WithLogger(logger)(config)
|
||||
agentConfig.WithMounter(mounter)(config)
|
||||
agentConfig.WithSyscall(syscall)(config)
|
||||
agentConfig.WithClient(client)(config)
|
||||
agentConfig.WithCloudInitRunner(cloudInit)(config)
|
||||
agentConfig.WithImageExtractor(extractor)(config)
|
||||
agentConfig.WithPlatform("linux/amd64")(config)
|
||||
config.ImageExtractor = extractor
|
||||
|
||||
spec, err = agentConfig.NewUpgradeSpec(config)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
Expect(spec.Entry).To(Equal(constants.BootEntryRecovery))
|
||||
Expect(spec.Recovery.Size).To(Equal(uint(100 + dummySourceSizeMb))) // We adding 100Mb on top
|
||||
})
|
||||
Describe(fmt.Sprintf("Booting from %s", constants.ActiveLabel), Label("active_label"), func() {
|
||||
var err error
|
||||
BeforeEach(func() {
|
||||
@@ -659,25 +624,3 @@ var _ = Describe("Upgrade Actions test", func() {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
func createDummyFile(fs vfs.FS, sizeMb int64) string {
|
||||
fileSize := int64(sizeMb * 1024 * 1024)
|
||||
|
||||
tmpFile, err := os.CreateTemp("", "dummyfile_*.tmp")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
tmpName := tmpFile.Name()
|
||||
tmpFile.Close()
|
||||
os.RemoveAll(tmpName)
|
||||
|
||||
dir := filepath.Dir(tmpName)
|
||||
err = fs.Mkdir(dir, os.ModePerm)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
f, err := fs.Create(tmpName)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
err = f.Truncate(fileSize)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
f.Close()
|
||||
|
||||
return tmpName
|
||||
}
|
||||
|
Reference in New Issue
Block a user