github.com/containers/podman/v4@v4.9.4/pkg/machine/e2e/set_test.go (about) 1 package e2e_test 2 3 import ( 4 "runtime" 5 "strconv" 6 "strings" 7 8 "github.com/containers/podman/v4/pkg/machine" 9 . "github.com/onsi/ginkgo/v2" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/gexec" 12 ) 13 14 var _ = Describe("podman machine set", func() { 15 var ( 16 mb *machineTestBuilder 17 testDir string 18 ) 19 20 BeforeEach(func() { 21 testDir, mb = setup() 22 }) 23 AfterEach(func() { 24 teardown(originalHomeDir, testDir, mb) 25 }) 26 27 It("set machine cpus, disk, memory", func() { 28 skipIfWSL("WSL cannot change set properties of disk, processor, or memory") 29 name := randomString() 30 i := new(initMachine) 31 session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() 32 Expect(err).ToNot(HaveOccurred()) 33 Expect(session).To(Exit(0)) 34 35 set := setMachine{} 36 setSession, err := mb.setName(name).setCmd(set.withCPUs(2).withDiskSize(102).withMemory(4096)).run() 37 Expect(err).ToNot(HaveOccurred()) 38 Expect(setSession).To(Exit(0)) 39 40 // shrinking disk size is verboten 41 shrink, err := mb.setName(name).setCmd(set.withDiskSize(5)).run() 42 Expect(err).ToNot(HaveOccurred()) 43 Expect(shrink).To(Exit(125)) 44 45 s := new(startMachine) 46 startSession, err := mb.setCmd(s).run() 47 Expect(err).ToNot(HaveOccurred()) 48 Expect(startSession).To(Exit(0)) 49 50 sshCPU := sshMachine{} 51 CPUsession, err := mb.setName(name).setCmd(sshCPU.withSSHCommand([]string{"lscpu", "|", "grep", "\"CPU(s):\"", "|", "head", "-1"})).run() 52 Expect(err).ToNot(HaveOccurred()) 53 Expect(CPUsession).To(Exit(0)) 54 Expect(CPUsession.outputToString()).To(ContainSubstring("2")) 55 56 sshDisk := sshMachine{} 57 diskSession, err := mb.setName(name).setCmd(sshDisk.withSSHCommand([]string{"sudo", "fdisk", "-l", "|", "grep", "Disk"})).run() 58 Expect(err).ToNot(HaveOccurred()) 59 Expect(diskSession).To(Exit(0)) 60 Expect(diskSession.outputToString()).To(ContainSubstring("102 GiB")) 61 62 sshMemory := sshMachine{} 63 memorySession, err := mb.setName(name).setCmd(sshMemory.withSSHCommand([]string{"cat", "/proc/meminfo", "|", "grep", "-i", "'memtotal'", "|", "grep", "-o", "'[[:digit:]]*'"})).run() 64 Expect(err).ToNot(HaveOccurred()) 65 Expect(memorySession).To(Exit(0)) 66 foundMemory, err := strconv.Atoi(memorySession.outputToString()) 67 Expect(err).ToNot(HaveOccurred()) 68 Expect(foundMemory).To(BeNumerically(">", 3800000)) 69 Expect(foundMemory).To(BeNumerically("<", 4200000)) 70 71 // Setting a running machine results in 125 72 runner, err := mb.setName(name).setCmd(set.withCPUs(4)).run() 73 Expect(err).ToNot(HaveOccurred()) 74 Expect(runner).To(Exit(125)) 75 }) 76 77 It("wsl cannot change disk, memory, processor", func() { 78 skipIfNotVmtype(machine.WSLVirt, "tests are only for WSL provider") 79 name := randomString() 80 i := new(initMachine) 81 session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() 82 Expect(err).ToNot(HaveOccurred()) 83 Expect(session).To(Exit(0)) 84 85 setMem := setMachine{} 86 setMemSession, err := mb.setName(name).setCmd(setMem.withMemory(4096)).run() 87 Expect(err).ToNot(HaveOccurred()) 88 Expect(setMemSession).To(Exit(125)) 89 Expect(setMemSession.errorToString()).To(ContainSubstring("changing memory not supported for WSL machines")) 90 91 setProc := setMachine{} 92 setProcSession, err := mb.setName(name).setCmd(setProc.withCPUs(2)).run() 93 Expect(err).ToNot(HaveOccurred()) 94 Expect(setProcSession.errorToString()).To(ContainSubstring("changing CPUs not supported for WSL machines")) 95 96 setDisk := setMachine{} 97 setDiskSession, err := mb.setName(name).setCmd(setDisk.withDiskSize(102)).run() 98 Expect(err).ToNot(HaveOccurred()) 99 Expect(setDiskSession.errorToString()).To(ContainSubstring("changing disk size not supported for WSL machines")) 100 }) 101 102 It("no settings should change if no flags", func() { 103 skipIfWSL("WSL cannot change set properties of disk, processor, or memory") 104 name := randomString() 105 i := new(initMachine) 106 session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() 107 Expect(err).ToNot(HaveOccurred()) 108 Expect(session).To(Exit(0)) 109 110 set := setMachine{} 111 setSession, err := mb.setName(name).setCmd(&set).run() 112 Expect(err).ToNot(HaveOccurred()) 113 Expect(setSession).To(Exit(0)) 114 115 s := new(startMachine) 116 startSession, err := mb.setCmd(s).run() 117 Expect(err).ToNot(HaveOccurred()) 118 Expect(startSession).To(Exit(0)) 119 120 ssh2 := sshMachine{} 121 cpus := runtime.NumCPU() / 2 122 if cpus == 0 { 123 cpus = 1 124 } 125 sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHCommand([]string{"lscpu", "|", "grep", "\"CPU(s):\"", "|", "head", "-1"})).run() 126 Expect(err).ToNot(HaveOccurred()) 127 Expect(sshSession2).To(Exit(0)) 128 Expect(sshSession2.outputToString()).To(ContainSubstring(strconv.Itoa(cpus))) 129 130 ssh3 := sshMachine{} 131 sshSession3, err := mb.setName(name).setCmd(ssh3.withSSHCommand([]string{"sudo", "fdisk", "-l", "|", "grep", "Disk"})).run() 132 Expect(err).ToNot(HaveOccurred()) 133 Expect(sshSession3).To(Exit(0)) 134 Expect(sshSession3.outputToString()).To(ContainSubstring("100 GiB")) 135 }) 136 137 It("set rootful with docker sock change", func() { 138 name := randomString() 139 i := new(initMachine) 140 session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() 141 Expect(err).ToNot(HaveOccurred()) 142 Expect(session).To(Exit(0)) 143 144 set := setMachine{} 145 setSession, err := mb.setName(name).setCmd(set.withRootful(true)).run() 146 Expect(err).ToNot(HaveOccurred()) 147 Expect(setSession).To(Exit(0)) 148 149 s := new(startMachine) 150 startSession, err := mb.setCmd(s).run() 151 Expect(err).ToNot(HaveOccurred()) 152 Expect(startSession).To(Exit(0)) 153 154 inspect := new(inspectMachine) 155 inspect = inspect.withFormat("{{.Rootful}}") 156 inspectSession, err := mb.setName(name).setCmd(inspect).run() 157 Expect(err).ToNot(HaveOccurred()) 158 Expect(inspectSession).To(Exit(0)) 159 Expect(inspectSession.outputToString()).To(Equal("true")) 160 161 ssh2 := sshMachine{} 162 sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHCommand([]string{"readlink /var/run/docker.sock"})).run() 163 Expect(err).ToNot(HaveOccurred()) 164 Expect(sshSession2).To(Exit(0)) 165 output := strings.TrimSpace(sshSession2.outputToString()) 166 Expect(output).To(Equal("/run/podman/podman.sock")) 167 }) 168 169 It("set user mode networking", func() { 170 if testProvider.VMType() != machine.WSLVirt { 171 Skip("Test is only for WSL") 172 } 173 name := randomString() 174 i := new(initMachine) 175 session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() 176 Expect(err).ToNot(HaveOccurred()) 177 Expect(session).To(Exit(0)) 178 179 set := setMachine{} 180 setSession, err := mb.setName(name).setCmd(set.withUserModeNetworking(true)).run() 181 Expect(err).ToNot(HaveOccurred()) 182 Expect(setSession).To(Exit(0)) 183 184 inspect := new(inspectMachine) 185 inspect = inspect.withFormat("{{.UserModeNetworking}}") 186 inspectSession, err := mb.setName(name).setCmd(inspect).run() 187 Expect(err).ToNot(HaveOccurred()) 188 Expect(inspectSession).To(Exit(0)) 189 Expect(inspectSession.outputToString()).To(Equal("true")) 190 }) 191 })