1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
package e2e_test
import (
"io/ioutil"
"os"
"runtime"
"time"
"github.com/containers/podman/v4/pkg/machine"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)
var _ = Describe("podman machine init", func() {
var (
mb *machineTestBuilder
testDir string
)
BeforeEach(func() {
testDir, mb = setup()
})
AfterEach(func() {
teardown(originalHomeDir, testDir, mb)
})
It("bad init name", func() {
i := initMachine{}
reallyLongName := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
session, err := mb.setName(reallyLongName).setCmd(&i).run()
Expect(err).To(BeNil())
Expect(session).To(Exit(125))
})
It("simple init", func() {
i := new(initMachine)
session, err := mb.setCmd(i.withImagePath(mb.imagePath)).run()
Expect(err).To(BeNil())
Expect(session).To(Exit(0))
inspectBefore, ec, err := mb.toQemuInspectInfo()
Expect(err).To(BeNil())
Expect(ec).To(BeZero())
Expect(len(inspectBefore)).To(BeNumerically(">", 0))
testMachine := inspectBefore[0]
Expect(testMachine.Name).To(Equal(mb.names[0]))
Expect(testMachine.Resources.CPUs).To(Equal(uint64(1)))
Expect(testMachine.Resources.Memory).To(Equal(uint64(2048)))
})
It("simple init with start", func() {
i := initMachine{}
session, err := mb.setCmd(i.withImagePath(mb.imagePath)).run()
Expect(err).To(BeNil())
Expect(session).To(Exit(0))
inspectBefore, ec, err := mb.toQemuInspectInfo()
Expect(ec).To(BeZero())
Expect(len(inspectBefore)).To(BeNumerically(">", 0))
Expect(err).To(BeNil())
Expect(len(inspectBefore)).To(BeNumerically(">", 0))
Expect(inspectBefore[0].Name).To(Equal(mb.names[0]))
s := startMachine{}
ssession, err := mb.setCmd(s).setTimeout(time.Minute * 10).run()
Expect(err).To(BeNil())
Expect(ssession).Should(Exit(0))
inspectAfter, ec, err := mb.toQemuInspectInfo()
Expect(err).To(BeNil())
Expect(ec).To(BeZero())
Expect(len(inspectBefore)).To(BeNumerically(">", 0))
Expect(len(inspectAfter)).To(BeNumerically(">", 0))
Expect(inspectAfter[0].State).To(Equal(machine.Running))
})
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()
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))
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
}
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()
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"))
})
})
|