podman

Форк
0
/
045-start.bats 
144 строки · 4.8 Кб
1
#!/usr/bin/env bats   -*- bats -*-
2

3
load helpers
4

5
@test "podman start --all - start all containers" {
6
    # Run a bunch of short-lived containers, with different --restart settings
7
    run_podman run -d $IMAGE /bin/true
8
    cid_none_implicit="$output"
9
    run_podman run -d --restart=no $IMAGE /bin/false
10
    cid_none_explicit="$output"
11
    run_podman run -d --restart=on-failure $IMAGE /bin/true
12
    cid_on_failure="$output"
13

14
    # Run one longer-lived one.
15
    run_podman run -d --restart=always $IMAGE sleep 20
16
    cid_always="$output"
17

18
    run_podman wait $cid_none_implicit $cid_none_explicit $cid_on_failure
19

20
    run_podman start --all
21
    is "$output" ".*$cid_none_implicit" "started: container with no --restart"
22
    is "$output" ".*$cid_none_explicit" "started: container with --restart=no"
23
    is "$output" ".*$cid_on_failure" "started: container with --restart=on-failure"
24
    assert "$output" !~ "$cid_always" \
25
           "podman start --all should not restart a running container"
26

27
    run_podman wait $cid_none_implicit $cid_none_explicit $cid_on_failure
28

29
    run_podman rm $cid_none_implicit $cid_none_explicit $cid_on_failure
30
    run_podman 0+w stop -t 1 $cid_always
31
    if ! is_remote; then
32
        require_warning "StopSignal SIGTERM failed to stop container .*, resorting to SIGKILL"
33
    fi
34
    run_podman rm $cid_always
35
}
36

37
@test "podman start --all with incompatible options" {
38
    expected="Error: either start all containers or the container(s) provided in the arguments"
39
    run_podman 125 start --all 12333
40
    is "$output" "$expected" "start --all, with args, throws error"
41
}
42

43
@test "podman start --filter - start only containers that match the filter" {
44
    c1="c1_always_$(random_string 15)"
45
    c2="c2_on_failure_$(random_string 15)"
46
    c3="c3_always_$(random_string 15)"
47

48
    run_podman create --name=$c1 --restart=always $IMAGE /bin/true
49
    c1_id="$output"
50
    run_podman create --name=$c2 --restart=on-failure $IMAGE /bin/true
51
    c2_id="$output"
52
    run_podman create --name=$c3 --restart=always $IMAGE /bin/true
53
    c3_id="$output"
54

55
    # Start via --filter
56
    run_podman start --filter restart-policy=always
57
    # Output order not sorted wrt creation time, so we need two regexes
58
    is "$output" ".*$c1_id.*" "--filter finds container 1"
59
    is "$output" ".*$c3_id.*" "--filter finds container 3"
60

61
    # Start via filtered names
62
    run_podman start --filter restart-policy=on-failure $c2 $c3
63
    is "$output" "$c2" "--filter finds container 2"
64

65
    # Nothing on match
66
    run_podman start --filter restart-policy=none --all
67
    is "$output" ""
68
}
69

70
@test "podman start --filter invalid-restart-policy - return error" {
71
    run_podman run -d $IMAGE /bin/true
72
    cid="$output"
73
    run_podman 125 start --filter restart-policy=fakepolicy $cid
74
    is "$output" "Error: fakepolicy invalid restart policy" \
75
       "CID of restart-policy=<not-exists> container"
76
}
77

78
@test "podman start --all --filter" {
79
    run_podman run -d $IMAGE /bin/true
80
    cid_exited_0="$output"
81
    run_podman run -d $IMAGE /bin/false
82
    cid_exited_1="$output"
83

84
    run_podman wait $cid_exited_0 $cid_exited_1
85
    run_podman start --all --filter exited=0
86
    is "$output" "$cid_exited_0"
87
}
88

89
@test "podman start print IDs or raw input" {
90
    # start --all must print the IDs
91
    run_podman create $IMAGE top
92
    ctrID="$output"
93
    run_podman start --all
94
    is "$output" "$ctrID"
95

96
    # start $input must print $input
97
    cname=$(random_string)
98
    run_podman create --name $cname $IMAGE top
99
    run_podman start $cname
100
    is "$output" $cname
101

102
    run_podman rm -t 0 -f $ctrID $cname
103
}
104

105
@test "podman start again with lower ulimit -u" {
106
    skip_if_not_rootless "tests ulimit -u changes in the rootless scenario"
107
    skip_if_remote "test relies on control of ulimit -u (not possible for remote)"
108
    # get current ulimit -u
109
    nrpoc_limit=$(ulimit -Hu)
110

111
    # create container
112
    run_podman create $IMAGE echo "hello"
113
    ctrID="$output"
114

115
    # inspect
116
    run_podman inspect $ctrID
117
    assert "$output" =~ '"Ulimits": \[\]' "Ulimits has to be empty after create"
118

119
    # start container for the first time
120
    run_podman start $ctrID
121
    is "$output" "$ctrID"
122

123
    # inspect
124
    run_podman inspect $ctrID --format '{{range .HostConfig.Ulimits}}{{if eq .Name "RLIMIT_NPROC" }}{{.Soft}}:{{.Hard}}{{end}}{{end}}'
125
    assert "$output" == "${nrpoc_limit}:${nrpoc_limit}" "Ulimit has to match ulimit -Hu"
126

127
    # lower ulimit -u by one
128
    ((nrpoc_limit--))
129

130
    # set new ulimit -u
131
    ulimit -u $nrpoc_limit
132

133
    # start container for the second time
134
    run_podman start $ctrID
135
    is "$output" "$ctrID"
136

137
    # inspect
138
    run_podman inspect $ctrID --format '{{range .HostConfig.Ulimits}}{{if eq .Name "RLIMIT_NPROC" }}{{.Soft}}:{{.Hard}}{{end}}{{end}}'
139
    assert "$output" == "${nrpoc_limit}:${nrpoc_limit}" "Ulimit has to match new ulimit -Hu"
140

141
    run_podman rm -t 0 -f $ctrID $cname
142
}
143

144
# vim: filetype=sh
145

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

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

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

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