mirror of
https://github.com/containers/podman.git
synced 2025-06-20 00:51:16 +08:00
@ -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]
|
||||
}
|
||||
|
@ -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))
|
||||
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()
|
||||
|
@ -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() {
|
||||
|
@ -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"))
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
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())
|
||||
|
Reference in New Issue
Block a user