-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow changing of CPUs, Memory, and Disk Size
Allow podman machine set to change CPUs, Memory and Disk size of a QEMU machine after its been created. Disk size can only be increased. If one setting fails to be changed, the other settings will still be applied. Signed-off-by: Ashley Cui <[email protected]>
- Loading branch information
1 parent
5ac00a7
commit e7390f3
Showing
8 changed files
with
419 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package e2e | ||
|
||
import ( | ||
"strconv" | ||
) | ||
|
||
type setMachine struct { | ||
cpus *uint | ||
diskSize *uint | ||
memory *uint | ||
|
||
cmd []string | ||
} | ||
|
||
func (i *setMachine) buildCmd(m *machineTestBuilder) []string { | ||
cmd := []string{"machine", "set"} | ||
if i.cpus != nil { | ||
cmd = append(cmd, "--cpus", strconv.Itoa(int(*i.cpus))) | ||
} | ||
if i.diskSize != nil { | ||
cmd = append(cmd, "--disk-size", strconv.Itoa(int(*i.diskSize))) | ||
} | ||
if i.memory != nil { | ||
cmd = append(cmd, "--memory", strconv.Itoa(int(*i.memory))) | ||
} | ||
cmd = append(cmd, m.name) | ||
i.cmd = cmd | ||
return cmd | ||
} | ||
|
||
func (i *setMachine) withCPUs(num uint) *setMachine { | ||
i.cpus = &num | ||
return i | ||
} | ||
func (i *setMachine) withDiskSize(size uint) *setMachine { | ||
i.diskSize = &size | ||
return i | ||
} | ||
|
||
func (i *setMachine) withMemory(num uint) *setMachine { | ||
i.memory = &num | ||
return i | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package e2e | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("podman machine set", func() { | ||
var ( | ||
mb *machineTestBuilder | ||
testDir string | ||
) | ||
|
||
BeforeEach(func() { | ||
testDir, mb = setup() | ||
}) | ||
AfterEach(func() { | ||
teardown(originalHomeDir, testDir, mb) | ||
}) | ||
|
||
It("set machine cpus", func() { | ||
name := randomString(12) | ||
i := new(initMachine) | ||
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() | ||
Expect(err).To(BeNil()) | ||
Expect(session.ExitCode()).To(Equal(0)) | ||
|
||
set := setMachine{} | ||
setSession, err := mb.setName(name).setCmd(set.withCPUs(2)).run() | ||
Expect(err).To(BeNil()) | ||
Expect(setSession.ExitCode()).To(Equal(0)) | ||
|
||
s := new(startMachine) | ||
startSession, err := mb.setCmd(s).run() | ||
Expect(err).To(BeNil()) | ||
Expect(startSession.ExitCode()).To(Equal(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.ExitCode()).To(Equal(0)) | ||
Expect(sshSession2.outputToString()).To(ContainSubstring("2")) | ||
|
||
}) | ||
|
||
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.ExitCode()).To(Equal(0)) | ||
|
||
set := setMachine{} | ||
setSession, err := mb.setName(name).setCmd(set.withDiskSize(102)).run() | ||
Expect(err).To(BeNil()) | ||
Expect(setSession.ExitCode()).To(Equal(0)) | ||
|
||
s := new(startMachine) | ||
startSession, err := mb.setCmd(s).run() | ||
Expect(err).To(BeNil()) | ||
Expect(startSession.ExitCode()).To(Equal(0)) | ||
|
||
ssh2 := sshMachine{} | ||
sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHComand([]string{"sudo", "fdisk", "-l", "|", "grep", "Disk"})).run() | ||
Expect(err).To(BeNil()) | ||
Expect(sshSession2.ExitCode()).To(Equal(0)) | ||
Expect(sshSession2.outputToString()).To(ContainSubstring("102 GiB")) | ||
}) | ||
|
||
It("decrease machine disk size should fail", func() { | ||
name := randomString(12) | ||
i := new(initMachine) | ||
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() | ||
Expect(err).To(BeNil()) | ||
Expect(session.ExitCode()).To(Equal(0)) | ||
|
||
set := setMachine{} | ||
setSession, _ := mb.setName(name).setCmd(set.withDiskSize(50)).run() | ||
// TODO seems like stderr is not being returned; re-enabled when fixed | ||
// Expect(err).To(BeNil()) | ||
Expect(setSession.ExitCode()).To(Not(Equal(0))) | ||
}) | ||
|
||
It("set machine ram", func() { | ||
|
||
name := randomString(12) | ||
i := new(initMachine) | ||
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() | ||
Expect(err).To(BeNil()) | ||
Expect(session.ExitCode()).To(Equal(0)) | ||
|
||
set := setMachine{} | ||
setSession, err := mb.setName(name).setCmd(set.withMemory(4000)).run() | ||
Expect(err).To(BeNil()) | ||
Expect(setSession.ExitCode()).To(Equal(0)) | ||
|
||
s := new(startMachine) | ||
startSession, err := mb.setCmd(s).run() | ||
Expect(err).To(BeNil()) | ||
Expect(startSession.ExitCode()).To(Equal(0)) | ||
|
||
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() | ||
Expect(err).To(BeNil()) | ||
Expect(sshSession2.ExitCode()).To(Equal(0)) | ||
Expect(sshSession2.outputToString()).To(ContainSubstring("3824")) | ||
}) | ||
|
||
It("no settings should change if no flags", func() { | ||
name := randomString(12) | ||
i := new(initMachine) | ||
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() | ||
Expect(err).To(BeNil()) | ||
Expect(session.ExitCode()).To(Equal(0)) | ||
|
||
set := setMachine{} | ||
setSession, err := mb.setName(name).setCmd(&set).run() | ||
Expect(err).To(BeNil()) | ||
Expect(setSession.ExitCode()).To(Equal(0)) | ||
|
||
s := new(startMachine) | ||
startSession, err := mb.setCmd(s).run() | ||
Expect(err).To(BeNil()) | ||
Expect(startSession.ExitCode()).To(Equal(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.ExitCode()).To(Equal(0)) | ||
Expect(sshSession2.outputToString()).To(ContainSubstring("1")) | ||
|
||
ssh3 := sshMachine{} | ||
sshSession3, err := mb.setName(name).setCmd(ssh3.withSSHComand([]string{"sudo", "fdisk", "-l", "|", "grep", "Disk"})).run() | ||
Expect(err).To(BeNil()) | ||
Expect(sshSession3.ExitCode()).To(Equal(0)) | ||
Expect(sshSession3.outputToString()).To(ContainSubstring("100 GiB")) | ||
}) | ||
|
||
}) |
Oops, something went wrong.