7
. "github.com/containers/podman/v5/test/utils"
8
. "github.com/onsi/ginkgo/v2"
9
. "github.com/onsi/gomega"
10
. "github.com/onsi/gomega/gexec"
13
var _ = Describe("Podman rmi", func() {
15
It("podman rmi bogus image", func() {
16
session := podmanTest.Podman([]string{"rmi", "debian:6.0.10"})
17
session.WaitWithDefaultTimeout()
18
Expect(session).Should(Exit(1))
22
It("podman rmi with fq name", func() {
23
podmanTest.AddImageToRWStore(ALPINE)
24
session := podmanTest.Podman([]string{"rmi", ALPINE})
25
session.WaitWithDefaultTimeout()
26
Expect(session).Should(ExitCleanly())
30
It("podman rmi with short name", func() {
31
podmanTest.AddImageToRWStore(CIRROS_IMAGE)
32
session := podmanTest.Podman([]string{"rmi", "cirros"})
33
session.WaitWithDefaultTimeout()
34
Expect(session).Should(ExitCleanly())
38
It("podman rmi all images", func() {
39
podmanTest.AddImageToRWStore(NGINX_IMAGE)
40
session := podmanTest.Podman([]string{"rmi", "-a"})
41
session.WaitWithDefaultTimeout()
42
images := podmanTest.Podman([]string{"images"})
43
images.WaitWithDefaultTimeout()
44
Expect(session).Should(ExitCleanly())
48
It("podman rmi all images forcibly with short options", func() {
49
podmanTest.AddImageToRWStore(NGINX_IMAGE)
50
session := podmanTest.Podman([]string{"rmi", "-fa"})
51
session.WaitWithDefaultTimeout()
52
Expect(session).Should(ExitCleanly())
56
It("podman rmi tagged image", func() {
57
podmanTest.AddImageToRWStore(CIRROS_IMAGE)
58
setup := podmanTest.Podman([]string{"images", "-q", CIRROS_IMAGE})
59
setup.WaitWithDefaultTimeout()
60
Expect(setup).Should(ExitCleanly())
62
session := podmanTest.Podman([]string{"tag", CIRROS_IMAGE, "foo:bar", "foo"})
63
session.WaitWithDefaultTimeout()
64
Expect(session).Should(ExitCleanly())
66
result := podmanTest.Podman([]string{"images", "-q", "foo"})
67
result.WaitWithDefaultTimeout()
68
Expect(result).Should(ExitCleanly())
70
Expect(result.OutputToString()).To(ContainSubstring(setup.OutputToString()))
73
It("podman rmi image with tags by ID cannot be done without force", func() {
74
podmanTest.AddImageToRWStore(CIRROS_IMAGE)
75
setup := podmanTest.Podman([]string{"images", "-q", CIRROS_IMAGE})
76
setup.WaitWithDefaultTimeout()
77
Expect(setup).Should(ExitCleanly())
78
cirrosID := setup.OutputToString()
80
session := podmanTest.Podman([]string{"tag", "cirros", "foo:bar", "foo"})
81
session.WaitWithDefaultTimeout()
82
Expect(session).Should(ExitCleanly())
84
// Trying without --force should fail
85
result := podmanTest.Podman([]string{"rmi", cirrosID})
86
result.WaitWithDefaultTimeout()
87
Expect(result).To(ExitWithError())
89
// With --force it should work
90
resultForce := podmanTest.Podman([]string{"rmi", "-f", cirrosID})
91
resultForce.WaitWithDefaultTimeout()
92
Expect(resultForce).Should(ExitCleanly())
95
It("podman rmi image that is a parent of another image", func() {
96
Skip("I need help with this one. i don't understand what is going on")
97
podmanTest.AddImageToRWStore(CIRROS_IMAGE)
98
session := podmanTest.Podman([]string{"run", "--name", "c_test", CIRROS_IMAGE, "true"})
99
session.WaitWithDefaultTimeout()
100
Expect(session).Should(ExitCleanly())
102
session = podmanTest.Podman([]string{"commit", "-q", "c_test", "test"})
103
session.WaitWithDefaultTimeout()
104
Expect(session).Should(ExitCleanly())
106
session = podmanTest.Podman([]string{"rm", "c_test"})
107
session.WaitWithDefaultTimeout()
108
Expect(session).Should(ExitCleanly())
110
session = podmanTest.Podman([]string{"rmi", CIRROS_IMAGE})
111
session.WaitWithDefaultTimeout()
112
Expect(session).Should(ExitCleanly())
114
session = podmanTest.Podman([]string{"images", "-q"})
115
session.WaitWithDefaultTimeout()
116
Expect(session).Should(ExitCleanly())
117
Expect(session.OutputToStringArray()).To(HaveLen(12))
119
session = podmanTest.Podman([]string{"images", "--sort", "created", "--format", "{{.Id}}", "--all"})
120
session.WaitWithDefaultTimeout()
121
Expect(session).Should(ExitCleanly())
122
Expect(session.OutputToStringArray()).To(HaveLen(13),
123
"Output from 'podman images -q -a'")
124
untaggedImg := session.OutputToStringArray()[1]
126
session = podmanTest.Podman([]string{"rmi", "-f", untaggedImg})
127
session.WaitWithDefaultTimeout()
128
Expect(session).Should(Exit(2), "UntaggedImg is '%s'", untaggedImg)
131
It("podman rmi image that is created from another named imaged", func() {
132
podmanTest.AddImageToRWStore(ALPINE)
133
session := podmanTest.Podman([]string{"create", "--name", "c_test1", ALPINE, "true"})
134
session.WaitWithDefaultTimeout()
135
Expect(session).Should(ExitCleanly())
137
session = podmanTest.Podman([]string{"commit", "-q", "c_test1", "test1"})
138
session.WaitWithDefaultTimeout()
139
Expect(session).Should(ExitCleanly())
141
session = podmanTest.Podman([]string{"create", "--name", "c_test2", "test1", "true"})
142
session.WaitWithDefaultTimeout()
143
Expect(session).Should(ExitCleanly())
145
session = podmanTest.Podman([]string{"commit", "-q", "c_test2", "test2"})
146
session.WaitWithDefaultTimeout()
147
Expect(session).Should(ExitCleanly())
149
session = podmanTest.Podman([]string{"rm", "-a"})
150
session.WaitWithDefaultTimeout()
151
Expect(session).Should(ExitCleanly())
153
session = podmanTest.Podman([]string{"rmi", "test2"})
154
session.WaitWithDefaultTimeout()
155
Expect(session).Should(ExitCleanly())
157
session = podmanTest.Podman([]string{"images", "-q"})
158
session.WaitWithDefaultTimeout()
159
Expect(session).Should(ExitCleanly())
160
Expect(session.OutputToStringArray()).To(HaveLen(len(CACHE_IMAGES) + 1))
163
It("podman rmi with cached images", func() {
164
podmanTest.AddImageToRWStore(CIRROS_IMAGE)
165
dockerfile := fmt.Sprintf(`FROM %s
170
podmanTest.BuildImage(dockerfile, "test", "true")
172
dockerfile = fmt.Sprintf(`FROM %s
179
podmanTest.BuildImage(dockerfile, "test2", "true")
181
session := podmanTest.Podman([]string{"images", "-q", "-a"})
182
session.WaitWithDefaultTimeout()
183
Expect(session).Should(ExitCleanly())
184
numOfImages := len(session.OutputToStringArray())
186
session = podmanTest.Podman([]string{"rmi", "test2"})
187
session.WaitWithDefaultTimeout()
188
Expect(session).Should(ExitCleanly())
190
session = podmanTest.Podman([]string{"images", "-q", "-a"})
191
session.WaitWithDefaultTimeout()
192
Expect(session).Should(ExitCleanly())
193
Expect(numOfImages - len(session.OutputToStringArray())).To(Equal(2))
195
session = podmanTest.Podman([]string{"rmi", "test"})
196
session.WaitWithDefaultTimeout()
197
Expect(session).Should(ExitCleanly())
199
session = podmanTest.Podman([]string{"images", "-q", "-a"})
200
session.WaitWithDefaultTimeout()
201
Expect(session).Should(ExitCleanly())
202
Expect(session.OutputToStringArray()).To(HaveLen(len(CACHE_IMAGES) + 1))
204
podmanTest.BuildImage(dockerfile, "test3", "true")
206
session = podmanTest.Podman([]string{"rmi", CIRROS_IMAGE})
207
session.WaitWithDefaultTimeout()
208
Expect(session).Should(ExitCleanly())
210
session = podmanTest.Podman([]string{"rmi", "test3"})
211
session.WaitWithDefaultTimeout()
212
Expect(session).Should(ExitCleanly())
214
session = podmanTest.Podman([]string{"images", "-q", "-a"})
215
session.WaitWithDefaultTimeout()
216
Expect(session).Should(ExitCleanly())
217
Expect(session.OutputToStringArray()).To(HaveLen(len(CACHE_IMAGES)))
220
It("podman rmi -a with no images should be exit 0", func() {
221
session := podmanTest.Podman([]string{"rmi", "-fa"})
222
session.WaitWithDefaultTimeout()
223
Expect(session).Should(ExitCleanly())
225
session2 := podmanTest.Podman([]string{"rmi", "-fa"})
226
session2.WaitWithDefaultTimeout()
227
Expect(session2).Should(ExitCleanly())
230
It("podman rmi -a with parent|child images", func() {
231
podmanTest.AddImageToRWStore(CIRROS_IMAGE)
232
dockerfile := fmt.Sprintf(`FROM %s AS base
240
podmanTest.BuildImage(dockerfile, "test", "true")
241
session := podmanTest.Podman([]string{"rmi", "-a"})
242
session.WaitWithDefaultTimeout()
243
Expect(session).Should(ExitCleanly())
245
images := podmanTest.Podman([]string{"images", "-aq"})
246
images.WaitWithDefaultTimeout()
247
Expect(images).Should(ExitCleanly())
248
Expect(images.OutputToStringArray()).To(HaveLen(len(CACHE_IMAGES)))
251
// Don't rerun all tests; just assume that if we get that diagnostic,
253
It("podman image rm is the same as rmi", func() {
254
session := podmanTest.Podman([]string{"image", "rm"})
255
session.WaitWithDefaultTimeout()
256
Expect(session).Should(Exit(125))
257
Expect(session.ErrorToString()).To(ContainSubstring("image name or ID must be specified"))
260
It("podman image rm - concurrent with shared layers", func() {
261
// #6510 has shown a fairly simple reproducer to force storage
262
// errors during parallel image removal. Since it's subject to
263
// a race, we may not hit the condition a 100 percent of times
264
// but ocal reproducers hit it all the time.
266
podmanTest.AddImageToRWStore(CIRROS_IMAGE)
267
var wg sync.WaitGroup
271
for i := 0; i < 10; i++ {
273
defer GinkgoRecover()
275
imageName := fmt.Sprintf("rmtest:%d", i)
276
containerfile := fmt.Sprintf(`FROM %s
277
RUN touch %s`, CIRROS_IMAGE, imageName)
279
podmanTest.BuildImage(containerfile, imageName, "false")
284
// A herd of concurrent removals
286
for i := 0; i < 10; i++ {
288
defer GinkgoRecover()
291
imageName := fmt.Sprintf("rmtest:%d", i)
292
session := podmanTest.Podman([]string{"rmi", "-f", imageName})
293
session.WaitWithDefaultTimeout()
294
Expect(session).Should(ExitCleanly())
300
It("podman rmi --no-prune with dangling parents", func() {
301
podmanTest.AddImageToRWStore(ALPINE)
302
session := podmanTest.Podman([]string{"create", "--name", "c_test1", ALPINE, "true"})
303
session.WaitWithDefaultTimeout()
304
Expect(session).Should(ExitCleanly())
306
session = podmanTest.Podman([]string{"commit", "-q", "c_test1", "test1"})
307
session.WaitWithDefaultTimeout()
308
Expect(session).Should(ExitCleanly())
310
session = podmanTest.Podman([]string{"create", "--name", "c_test2", "test1", "true"})
311
session.WaitWithDefaultTimeout()
312
Expect(session).Should(ExitCleanly())
314
session = podmanTest.Podman([]string{"commit", "-q", "c_test2", "test2"})
315
session.WaitWithDefaultTimeout()
316
Expect(session).Should(ExitCleanly())
317
imageID2 := session.OutputToString()
319
session = podmanTest.Podman([]string{"create", "--name", "c_test3", "test2", "true"})
320
session.WaitWithDefaultTimeout()
321
Expect(session).Should(ExitCleanly())
323
session = podmanTest.Podman([]string{"commit", "-q", "c_test3", "test3"})
324
session.WaitWithDefaultTimeout()
325
Expect(session).Should(ExitCleanly())
326
imageID3 := session.OutputToString()
328
session = podmanTest.Podman([]string{"untag", "test2"})
329
session.WaitWithDefaultTimeout()
330
Expect(session).Should(ExitCleanly())
332
session = podmanTest.Podman([]string{"untag", "test1"})
333
session.WaitWithDefaultTimeout()
334
Expect(session).Should(ExitCleanly())
336
session = podmanTest.Podman([]string{"rmi", "-f", "--no-prune", "test3"})
337
session.WaitWithDefaultTimeout()
338
Expect(session).Should(ExitCleanly())
339
Expect(session.OutputToString()).To(ContainSubstring(imageID3))
340
Expect(session.OutputToString()).NotTo(ContainSubstring(imageID2))
343
It("podman rmi --no-prune with undangling parents", func() {
344
podmanTest.AddImageToRWStore(ALPINE)
345
session := podmanTest.Podman([]string{"create", "--name", "c_test1", ALPINE, "true"})
346
session.WaitWithDefaultTimeout()
347
Expect(session).Should(ExitCleanly())
349
session = podmanTest.Podman([]string{"commit", "-q", "c_test1", "test1"})
350
session.WaitWithDefaultTimeout()
351
Expect(session).Should(ExitCleanly())
353
session = podmanTest.Podman([]string{"create", "--name", "c_test2", "test1", "true"})
354
session.WaitWithDefaultTimeout()
355
Expect(session).Should(ExitCleanly())
357
session = podmanTest.Podman([]string{"commit", "-q", "c_test2", "test2"})
358
session.WaitWithDefaultTimeout()
359
Expect(session).Should(ExitCleanly())
360
imageID2 := session.OutputToString()
362
session = podmanTest.Podman([]string{"create", "--name", "c_test3", "test2", "true"})
363
session.WaitWithDefaultTimeout()
364
Expect(session).Should(ExitCleanly())
366
session = podmanTest.Podman([]string{"commit", "-q", "c_test3", "test3"})
367
session.WaitWithDefaultTimeout()
368
Expect(session).Should(ExitCleanly())
369
imageID3 := session.OutputToString()
371
session = podmanTest.Podman([]string{"rmi", "-f", "--no-prune", "test3"})
372
session.WaitWithDefaultTimeout()
373
Expect(session).Should(ExitCleanly())
374
Expect(session.OutputToString()).To(ContainSubstring(imageID3))
375
Expect(session.OutputToString()).NotTo(ContainSubstring(imageID2))