podman

Форк
0
/
pod_infra_container_test.go 
431 строка · 15.7 Кб
1
package integration
2

3
import (
4
	"strconv"
5

6
	. "github.com/containers/podman/v5/test/utils"
7
	. "github.com/onsi/ginkgo/v2"
8
	. "github.com/onsi/gomega"
9
)
10

11
var _ = Describe("Podman pod create", func() {
12

13
	It("podman create infra container", func() {
14
		session := podmanTest.Podman([]string{"pod", "create"})
15
		session.WaitWithDefaultTimeout()
16
		Expect(session).Should(ExitCleanly())
17
		podID := session.OutputToString()
18

19
		check := podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc"})
20
		check.WaitWithDefaultTimeout()
21
		Expect(check.OutputToString()).To(ContainSubstring(podID))
22
		Expect(check.OutputToStringArray()).To(HaveLen(1))
23

24
		check = podmanTest.Podman([]string{"ps", "-qa", "--no-trunc"})
25
		check.WaitWithDefaultTimeout()
26
		Expect(check.OutputToStringArray()).To(HaveLen(1))
27
	})
28

29
	It("podman start infra container", func() {
30
		session := podmanTest.Podman([]string{"pod", "create"})
31
		session.WaitWithDefaultTimeout()
32
		Expect(session).Should(ExitCleanly())
33
		podID := session.OutputToString()
34

35
		session = podmanTest.Podman([]string{"pod", "start", podID})
36
		session.WaitWithDefaultTimeout()
37
		Expect(session).Should(ExitCleanly())
38

39
		check := podmanTest.Podman([]string{"ps", "-qa", "--no-trunc", "--filter", "status=running"})
40
		check.WaitWithDefaultTimeout()
41
		Expect(session).Should(ExitCleanly())
42
		Expect(check.OutputToStringArray()).To(HaveLen(1))
43
	})
44

45
	It("podman start infra container different image", func() {
46
		session := podmanTest.Podman([]string{"pod", "create", "--infra-image", BB})
47
		session.WaitWithDefaultTimeout()
48
		Expect(session).Should(ExitCleanly())
49
		podID := session.OutputToString()
50

51
		session = podmanTest.Podman([]string{"pod", "start", podID})
52
		session.WaitWithDefaultTimeout()
53
		// If we use the default entry point, we should exit with no error
54
		Expect(session).Should(ExitCleanly())
55
	})
56

57
	It("podman infra container namespaces", func() {
58
		session := podmanTest.Podman([]string{"pod", "create"})
59
		session.WaitWithDefaultTimeout()
60
		Expect(session).Should(ExitCleanly())
61
		podID := session.OutputToString()
62

63
		session = podmanTest.Podman([]string{"pod", "start", podID})
64
		session.WaitWithDefaultTimeout()
65
		Expect(session).Should(ExitCleanly())
66

67
		session = podmanTest.RunTopContainerInPod("", podID)
68
		session.WaitWithDefaultTimeout()
69
		Expect(session).Should(ExitCleanly())
70

71
		check := podmanTest.Podman([]string{"ps", "-a", "--no-trunc", "--ns", "--format", "{{.Namespaces.IPC}} {{.Namespaces.NET}}"})
72
		check.WaitWithDefaultTimeout()
73
		Expect(session).Should(ExitCleanly())
74
		Expect(check.OutputToStringArray()).To(HaveLen(2))
75
		Expect(check.OutputToStringArray()[0]).To(Equal(check.OutputToStringArray()[1]))
76

77
		check = podmanTest.Podman([]string{"ps", "-a", "--no-trunc", "--ns", "--format", "{{.IPC}} {{.NET}}"})
78
		check.WaitWithDefaultTimeout()
79
		Expect(session).Should(ExitCleanly())
80
		Expect(check.OutputToStringArray()).To(HaveLen(2))
81
		Expect(check.OutputToStringArray()[0]).To(Equal(check.OutputToStringArray()[1]))
82
	})
83

84
	It("podman pod correctly sets up NetNS", func() {
85
		session := podmanTest.Podman([]string{"pod", "create", "--share", "net"})
86
		session.WaitWithDefaultTimeout()
87
		Expect(session).Should(ExitCleanly())
88
		podID := session.OutputToString()
89

90
		session = podmanTest.Podman([]string{"pod", "start", podID})
91
		session.WaitWithDefaultTimeout()
92
		Expect(session).Should(ExitCleanly())
93

94
		session = podmanTest.Podman([]string{"run", "-d", "--pod", podID, NGINX_IMAGE})
95
		session.WaitWithDefaultTimeout()
96
		Expect(session).Should(ExitCleanly())
97

98
		session = podmanTest.Podman([]string{"run", "--pod", podID, fedoraMinimal, "curl", "-s", "--retry", "2", "--retry-connrefused", "-f", "localhost:80"})
99
		session.WaitWithDefaultTimeout()
100
		Expect(session).Should(ExitCleanly())
101

102
		session = podmanTest.Podman([]string{"run", fedoraMinimal, "curl", "-f", "localhost"})
103
		session.WaitWithDefaultTimeout()
104
		Expect(session).To(ExitWithError())
105

106
		session = podmanTest.Podman([]string{"pod", "create", "--network", "host"})
107
		session.WaitWithDefaultTimeout()
108
		Expect(session).Should(ExitCleanly())
109

110
		session = podmanTest.Podman([]string{"run", "--name", "hostCtr", "--pod", session.OutputToString(), ALPINE, "readlink", "/proc/self/ns/net"})
111
		session.WaitWithDefaultTimeout()
112
		Expect(session).Should(ExitCleanly())
113

114
		ns := SystemExec("readlink", []string{"/proc/self/ns/net"})
115
		ns.WaitWithDefaultTimeout()
116
		Expect(ns).Should(ExitCleanly())
117
		netns := ns.OutputToString()
118
		Expect(netns).ToNot(BeEmpty())
119

120
		Expect(session.OutputToString()).To(Equal(netns))
121

122
		// Sanity Check for podman inspect
123
		session = podmanTest.Podman([]string{"inspect", "--format", "'{{.NetworkSettings.SandboxKey}}'", "hostCtr"})
124
		session.WaitWithDefaultTimeout()
125
		Expect(session).Should(ExitCleanly())
126
		Expect(session.OutputToString()).Should(Equal("''")) // no network path... host
127

128
	})
129

130
	It("podman pod correctly sets up IPCNS", func() {
131
		session := podmanTest.Podman([]string{"pod", "create", "--share", "ipc"})
132
		session.WaitWithDefaultTimeout()
133
		Expect(session).Should(ExitCleanly())
134
		podID := session.OutputToString()
135

136
		session = podmanTest.Podman([]string{"pod", "start", podID})
137
		session.WaitWithDefaultTimeout()
138
		Expect(session).Should(ExitCleanly())
139

140
		session = podmanTest.Podman([]string{"run", "--pod", podID, fedoraMinimal, "/bin/sh", "-c", "'touch /dev/shm/hi'"})
141
		session.WaitWithDefaultTimeout()
142
		if session.ExitCode() != 0 {
143
			Skip("ShmDir not initialized, skipping...")
144
		}
145
		Expect(session).Should(ExitCleanly())
146

147
		session = podmanTest.Podman([]string{"run", "--pod", podID, fedoraMinimal, "/bin/sh", "-c", "'ls /dev/shm'"})
148
		session.WaitWithDefaultTimeout()
149
		Expect(session).Should(ExitCleanly())
150
		Expect(session.OutputToString()).To(Equal("hi"))
151
	})
152

153
	It("podman pod correctly sets up PIDNS", func() {
154
		session := podmanTest.Podman([]string{"pod", "create", "--share", "pid", "--name", "test-pod"})
155
		session.WaitWithDefaultTimeout()
156
		Expect(session).Should(ExitCleanly())
157
		podID := session.OutputToString()
158

159
		session = podmanTest.Podman([]string{"pod", "start", podID})
160
		session.WaitWithDefaultTimeout()
161
		Expect(session).Should(ExitCleanly())
162

163
		session = podmanTest.RunTopContainerInPod("test-ctr", podID)
164
		session.WaitWithDefaultTimeout()
165
		Expect(session).Should(ExitCleanly())
166

167
		check := podmanTest.Podman([]string{"top", "test-ctr", "pid"})
168
		check.WaitWithDefaultTimeout()
169
		Expect(check).Should(ExitCleanly())
170
		PIDs := check.OutputToStringArray()
171
		Expect(PIDs).To(HaveLen(3))
172

173
		ctrPID, _ := strconv.Atoi(PIDs[1])
174
		infraPID, _ := strconv.Atoi(PIDs[2])
175
		Expect(ctrPID).To(BeNumerically("<", infraPID))
176
	})
177

178
	It("podman pod doesn't share PIDNS if requested to not", func() {
179
		session := podmanTest.Podman([]string{"pod", "create", "--share", "net", "--name", "test-pod"})
180
		session.WaitWithDefaultTimeout()
181
		Expect(session).Should(ExitCleanly())
182
		podID := session.OutputToString()
183

184
		session = podmanTest.Podman([]string{"pod", "start", podID})
185
		session.WaitWithDefaultTimeout()
186
		Expect(session).Should(ExitCleanly())
187

188
		session = podmanTest.RunTopContainerInPod("test-ctr", podID)
189
		session.WaitWithDefaultTimeout()
190
		Expect(session).Should(ExitCleanly())
191

192
		check := podmanTest.Podman([]string{"top", "test-ctr", "pid"})
193
		check.WaitWithDefaultTimeout()
194
		Expect(check).Should(ExitCleanly())
195
		ctrTop := check.OutputToStringArray()
196

197
		check = podmanTest.Podman([]string{"top", podID[:12] + "-infra", "pid"})
198
		check.WaitWithDefaultTimeout()
199
		Expect(check).Should(ExitCleanly())
200
		infraTop := check.OutputToStringArray()
201

202
		ctrPID, _ := strconv.Atoi(ctrTop[1])
203
		infraPID, _ := strconv.Atoi(infraTop[1])
204
		Expect(ctrPID).To(Equal(infraPID))
205
	})
206

207
	It("podman pod container can override pod net NS", func() {
208
		session := podmanTest.Podman([]string{"pod", "create", "--share", "net"})
209
		session.WaitWithDefaultTimeout()
210
		Expect(session).Should(ExitCleanly())
211
		podID := session.OutputToString()
212

213
		session = podmanTest.Podman([]string{"pod", "start", podID})
214
		session.WaitWithDefaultTimeout()
215
		Expect(session).Should(ExitCleanly())
216

217
		session = podmanTest.Podman([]string{"run", "-d", "--pod", podID, NGINX_IMAGE})
218
		session.WaitWithDefaultTimeout()
219
		Expect(session).Should(ExitCleanly())
220

221
		session = podmanTest.Podman([]string{"run", "--pod", podID, "--network", "bridge", NGINX_IMAGE, "curl", "-f", "localhost"})
222
		session.WaitWithDefaultTimeout()
223
		Expect(session).To(ExitWithError())
224
	})
225

226
	It("podman pod container can override pod pid NS", func() {
227
		SkipIfRootlessCgroupsV1("Not supported for rootless + CgroupsV1")
228
		session := podmanTest.Podman([]string{"pod", "create", "--share", "pid"})
229
		session.WaitWithDefaultTimeout()
230
		Expect(session).Should(ExitCleanly())
231
		podID := session.OutputToString()
232

233
		session = podmanTest.Podman([]string{"pod", "start", podID})
234
		session.WaitWithDefaultTimeout()
235
		Expect(session).Should(ExitCleanly())
236

237
		session = podmanTest.Podman([]string{"run", "--pod", podID, "--pid", "host", "-d", ALPINE, "top"})
238
		session.WaitWithDefaultTimeout()
239
		Expect(session).Should(ExitCleanly())
240

241
		check := podmanTest.Podman([]string{"ps", "-a", "--ns", "--format", "{{.Namespaces.PIDNS}}"})
242
		check.WaitWithDefaultTimeout()
243
		Expect(check).Should(ExitCleanly())
244
		outputArray := check.OutputToStringArray()
245
		Expect(outputArray).To(HaveLen(2))
246

247
		check = podmanTest.Podman([]string{"ps", "-a", "--ns", "--format", "{{.PIDNS}}"})
248
		check.WaitWithDefaultTimeout()
249
		Expect(check).Should(ExitCleanly())
250
		outputArray = check.OutputToStringArray()
251
		Expect(outputArray).To(HaveLen(2))
252

253
		PID1 := outputArray[0]
254
		PID2 := outputArray[1]
255
		Expect(PID1).To(Not(Equal(PID2)))
256
	})
257

258
	It("podman pod container can override pod not sharing pid", func() {
259
		session := podmanTest.Podman([]string{"pod", "create", "--share", "net"})
260
		session.WaitWithDefaultTimeout()
261
		Expect(session).Should(ExitCleanly())
262
		podID := session.OutputToString()
263

264
		session = podmanTest.Podman([]string{"pod", "start", podID})
265
		session.WaitWithDefaultTimeout()
266
		Expect(session).Should(ExitCleanly())
267

268
		session = podmanTest.Podman([]string{"run", "--pod", podID, "--pid", "pod", "-d", ALPINE, "top"})
269
		session.WaitWithDefaultTimeout()
270
		Expect(session).Should(ExitCleanly())
271

272
		check := podmanTest.Podman([]string{"ps", "-a", "--ns", "--format", "{{.PIDNS}}"})
273
		check.WaitWithDefaultTimeout()
274
		Expect(check).Should(ExitCleanly())
275
		outputArray := check.OutputToStringArray()
276
		Expect(outputArray).To(HaveLen(2))
277

278
		PID1 := outputArray[0]
279
		PID2 := outputArray[1]
280
		Expect(PID1).To(Equal(PID2))
281
	})
282

283
	It("podman pod container can override pod ipc NS", func() {
284
		session := podmanTest.Podman([]string{"pod", "create", "--share", "ipc"})
285
		session.WaitWithDefaultTimeout()
286
		Expect(session).Should(ExitCleanly())
287
		podID := session.OutputToString()
288

289
		session = podmanTest.Podman([]string{"pod", "start", podID})
290
		session.WaitWithDefaultTimeout()
291
		Expect(session).Should(ExitCleanly())
292

293
		session = podmanTest.Podman([]string{"run", "--pod", podID, "--ipc", "host", "-d", ALPINE, "top"})
294
		session.WaitWithDefaultTimeout()
295
		Expect(session).Should(ExitCleanly())
296

297
		check := podmanTest.Podman([]string{"ps", "-a", "--ns", "--format", "{{.IPC}}"})
298
		check.WaitWithDefaultTimeout()
299
		Expect(check).Should(ExitCleanly())
300
		outputArray := check.OutputToStringArray()
301
		Expect(outputArray).To(HaveLen(2))
302

303
		PID1 := outputArray[0]
304
		PID2 := outputArray[1]
305
		Expect(PID1).To(Not(Equal(PID2)))
306
	})
307

308
	It("podman pod infra container deletion", func() {
309
		session := podmanTest.Podman([]string{"pod", "create", "--share", "ipc"})
310
		session.WaitWithDefaultTimeout()
311
		Expect(session).Should(ExitCleanly())
312
		podID := session.OutputToString()
313

314
		session = podmanTest.Podman([]string{"ps", "-aq"})
315
		session.WaitWithDefaultTimeout()
316
		Expect(session).Should(ExitCleanly())
317
		infraID := session.OutputToString()
318

319
		session = podmanTest.Podman([]string{"rm", infraID})
320
		session.WaitWithDefaultTimeout()
321
		Expect(session).To(ExitWithError())
322

323
		session = podmanTest.Podman([]string{"pod", "rm", podID})
324
		session.WaitWithDefaultTimeout()
325
		Expect(session).Should(ExitCleanly())
326
	})
327

328
	It("podman run in pod starts infra", func() {
329
		session := podmanTest.Podman([]string{"pod", "create"})
330
		session.WaitWithDefaultTimeout()
331
		Expect(session).Should(ExitCleanly())
332
		podID := session.OutputToString()
333

334
		result := podmanTest.Podman([]string{"ps", "-aq"})
335
		result.WaitWithDefaultTimeout()
336
		Expect(result).Should(ExitCleanly())
337
		infraID := result.OutputToString()
338

339
		result = podmanTest.Podman([]string{"run", "--pod", podID, "-d", ALPINE, "top"})
340
		result.WaitWithDefaultTimeout()
341
		Expect(result).Should(ExitCleanly())
342

343
		result = podmanTest.Podman([]string{"ps", "-aq"})
344
		result.WaitWithDefaultTimeout()
345
		Expect(result).Should(ExitCleanly())
346
		Expect(result.OutputToStringArray()).ShouldNot(BeEmpty())
347

348
		Expect(result.OutputToString()).To(ContainSubstring(infraID))
349
	})
350

351
	It("podman start in pod starts infra", func() {
352
		session := podmanTest.Podman([]string{"pod", "create"})
353
		session.WaitWithDefaultTimeout()
354
		Expect(session).Should(ExitCleanly())
355
		podID := session.OutputToString()
356

357
		result := podmanTest.Podman([]string{"ps", "-aq"})
358
		result.WaitWithDefaultTimeout()
359
		Expect(result).Should(ExitCleanly())
360
		infraID := result.OutputToString()
361

362
		result = podmanTest.Podman([]string{"create", "--pod", podID, ALPINE, "ls"})
363
		result.WaitWithDefaultTimeout()
364
		Expect(result).Should(ExitCleanly())
365
		ctrID := result.OutputToString()
366

367
		result = podmanTest.Podman([]string{"start", ctrID})
368
		result.WaitWithDefaultTimeout()
369
		Expect(result).Should(ExitCleanly())
370

371
		result = podmanTest.Podman([]string{"ps", "-aq"})
372
		result.WaitWithDefaultTimeout()
373
		Expect(result).Should(ExitCleanly())
374
		Expect(result.OutputToStringArray()).ShouldNot(BeEmpty())
375

376
		Expect(result.OutputToString()).To(ContainSubstring(infraID))
377
	})
378

379
	It("podman run --add-host in pod should fail", func() {
380
		session := podmanTest.Podman([]string{"pod", "create", "--add-host", "host1:127.0.0.1"})
381
		session.WaitWithDefaultTimeout()
382
		Expect(session).Should(ExitCleanly())
383
		podID := session.OutputToString()
384

385
		session = podmanTest.Podman([]string{"create", "--pod", podID, "--add-host", "foobar:127.0.0.1", ALPINE, "ping", "-c", "1", "foobar"})
386
		session.WaitWithDefaultTimeout()
387
		Expect(session).Should(ExitWithError())
388
		Expect(session.ErrorToString()).To(ContainSubstring("extra host entries must be specified on the pod: network cannot be configured when it is shared with a pod"))
389

390
		// verify we can see the pods hosts
391
		session = podmanTest.Podman([]string{"run", "--cap-add", "net_raw", "--pod", podID, ALPINE, "ping", "-c", "1", "host1"})
392
		session.WaitWithDefaultTimeout()
393
		Expect(session).Should(ExitCleanly())
394
	})
395

396
	It("podman run hostname is shared", func() {
397
		session := podmanTest.Podman([]string{"pod", "create"})
398
		session.WaitWithDefaultTimeout()
399
		Expect(session).Should(ExitCleanly())
400
		podID := session.OutputToString()
401

402
		// verify we can add a host to the infra's /etc/hosts
403
		session = podmanTest.Podman([]string{"run", "--pod", podID, ALPINE, "hostname"})
404
		session.WaitWithDefaultTimeout()
405
		Expect(session).Should(ExitCleanly())
406
		hostname := session.OutputToString()
407

408
		infraName := podID[:12] + "-infra"
409
		// verify we can see the other hosts of infra's /etc/hosts
410
		session = podmanTest.Podman([]string{"inspect", infraName})
411
		session.WaitWithDefaultTimeout()
412
		Expect(session).Should(ExitCleanly())
413
		Expect(session.OutputToString()).To(ContainSubstring(hostname))
414
	})
415

416
	tests := []string{"", "none"}
417
	for _, test := range tests {
418
		test := test
419
		It("podman pod create --share="+test+" should not create an infra ctr", func() {
420
			session := podmanTest.Podman([]string{"pod", "create", "--share", test})
421
			session.WaitWithDefaultTimeout()
422
			Expect(session).Should(ExitCleanly())
423

424
			session = podmanTest.Podman([]string{"pod", "inspect", "--format", "{{.NumContainers}}", session.OutputToString()})
425
			session.WaitWithDefaultTimeout()
426
			Expect(session).Should(ExitCleanly())
427
			Expect(session.OutputToString()).Should(Equal("0"))
428
		})
429
	}
430

431
})
432

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

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

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

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