summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoropenshift-ci[bot] <75433959+openshift-ci[bot]@users.noreply.github.com>2022-07-08 15:33:29 +0000
committerGitHub <noreply@github.com>2022-07-08 15:33:29 +0000
commit80f0ead64ab8a9998c2486ceeaf4e994821c9498 (patch)
tree3b535fea1ccce9b471a6b193ce1ba185d3e5d43f
parentcc6aac5be7953a5660d84d8e601ce418016e1ff3 (diff)
parent76d887c7702321894c28a7479e696ef45f36143c (diff)
downloadpodman-80f0ead64ab8a9998c2486ceeaf4e994821c9498.tar.gz
podman-80f0ead64ab8a9998c2486ceeaf4e994821c9498.tar.bz2
podman-80f0ead64ab8a9998c2486ceeaf4e994821c9498.zip
Merge pull request #14853 from baude/machinetestsfix
Fix machine tests
-rw-r--r--pkg/machine/e2e/config.go13
-rw-r--r--pkg/machine/e2e/init_test.go19
-rw-r--r--pkg/machine/e2e/inspect_test.go20
-rw-r--r--pkg/machine/e2e/list_test.go3
-rw-r--r--pkg/machine/e2e/machine_test.go9
-rw-r--r--pkg/machine/e2e/set_test.go13
6 files changed, 36 insertions, 41 deletions
diff --git a/pkg/machine/e2e/config.go b/pkg/machine/e2e/config.go
index 248a2f0ad..b3fe74b0c 100644
--- a/pkg/machine/e2e/config.go
+++ b/pkg/machine/e2e/config.go
@@ -3,7 +3,6 @@ package e2e
import (
"encoding/json"
"fmt"
- "math/rand"
"os"
"os/exec"
"path/filepath"
@@ -13,6 +12,7 @@ import (
"github.com/containers/podman/v4/pkg/machine"
"github.com/containers/podman/v4/pkg/machine/qemu"
"github.com/containers/podman/v4/pkg/util"
+ "github.com/containers/storage/pkg/stringid"
. "github.com/onsi/ginkgo" //nolint:golint,stylecheck
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
@@ -136,14 +136,14 @@ func (m *machineTestBuilder) setTimeout(timeout time.Duration) *machineTestBuild
// toQemuInspectInfo is only for inspecting qemu machines. Other providers will need
// to make their own.
-func (mb *machineTestBuilder) toQemuInspectInfo() ([]qemuMachineInspectInfo, int, error) {
+func (mb *machineTestBuilder) toQemuInspectInfo() ([]machine.InspectInfo, int, error) {
args := []string{"machine", "inspect"}
args = append(args, mb.names...)
session, err := runWrapper(mb.podmanBinary, args, defaultTimeout, true)
if err != nil {
return nil, -1, err
}
- mii := []qemuMachineInspectInfo{}
+ mii := []machine.InspectInfo{}
err = json.Unmarshal(session.Bytes(), &mii)
return mii, session.ExitCode(), err
}
@@ -179,10 +179,5 @@ func (m *machineTestBuilder) init() {}
// randomString returns a string of given length composed of random characters
func randomString(n int) string {
- var randomLetters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
- b := make([]rune, n)
- for i := range b {
- b[i] = randomLetters[rand.Intn(len(randomLetters))]
- }
- return string(b)
+ return stringid.GenerateRandomID()[0:12]
}
diff --git a/pkg/machine/e2e/init_test.go b/pkg/machine/e2e/init_test.go
index 6949eb0af..40f140cae 100644
--- a/pkg/machine/e2e/init_test.go
+++ b/pkg/machine/e2e/init_test.go
@@ -3,6 +3,7 @@ package e2e
import (
"io/ioutil"
"os"
+ "runtime"
"time"
"github.com/containers/podman/v4/pkg/machine"
@@ -44,9 +45,9 @@ var _ = Describe("podman machine init", func() {
Expect(len(inspectBefore)).To(BeNumerically(">", 0))
testMachine := inspectBefore[0]
- Expect(testMachine.VM.Name).To(Equal(mb.names[0]))
- Expect(testMachine.VM.CPUs).To(Equal(uint64(1)))
- Expect(testMachine.VM.Memory).To(Equal(uint64(2048)))
+ Expect(testMachine.Name).To(Equal(mb.names[0]))
+ Expect(testMachine.Resources.CPUs).To(Equal(uint64(1)))
+ Expect(testMachine.Resources.Memory).To(Equal(uint64(2048)))
})
@@ -61,7 +62,7 @@ var _ = Describe("podman machine init", func() {
Expect(len(inspectBefore)).To(BeNumerically(">", 0))
Expect(err).To(BeNil())
Expect(len(inspectBefore)).To(BeNumerically(">", 0))
- Expect(inspectBefore[0].VM.Name).To(Equal(mb.names[0]))
+ Expect(inspectBefore[0].Name).To(Equal(mb.names[0]))
s := startMachine{}
ssession, err := mb.setCmd(s).setTimeout(time.Minute * 10).run()
@@ -104,7 +105,15 @@ var _ = Describe("podman machine init", func() {
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()
Expect(err).To(BeNil())
Expect(memorySession).To(Exit(0))
- Expect(memorySession.outputToString()).To(ContainSubstring("3824"))
+ switch runtime.GOOS {
+ // os's handle memory differently
+ case "linux":
+ Expect(memorySession.outputToString()).To(ContainSubstring("3821"))
+ case "darwin":
+ Expect(memorySession.outputToString()).To(ContainSubstring("3824"))
+ default:
+ // add windows when testing on that platform
+ }
sshTimezone := sshMachine{}
timezoneSession, err := mb.setName(name).setCmd(sshTimezone.withSSHComand([]string{"date"})).run()
diff --git a/pkg/machine/e2e/inspect_test.go b/pkg/machine/e2e/inspect_test.go
index cdf13bb1a..93fb8cc2b 100644
--- a/pkg/machine/e2e/inspect_test.go
+++ b/pkg/machine/e2e/inspect_test.go
@@ -1,11 +1,9 @@
package e2e
import (
- "encoding/json"
"strings"
"github.com/containers/podman/v4/pkg/machine"
- "github.com/containers/podman/v4/pkg/machine/qemu"
jsoniter "github.com/json-iterator/go"
. "github.com/onsi/ginkgo"
@@ -51,24 +49,6 @@ var _ = Describe("podman machine stop", func() {
Expect(err).To(BeNil())
Expect(inspectSession).To(Exit(0))
Expect(inspectSession.Bytes()).To(ContainSubstring("foo1"))
-
- type fakeInfos struct {
- Status string
- VM qemu.MachineVM
- }
- infos := make([]fakeInfos, 0, 2)
- err = json.Unmarshal(inspectSession.Bytes(), &infos)
- Expect(err).ToNot(HaveOccurred())
- Expect(len(infos)).To(Equal(2))
-
- // rm := new(rmMachine)
- // // Must manually clean up due to multiple names
- // for _, name := range []string{"foo1", "foo2"} {
- // mb.setName(name).setCmd(rm.withForce()).run()
- // mb.names = []string{}
- // }
- // mb.names = []string{}
-
})
It("inspect with go format", func() {
diff --git a/pkg/machine/e2e/list_test.go b/pkg/machine/e2e/list_test.go
index 9e3e9956c..fb855c61e 100644
--- a/pkg/machine/e2e/list_test.go
+++ b/pkg/machine/e2e/list_test.go
@@ -130,7 +130,7 @@ var _ = Describe("podman machine list", func() {
// --format json
list2 := new(listMachine)
list2 = list2.withFormat("json")
- listSession2, err := mb.setName("foo1").setCmd(list2).run()
+ listSession2, err := mb.setCmd(list2).run()
Expect(err).To(BeNil())
Expect(listSession2).To(Exit(0))
@@ -145,7 +145,6 @@ var _ = Describe("podman machine list", func() {
Expect(listSession3).To(Exit(0))
listNames3 := listSession3.outputToStringSlice()
Expect(listNames3).To(HaveLen(2))
- Expect(listNames3).To(ContainSubstring("NAME"))
})
})
diff --git a/pkg/machine/e2e/machine_test.go b/pkg/machine/e2e/machine_test.go
index 657014b05..7b063937d 100644
--- a/pkg/machine/e2e/machine_test.go
+++ b/pkg/machine/e2e/machine_test.go
@@ -22,7 +22,7 @@ func TestMain(m *testing.M) {
}
const (
- defaultStream string = "podman-testing"
+ defaultStream string = "testing"
)
var (
@@ -97,6 +97,9 @@ func setup() (string, *machineTestBuilder) {
if err := os.Setenv("HOME", homeDir); err != nil {
Fail("failed to set home dir")
}
+ if err := os.Setenv("XDG_RUNTIME_DIR", homeDir); err != nil {
+ Fail("failed to set xdg_runtime dir")
+ }
if err := os.Unsetenv("SSH_AUTH_SOCK"); err != nil {
Fail("unable to unset SSH_AUTH_SOCK")
}
@@ -120,9 +123,9 @@ func setup() (string, *machineTestBuilder) {
}
func teardown(origHomeDir string, testDir string, mb *machineTestBuilder) {
- s := new(stopMachine)
+ r := new(rmMachine)
for _, name := range mb.names {
- if _, err := mb.setName(name).setCmd(s).run(); err != nil {
+ if _, err := mb.setName(name).setCmd(r.withForce()).run(); err != nil {
fmt.Printf("error occurred rm'ing machine: %q\n", err)
}
}
diff --git a/pkg/machine/e2e/set_test.go b/pkg/machine/e2e/set_test.go
index 15215a44d..80cb89488 100644
--- a/pkg/machine/e2e/set_test.go
+++ b/pkg/machine/e2e/set_test.go
@@ -1,6 +1,8 @@
package e2e
import (
+ "runtime"
+
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
@@ -57,8 +59,15 @@ var _ = Describe("podman machine set", func() {
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()
Expect(err).To(BeNil())
Expect(memorySession).To(Exit(0))
- Expect(memorySession.outputToString()).To(ContainSubstring("3824"))
-
+ switch runtime.GOOS {
+ // it seems macos and linux handle memory differently
+ case "linux":
+ Expect(memorySession.outputToString()).To(ContainSubstring("3821"))
+ case "darwin":
+ Expect(memorySession.outputToString()).To(ContainSubstring("3824"))
+ default:
+ // windows can go here if we ever run tests there
+ }
// Setting a running machine results in 125
runner, err := mb.setName(name).setCmd(set.withCPUs(4)).run()
Expect(err).To(BeNil())