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 top", func() {
15
It("podman pod top without pod name or id", func() {
16
result := podmanTest.Podman([]string{"pod", "top"})
17
result.WaitWithDefaultTimeout()
18
Expect(result).Should(Exit(125))
21
It("podman pod top on bogus pod", func() {
22
result := podmanTest.Podman([]string{"pod", "top", "1234"})
23
result.WaitWithDefaultTimeout()
24
Expect(result).Should(Exit(125))
27
It("podman pod top on non-running pod", func() {
28
_, ec, podid := podmanTest.CreatePod(nil)
29
Expect(ec).To(Equal(0))
31
result := podmanTest.Podman([]string{"top", podid})
32
result.WaitWithDefaultTimeout()
33
Expect(result).Should(Exit(125))
36
It("podman pod top on pod", func() {
37
_, ec, podid := podmanTest.CreatePod(nil)
38
Expect(ec).To(Equal(0))
40
session := podmanTest.Podman([]string{"run", "-d", "--pod", podid, ALPINE, "top", "-d", "2"})
41
session.WaitWithDefaultTimeout()
42
Expect(session).Should(ExitCleanly())
47
result := podmanTest.Podman([]string{"pod", "top", podid})
48
result.WaitWithDefaultTimeout()
49
Expect(result).Should(ExitCleanly())
50
Expect(len(result.OutputToStringArray())).To(BeNumerically(">", 1))
53
It("podman pod top with options", func() {
54
_, ec, podid := podmanTest.CreatePod(nil)
55
Expect(ec).To(Equal(0))
57
session := podmanTest.Podman([]string{"run", "-d", "--pod", podid, ALPINE, "top", "-d", "2"})
58
session.WaitWithDefaultTimeout()
59
Expect(session).Should(ExitCleanly())
61
result := podmanTest.Podman([]string{"pod", "top", podid, "pid", "%C", "args"})
62
result.WaitWithDefaultTimeout()
63
Expect(result).Should(ExitCleanly())
64
Expect(len(result.OutputToStringArray())).To(BeNumerically(">", 1))
67
It("podman pod top on pod invalid options", func() {
68
_, ec, podid := podmanTest.CreatePod(nil)
69
Expect(ec).To(Equal(0))
71
session := podmanTest.Podman([]string{"run", "-d", "--pod", podid, ALPINE, "top", "-d", "2"})
72
session.WaitWithDefaultTimeout()
73
Expect(session).Should(ExitCleanly())
75
// We need to pass -eo to force executing ps in the Alpine container.
76
// Alpines stripped down ps(1) is accepting any kind of weird input in
77
// contrast to others, such that a `ps invalid` will silently ignore
78
// the wrong input and still print the -ef output instead.
79
result := podmanTest.Podman([]string{"pod", "top", podid, "-eo", "invalid"})
80
result.WaitWithDefaultTimeout()
81
Expect(result).Should(Exit(125))
84
It("podman pod top on pod with containers in same pid namespace", func() {
85
_, ec, podid := podmanTest.CreatePod(nil)
86
Expect(ec).To(Equal(0))
88
session := podmanTest.Podman([]string{"run", "-d", "--pod", podid, ALPINE, "top", "-d", "2"})
89
session.WaitWithDefaultTimeout()
90
Expect(session).Should(ExitCleanly())
91
cid := session.OutputToString()
93
session = podmanTest.Podman([]string{"run", "-d", "--pod", podid, "--pid", fmt.Sprintf("container:%s", cid), ALPINE, "top", "-d", "2"})
94
session.WaitWithDefaultTimeout()
95
Expect(session).Should(ExitCleanly())
97
result := podmanTest.Podman([]string{"pod", "top", podid})
98
result.WaitWithDefaultTimeout()
99
Expect(result).Should(ExitCleanly())
100
Expect(result.OutputToStringArray()).To(HaveLen(3))
103
It("podman pod top on pod with containers in different namespace", func() {
104
_, ec, podid := podmanTest.CreatePod(nil)
105
Expect(ec).To(Equal(0))
107
session := podmanTest.Podman([]string{"run", "-d", "--pod", podid, ALPINE, "top", "-d", "2"})
108
session.WaitWithDefaultTimeout()
109
Expect(session).Should(ExitCleanly())
111
session = podmanTest.Podman([]string{"run", "-d", "--pod", podid, ALPINE, "top", "-d", "2"})
112
session.WaitWithDefaultTimeout()
113
Expect(session).Should(ExitCleanly())
115
for i := 0; i < 10; i++ {
116
GinkgoWriter.Println("Waiting for containers to be running .... ")
117
if podmanTest.NumberOfContainersRunning() == 2 {
120
time.Sleep(1 * time.Second)
122
result := podmanTest.Podman([]string{"pod", "top", podid})
123
result.WaitWithDefaultTimeout()
124
Expect(result).Should(ExitCleanly())
125
Expect(result.OutputToStringArray()).To(HaveLen(3))