aboutsummaryrefslogtreecommitdiff
path: root/pkg/machine
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2022-08-08 14:38:31 -0500
committerMatthew Heon <mheon@redhat.com>2022-08-10 16:46:05 -0400
commitb619c7a722cd84c180522034b50024d0ce107770 (patch)
treeebf89712729aae5c37ac54ed698da980759e9f87 /pkg/machine
parenta3778b05123e061d787ba1b36ef4e077e852c91a (diff)
downloadpodman-b619c7a722cd84c180522034b50024d0ce107770.tar.gz
podman-b619c7a722cd84c180522034b50024d0ce107770.tar.bz2
podman-b619c7a722cd84c180522034b50024d0ce107770.zip
check memory test based on range
when verifying that the memory was set correctly for a podman machine instance, we check if the number is between a range because based on architecture, operating system, and memory itself this number can differ significantly. Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/machine')
-rw-r--r--pkg/machine/e2e/init_test.go19
-rw-r--r--pkg/machine/e2e/set_test.go20
2 files changed, 15 insertions, 24 deletions
diff --git a/pkg/machine/e2e/init_test.go b/pkg/machine/e2e/init_test.go
index b246dc4da..859a3ca46 100644
--- a/pkg/machine/e2e/init_test.go
+++ b/pkg/machine/e2e/init_test.go
@@ -3,7 +3,7 @@ package e2e_test
import (
"io/ioutil"
"os"
- "runtime"
+ "strconv"
"time"
"github.com/containers/podman/v4/pkg/machine"
@@ -80,7 +80,7 @@ var _ = Describe("podman machine init", func() {
It("machine init with cpus, disk size, memory, timezone", func() {
name := randomString()
i := new(initMachine)
- session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath).withCPUs(2).withDiskSize(102).withMemory(4000).withTimezone("Pacific/Honolulu")).run()
+ session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath).withCPUs(2).withDiskSize(102).withMemory(4096).withTimezone("Pacific/Honolulu")).run()
Expect(err).To(BeNil())
Expect(session).To(Exit(0))
@@ -102,18 +102,13 @@ var _ = Describe("podman machine init", func() {
Expect(diskSession.outputToString()).To(ContainSubstring("102 GiB"))
sshMemory := sshMachine{}
- memorySession, err := mb.setName(name).setCmd(sshMemory.withSSHComand([]string{"cat", "/proc/meminfo", "|", "numfmt", "--field", "2", "--from-unit=Ki", "--to-unit=Mi", "|", "sed", "'s/ kB/M/g'", "|", "grep", "MemTotal"})).run()
+ memorySession, err := mb.setName(name).setCmd(sshMemory.withSSHComand([]string{"cat", "/proc/meminfo", "|", "grep", "-i", "'memtotal'", "|", "grep", "-o", "'[[:digit:]]*'"})).run()
Expect(err).To(BeNil())
Expect(memorySession).To(Exit(0))
- switch runtime.GOOS {
- // os's handle memory differently
- case "linux":
- Expect(memorySession.outputToString()).To(ContainSubstring("3822"))
- case "darwin":
- Expect(memorySession.outputToString()).To(ContainSubstring("3824"))
- default:
- // add windows when testing on that platform
- }
+ foundMemory, err := strconv.Atoi(memorySession.outputToString())
+ Expect(err).To(BeNil())
+ Expect(foundMemory).To(BeNumerically(">", 3800000))
+ Expect(foundMemory).To(BeNumerically("<", 4200000))
sshTimezone := sshMachine{}
timezoneSession, err := mb.setName(name).setCmd(sshTimezone.withSSHComand([]string{"date"})).run()
diff --git a/pkg/machine/e2e/set_test.go b/pkg/machine/e2e/set_test.go
index 4839e33da..a32bb72f2 100644
--- a/pkg/machine/e2e/set_test.go
+++ b/pkg/machine/e2e/set_test.go
@@ -1,7 +1,7 @@
package e2e_test
import (
- "runtime"
+ "strconv"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@@ -29,7 +29,7 @@ var _ = Describe("podman machine set", func() {
Expect(session).To(Exit(0))
set := setMachine{}
- setSession, err := mb.setName(name).setCmd(set.withCPUs(2).withDiskSize(102).withMemory(4000)).run()
+ setSession, err := mb.setName(name).setCmd(set.withCPUs(2).withDiskSize(102).withMemory(4096)).run()
Expect(err).To(BeNil())
Expect(setSession).To(Exit(0))
@@ -56,18 +56,14 @@ var _ = Describe("podman machine set", func() {
Expect(diskSession.outputToString()).To(ContainSubstring("102 GiB"))
sshMemory := sshMachine{}
- memorySession, err := mb.setName(name).setCmd(sshMemory.withSSHComand([]string{"cat", "/proc/meminfo", "|", "numfmt", "--field", "2", "--from-unit=Ki", "--to-unit=Mi", "|", "sed", "'s/ kB/M/g'", "|", "grep", "MemTotal"})).run()
+ memorySession, err := mb.setName(name).setCmd(sshMemory.withSSHComand([]string{"cat", "/proc/meminfo", "|", "grep", "-i", "'memtotal'", "|", "grep", "-o", "'[[:digit:]]*'"})).run()
Expect(err).To(BeNil())
Expect(memorySession).To(Exit(0))
- switch runtime.GOOS {
- // it seems macos and linux handle memory differently
- case "linux":
- Expect(memorySession.outputToString()).To(ContainSubstring("3822"))
- case "darwin":
- Expect(memorySession.outputToString()).To(ContainSubstring("3824"))
- default:
- // windows can go here if we ever run tests there
- }
+ foundMemory, err := strconv.Atoi(memorySession.outputToString())
+ Expect(err).To(BeNil())
+ Expect(foundMemory).To(BeNumerically(">", 3800000))
+ Expect(foundMemory).To(BeNumerically("<", 4200000))
+
// Setting a running machine results in 125
runner, err := mb.setName(name).setCmd(set.withCPUs(4)).run()
Expect(err).To(BeNil())