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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
|
package integration
import (
"fmt"
"os"
"regexp"
"sort"
"strings"
. "github.com/containers/podman/v2/test/utils"
"github.com/docker/go-units"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Podman ps", func() {
var (
tempdir string
err error
podmanTest *PodmanTestIntegration
)
BeforeEach(func() {
tempdir, err = CreateTempDirInTempDir()
if err != nil {
os.Exit(1)
}
podmanTest = PodmanTestCreate(tempdir)
podmanTest.Setup()
podmanTest.SeedImages()
})
AfterEach(func() {
podmanTest.Cleanup()
f := CurrentGinkgoTestDescription()
processTestResult(f)
})
It("podman ps no containers", func() {
session := podmanTest.Podman([]string{"ps"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
})
It("podman ps default", func() {
session := podmanTest.RunTopContainer("")
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
result := podmanTest.Podman([]string{"ps"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0))
})
It("podman ps all", func() {
_, ec, _ := podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))
result := podmanTest.Podman([]string{"ps", "-a"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0))
})
It("podman container list all", func() {
_, ec, _ := podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))
result := podmanTest.Podman([]string{"container", "list", "-a"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0))
result = podmanTest.Podman([]string{"container", "ls", "-a"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0))
})
It("podman ps size flag", func() {
_, ec, _ := podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))
result := podmanTest.Podman([]string{"ps", "-a", "--size"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0))
})
It("podman ps quiet flag", func() {
_, ec, fullCid := podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))
result := podmanTest.Podman([]string{"ps", "-a", "-q"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0))
Expect(fullCid).To(ContainSubstring(result.OutputToStringArray()[0]))
})
It("podman ps latest flag", func() {
SkipIfRemote("--latest is not supported on podman-remote")
_, ec, _ := podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))
_, ec, _ = podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))
result := podmanTest.Podman([]string{"ps", "-q", "--latest"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(len(result.OutputToStringArray())).Should(Equal(1))
})
It("podman ps last flag", func() {
Skip("--last flag nonfunctional and disabled")
// Make sure that non-running containers are being counted as
// well.
session := podmanTest.Podman([]string{"create", "alpine", "top"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
result := podmanTest.Podman([]string{"ps", "--last", "2"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(len(result.OutputToStringArray())).Should(Equal(2)) // 1 container
_, ec, _ := podmanTest.RunLsContainer("test1")
Expect(ec).To(Equal(0))
_, ec, _ = podmanTest.RunLsContainer("test2")
Expect(ec).To(Equal(0))
_, ec, _ = podmanTest.RunLsContainer("test3")
Expect(ec).To(Equal(0))
result = podmanTest.Podman([]string{"ps", "--last", "2"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(len(result.OutputToStringArray())).Should(Equal(3)) // 2 containers
result = podmanTest.Podman([]string{"ps", "--last", "3"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(len(result.OutputToStringArray())).Should(Equal(4)) // 3 containers
result = podmanTest.Podman([]string{"ps", "--last", "100"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(len(result.OutputToStringArray())).Should(Equal(5)) // 4 containers (3 running + 1 created)
})
It("podman ps no-trunc", func() {
_, ec, fullCid := podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))
result := podmanTest.Podman([]string{"ps", "-aq", "--no-trunc"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0))
Expect(fullCid).To(Equal(result.OutputToStringArray()[0]))
})
It("podman ps namespace flag", func() {
_, ec, _ := podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))
result := podmanTest.Podman([]string{"ps", "-a", "--namespace"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0))
})
It("podman ps with no containers is valid json format", func() {
result := podmanTest.Podman([]string{"ps", "--format", "json"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(result.IsJSONOutputValid()).To(BeTrue())
})
It("podman ps namespace flag with json format", func() {
_, ec, _ := podmanTest.RunLsContainer("test1")
Expect(ec).To(Equal(0))
result := podmanTest.Podman([]string{"ps", "-a", "--ns", "--format", "json"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(result.IsJSONOutputValid()).To(BeTrue())
})
It("podman ps print a human-readable `Status` with json format", func() {
_, ec, _ := podmanTest.RunLsContainer("test1")
Expect(ec).To(Equal(0))
result := podmanTest.Podman([]string{"ps", "-a", "--format", "json"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(result.IsJSONOutputValid()).To(BeTrue())
// must contain "Status"
match, StatusLine := result.GrepString(`Status`)
Expect(match).To(BeTrue())
// container is running or exit, so it must contain `ago`
Expect(StatusLine[0]).To(ContainSubstring("ago"))
})
It("podman ps namespace flag with go template format", func() {
Skip(v2fail)
_, ec, _ := podmanTest.RunLsContainer("test1")
Expect(ec).To(Equal(0))
result := podmanTest.Podman([]string{"ps", "-a", "--format", "table {{.ID}} {{.Image}} {{.ImageID}} {{.Labels}}"})
result.WaitWithDefaultTimeout()
Expect(strings.Contains(result.OutputToStringArray()[0], "table")).To(BeFalse())
Expect(strings.Contains(result.OutputToStringArray()[0], "ID")).To(BeTrue())
Expect(strings.Contains(result.OutputToStringArray()[0], "ImageID")).To(BeTrue())
Expect(strings.Contains(result.OutputToStringArray()[1], "alpine:latest")).To(BeTrue())
Expect(result.ExitCode()).To(Equal(0))
})
It("podman ps ancestor filter flag", func() {
_, ec, _ := podmanTest.RunLsContainer("test1")
Expect(ec).To(Equal(0))
result := podmanTest.Podman([]string{"ps", "-a", "--filter", "ancestor=docker.io/library/alpine:latest"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
})
It("podman ps id filter flag", func() {
_, ec, fullCid := podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))
result := podmanTest.Podman([]string{"ps", "-a", "--filter", fmt.Sprintf("id=%s", fullCid)})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
})
It("podman ps id filter flag", func() {
session := podmanTest.RunTopContainer("")
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
fullCid := session.OutputToString()
result := podmanTest.Podman([]string{"ps", "-aq", "--no-trunc", "--filter", "status=running"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(result.OutputToStringArray()[0]).To(Equal(fullCid))
})
It("podman ps multiple filters", func() {
session := podmanTest.Podman([]string{"run", "-d", "--name", "test1", "--label", "key1=value1", ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
fullCid := session.OutputToString()
session2 := podmanTest.Podman([]string{"run", "-d", "--name", "test2", "--label", "key1=value1", ALPINE, "top"})
session2.WaitWithDefaultTimeout()
Expect(session2.ExitCode()).To(Equal(0))
result := podmanTest.Podman([]string{"ps", "-aq", "--no-trunc", "--filter", "name=test1", "--filter", "label=key1=value1"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
output := result.OutputToStringArray()
Expect(len(output)).To(Equal(1))
Expect(output[0]).To(Equal(fullCid))
})
It("podman ps filter by exited does not need all", func() {
ctr := podmanTest.Podman([]string{"run", "-t", "-i", ALPINE, "ls", "/"})
ctr.WaitWithDefaultTimeout()
Expect(ctr.ExitCode()).To(Equal(0))
psAll := podmanTest.Podman([]string{"ps", "-aq", "--no-trunc"})
psAll.WaitWithDefaultTimeout()
Expect(psAll.ExitCode()).To(Equal(0))
psFilter := podmanTest.Podman([]string{"ps", "--no-trunc", "--quiet", "--filter", "status=exited"})
psFilter.WaitWithDefaultTimeout()
Expect(psFilter.ExitCode()).To(Equal(0))
Expect(psAll.OutputToString()).To(Equal(psFilter.OutputToString()))
})
It("podman filter without status does not find non-running", func() {
ctrName := "aContainerName"
ctr := podmanTest.Podman([]string{"create", "--name", ctrName, "-t", "-i", ALPINE, "ls", "/"})
ctr.WaitWithDefaultTimeout()
Expect(ctr.ExitCode()).To(Equal(0))
psFilter := podmanTest.Podman([]string{"ps", "--no-trunc", "--quiet", "--format", "{{.Names}}", "--filter", fmt.Sprintf("name=%s", ctrName)})
psFilter.WaitWithDefaultTimeout()
Expect(psFilter.ExitCode()).To(Equal(0))
Expect(strings.Contains(psFilter.OutputToString(), ctrName)).To(BeFalse())
})
It("podman ps mutually exclusive flags", func() {
session := podmanTest.Podman([]string{"ps", "-aqs"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
session = podmanTest.Podman([]string{"ps", "-a", "--ns", "-s"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
})
It("podman --sort by size", func() {
session := podmanTest.Podman([]string{"create", "busybox", "ls"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"create", "-dt", ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"ps", "-a", "-s", "--sort=size", "--format", "{{.Size}}"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
sortedArr := session.OutputToStringArray()
// TODO: This may be broken - the test was running without the
// ability to perform any sorting for months and succeeded
// without error.
Expect(sort.SliceIsSorted(sortedArr, func(i, j int) bool {
r := regexp.MustCompile(`^\S+\s+\(virtual (\S+)\)`)
matches1 := r.FindStringSubmatch(sortedArr[i])
matches2 := r.FindStringSubmatch(sortedArr[j])
// sanity check in case an oddly formatted size appears
if len(matches1) < 2 || len(matches2) < 2 {
return sortedArr[i] < sortedArr[j]
} else {
size1, _ := units.FromHumanSize(matches1[1])
size2, _ := units.FromHumanSize(matches2[1])
return size1 < size2
}
})).To(BeTrue())
})
It("podman --sort by command", func() {
session := podmanTest.RunTopContainer("")
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"run", "-d", ALPINE, "pwd"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"ps", "-a", "--sort=command", "--format", "{{.Command}}"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
sortedArr := session.OutputToStringArray()
Expect(sort.SliceIsSorted(sortedArr, func(i, j int) bool { return sortedArr[i] < sortedArr[j] })).To(BeTrue())
})
It("podman --pod", func() {
_, ec, podid := podmanTest.CreatePod("")
Expect(ec).To(Equal(0))
session := podmanTest.RunTopContainerInPod("", podid)
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"ps", "--pod", "--no-trunc"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session.OutputToString()).To(ContainSubstring(podid))
})
It("podman --pod with a non-empty pod name", func() {
podName := "testPodName"
_, ec, podid := podmanTest.CreatePod(podName)
Expect(ec).To(Equal(0))
session := podmanTest.RunTopContainerInPod("", podName)
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
// "--no-trunc" must be given. If not it will trunc the pod ID
// in the output and you will have to trunc it in the test too.
session = podmanTest.Podman([]string{"ps", "--pod", "--no-trunc"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
output := session.OutputToString()
Expect(output).To(ContainSubstring(podid))
Expect(output).To(ContainSubstring(podName))
})
It("podman ps test with port range", func() {
session := podmanTest.RunTopContainer("")
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"run", "-dt", "-p", "2000-2006:2000-2006", ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"ps", "--format", "{{.Ports}}"})
session.WaitWithDefaultTimeout()
Expect(session.OutputToString()).To(ContainSubstring("0.0.0.0:2000-2006"))
})
It("podman ps sync flag", func() {
session := podmanTest.RunTopContainer("")
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
fullCid := session.OutputToString()
result := podmanTest.Podman([]string{"ps", "-q", "--no-trunc", "--sync"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(result.OutputToStringArray()[0]).To(Equal(fullCid))
})
It("podman ps filter name regexp", func() {
session := podmanTest.Podman([]string{"run", "-d", "--name", "test1", ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
fullCid := session.OutputToString()
session2 := podmanTest.Podman([]string{"run", "-d", "--name", "test11", ALPINE, "top"})
session2.WaitWithDefaultTimeout()
Expect(session2.ExitCode()).To(Equal(0))
result := podmanTest.Podman([]string{"ps", "-aq", "--no-trunc", "--filter", "name=test1"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
output := result.OutputToStringArray()
Expect(len(output)).To(Equal(2))
result = podmanTest.Podman([]string{"ps", "-aq", "--no-trunc", "--filter", "name=test1$"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
output = result.OutputToStringArray()
Expect(len(output)).To(Equal(1))
Expect(output[0]).To(Equal(fullCid))
})
It("podman ps quiet template", func() {
ctrName := "testCtr"
session := podmanTest.Podman([]string{"run", "-d", "--name", ctrName, ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
result := podmanTest.Podman([]string{"ps", "-q", "-a", "--format", "{{ .Names }}"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
output := result.OutputToStringArray()
Expect(len(output)).To(Equal(1))
Expect(output[0]).To(Equal(ctrName))
})
It("podman ps test with port shared with pod", func() {
podName := "testPod"
pod := podmanTest.Podman([]string{"pod", "create", "-p", "8080:80", "--name", podName})
pod.WaitWithDefaultTimeout()
Expect(pod.ExitCode()).To(Equal(0))
ctrName := "testCtr"
session := podmanTest.Podman([]string{"run", "--name", ctrName, "-dt", "--pod", podName, ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
ps := podmanTest.Podman([]string{"ps", "--filter", fmt.Sprintf("name=%s", ctrName), "--format", "{{.Ports}}"})
ps.WaitWithDefaultTimeout()
Expect(ps.ExitCode()).To(Equal(0))
Expect(ps.OutputToString()).To(ContainSubstring("0.0.0.0:8080->80/tcp"))
})
It("podman ps truncate long create command", func() {
session := podmanTest.Podman([]string{"run", ALPINE, "echo", "very", "long", "create", "command"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"ps", "-a"})
session.WaitWithDefaultTimeout()
Expect(session.OutputToString()).To(ContainSubstring("echo very long cr..."))
})
It("podman ps --format {{RunningFor}}", func() {
_, ec, _ := podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))
result := podmanTest.Podman([]string{"ps", "-a", "--format", "{{.RunningFor}}"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(result.OutputToString()).To(ContainSubstring("ago"))
})
})
|