podman

Форк
0
/
pod_top_test.go 
127 строк · 4.2 Кб
1
package integration
2

3
import (
4
	"fmt"
5
	"time"
6

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"
11
)
12

13
var _ = Describe("Podman top", func() {
14

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))
19
	})
20

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))
25
	})
26

27
	It("podman pod top on non-running pod", func() {
28
		_, ec, podid := podmanTest.CreatePod(nil)
29
		Expect(ec).To(Equal(0))
30

31
		result := podmanTest.Podman([]string{"top", podid})
32
		result.WaitWithDefaultTimeout()
33
		Expect(result).Should(Exit(125))
34
	})
35

36
	It("podman pod top on pod", func() {
37
		_, ec, podid := podmanTest.CreatePod(nil)
38
		Expect(ec).To(Equal(0))
39

40
		session := podmanTest.Podman([]string{"run", "-d", "--pod", podid, ALPINE, "top", "-d", "2"})
41
		session.WaitWithDefaultTimeout()
42
		Expect(session).Should(ExitCleanly())
43

44
		if !IsRemote() {
45
			podid = "-l"
46
		}
47
		result := podmanTest.Podman([]string{"pod", "top", podid})
48
		result.WaitWithDefaultTimeout()
49
		Expect(result).Should(ExitCleanly())
50
		Expect(len(result.OutputToStringArray())).To(BeNumerically(">", 1))
51
	})
52

53
	It("podman pod top with options", func() {
54
		_, ec, podid := podmanTest.CreatePod(nil)
55
		Expect(ec).To(Equal(0))
56

57
		session := podmanTest.Podman([]string{"run", "-d", "--pod", podid, ALPINE, "top", "-d", "2"})
58
		session.WaitWithDefaultTimeout()
59
		Expect(session).Should(ExitCleanly())
60

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))
65
	})
66

67
	It("podman pod top on pod invalid options", func() {
68
		_, ec, podid := podmanTest.CreatePod(nil)
69
		Expect(ec).To(Equal(0))
70

71
		session := podmanTest.Podman([]string{"run", "-d", "--pod", podid, ALPINE, "top", "-d", "2"})
72
		session.WaitWithDefaultTimeout()
73
		Expect(session).Should(ExitCleanly())
74

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))
82
	})
83

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))
87

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()
92

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())
96

97
		result := podmanTest.Podman([]string{"pod", "top", podid})
98
		result.WaitWithDefaultTimeout()
99
		Expect(result).Should(ExitCleanly())
100
		Expect(result.OutputToStringArray()).To(HaveLen(3))
101
	})
102

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))
106

107
		session := podmanTest.Podman([]string{"run", "-d", "--pod", podid, ALPINE, "top", "-d", "2"})
108
		session.WaitWithDefaultTimeout()
109
		Expect(session).Should(ExitCleanly())
110

111
		session = podmanTest.Podman([]string{"run", "-d", "--pod", podid, ALPINE, "top", "-d", "2"})
112
		session.WaitWithDefaultTimeout()
113
		Expect(session).Should(ExitCleanly())
114

115
		for i := 0; i < 10; i++ {
116
			GinkgoWriter.Println("Waiting for containers to be running .... ")
117
			if podmanTest.NumberOfContainersRunning() == 2 {
118
				break
119
			}
120
			time.Sleep(1 * time.Second)
121
		}
122
		result := podmanTest.Podman([]string{"pod", "top", podid})
123
		result.WaitWithDefaultTimeout()
124
		Expect(result).Should(ExitCleanly())
125
		Expect(result.OutputToStringArray()).To(HaveLen(3))
126
	})
127
})
128

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

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

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

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