summaryrefslogtreecommitdiff
path: root/pkg/machine/e2e
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/machine/e2e')
-rw-r--r--pkg/machine/e2e/config.go13
-rw-r--r--pkg/machine/e2e/config_info.go20
-rw-r--r--pkg/machine/e2e/info_test.go58
-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.go11
-rw-r--r--pkg/machine/e2e/machine_test.go9
-rw-r--r--pkg/machine/e2e/set_test.go13
8 files changed, 119 insertions, 44 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/config_info.go b/pkg/machine/e2e/config_info.go
new file mode 100644
index 000000000..410c7e518
--- /dev/null
+++ b/pkg/machine/e2e/config_info.go
@@ -0,0 +1,20 @@
+package e2e
+
+type infoMachine struct {
+ format string
+ cmd []string
+}
+
+func (i *infoMachine) buildCmd(m *machineTestBuilder) []string {
+ cmd := []string{"machine", "info"}
+ if len(i.format) > 0 {
+ cmd = append(cmd, "--format", i.format)
+ }
+ i.cmd = cmd
+ return cmd
+}
+
+func (i *infoMachine) withFormat(format string) *infoMachine {
+ i.format = format
+ return i
+}
diff --git a/pkg/machine/e2e/info_test.go b/pkg/machine/e2e/info_test.go
new file mode 100644
index 000000000..eeabb78af
--- /dev/null
+++ b/pkg/machine/e2e/info_test.go
@@ -0,0 +1,58 @@
+package e2e
+
+import (
+ "github.com/containers/podman/v4/cmd/podman/machine"
+ jsoniter "github.com/json-iterator/go"
+ . "github.com/onsi/ginkgo"
+ . "github.com/onsi/gomega"
+ . "github.com/onsi/gomega/gexec"
+)
+
+var _ = Describe("podman machine info", func() {
+ var (
+ mb *machineTestBuilder
+ testDir string
+ )
+
+ BeforeEach(func() {
+ testDir, mb = setup()
+ })
+ AfterEach(func() {
+ teardown(originalHomeDir, testDir, mb)
+ })
+
+ It("machine info", func() {
+ info := new(infoMachine)
+ infoSession, err := mb.setCmd(info).run()
+ Expect(err).NotTo(HaveOccurred())
+ Expect(infoSession).Should(Exit(0))
+
+ // Verify go template works and check for no running machines
+ info = new(infoMachine)
+ infoSession, err = mb.setCmd(info.withFormat("{{.Host.NumberOfMachines}}")).run()
+ Expect(err).NotTo(HaveOccurred())
+ Expect(infoSession).Should(Exit(0))
+ Expect(infoSession.outputToString()).To(Equal("0"))
+
+ // Create a machine and check if info has been updated
+ i := new(initMachine)
+ initSession, err := mb.setCmd(i.withImagePath(mb.imagePath)).run()
+ Expect(err).To(BeNil())
+ Expect(initSession).To(Exit(0))
+
+ info = new(infoMachine)
+ infoSession, err = mb.setCmd(info.withFormat("{{.Host.NumberOfMachines}}")).run()
+ Expect(err).NotTo(HaveOccurred())
+ Expect(infoSession).Should(Exit(0))
+ Expect(infoSession.outputToString()).To(Equal("1"))
+
+ // Check if json is in correct format
+ infoSession, err = mb.setCmd(info.withFormat("json")).run()
+ Expect(err).NotTo(HaveOccurred())
+ Expect(infoSession).Should(Exit(0))
+
+ infoReport := &machine.Info{}
+ err = jsoniter.Unmarshal(infoSession.Bytes(), infoReport)
+ Expect(err).To(BeNil())
+ })
+})
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 e2121e7bf..fb855c61e 100644
--- a/pkg/machine/e2e/list_test.go
+++ b/pkg/machine/e2e/list_test.go
@@ -2,9 +2,10 @@ package e2e
import (
"strings"
+ "time"
"github.com/containers/common/pkg/util"
- "github.com/containers/podman/v4/cmd/podman/machine"
+ "github.com/containers/podman/v4/pkg/domain/entities"
jsoniter "github.com/json-iterator/go"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@@ -87,7 +88,7 @@ var _ = Describe("podman machine list", func() {
startSession, err := mb.setCmd(s).runWithoutWait()
Expect(err).To(BeNil())
l := new(listMachine)
- for { // needs to be infinite because we need to check if running when inspect returns to avoid race conditions.
+ for i := 0; i < 30; i++ {
listSession, err := mb.setCmd(l).run()
Expect(listSession).To(Exit(0))
Expect(err).To(BeNil())
@@ -96,6 +97,7 @@ var _ = Describe("podman machine list", func() {
} else {
break
}
+ time.Sleep(3 * time.Second)
}
Expect(startSession).To(Exit(0))
listSession, err := mb.setCmd(l).run()
@@ -128,11 +130,11 @@ 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))
- var listResponse []*machine.ListReporter
+ var listResponse []*entities.ListReporter
err = jsoniter.Unmarshal(listSession.Bytes(), &listResponse)
Expect(err).To(BeNil())
@@ -143,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())