podman

Форк
0
/
update_test.go 
241 строка · 8.2 Кб
1
package integration
2

3
import (
4
	"github.com/containers/common/pkg/cgroupv2"
5
	. "github.com/containers/podman/v5/test/utils"
6
	. "github.com/onsi/ginkgo/v2"
7
	. "github.com/onsi/gomega"
8
)
9

10
var _ = Describe("Podman update", func() {
11

12
	It("podman update container all options v1", func() {
13
		SkipIfCgroupV2("testing flags that only work in cgroup v1")
14
		SkipIfRootless("many of these handlers are not enabled while rootless in CI")
15
		session := podmanTest.Podman([]string{"run", "-dt", ALPINE})
16
		session.WaitWithDefaultTimeout()
17
		Expect(session).Should(ExitCleanly())
18

19
		ctrID := session.OutputToString()
20

21
		commonArgs := []string{
22
			"update",
23
			"--cpus", "5",
24
			"--cpuset-cpus", "0",
25
			"--cpu-shares", "123",
26
			"--cpuset-mems", "0",
27
			"--memory", "1G",
28
			"--memory-swap", "2G",
29
			"--memory-reservation", "2G",
30
			"--memory-swappiness", "50",
31
			"--pids-limit", "123", ctrID}
32

33
		session = podmanTest.Podman(commonArgs)
34
		session.WaitWithDefaultTimeout()
35
		Expect(session).Should(ExitCleanly())
36

37
		// checking cpu quota from --cpus
38
		podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/cpu/cpu.cfs_quota_us", "500000")
39

40
		// checking cpuset-cpus
41
		podmanTest.CheckFileInContainer(ctrID, "/sys/fs/cgroup/cpuset/cpuset.cpus", "0")
42

43
		// checking cpuset-mems
44
		podmanTest.CheckFileInContainer(ctrID, "/sys/fs/cgroup/cpuset/cpuset.mems", "0")
45

46
		// checking memory limit
47
		podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/memory/memory.limit_in_bytes", "1073741824")
48

49
		// checking memory-swap
50
		podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes", "2147483648")
51

52
		// checking cpu-shares
53
		podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/cpu/cpu.shares", "123")
54

55
		// checking pids-limit
56
		podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/pids/pids.max", "123")
57
	})
58

59
	It("podman update container unspecified pid limit", func() {
60
		SkipIfCgroupV1("testing flags that only work in cgroup v2")
61
		SkipIfRootless("many of these handlers are not enabled while rootless in CI")
62
		session := podmanTest.Podman([]string{"run", "-dt", "--pids-limit", "-1", ALPINE})
63
		session.WaitWithDefaultTimeout()
64
		Expect(session).Should(ExitCleanly())
65

66
		ctrID := session.OutputToString()
67

68
		commonArgs := []string{
69
			"update",
70
			"--cpus", "5",
71
			ctrID}
72

73
		session = podmanTest.Podman(commonArgs)
74
		session.WaitWithDefaultTimeout()
75
		Expect(session).Should(ExitCleanly())
76

77
		ctrID = session.OutputToString()
78

79
		// checking pids-limit was not changed after update when not specified as an option
80
		podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/pids.max", "max")
81
	})
82

83
	It("podman update container all options v2", func() {
84
		SkipIfCgroupV1("testing flags that only work in cgroup v2")
85
		SkipIfRootless("many of these handlers are not enabled while rootless in CI")
86
		session := podmanTest.Podman([]string{"run", "-dt", ALPINE})
87
		session.WaitWithDefaultTimeout()
88
		Expect(session).Should(ExitCleanly())
89

90
		ctrID := session.OutputToString()
91

92
		commonArgs := []string{
93
			"update",
94
			"--cpus", "5",
95
			"--cpuset-cpus", "0",
96
			"--cpu-shares", "123",
97
			"--cpuset-mems", "0",
98
			"--memory", "1G",
99
			"--memory-swap", "2G",
100
			"--memory-reservation", "2G",
101
			"--blkio-weight", "123",
102
			"--device-read-bps", "/dev/zero:10mb",
103
			"--device-write-bps", "/dev/zero:10mb",
104
			"--device-read-iops", "/dev/zero:1000",
105
			"--device-write-iops", "/dev/zero:1000",
106
			"--pids-limit", "123",
107
			ctrID}
108

109
		session = podmanTest.Podman(commonArgs)
110
		session.WaitWithDefaultTimeout()
111
		Expect(session).Should(ExitCleanly())
112

113
		ctrID = session.OutputToString()
114

115
		// checking cpu quota and period
116
		podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/cpu.max", "500000")
117

118
		// checking blkio weight
119
		podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/io.bfq.weight", "123")
120

121
		// checking device-read/write-bps/iops
122
		podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/io.max", "rbps=10485760 wbps=10485760 riops=1000 wiops=1000")
123

124
		// checking cpuset-cpus
125
		podmanTest.CheckFileInContainer(ctrID, "/sys/fs/cgroup/cpuset.cpus", "0")
126

127
		// checking cpuset-mems
128
		podmanTest.CheckFileInContainer(ctrID, "/sys/fs/cgroup/cpuset.mems", "0")
129

130
		// checking memory limit
131
		podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/memory.max", "1073741824")
132

133
		// checking memory-swap
134
		podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/memory.swap.max", "1073741824")
135

136
		// checking cpu-shares
137
		podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/cpu.weight", "5")
138

139
		// checking pids-limit
140
		podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/pids.max", "123")
141
	})
142

143
	It("podman update keep original resources if not overridden", func() {
144
		SkipIfRootless("many of these handlers are not enabled while rootless in CI")
145
		session := podmanTest.Podman([]string{"run", "-dt", "--cpus", "5", ALPINE})
146
		session.WaitWithDefaultTimeout()
147
		Expect(session).Should(ExitCleanly())
148

149
		session = podmanTest.Podman([]string{
150
			"update",
151
			"--memory", "1G",
152
			session.OutputToString(),
153
		})
154

155
		session.WaitWithDefaultTimeout()
156
		Expect(session).Should(ExitCleanly())
157

158
		ctrID := session.OutputToString()
159

160
		path := "/sys/fs/cgroup/cpu/cpu.cfs_quota_us"
161
		if v2, _ := cgroupv2.Enabled(); v2 {
162
			path = "/sys/fs/cgroup/cpu.max"
163
		}
164

165
		podmanTest.CheckFileInContainerSubstring(ctrID, path, "500000")
166
	})
167

168
	It("podman update persists changes", func() {
169
		SkipIfCgroupV1("testing flags that only work in cgroup v2")
170
		SkipIfRootless("many of these handlers are not enabled while rootless in CI")
171

172
		memoryInspect := ".HostConfig.Memory"
173
		memoryCgroup := "/sys/fs/cgroup/memory.max"
174
		mem512m := "536870912"
175
		mem256m := "268435456"
176

177
		testCtr := "test-ctr-name"
178
		ctr1 := podmanTest.Podman([]string{"run", "-d", "--name", testCtr, "-m", "512m", ALPINE, "top"})
179
		ctr1.WaitWithDefaultTimeout()
180
		Expect(ctr1).Should(ExitCleanly())
181

182
		podmanTest.CheckContainerSingleField(testCtr, memoryInspect, mem512m)
183
		podmanTest.CheckFileInContainer(testCtr, memoryCgroup, mem512m)
184

185
		update := podmanTest.Podman([]string{"update", "-m", "256m", testCtr})
186
		update.WaitWithDefaultTimeout()
187
		Expect(update).Should(ExitCleanly())
188

189
		podmanTest.CheckContainerSingleField(testCtr, memoryInspect, mem256m)
190
		podmanTest.CheckFileInContainer(testCtr, memoryCgroup, mem256m)
191

192
		restart := podmanTest.Podman([]string{"restart", testCtr})
193
		restart.WaitWithDefaultTimeout()
194
		Expect(restart).Should(ExitCleanly())
195

196
		podmanTest.CheckContainerSingleField(testCtr, memoryInspect, mem256m)
197
		podmanTest.CheckFileInContainer(testCtr, memoryCgroup, mem256m)
198

199
		pause := podmanTest.Podman([]string{"pause", testCtr})
200
		pause.WaitWithDefaultTimeout()
201
		Expect(pause).Should(ExitCleanly())
202

203
		update2 := podmanTest.Podman([]string{"update", "-m", "512m", testCtr})
204
		update2.WaitWithDefaultTimeout()
205
		Expect(update2).Should(ExitCleanly())
206

207
		unpause := podmanTest.Podman([]string{"unpause", testCtr})
208
		unpause.WaitWithDefaultTimeout()
209
		Expect(unpause).Should(ExitCleanly())
210

211
		podmanTest.CheckContainerSingleField(testCtr, memoryInspect, mem512m)
212
		podmanTest.CheckFileInContainer(testCtr, memoryCgroup, mem512m)
213
	})
214

215
	It("podman update sets restart policy", func() {
216
		restartPolicyName := ".HostConfig.RestartPolicy.Name"
217
		restartPolicyRetries := ".HostConfig.RestartPolicy.MaximumRetryCount"
218

219
		testCtr := "test-ctr-name"
220
		ctr1 := podmanTest.Podman([]string{"run", "-dt", "--name", testCtr, ALPINE, "top"})
221
		ctr1.WaitWithDefaultTimeout()
222
		Expect(ctr1).Should(ExitCleanly())
223

224
		podmanTest.CheckContainerSingleField(testCtr, restartPolicyName, "no")
225
		podmanTest.CheckContainerSingleField(testCtr, restartPolicyRetries, "0")
226

227
		update1 := podmanTest.Podman([]string{"update", "--restart", "on-failure:5", testCtr})
228
		update1.WaitWithDefaultTimeout()
229
		Expect(update1).Should(ExitCleanly())
230

231
		podmanTest.CheckContainerSingleField(testCtr, restartPolicyName, "on-failure")
232
		podmanTest.CheckContainerSingleField(testCtr, restartPolicyRetries, "5")
233

234
		update2 := podmanTest.Podman([]string{"update", "--restart", "always", testCtr})
235
		update2.WaitWithDefaultTimeout()
236
		Expect(update2).Should(ExitCleanly())
237

238
		podmanTest.CheckContainerSingleField(testCtr, restartPolicyName, "always")
239
		podmanTest.CheckContainerSingleField(testCtr, restartPolicyRetries, "0")
240
	})
241
})
242

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.