-
Notifications
You must be signed in to change notification settings - Fork 90
/
check-application
executable file
·3187 lines (2615 loc) · 155 KB
/
check-application
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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/common/pywrap", sys.argv)
# Run this with --help to see available options for tracing and debugging
# See https://github.com/cockpit-project/cockpit/blob/main/test/common/testlib.py
# "class Browser" and "class MachineCase" for the available API.
import json
import re
import sys
import time
import testlib
from machine.machine_core import ssh_connection
REGISTRIES_CONF = """
[registries.search]
registries = ['localhost:5000', 'localhost:6000']
[registries.insecure]
registries = ['localhost:80', 'localhost:5000', 'localhost:6000']
"""
NOT_RUNNING = ["Exited", "Stopped"]
# image names used in tests
IMG_ALPINE = "localhost/test-alpine"
IMG_ALPINE_LATEST = IMG_ALPINE + ":latest"
IMG_BUSYBOX = "localhost/test-busybox"
IMG_BUSYBOX_LATEST = IMG_BUSYBOX + ":latest"
IMG_REGISTRY = "localhost/test-registry"
IMG_REGISTRY_LATEST = IMG_REGISTRY + ":latest"
# nginx configuration to simulate a registry without search API (like ghcr.io)
NGINX_DEFAULT_CONF = """
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
proxy_pass http://localhost:5000/;
}
# Simulate a registry without search API, like ghcr.io
location ^~ /v2/_catalog {
return 403;
}
}
"""
def podman_version(cls):
version = cls.execute(False, "podman -v").strip().split(' ')[-1]
# HACK: handle possible rc versions such as 4.4.0-rc2
return tuple(int(v.split('-')[0]) for v in version.split('.'))
def showImages(browser):
if browser.attr("#containers-images button.pf-v5-c-expandable-section__toggle", "aria-expanded") == 'false':
browser.click("#containers-images button.pf-v5-c-expandable-section__toggle")
def checkImage(browser, name, owner):
showImages(browser)
browser.wait_visible("#containers-images table")
browser.wait_js_func("""(function (first, last) {
let items = ph_select("#containers-images table tbody");
for (i = 0; i < items.length; i++)
if (items[i].innerText.trim().startsWith(first) && items[i].innerText.trim().includes(last))
return true;
return false;
})""", name, owner)
@testlib.nondestructive
class TestApplication(testlib.MachineCase):
def setUp(self):
super().setUp()
m = self.machine
m.execute("""
systemctl stop podman.service; systemctl --now enable podman.socket
# Ensure podman is really stopped, otherwise it keeps the containers/ directory busy
pkill -e -9 podman || true
while pgrep podman; do sleep 0.1; done
pkill -e -9 conmon || true
while pgrep conmon; do sleep 0.1; done
findmnt --list -otarget | grep /var/lib/containers/. | xargs -r umount
sync
""")
# backup/restore pristine podman state, so that tests can run on existing testbeds
self.restore_dir("/var/lib/containers")
self.addCleanup(m.execute, """
systemctl stop podman.service podman.socket
# HACK: system reset has 10s timeout, make that faster with an extra `stop`
# https://github.com/containers/podman/issues/21874
podman stop --time 0 --all
podman pod stop --time 0 --all
systemctl reset-failed podman.service podman.socket
podman system reset --force
pkill -e -9 podman || true
while pgrep podman; do sleep 0.1; done
pkill -e -9 conmon || true
while pgrep conmon; do sleep 0.1; done
# HACK: sometimes podman leaks mounts
findmnt --list -otarget | grep /var/lib/containers/. | xargs -r umount
sync
""")
# Create admin session
m.execute("""
if [ ! -d /home/admin/.ssh ]; then
mkdir /home/admin/.ssh
cp /root/.ssh/* /home/admin/.ssh
chown -R admin:admin /home/admin/.ssh
chmod -R go-wx /home/admin/.ssh
fi
""")
self.admin_s = ssh_connection.SSHConnection(user="admin",
address=m.ssh_address,
ssh_port=m.ssh_port,
identity_file=m.identity_file)
# Enable user service as well; copy our images (except cockpit/ws) from system
self.admin_s.execute("""
systemctl --user stop podman.service
for img in $(ls /var/lib/test-images/*.tar | grep -v cockpitws); do podman load < "$img"; done
systemctl --now --user enable podman.socket
""")
self.addCleanup(self.admin_s.execute, """
systemctl --user stop podman.service podman.socket
podman system reset --force
""")
# HACK: system reset has 10s timeout, make that faster with an extra `stop`
# https://github.com/containers/podman/issues/21874
# Ubuntu 22.04 has old podman that does not know about rm --time
if m.image == 'ubuntu-2204':
self.addCleanup(self.admin_s.execute, "podman rm --force --all", timeout=300)
self.addCleanup(self.admin_s.execute, "podman pod rm --force --all", timeout=300)
else:
self.addCleanup(self.admin_s.execute, "podman rm --force --time 0 --all")
self.addCleanup(self.admin_s.execute, "podman pod rm --force --time 0 --all")
# But disable it globally so that "systemctl --user disable" does what we expect
m.execute("systemctl --global disable podman.socket")
self.allow_journal_messages("/run.*/podman/podman: couldn't connect.*")
self.allow_journal_messages(".*/run.*/podman/podman.*Connection reset by peer")
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1008249
self.has_criu = "debian" not in m.image and "ubuntu" not in m.image
self.has_selinux = not any(img in m.image for img in ["arch", "debian", "ubuntu", "suse"])
self.has_cgroupsV2 = not m.image.startswith('rhel-8')
self.system_images_count = int(self.execute(True, "podman images -n | wc -l").strip())
self.user_images_count = int(self.execute(False, "podman images -n | wc -l").strip())
# allow console.error
self.allow_browser_errors(
".*couldn't search registry \".*\": pinging container registry .*",
".*Error occurred while connecting console: cannot resize session: cannot resize container.*",
)
def tearDown(self):
if self.getError():
# dump container logs for debugging
for auth in [False, True]:
print(f"----- {'system' if auth else 'user'} containers -----", file=sys.stderr)
self.execute(auth, "podman ps -a >&2")
self.execute(auth, 'for c in $(podman ps -aq); do echo "---- $c ----" >&2; podman logs $c >&2; done')
super().tearDown()
def getRestartPolicy(self, auth, container_name):
cmd = f"podman inspect --format '{{{{.HostConfig.RestartPolicy}}}}' {container_name}"
return self.execute(auth, cmd).strip()
def waitNumImages(self, expected):
self.browser.wait_js_func("ph_count_check", "#containers-images table[aria-label='Images'] > tbody", expected)
def waitNumContainers(self, expected, auth):
if auth and self.machine.ostree_image:
extra = 1 # cockpit/ws
else:
extra = 0
self.browser.wait_js_func("ph_count_check", "#containers-containers tbody", expected + extra)
def performContainerAction(self, container, cmd):
b = self.browser
b.click(f"#containers-containers tbody tr:contains('{container}') .pf-v5-c-menu-toggle")
b.click(f"#containers-containers tbody tr:contains('{container}') button.pf-v5-c-menu__item:contains({cmd})")
def getContainerAction(self, container, cmd):
return f"#containers-containers tbody tr:contains('{container}') button.pf-v5-c-menu__item:contains({cmd})"
def toggleExpandedContainer(self, container):
b = self.browser
b.click(f"#containers-containers tbody tr:contains('{container}') .pf-v5-c-table__toggle button")
def getContainerAttr(self, container, key, selector=""):
b = self.browser
return b.text(f"#containers-containers tbody tr:contains('{container}') > td[data-label={key}] {selector}")
def execute(self, system, cmd):
if system:
return self.machine.execute(cmd)
else:
return self.admin_s.execute(cmd)
def login(self, system=True):
# HACK: The first rootless call often gets stuck or fails
# In such case we have alert banner to start the service (or just empty state)
# A real user would just hit the button so lets do the same as this is always getting
# back to us and we waste too much time reporting to podman with mixed results.
# Examples:
# https://github.com/containers/podman/issues/8762
# https://github.com/containers/podman/issues/9251
# https://github.com/containers/podman/issues/6660
b = self.browser
self.login_and_go("/podman", superuser=system)
b.wait_visible("#app")
with self.browser.wait_timeout(30):
try:
b.wait_not_in_text("#containers-containers", "Loading")
b.wait_not_present("#overview div.pf-v5-c-alert")
except testlib.Error:
if system:
b.click("#overview div.pf-v5-c-alert .pf-v5-c-alert__action > button:contains(Start)")
b.wait_not_present("#overview div.pf-v5-c-alert")
else:
b.click("#app .pf-v5-c-empty-state button.pf-m-primary")
b.wait_not_present("#app .pf-v5-c-empty-state button")
def waitPodRow(self, podName, present=False):
if present:
self.browser.wait_visible("#table-" + podName)
else:
self.browser.wait_not_present("#table-" + podName)
def waitPodContainer(self, podName, containerList, system=True):
if len(containerList):
for container in containerList:
self.waitContainer(container["id"], system, name=container["name"], image=container["image"],
cmd=container["command"], state=container["state"], pod=podName)
else:
if self.browser.val("#containers-containers-filter") == "all":
self.browser.wait_in_text("#table-" + podName + " .pf-v5-c-empty-state", "No containers in this pod")
else:
self.browser.wait_in_text("#table-" + podName + " .pf-v5-c-empty-state",
"No running containers in this pod")
def waitContainerRow(self, container, present=True):
b = self.browser
if present:
b.wait_visible(f'#containers-containers td[data-label="Container"]:contains("{container}")')
else:
b.wait_not_present(f'#containers-containers td[data-label="Container"]:contains("{container}")')
def performPodAction(self, podName, podOwner, action):
b = self.browser
b.click(f"#pod-{podName}-{podOwner}-action-toggle")
b.click(f"ul.pf-v5-c-menu__list li > button.pod-action-{action.lower()}")
b.wait_not_present("ul.pf-v5-c-menu__list")
def getStartTime(self, container: str, *, auth: bool) -> str:
# don't format the raw time strings from the API, force json format
out = self.execute(auth, "podman inspect --format '{{json .State.StartedAt}}' " + container)
return out.strip().replace('"', '')
def waitRestart(self, container: str, old_start: str, *, auth: bool) -> str:
for _ in range(10):
new_start = self.getStartTime(container, auth=auth)
if new_start > old_start:
return new_start
time.sleep(1)
else:
self.fail("Timed out waiting for StartedAt change")
return '' # quiesce mypy, not reached
def setupRegistry(self):
m = self.machine
self.execute(True, f"""
podman run -d -p 5000:5000 --name registry --stop-timeout 0 {IMG_REGISTRY}
podman run -d -p 6000:5000 --name registry_alt --stop-timeout 0 {IMG_REGISTRY}
""")
# Add local insecure registry into registries conf
m.write("/etc/containers/registries.conf", REGISTRIES_CONF)
self.execute(True, "systemctl stop podman.service")
def testPods(self):
b = self.browser
self.login()
self.filter_containers("running")
if not self.machine.ostree_image:
b.wait_in_text("#containers-containers", "No running containers")
# Run a pods as system
self.machine.execute("podman pod create --infra=false --name pod-1")
self.waitPodRow("pod-1", False)
self.filter_containers("all")
self.waitPodContainer("pod-1", [])
def get_pod_cpu_usage(pod_name):
cpu = self.browser.text(f"#table-{pod_name}-title .pod-cpu")
self.assertIn('%', cpu)
return float(cpu[:-1])
def get_pod_memory(pod_name):
memory = self.browser.text(f"#table-{pod_name}-title .pod-memory")
try:
value, unit = memory.split(' ')
self.assertIn(unit, ["GB", "MB", "kB", "B"])
return float(value)
except ValueError:
# no unit → only for 0 or not initialized yet
self.assertIn(memory, ["0", ""])
return 0
run_cmd = f"podman run -d --pod pod-1 --name test-pod-1-system --stop-timeout 0 {IMG_ALPINE} sleep 100"
containerId = self.machine.execute(run_cmd).strip()
self.waitPodContainer("pod-1", [{"name": "test-pod-1-system", "image": IMG_ALPINE,
"command": "sleep 100", "state": "Running", "id": containerId}])
cpu = get_pod_cpu_usage("pod-1")
b.wait(lambda: get_pod_memory("pod-1") > 0)
# Test that cpu usage increases
self.machine.execute("podman exec -di test-pod-1-system sh -c 'dd bs=1024 < /dev/urandom > /dev/null'")
b.wait(lambda: get_pod_cpu_usage("pod-1") > cpu)
self.machine.execute("podman pod stop -t0 pod-1") # disable timeout, so test doesn't wait endlessly
self.waitPodContainer("pod-1", [{"name": "test-pod-1-system", "image": IMG_ALPINE,
"command": "sleep 100", "state": NOT_RUNNING, "id": containerId}])
self.filter_containers("running")
self.waitPodRow("pod-1", False)
self.filter_containers("all")
b.set_input_text('#containers-filter', 'pod-1')
self.waitPodContainer("pod-1", [{"name": "test-pod-1-system", "image": IMG_ALPINE,
"command": "sleep 100", "state": NOT_RUNNING, "id": containerId}])
b.set_input_text('#containers-filter', 'test-pod-1-system')
self.waitPodContainer("pod-1", [{"name": "test-pod-1-system", "image": IMG_ALPINE,
"command": "sleep 100", "state": NOT_RUNNING, "id": containerId}])
# TODO add pixel test when this is again reachable - https://github.com/cockpit-project/bots/issues/2463
# Check Pod Actions
self.performPodAction("pod-1", "system", "Start")
self.waitPodContainer("pod-1", [{"name": "test-pod-1-system", "image": IMG_ALPINE,
"command": "sleep 100", "state": "Running", "id": containerId}])
self.performPodAction("pod-1", "system", "Pause")
self.waitPodContainer("pod-1", [{"name": "test-pod-1-system", "image": IMG_ALPINE,
"command": "sleep 100", "state": "Paused", "id": containerId}])
self.performPodAction("pod-1", "system", "Unpause")
self.waitPodContainer("pod-1", [{"name": "test-pod-1-system", "image": IMG_ALPINE,
"command": "sleep 100", "state": "Running", "id": containerId}])
self.performPodAction("pod-1", "system", "Stop")
self.waitPodContainer("pod-1", [{"name": "test-pod-1-system", "image": IMG_ALPINE,
"command": "sleep 100", "state": NOT_RUNNING, "id": containerId}])
self.machine.execute("podman pod start pod-1")
self.waitPodContainer("pod-1", [{"name": "test-pod-1-system", "image": IMG_ALPINE,
"command": "sleep 100", "state": "Running", "id": containerId}])
old_start = self.getStartTime("test-pod-1-system", auth=True)
self.performPodAction("pod-1", "system", "Restart")
self.waitRestart("test-pod-1-system", old_start, auth=True)
self.performPodAction("pod-1", "system", "Delete")
b.click(".pf-v5-c-modal-box button:contains(Delete)")
# Alert should be shown, that running pods need to be force deleted.
b.wait_in_text(".pf-v5-c-modal-box__body .pf-v5-c-list", "test-pod-1-system")
b.click(".pf-v5-c-modal-box button:contains('Force delete')")
self.waitPodRow("pod-1", False)
# HACK: there is some race here which steals the focus from the filter input and selects the page text instead
for _ in range(3):
b.focus('#containers-filter')
time.sleep(1)
if b.eval_js('document.activeElement == document.querySelector("#containers-filter")'):
break
b.set_input_text('#containers-filter', '')
self.machine.execute("podman pod create --infra=false --name pod-2")
self.waitPodContainer("pod-2", [])
run_cmd = f"podman run -d --pod pod-2 --name test-pod-2-system --stop-timeout 0 {IMG_ALPINE} sleep 100"
containerId = self.machine.execute(run_cmd).strip()
self.waitPodContainer("pod-2", [{"name": "test-pod-2-system", "image": IMG_ALPINE,
"command": "sleep 100", "state": "Running", "id": containerId}])
self.machine.execute("podman rm --force -t0 test-pod-2-system")
self.waitPodContainer("pod-2", [])
self.performPodAction("pod-2", "system", "Delete")
b.wait_not_in_text(".pf-v5-c-modal-box__body", "test-pod-2-system")
b.click(".pf-v5-c-modal-box button:contains('Delete')")
self.waitPodRow("pod-2", False)
# Volumes / mounts
self.machine.execute("podman pod create -p 9999:9999 -v /tmp:/app --name pod-3")
self.machine.execute("podman pod start pod-3")
self.waitPodContainer("pod-3", [])
# Verify 1 port mapping
b.wait_in_text("#table-pod-3-title .pod-details-ports-btn", "1")
b.click("#table-pod-3-title .pod-details-ports-btn")
b.wait_in_text(".pf-v5-c-popover__content", "0.0.0.0:9999 → 9999/tcp")
# Verify 1 mount
b.wait_in_text("#table-pod-3-title .pod-details-volumes-btn", "1")
b.click("#table-pod-3-title .pod-details-volumes-btn")
b.wait_in_text(".pf-v5-c-popover__content", "/tmp ↔ /app")
def testBasicSystem(self):
self._testBasic(True)
b = self.browser
# Test dropping and gaining privileges
b.set_val("#containers-containers-owner", "all")
self.filter_containers("all")
self.execute(False, "podman pod create --infra=false --name pod_user")
self.execute(True, "podman pod create --infra=false --name pod_system")
checkImage(b, IMG_REGISTRY, "system")
checkImage(b, IMG_REGISTRY, "admin")
b.wait_visible("#containers-containers .pod-name:contains('pod_user')")
b.wait_visible("#containers-containers .pod-name:contains('pod_system')")
b.wait_visible("#containers-containers .container-name:contains('a')")
b.wait_visible("#containers-containers .container-name:contains('b')")
# Drop privileges - all system things should disappear
b.drop_superuser()
b.wait_not_present("#containers-containers .pod-name:contains('pod_system')")
b.wait_not_present("#containers-containers .container-name:contains('a')")
b.wait_visible("#containers-containers .pod-name:contains('pod_user')")
b.wait_visible("#containers-containers .container-name:contains('b')")
# Checking images is harder but if there would be more than one this would fail
b.wait_visible(f"#containers-images:contains('{IMG_REGISTRY}')")
# Owner select should disappear
b.wait_not_present("#containers-containers-owner")
# Also user selection in image download should not be visible
b.click("#image-actions-dropdown")
b.click("button:contains(Download new image)")
b.wait_visible('div.pf-v5-c-modal-box header:contains("Search for an image")')
b.wait_visible("div.pf-v5-c-modal-box footer button:contains(Download):disabled")
b.wait_not_present("#as-user")
b.click(".pf-v5-c-modal-box button:contains('Cancel')")
b.wait_not_present('div.pf-v5-c-modal-box header:contains("Search for an image")')
# Gain privileges
b.become_superuser(passwordless=self.machine.image == "rhel4edge")
# We are notified that we can also start the system one
b.wait_in_text("#overview div.pf-v5-c-alert .pf-v5-c-alert__title", "System Podman service is also available")
b.click("#overview div.pf-v5-c-alert .pf-v5-c-alert__action > button:contains(Start)")
b.wait_not_present("#overview div.pf-v5-c-alert .pf-v5-c-alert__title")
checkImage(b, IMG_REGISTRY, "system")
checkImage(b, IMG_REGISTRY, "admin")
b.wait_visible("#containers-containers .pod-name:contains('pod_user')")
b.wait_visible("#containers-containers .pod-name:contains('pod_system')")
b.wait_visible("#containers-containers .container-name:contains('a')")
b.wait_visible("#containers-containers .container-name:contains('b')")
# Owner select should appear
b.wait_visible("#containers-containers-owner")
# Also user selection in image download should be visible
b.click("#image-actions-dropdown")
b.click("button:contains(Download new image)")
b.wait_visible('div.pf-v5-c-modal-box header:contains("Search for an image")')
b.wait_visible("div.pf-v5-c-modal-box footer button:contains(Download):disabled")
b.wait_visible("#as-user")
b.click(".pf-v5-c-modal-box button:contains('Cancel')")
b.wait_not_present('div.pf-v5-c-modal-box header:contains("Search for an image")')
# Check that when we filter only system stuff an then drop privileges that we show user stuff
b.set_val("#containers-containers-owner", "system")
b.wait_not_present("#containers-containers .pod-name:contains('pod_user')")
b.wait_not_present("#containers-containers .container-name:contains('b')")
# Checking images is harder but if there would be more than one this would fail
b.wait_visible(f"#containers-images:contains('{IMG_REGISTRY}')")
b.drop_superuser()
b.wait_visible("#containers-containers .pod-name:contains('pod_user')")
b.wait_visible("#containers-containers .container-name:contains('b')")
# Checking images is harder but if there would be more than one this would fail
b.wait_visible(f"#containers-images:contains('{IMG_REGISTRY}')")
# Check showing of entrypoint
b.click("#containers-containers-create-container-btn")
b.click("#create-image-image-select-typeahead")
b.click(f'button.pf-v5-c-select__menu-item:contains("{IMG_REGISTRY}")')
b.wait_val("#run-image-dialog-command", '/etc/docker/registry/config.yml')
b.wait_text("#run-image-dialog-entrypoint", '/entrypoint.sh')
# Deleting image will cleanup both command and entrypoint
b.click("button.pf-v5-c-select__toggle-clear")
b.wait_val("#run-image-dialog-command", '')
b.wait_not_present("#run-image-dialog-entrypoint")
# Edited command will not be cleared
b.click("#create-image-image-select-typeahead")
b.click(f'button.pf-v5-c-select__menu-item:contains("{IMG_REGISTRY}")')
b.wait_val("#run-image-dialog-command", '/etc/docker/registry/config.yml')
b.set_input_text("#run-image-dialog-command", '/etc/docker/registry/config.yaml')
b.click("button.pf-v5-c-select__toggle-clear")
b.wait_not_present("#run-image-dialog-entrypoint")
b.wait_val("#run-image-dialog-command", '/etc/docker/registry/config.yaml')
# Setting a new image will still keep the old command and not prefill it
b.click("#create-image-image-select-typeahead")
b.click(f'button.pf-v5-c-select__menu-item:contains({IMG_ALPINE})')
b.wait_visible("#run-image-dialog-pull-latest-image")
b.wait_val("#run-image-dialog-command", '/etc/docker/registry/config.yaml')
b.logout()
if self.machine.ostree_image:
self.machine.execute("echo foobar | passwd --stdin root")
self.write_file("/etc/ssh/sshd_config.d/99-root-password.conf", "PermitRootLogin yes",
post_restore_action="systemctl try-restart sshd")
self.machine.execute("systemctl try-restart sshd")
# Test that when root is logged in we don't present "user" and "system"
self.login_and_go("/podman", user="root", enable_root_login=True)
b.wait_visible("#app")
# `User Service is also available` banner should not be present
b.wait_not_present("#overview div.pf-v5-c-alert")
# There should not be any duplicate images listed
# The "busybox" and "alpine" images have been deleted by _testBasic.
showImages(b)
self.waitNumImages(self.system_images_count - 2)
# There should not be 'owner' selector
b.wait_not_present("#containers-containers-owner")
# Test the isSystem boolean for searching
# https://github.com/cockpit-project/cockpit-podman/pull/891
b.click("#containers-containers-create-container-btn")
b.set_input_text("#create-image-image-select-typeahead", "registry")
b.wait_visible('button.pf-v5-c-select__menu-item:contains("registry")')
self.confirm_modal("Cancel")
def testBasicUser(self):
self._testBasic(False)
def _testBasic(self, auth):
b = self.browser
def clickDeleteImage(image_sel):
b.click(f'{image_sel} .pf-v5-c-menu-toggle')
b.click(image_sel + " button.btn-delete")
if not auth:
self.allow_browser_errors("Failed to start system podman.socket.*")
expected_ws = ""
if auth and self.machine.ostree_image:
expected_ws += "ws"
self.login(auth)
# Check all containers
if auth:
checkImage(b, IMG_ALPINE, "system")
checkImage(b, IMG_BUSYBOX, "system")
checkImage(b, IMG_REGISTRY, "system")
checkImage(b, IMG_ALPINE, "admin")
checkImage(b, IMG_BUSYBOX, "admin")
checkImage(b, IMG_REGISTRY, "admin")
# Check order of images
text = b.text("#containers-images table")
if auth:
# all user images before all system images
self.assertRegex(text, ".*admin.*system.*")
self.assertNotRegex(text, ".*system.*admin.*")
else:
self.assertNotIn("system", text)
# images are sorted alphabetically
self.assertRegex(text, ".*/test-alpine.*/test-busybox.*/test-registry")
# build a dummy image so that the timestamp is "today" (for predictable pixel tests)
# ensure that CMD neither comes first (podman rmi leaves that layer otherwise)
# nor last (then the topmost layer does not match the image ID)
IMG_HELLO_LATEST = "localhost/test-hello:latest"
self.machine.execute(f"""set -eu; D={self.vm_tmpdir}/hello;
mkdir $D
printf 'FROM scratch\\nCOPY test.txt /\\nCMD ["/run.sh"]\\nCOPY test.txt /test2.txt\\n' > $D/Containerfile
echo hello > $D/test.txt""")
self.execute(auth, f"podman build -t {IMG_HELLO_LATEST} {self.vm_tmpdir}/hello")
# prepare image ids - much easier to pick a specific container
images = {}
for image in self.execute(auth, "podman images --noheading --no-trunc").strip().split("\n"):
# <name> <tag> sha256:<sha> <other things>
items = image.split()
images[f"{items[0]}:{items[1]}"] = items[2].split(":")[-1]
# show image listing toggle
hello_sel = f"#containers-images tbody tr[data-row-id=\"{images[IMG_HELLO_LATEST]}{auth}\"]".lower()
b.wait_visible(hello_sel)
b.click(hello_sel + " td.pf-v5-c-table__toggle button")
b.click(hello_sel + " .pf-v5-c-menu-toggle")
b.wait_visible(hello_sel + " button.btn-delete")
b.wait_in_text("#containers-images tbody.pf-m-expanded tr .image-details:first-child", "Command/run.sh")
# Show history
b.click("#containers-images tbody.pf-m-expanded .pf-v5-c-tabs__list li:nth-child(2) button")
first_row_sel = "#containers-images .pf-v5-c-table__expandable-row.pf-m-expanded tbody:first-of-type"
b.wait_in_text(f"{first_row_sel} td[data-label=\"ID\"]",
images[IMG_HELLO_LATEST][:12])
created_sel = f"{first_row_sel} td[data-label=\"Created\"]"
b.wait_text(f"{created_sel}", "less than a minute ago")
# topmost (last) layer
created_sel = f"{first_row_sel} td[data-label=\"Created by\"]"
b.wait_in_text(f"{created_sel}", "COPY")
b.wait_in_text(f"{created_sel}", "in /test2.txt")
# initial (first) layer
last_row_sel = "#containers-images .pf-v5-c-table__expandable-row.pf-m-expanded tbody:last-of-type"
b.wait_in_text(f"{last_row_sel} td[data-label=\"Created by\"]", "COPY")
self.execute(auth, f"podman rmi {IMG_HELLO_LATEST}")
b.wait_not_present(hello_sel)
# make sure no running containers shown; on CoreOS there's the cockpit/ws container
self.filter_containers('running')
if auth and self.machine.ostree_image:
self.waitContainerRow("ws")
else:
b.wait_in_text("#containers-containers", "No running containers")
if auth:
# Run two containers as system (first exits immediately)
self.execute(auth, f"podman run -d --name test-sh-system --stop-timeout 0 {IMG_ALPINE} sh")
self.execute(auth, f"podman run -d --name swamped-crate-system --stop-timeout 0 {IMG_BUSYBOX} sleep 1000")
# Run two containers as admin (first exits immediately)
self.execute(False, f"podman run -d --name test-sh-user --stop-timeout 0 {IMG_ALPINE} sh")
self.execute(False, f"podman run -d --name swamped-crate-user --stop-timeout 0 {IMG_BUSYBOX} sleep 1000")
# Test owner filtering
if auth:
self.waitNumImages(self.user_images_count + self.system_images_count)
self.waitNumContainers(2, True)
def verify_system():
self.waitNumImages(self.system_images_count)
b.wait_in_text("#containers-images", "system")
self.waitNumContainers(1, True)
b.wait_in_text("#containers-containers", "system")
b.set_val("#containers-containers-owner", "system")
verify_system()
b.set_val("#containers-containers-owner", "all")
b.go("#/?owner=system")
verify_system()
def verify_user():
self.waitNumImages(self.user_images_count)
b.wait_in_text("#containers-images", "admin")
self.waitNumContainers(1, False)
b.wait_in_text("#containers-containers", "admin")
b.set_val("#containers-containers-owner", "user")
verify_user()
b.set_val("#containers-containers-owner", "all")
b.go("#/?owner=user")
verify_user()
b.set_val("#containers-containers-owner", "all")
self.waitNumImages(self.user_images_count + self.system_images_count)
self.waitNumContainers(2, True)
else: # No 'owner' selector when not privileged
b.wait_not_present("#containers-containers-owner")
user_containers = {}
system_containers = {}
for container in self.execute(True, "podman ps --all --no-trunc").strip().split("\n")[1:]:
# <sha> <other things> <name>
items = container.split()
system_containers[items[-1]] = items[0]
for container in self.execute(False, "podman ps --all --no-trunc").strip().split("\n")[1:]:
# <sha> <other things> <name>
items = container.split()
user_containers[items[-1]] = items[0]
# running busybox shown
if auth:
self.waitContainerRow("swamped-crate-system")
self.waitContainer(system_containers["swamped-crate-system"], True, name='swamped-crate-system',
image=IMG_BUSYBOX, cmd="sleep 1000", state='Running')
self.waitContainerRow("swamped-crate-user")
self.waitContainer(user_containers["swamped-crate-user"], False, name='swamped-crate-user',
image=IMG_BUSYBOX, cmd="sleep 1000", state='Running')
# exited alpine not shown
b.wait_not_in_text("#containers-containers", "alpine")
# show all containers and check status
b.go("#/?container=all")
# exited alpine under everything list
b.wait_visible("#containers-containers")
if auth:
self.waitContainer(system_containers["test-sh-system"], True, name='test-sh-system', image=IMG_ALPINE,
cmd='sh', state=NOT_RUNNING)
self.waitContainer(user_containers["test-sh-user"], False, name='test-sh-user', image=IMG_ALPINE,
cmd='sh', state=NOT_RUNNING)
self.performContainerAction("swamped-crate-user", "Delete")
self.confirm_modal("Cancel")
if auth:
self.performContainerAction("swamped-crate-system", "Delete")
self.confirm_modal("Cancel")
# Checked order of containers
expected = ["swamped-crate-user", "test-sh-user"]
if auth:
expected.extend(["swamped-crate-system", "test-sh-system"])
expected.extend([expected_ws])
b.wait_collected_text("#containers-containers .container-name", ''.join(sorted(expected)))
# show running container
self.filter_containers('running')
if auth:
self.waitContainer(system_containers["swamped-crate-system"], True, name='swamped-crate-system',
image=IMG_BUSYBOX, cmd="sleep 1000", state='Running')
self.waitContainer(user_containers["swamped-crate-user"], False, name='swamped-crate-user',
image=IMG_BUSYBOX, cmd="sleep 1000", state='Running')
# check exited alpine not in running list
b.wait_not_in_text("#containers-containers", "alpine")
# delete running container busybox using force delete
if auth:
self.performContainerAction("swamped-crate-system", "Delete")
self.confirm_modal("Force delete")
self.waitContainerRow("swamped-crate-system", False)
self.filter_containers("all")
self.performContainerAction("swamped-crate-user", "Delete")
self.confirm_modal("Force delete")
self.waitContainerRow("swamped-crate-user", False)
self.waitContainerRow("test-sh-user")
self.performContainerAction("test-sh-user", "Delete")
self.confirm_modal("Delete")
b.wait_not_in_text("#containers-containers", "test-sh-user")
if auth:
self.waitContainerRow("test-sh-system")
self.performContainerAction("test-sh-system", "Delete")
self.confirm_modal("Delete")
b.wait_not_in_text("#containers-containers", "test-sh-system")
# delete image busybox that hasn't been used
# First try to just untag and then remove with more tags
self.execute(auth, f"podman tag {IMG_BUSYBOX} {IMG_BUSYBOX}:1")
self.execute(auth, f"podman tag {IMG_BUSYBOX} {IMG_BUSYBOX}:2")
self.execute(auth, f"podman tag {IMG_BUSYBOX} {IMG_BUSYBOX}:3")
self.execute(auth, f"podman tag {IMG_BUSYBOX} {IMG_BUSYBOX}:4")
busybox_sel = f"#containers-images tbody tr[data-row-id=\"{images[IMG_BUSYBOX_LATEST]}{auth}\"]".lower()
b.click(busybox_sel + " td.pf-v5-c-table__toggle button")
b.wait_in_text(busybox_sel + " + tr", f"{IMG_BUSYBOX}:1")
b.wait_in_text(busybox_sel + " + tr", f"{IMG_BUSYBOX}:2")
b.wait_in_text(busybox_sel + " + tr", f"{IMG_BUSYBOX}:3")
b.wait_in_text(busybox_sel + " + tr", f"{IMG_BUSYBOX}:4")
clickDeleteImage(busybox_sel)
self.assertTrue(b.get_checked(f".pf-v5-c-check__input[aria-label='{IMG_BUSYBOX_LATEST}']"))
b.set_checked(f".pf-v5-c-check__input[aria-label='{IMG_BUSYBOX}:1']", True)
b.set_checked(f".pf-v5-c-check__input[aria-label='{IMG_BUSYBOX}:3']", True)
b.set_checked(f".pf-v5-c-check__input[aria-label='{IMG_BUSYBOX_LATEST}']", False)
self.confirm_modal("Delete")
b.wait_in_text(busybox_sel + " + tr", f"{IMG_BUSYBOX_LATEST}")
b.wait_in_text(busybox_sel + " + tr", f"{IMG_BUSYBOX}:2")
b.wait_not_in_text(busybox_sel + " + tr", f"{IMG_BUSYBOX}:1")
b.wait_not_in_text(busybox_sel + " + tr", f"{IMG_BUSYBOX}:3")
clickDeleteImage(busybox_sel)
b.click("#delete-all")
self.assertTrue(b.get_checked(f".pf-v5-c-check__input[aria-label='{IMG_BUSYBOX_LATEST}']"))
self.assertTrue(b.get_checked(f".pf-v5-c-check__input[aria-label='{IMG_BUSYBOX}:2']"))
self.assertTrue(b.get_checked(f".pf-v5-c-check__input[aria-label='{IMG_BUSYBOX}:4']"))
self.confirm_modal("Delete")
self.confirm_modal("Force delete")
b.wait_not_present(busybox_sel)
# Check that we correctly show networking information
# Rootless don't have this info
if auth:
self.execute(auth, f"podman run -dt --name net_check --stop-timeout 0 {IMG_ALPINE}")
self.toggleExpandedContainer("net_check")
b.wait_in_text(".pf-m-expanded .container-details-networking",
self.execute(auth, """
podman inspect --format '{{.NetworkSettings.Gateway}}' net_check""").strip())
b.wait_in_text(".pf-m-expanded .container-details-networking",
self.execute(auth, """
podman inspect --format '{{.NetworkSettings.IPAddress}}' net_check""").strip())
b.wait_in_text(".pf-m-expanded .container-details-networking",
self.execute(auth, """
podman inspect --format '{{.NetworkSettings.MacAddress}}' net_check""").strip())
self.execute(auth, "podman stop net_check")
b.wait(lambda: self.execute(True, "podman ps --all | grep -e net_check -e Exited"))
self.toggleExpandedContainer("net_check")
sha = self.execute(auth, "podman inspect --format '{{.Id}}' net_check").strip()
self.waitContainer(sha, auth, state='Exited')
# delete image alpine that has been used by a container
self.execute(auth, f"podman run -d --name test-sh4 --stop-timeout 0 {IMG_ALPINE} sh")
# our pixel test expects both containers to be in state "Exited"
sha = self.execute(auth, "podman inspect --format '{{.Id}}' test-sh4").strip()
self.waitContainer(sha, auth, name="test-sh4", state='Exited')
if auth:
b.assert_pixels('#app', "overview", ignore=[".ignore-pixels"], skip_layouts=["rtl", "mobile"])
alpine_sel = f"#containers-images tbody tr[data-row-id=\"{images[IMG_ALPINE_LATEST]}{auth}\"]".lower()
b.wait_visible(alpine_sel)
b.click(alpine_sel + " td.pf-v5-c-table__toggle button")
clickDeleteImage(alpine_sel)
self.confirm_modal("Delete")
self.confirm_modal("Force delete")
b.wait_not_present(alpine_sel)
b.wait_collected_text("#containers-containers .container-name", expected_ws)
self.execute(auth, f"podman run -d --name c --stop-timeout 0 {IMG_REGISTRY} sh")
b.wait_collected_text("#containers-containers .container-name", "c" + expected_ws)
self.execute(auth, f"podman run -d --name a --stop-timeout 0 {IMG_REGISTRY} sh")
b.wait_collected_text("#containers-containers .container-name", "ac" + expected_ws)
self.execute(False, f"podman run -d --name b --stop-timeout 0 {IMG_REGISTRY} sh")
if auth:
b.wait_collected_text("#containers-containers .container-name", "abc" + expected_ws)
self.execute(False, f"podman run -d --name doremi --stop-timeout 0 {IMG_REGISTRY} sh")
b.wait_collected_text("#containers-containers .container-name", "abcdoremi" + expected_ws)
b.wait(lambda: self.getContainerAttr("doremi", "State") in NOT_RUNNING)
else:
b.wait_collected_text("#containers-containers .container-name", "abc")
# Test intermediate images
b.wait_not_present(".listing-action")
tmpdir = self.execute(auth, "mktemp -d").strip()
self.execute(auth, f"echo 'FROM {IMG_REGISTRY}\nRUN ls' > {tmpdir}/Dockerfile")
self.execute(auth, f"podman build {tmpdir}")
b.wait_not_in_text("#containers-images", "<none>:<none>")
b.click(".listing-action button:contains('Show intermediate images')")
b.wait_in_text("#containers-images", "<none>:<none>")
b.wait_text("#containers-images tbody:last-child td[data-label=Created]", "less than a minute ago")
b.click(".listing-action button:contains('Hide intermediate images')")
b.wait_not_in_text("#containers-images", "<none>:<none>")
# Intermediate images are not shown in create container dialog
b.click("#containers-containers-create-container-btn")
b.wait_visible('div.pf-v5-c-modal-box header:contains("Create container")')
b.click("#create-image-image-select-typeahead")
b.wait_visible(f".pf-v5-c-select__menu-item:contains('{IMG_REGISTRY}')")
b.wait_not_present(".pf-v5-c-select__menu-item:contains('none')")
b.click(".pf-v5-c-modal-box .btn-cancel")
b.wait_not_present(".pf-v5-c-modal-box")
# Delete intermediate images
intermediate_image_sel = "#containers-images tbody:last-child:contains('<none>:<none>')"
b.click(".listing-action button:contains('Show intermediate images')")
clickDeleteImage(intermediate_image_sel)
self.confirm_modal("Delete")
b.wait_not_present(intermediate_image_sel)
# Create intermediate image and use it in a container
tmpdir = self.execute(auth, "mktemp -d").strip()
self.execute(auth, f"echo 'FROM {IMG_REGISTRY}\nRUN ls' > {tmpdir}/Dockerfile")
IMG_INTERMEDIATE = 'localhost/test-intermediate'
self.execute(auth, f"podman build -t {IMG_INTERMEDIATE} {tmpdir}")
b.click(f'#containers-images tbody tr:contains("{IMG_INTERMEDIATE}") .ct-container-create')
b.wait_visible('div.pf-v5-c-modal-box header:contains("Create container")')
b.click("#create-image-create-btn")
b.wait_not_present("div.pf-v5-c-modal-box")
self.waitContainerRow(IMG_INTERMEDIATE)
# Integration tab should not crash with an intermediate image
self.toggleExpandedContainer(IMG_INTERMEDIATE)
b.click(".pf-m-expanded button:contains('Integration')")
# Delete intermediate image which is in use
self.execute(auth, f"podman untag {IMG_INTERMEDIATE}")
clickDeleteImage(intermediate_image_sel)
self.confirm_modal("Delete")
self.confirm_modal("Force delete")
b.wait_not_in_text("#containers-images", "<none>:<none>")
b.wait_not_in_text("#containers-containers", IMG_INTERMEDIATE)
def testCommitUser(self):
self._testCommit(False)
def testCommitSystem(self):
self._testCommit(True)
def _testCommit(self, auth):
b = self.browser
self.allow_browser_errors("Failed to commit container .* repository name must be lowercase")
self.login(auth)
# run a container (will exit immediately) and test the display of commit modal
self.execute(auth, f"podman run -d --name test-sh0 --stop-timeout 0 {IMG_ALPINE} sh -c 'ls -a'")
self.filter_containers("all")
self.waitContainerRow("test-sh0")
self.toggleExpandedContainer("test-sh0")
self.performContainerAction("test-sh0", "Commit")
b.wait_visible(".pf-v5-c-modal-box")
b.wait_in_text(".pf-v5-c-modal-box__description", "state of the test-sh0 container")
# Empty name yields warning
b.click("button:contains(Commit)")
b.wait_text("#commit-dialog-image-name-helper", "Image name is required")
b.wait_visible("button:contains(Commit):disabled")
b.wait_visible("button:contains('Force commit')")
# Warning should be cleaned when updating name
b.set_input_text("#commit-dialog-image-name", "foobar")
b.wait_not_present("button:contains('Force commit')")
b.wait_not_present("#commit-dialog-image-name-helper")
# Existing name yields warning
b.set_input_text("#commit-dialog-image-name", IMG_ALPINE)
b.click("button:contains(Commit)")
b.wait_text("#commit-dialog-image-name-helper", "Image name is not unique")
b.wait_visible("button:contains(Commit):disabled")
b.wait_visible("button:contains('Force commit')")
# Warning should be cleaned when updating tag
b.set_input_text("#commit-dialog-image-tag", "foobar")
b.wait_not_present("button:contains('Force commit')")
b.wait_not_present("#commit-dialog-image-name-helper")
# Check failing commit
b.set_input_text("#commit-dialog-image-name", "TEST")
b.click("button:contains(Commit)")
b.wait_in_text(".pf-v5-c-alert", "Failed to commit container test-sh0")
b.wait_in_text(".pf-v5-c-alert", "repository name must be lowercase")
# Test cancel
self.confirm_modal("Cancel")
# Force commit empty container
self.performContainerAction("test-sh0", "Commit")
b.wait_visible(".pf-v5-c-modal-box")
# We prefill command
b.wait_val("#commit-dialog-command", 'sh -c "ls -a"')
# Test docker format
b.set_checked("#commit-dialog-docker", True)
b.click("button:contains(Commit)")
self.confirm_modal("Force commit")
# don't use waitNumImages() here, as we want to include anonymous images
def waitImageCount(expected):
if auth:
expected += self.system_images_count
b.wait_in_text("#containers-images", f"{expected} images")
waitImageCount(self.user_images_count + 1)
image_id = self.execute(auth, "podman images --sort created --format '{{.Id}}' | head -n 1").strip()
manifest_type = self.execute(auth, "podman inspect --format '{{.ManifestType}}' " + image_id).strip()
cmd = self.execute(auth, "podman inspect --format '{{.Config.Cmd}}' " + image_id).strip()
self.assertIn("docker.distribution.manifest", manifest_type)
self.assertEqual("[sh -c ls -a]", cmd)
# Commit with name, tag, author and edited command
self.performContainerAction("test-sh0", "Commit")
b.wait_visible(".pf-v5-c-modal-box")
b.set_input_text("#commit-dialog-image-name", "newname")
b.set_input_text("#commit-dialog-image-tag", "24")
b.set_input_text("#commit-dialog-author", "MM")
b.set_input_text("#commit-dialog-command", "sh -c 'ps'")
if auth: