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"
10
var _ = Describe("Podman update", func() {
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())
19
ctrID := session.OutputToString()
21
commonArgs := []string{
25
"--cpu-shares", "123",
28
"--memory-swap", "2G",
29
"--memory-reservation", "2G",
30
"--memory-swappiness", "50",
31
"--pids-limit", "123", ctrID}
33
session = podmanTest.Podman(commonArgs)
34
session.WaitWithDefaultTimeout()
35
Expect(session).Should(ExitCleanly())
37
// checking cpu quota from --cpus
38
podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/cpu/cpu.cfs_quota_us", "500000")
40
// checking cpuset-cpus
41
podmanTest.CheckFileInContainer(ctrID, "/sys/fs/cgroup/cpuset/cpuset.cpus", "0")
43
// checking cpuset-mems
44
podmanTest.CheckFileInContainer(ctrID, "/sys/fs/cgroup/cpuset/cpuset.mems", "0")
46
// checking memory limit
47
podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/memory/memory.limit_in_bytes", "1073741824")
49
// checking memory-swap
50
podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes", "2147483648")
52
// checking cpu-shares
53
podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/cpu/cpu.shares", "123")
55
// checking pids-limit
56
podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/pids/pids.max", "123")
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())
66
ctrID := session.OutputToString()
68
commonArgs := []string{
73
session = podmanTest.Podman(commonArgs)
74
session.WaitWithDefaultTimeout()
75
Expect(session).Should(ExitCleanly())
77
ctrID = session.OutputToString()
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")
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())
90
ctrID := session.OutputToString()
92
commonArgs := []string{
96
"--cpu-shares", "123",
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",
109
session = podmanTest.Podman(commonArgs)
110
session.WaitWithDefaultTimeout()
111
Expect(session).Should(ExitCleanly())
113
ctrID = session.OutputToString()
115
// checking cpu quota and period
116
podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/cpu.max", "500000")
118
// checking blkio weight
119
podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/io.bfq.weight", "123")
121
// checking device-read/write-bps/iops
122
podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/io.max", "rbps=10485760 wbps=10485760 riops=1000 wiops=1000")
124
// checking cpuset-cpus
125
podmanTest.CheckFileInContainer(ctrID, "/sys/fs/cgroup/cpuset.cpus", "0")
127
// checking cpuset-mems
128
podmanTest.CheckFileInContainer(ctrID, "/sys/fs/cgroup/cpuset.mems", "0")
130
// checking memory limit
131
podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/memory.max", "1073741824")
133
// checking memory-swap
134
podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/memory.swap.max", "1073741824")
136
// checking cpu-shares
137
podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/cpu.weight", "5")
139
// checking pids-limit
140
podmanTest.CheckFileInContainerSubstring(ctrID, "/sys/fs/cgroup/pids.max", "123")
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())
149
session = podmanTest.Podman([]string{
152
session.OutputToString(),
155
session.WaitWithDefaultTimeout()
156
Expect(session).Should(ExitCleanly())
158
ctrID := session.OutputToString()
160
path := "/sys/fs/cgroup/cpu/cpu.cfs_quota_us"
161
if v2, _ := cgroupv2.Enabled(); v2 {
162
path = "/sys/fs/cgroup/cpu.max"
165
podmanTest.CheckFileInContainerSubstring(ctrID, path, "500000")
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")
172
memoryInspect := ".HostConfig.Memory"
173
memoryCgroup := "/sys/fs/cgroup/memory.max"
174
mem512m := "536870912"
175
mem256m := "268435456"
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())
182
podmanTest.CheckContainerSingleField(testCtr, memoryInspect, mem512m)
183
podmanTest.CheckFileInContainer(testCtr, memoryCgroup, mem512m)
185
update := podmanTest.Podman([]string{"update", "-m", "256m", testCtr})
186
update.WaitWithDefaultTimeout()
187
Expect(update).Should(ExitCleanly())
189
podmanTest.CheckContainerSingleField(testCtr, memoryInspect, mem256m)
190
podmanTest.CheckFileInContainer(testCtr, memoryCgroup, mem256m)
192
restart := podmanTest.Podman([]string{"restart", testCtr})
193
restart.WaitWithDefaultTimeout()
194
Expect(restart).Should(ExitCleanly())
196
podmanTest.CheckContainerSingleField(testCtr, memoryInspect, mem256m)
197
podmanTest.CheckFileInContainer(testCtr, memoryCgroup, mem256m)
199
pause := podmanTest.Podman([]string{"pause", testCtr})
200
pause.WaitWithDefaultTimeout()
201
Expect(pause).Should(ExitCleanly())
203
update2 := podmanTest.Podman([]string{"update", "-m", "512m", testCtr})
204
update2.WaitWithDefaultTimeout()
205
Expect(update2).Should(ExitCleanly())
207
unpause := podmanTest.Podman([]string{"unpause", testCtr})
208
unpause.WaitWithDefaultTimeout()
209
Expect(unpause).Should(ExitCleanly())
211
podmanTest.CheckContainerSingleField(testCtr, memoryInspect, mem512m)
212
podmanTest.CheckFileInContainer(testCtr, memoryCgroup, mem512m)
215
It("podman update sets restart policy", func() {
216
restartPolicyName := ".HostConfig.RestartPolicy.Name"
217
restartPolicyRetries := ".HostConfig.RestartPolicy.MaximumRetryCount"
219
testCtr := "test-ctr-name"
220
ctr1 := podmanTest.Podman([]string{"run", "-dt", "--name", testCtr, ALPINE, "top"})
221
ctr1.WaitWithDefaultTimeout()
222
Expect(ctr1).Should(ExitCleanly())
224
podmanTest.CheckContainerSingleField(testCtr, restartPolicyName, "no")
225
podmanTest.CheckContainerSingleField(testCtr, restartPolicyRetries, "0")
227
update1 := podmanTest.Podman([]string{"update", "--restart", "on-failure:5", testCtr})
228
update1.WaitWithDefaultTimeout()
229
Expect(update1).Should(ExitCleanly())
231
podmanTest.CheckContainerSingleField(testCtr, restartPolicyName, "on-failure")
232
podmanTest.CheckContainerSingleField(testCtr, restartPolicyRetries, "5")
234
update2 := podmanTest.Podman([]string{"update", "--restart", "always", testCtr})
235
update2.WaitWithDefaultTimeout()
236
Expect(update2).Should(ExitCleanly())
238
podmanTest.CheckContainerSingleField(testCtr, restartPolicyName, "always")
239
podmanTest.CheckContainerSingleField(testCtr, restartPolicyRetries, "0")