Merge pull request #25841 from baude/initunits

Correct units in init error message
This commit is contained in:
openshift-merge-bot[bot]
2025-04-10 12:06:14 +00:00
committed by GitHub
2 changed files with 4 additions and 3 deletions

View File

@ -249,7 +249,7 @@ func checkMaxMemory(newMem strongunits.MiB) error {
return err return err
} }
if total := strongunits.B(memStat.Total); strongunits.B(memStat.Total) < newMem.ToBytes() { if total := strongunits.B(memStat.Total); strongunits.B(memStat.Total) < newMem.ToBytes() {
return fmt.Errorf("requested amount of memory (%d MB) greater than total system memory (%d MB)", newMem, total) return fmt.Errorf("requested amount of memory (%d MB) greater than total system memory (%d MB)", newMem, strongunits.ToMib(total))
} }
return nil return nil
} }

View File

@ -71,11 +71,12 @@ var _ = Describe("podman machine init", func() {
// this comes in bytes // this comes in bytes
memStat, err := mem.VirtualMemory() memStat, err := mem.VirtualMemory()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
total := strongunits.ToMib(strongunits.B(memStat.Total)) + 1024 systemMem := strongunits.ToMib(strongunits.B(memStat.Total))
badMem := initMachine{} badMem := initMachine{}
badMemSession, err := mb.setCmd(badMem.withMemory(uint(total))).run() badMemSession, err := mb.setCmd(badMem.withMemory(uint(systemMem + 1024))).run()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(badMemSession.errorToString()).To(ContainSubstring(fmt.Sprintf("greater than total system memory (%d MB)", systemMem)))
Expect(badMemSession).To(Exit(125)) Expect(badMemSession).To(Exit(125))
}) })