Skip to content

Commit 521b245

Browse files
committed
Correct units in init error message
When trying to initialize a machine with more memory that the system has we were outputting an error message in the wrong unit. It should have been in MB and B. This was found as part of #25803 but is not the solution for that issue. Signed-off-by: Brent Baude <[email protected]>
1 parent ce7db6e commit 521b245

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

cmd/podman/machine/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func checkMaxMemory(newMem strongunits.MiB) error {
249249
return err
250250
}
251251
if total := strongunits.B(memStat.Total); strongunits.B(memStat.Total) < newMem.ToBytes() {
252-
return fmt.Errorf("requested amount of memory (%d MB) greater than total system memory (%d MB)", newMem, total)
252+
return fmt.Errorf("requested amount of memory (%d MB) greater than total system memory (%d MB)", newMem, strongunits.ToMib(total))
253253
}
254254
return nil
255255
}

pkg/machine/e2e/init_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ var _ = Describe("podman machine init", func() {
7171
// this comes in bytes
7272
memStat, err := mem.VirtualMemory()
7373
Expect(err).ToNot(HaveOccurred())
74-
total := strongunits.ToMib(strongunits.B(memStat.Total)) + 1024
74+
systemMem := strongunits.ToMib(strongunits.B(memStat.Total))
7575

7676
badMem := initMachine{}
77-
badMemSession, err := mb.setCmd(badMem.withMemory(uint(total))).run()
77+
badMemSession, err := mb.setCmd(badMem.withMemory(uint(systemMem + 1024))).run()
7878
Expect(err).ToNot(HaveOccurred())
79+
Expect(badMemSession.errorToString()).To(ContainSubstring(fmt.Sprintf("greater than total system memory (%d MB)", systemMem)))
7980
Expect(badMemSession).To(Exit(125))
8081
})
8182

0 commit comments

Comments
 (0)