aboutsummaryrefslogtreecommitdiff
path: root/pkg/machine/e2e/set_test.go
blob: 4b95bde8ec3aade9472cc552e35c0e2ddf95cbc6 (plain)
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
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"))
	})

})