summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-05-11 03:03:31 -0400
committerGitHub <noreply@github.com>2022-05-11 03:03:31 -0400
commitc379014ee4e57dc19669ae92f45f8e4c0814295b (patch)
tree10ea46b3a202da6caa1f6761704d30c67b6e8baf /pkg
parented1ba27f8dc33672e8361c6c1a71cf95b1b79e9a (diff)
parentc7c00ce55199c1e569953a4a03055268ecca147e (diff)
downloadpodman-c379014ee4e57dc19669ae92f45f8e4c0814295b.tar.gz
podman-c379014ee4e57dc19669ae92f45f8e4c0814295b.tar.bz2
podman-c379014ee4e57dc19669ae92f45f8e4c0814295b.zip
Merge pull request #14170 from ashley-cui/machtests
Add more machine tests
Diffstat (limited to 'pkg')
-rw-r--r--pkg/machine/e2e/config_init.go1
-rw-r--r--pkg/machine/e2e/init_test.go65
-rw-r--r--pkg/machine/e2e/inspect_test.go27
-rw-r--r--pkg/machine/e2e/list_test.go41
-rw-r--r--pkg/machine/e2e/set_test.go72
5 files changed, 151 insertions, 55 deletions
diff --git a/pkg/machine/e2e/config_init.go b/pkg/machine/e2e/config_init.go
index 2340a1133..7f18cce7d 100644
--- a/pkg/machine/e2e/config_init.go
+++ b/pkg/machine/e2e/config_init.go
@@ -25,6 +25,7 @@ type initMachine struct {
memory *uint
now bool
timezone string
+ rootful bool
volumes []string
cmd []string
diff --git a/pkg/machine/e2e/init_test.go b/pkg/machine/e2e/init_test.go
index 304122738..6949eb0af 100644
--- a/pkg/machine/e2e/init_test.go
+++ b/pkg/machine/e2e/init_test.go
@@ -1,6 +1,8 @@
package e2e
import (
+ "io/ioutil"
+ "os"
"time"
"github.com/containers/podman/v4/pkg/machine"
@@ -74,4 +76,67 @@ var _ = Describe("podman machine init", func() {
Expect(inspectAfter[0].State).To(Equal(machine.Running))
})
+ It("machine init with cpus, disk size, memory, timezone", func() {
+ name := randomString(12)
+ i := new(initMachine)
+ session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath).withCPUs(2).withDiskSize(102).withMemory(4000).withTimezone("Pacific/Honolulu")).run()
+ Expect(err).To(BeNil())
+ Expect(session).To(Exit(0))
+
+ s := new(startMachine)
+ startSession, err := mb.setCmd(s).run()
+ Expect(err).To(BeNil())
+ Expect(startSession).To(Exit(0))
+
+ sshCPU := sshMachine{}
+ CPUsession, err := mb.setName(name).setCmd(sshCPU.withSSHComand([]string{"lscpu", "|", "grep", "\"CPU(s):\"", "|", "head", "-1"})).run()
+ Expect(err).To(BeNil())
+ Expect(CPUsession).To(Exit(0))
+ Expect(CPUsession.outputToString()).To(ContainSubstring("2"))
+
+ sshDisk := sshMachine{}
+ diskSession, err := mb.setName(name).setCmd(sshDisk.withSSHComand([]string{"sudo", "fdisk", "-l", "|", "grep", "Disk"})).run()
+ Expect(err).To(BeNil())
+ Expect(diskSession).To(Exit(0))
+ 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()
+ Expect(err).To(BeNil())
+ Expect(memorySession).To(Exit(0))
+ Expect(memorySession.outputToString()).To(ContainSubstring("3824"))
+
+ sshTimezone := sshMachine{}
+ timezoneSession, err := mb.setName(name).setCmd(sshTimezone.withSSHComand([]string{"date"})).run()
+ Expect(err).To(BeNil())
+ Expect(timezoneSession).To(Exit(0))
+ Expect(timezoneSession.outputToString()).To(ContainSubstring("HST"))
+ })
+
+ It("machine init with volume", func() {
+ tmpDir, err := ioutil.TempDir("", "")
+ Expect(err).To(BeNil())
+ _, err = ioutil.TempFile(tmpDir, "example")
+ Expect(err).To(BeNil())
+ mount := tmpDir + ":/testmountdir"
+ defer os.RemoveAll(tmpDir)
+
+ name := randomString(12)
+ i := new(initMachine)
+ session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath).withVolume(mount)).run()
+ Expect(err).To(BeNil())
+ Expect(session).To(Exit(0))
+
+ s := new(startMachine)
+ startSession, err := mb.setCmd(s).run()
+ Expect(err).To(BeNil())
+ Expect(startSession).To(Exit(0))
+
+ ssh2 := sshMachine{}
+ sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHComand([]string{"ls /testmountdir"})).run()
+ Expect(err).To(BeNil())
+ Expect(sshSession2).To(Exit(0))
+ Expect(sshSession2.outputToString()).To(ContainSubstring("example"))
+ })
+
})
diff --git a/pkg/machine/e2e/inspect_test.go b/pkg/machine/e2e/inspect_test.go
index b34285dd8..2c9de5664 100644
--- a/pkg/machine/e2e/inspect_test.go
+++ b/pkg/machine/e2e/inspect_test.go
@@ -3,7 +3,9 @@ package e2e
import (
"encoding/json"
+ "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"
. "github.com/onsi/gomega"
@@ -67,4 +69,29 @@ var _ = Describe("podman machine stop", func() {
// mb.names = []string{}
})
+
+ It("inspect with go format", func() {
+ name := randomString(12)
+ i := new(initMachine)
+ session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
+ Expect(err).To(BeNil())
+ Expect(session).To(Exit(0))
+
+ // regular inspect should
+ inspectJson := new(inspectMachine)
+ inspectSession, err := mb.setName(name).setCmd(inspectJson).run()
+ Expect(err).To(BeNil())
+ Expect(inspectSession).To(Exit(0))
+
+ var inspectInfo []machine.InspectInfo
+ err = jsoniter.Unmarshal(inspectSession.Bytes(), &inspectInfo)
+ Expect(err).To(BeNil())
+
+ inspect := new(inspectMachine)
+ inspect = inspect.withFormat("{{.Name}}")
+ inspectSession, err = mb.setName(name).setCmd(inspect).run()
+ Expect(err).To(BeNil())
+ Expect(inspectSession).To(Exit(0))
+ Expect(inspectSession.Bytes()).To(ContainSubstring(name))
+ })
})
diff --git a/pkg/machine/e2e/list_test.go b/pkg/machine/e2e/list_test.go
index 0ce9063f9..0bc867047 100644
--- a/pkg/machine/e2e/list_test.go
+++ b/pkg/machine/e2e/list_test.go
@@ -4,6 +4,8 @@ import (
"strings"
"github.com/containers/buildah/util"
+ "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"
@@ -40,7 +42,7 @@ var _ = Describe("podman machine list", func() {
Expect(len(secondList.outputToStringSlice())).To(Equal(2)) // one machine and the header
})
- It("list machines with quiet", func() {
+ It("list machines with quiet or noheading", func() {
// Random names for machines to test list
name1 := randomString(12)
name2 := randomString(12)
@@ -51,6 +53,11 @@ var _ = Describe("podman machine list", func() {
Expect(firstList).Should(Exit(0))
Expect(len(firstList.outputToStringSlice())).To(Equal(0)) // No header with quiet
+ noheaderSession, err := mb.setCmd(list.withNoHeading()).run() // noheader
+ Expect(err).NotTo(HaveOccurred())
+ Expect(noheaderSession).Should(Exit(0))
+ Expect(len(noheaderSession.outputToStringSlice())).To(Equal(0))
+
i := new(initMachine)
session, err := mb.setName(name1).setCmd(i.withImagePath(mb.imagePath)).run()
Expect(err).To(BeNil())
@@ -97,6 +104,38 @@ var _ = Describe("podman machine list", func() {
Expect(listSession.outputToString()).To(ContainSubstring("Currently running"))
Expect(listSession.outputToString()).NotTo(ContainSubstring("Less than a second ago")) // check to make sure time created is accurate
})
+
+ It("list with --format", func() {
+ // Random names for machines to test list
+ name1 := randomString(12)
+
+ i := new(initMachine)
+ session, err := mb.setName(name1).setCmd(i.withImagePath(mb.imagePath)).run()
+ Expect(err).To(BeNil())
+ Expect(session).To(Exit(0))
+
+ // go format
+ list := new(listMachine)
+ listSession, err := mb.setCmd(list.withFormat("{{.Name}}").withNoHeading()).run()
+ Expect(err).NotTo(HaveOccurred())
+ Expect(listSession).To(Exit(0))
+ Expect(len(listSession.outputToStringSlice())).To(Equal(1))
+
+ listNames := listSession.outputToStringSlice()
+ stripAsterisk(listNames)
+ Expect(util.StringInSlice(name1, listNames)).To(BeTrue())
+
+ // --format json
+ list2 := new(listMachine)
+ list2 = list2.withFormat("json")
+ listSession2, err := mb.setName("foo1").setCmd(list2).run()
+ Expect(err).To(BeNil())
+ Expect(listSession2).To(Exit(0))
+
+ var listResponse []*machine.ListReporter
+ err = jsoniter.Unmarshal(listSession.Bytes(), &listResponse)
+ Expect(err).To(BeNil())
+ })
})
func stripAsterisk(sl []string) {
diff --git a/pkg/machine/e2e/set_test.go b/pkg/machine/e2e/set_test.go
index 9af29c560..15215a44d 100644
--- a/pkg/machine/e2e/set_test.go
+++ b/pkg/machine/e2e/set_test.go
@@ -19,7 +19,7 @@ var _ = Describe("podman machine set", func() {
teardown(originalHomeDir, testDir, mb)
})
- It("set machine cpus", func() {
+ It("set machine cpus, disk, memory", func() {
name := randomString(12)
i := new(initMachine)
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
@@ -27,40 +27,11 @@ var _ = Describe("podman machine set", func() {
Expect(session).To(Exit(0))
set := setMachine{}
- setSession, err := mb.setName(name).setCmd(set.withCPUs(2)).run()
+ setSession, err := mb.setName(name).setCmd(set.withCPUs(2).withDiskSize(102).withMemory(4000)).run()
Expect(err).To(BeNil())
Expect(setSession).To(Exit(0))
- s := new(startMachine)
- startSession, err := mb.setCmd(s).run()
- Expect(err).To(BeNil())
- Expect(startSession).To(Exit(0))
-
- ssh2 := sshMachine{}
- sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHComand([]string{"lscpu", "|", "grep", "\"CPU(s):\"", "|", "head", "-1"})).run()
- Expect(err).To(BeNil())
- Expect(sshSession2).To(Exit(0))
- Expect(sshSession2.outputToString()).To(ContainSubstring("2"))
-
- // Setting a running machine results in 125
- runner, err := mb.setName(name).setCmd(set.withCPUs(4)).run()
- Expect(err).To(BeNil())
- Expect(runner).To(Exit(125))
- })
-
- It("increase machine disk size", func() {
- name := randomString(12)
- i := new(initMachine)
- session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
- Expect(err).To(BeNil())
- Expect(session).To(Exit(0))
-
- set := setMachine{}
- setSession, err := mb.setName(name).setCmd(set.withDiskSize(102)).run()
- Expect(err).To(BeNil())
- Expect(setSession).To(Exit(0))
-
- // shrinking disk size iss verboten
+ // shrinking disk size is verboten
shrink, err := mb.setName(name).setCmd(set.withDiskSize(5)).run()
Expect(err).To(BeNil())
Expect(shrink).To(Exit(125))
@@ -70,35 +41,28 @@ var _ = Describe("podman machine set", func() {
Expect(err).To(BeNil())
Expect(startSession).To(Exit(0))
- ssh2 := sshMachine{}
- sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHComand([]string{"sudo", "fdisk", "-l", "|", "grep", "Disk"})).run()
- Expect(err).To(BeNil())
- Expect(sshSession2).To(Exit(0))
- Expect(sshSession2.outputToString()).To(ContainSubstring("102 GiB"))
- })
-
- It("set machine ram", func() {
- name := randomString(12)
- i := new(initMachine)
- session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
+ sshCPU := sshMachine{}
+ CPUsession, err := mb.setName(name).setCmd(sshCPU.withSSHComand([]string{"lscpu", "|", "grep", "\"CPU(s):\"", "|", "head", "-1"})).run()
Expect(err).To(BeNil())
- Expect(session).To(Exit(0))
+ Expect(CPUsession).To(Exit(0))
+ Expect(CPUsession.outputToString()).To(ContainSubstring("2"))
- set := setMachine{}
- setSession, err := mb.setName(name).setCmd(set.withMemory(4000)).run()
+ sshDisk := sshMachine{}
+ diskSession, err := mb.setName(name).setCmd(sshDisk.withSSHComand([]string{"sudo", "fdisk", "-l", "|", "grep", "Disk"})).run()
Expect(err).To(BeNil())
- Expect(setSession).To(Exit(0))
+ Expect(diskSession).To(Exit(0))
+ Expect(diskSession.outputToString()).To(ContainSubstring("102 GiB"))
- s := new(startMachine)
- startSession, err := mb.setCmd(s).run()
+ 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()
Expect(err).To(BeNil())
- Expect(startSession).To(Exit(0))
+ Expect(memorySession).To(Exit(0))
+ Expect(memorySession.outputToString()).To(ContainSubstring("3824"))
- ssh2 := sshMachine{}
- sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHComand([]string{"cat", "/proc/meminfo", "|", "numfmt", "--field", "2", "--from-unit=Ki", "--to-unit=Mi", "|", "sed", "'s/ kB/M/g'", "|", "grep", "MemTotal"})).run()
+ // Setting a running machine results in 125
+ runner, err := mb.setName(name).setCmd(set.withCPUs(4)).run()
Expect(err).To(BeNil())
- Expect(sshSession2).To(Exit(0))
- Expect(sshSession2.outputToString()).To(ContainSubstring("3824"))
+ Expect(runner).To(Exit(125))
})
It("no settings should change if no flags", func() {