Merge pull request #19284 from ygalblum/quadlet-kube-replace-journalctl

Quadlet system test - do not rely on journalctl in kube file tests
This commit is contained in:
OpenShift Merge Robot 2023-07-19 16:02:59 +02:00 committed by GitHub
commit a977c8281e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 30 additions and 18 deletions

View File

@ -517,6 +517,8 @@ EOF
@test "quadlet kube - basic" { @test "quadlet kube - basic" {
# Create the YAMl file # Create the YAMl file
pod_name="test_pod"
container_name="test"
yaml_source="$PODMAN_TMPDIR/basic_$(random_string).yaml" yaml_source="$PODMAN_TMPDIR/basic_$(random_string).yaml"
cat >$yaml_source <<EOF cat >$yaml_source <<EOF
apiVersion: v1 apiVersion: v1
@ -524,13 +526,16 @@ kind: Pod
metadata: metadata:
labels: labels:
app: test app: test
name: test_pod name: $pod_name
spec: spec:
containers: containers:
- command: - command:
- top - "sh"
args:
- "-c"
- "echo STARTED CONTAINER; top -b"
image: $IMAGE image: $IMAGE
name: test name: $container_name
EOF EOF
# Create the Quadlet file # Create the Quadlet file
@ -543,9 +548,8 @@ EOF
run_quadlet "$quadlet_file" run_quadlet "$quadlet_file"
service_setup $QUADLET_SERVICE_NAME service_setup $QUADLET_SERVICE_NAME
# Ensure we have output. Output is synced via sd-notify (socat in Exec) # Ensure we have output.
run journalctl "--since=$STARTED_TIME" --unit="$QUADLET_SERVICE_NAME" wait_for_output "STARTED CONTAINER" $pod_name-$container_name
is "$output" '.*Started.*\.service.*'
run_podman container inspect --format "{{.State.Status}}" test_pod-test run_podman container inspect --format "{{.State.Status}}" test_pod-test
is "$output" "running" "container should be started by systemd and hence be running" is "$output" "running" "container should be started by systemd and hence be running"
@ -572,6 +576,8 @@ EOF
local network_name="foo" local network_name="foo"
# Create the YAMl file # Create the YAMl file
pod_name="test_pod"
container_name="test"
yaml_source="$PODMAN_TMPDIR/basic_$(random_string).yaml" yaml_source="$PODMAN_TMPDIR/basic_$(random_string).yaml"
cat >$yaml_source <<EOF cat >$yaml_source <<EOF
apiVersion: v1 apiVersion: v1
@ -579,13 +585,16 @@ kind: Pod
metadata: metadata:
labels: labels:
app: test app: test
name: test_pod name: $pod_name
spec: spec:
containers: containers:
- command: - command:
- top - "sh"
args:
- "-c"
- "echo STARTED CONTAINER; top -b"
image: $IMAGE image: $IMAGE
name: test name: $container_name
EOF EOF
# Create the Quadlet file # Create the Quadlet file
@ -609,9 +618,8 @@ EOF
# Network should exist # Network should exist
run_podman network exists $network_name run_podman network exists $network_name
# Ensure we have output. Output is synced via sd-notify (socat in Exec) # Ensure we have output.
run journalctl "--since=$STARTED_TIME" --unit="$QUADLET_SERVICE_NAME" wait_for_output "STARTED CONTAINER" $pod_name-$container_name
assert "$output" =~ '.*Started.*\.service.*'
run_podman container inspect --format "{{.State.Status}}" test_pod-test run_podman container inspect --format "{{.State.Status}}" test_pod-test
assert "$output" =~ "running" "container should be started by systemd and hence be running" assert "$output" =~ "running" "container should be started by systemd and hence be running"
@ -846,6 +854,8 @@ EOF
} }
@test "quadlet - exit-code propagation" { @test "quadlet - exit-code propagation" {
pod_name="test_pod"
container_name="ctr"
exit_tests=" exit_tests="
all | true | 0 | inactive all | true | 0 | inactive
all | false | 137 | failed all | false | 137 | failed
@ -862,14 +872,17 @@ kind: Pod
metadata: metadata:
labels: labels:
app: test app: test
name: test_pod name: $pod_name
spec: spec:
restartPolicy: Never restartPolicy: Never
containers: containers:
- name: ctr - name: $container_name
image: $IMAGE image: $IMAGE
command: command:
- $cmd - "sh"
args:
- "-c"
- "echo STARTED CONTAINER; $cmd"
EOF EOF
cat > $quadlet_file <<EOF cat > $quadlet_file <<EOF
[Kube] [Kube]
@ -885,9 +898,8 @@ EOF
service_setup $QUADLET_SERVICE_NAME service_setup $QUADLET_SERVICE_NAME
# Ensure we have output. Output is synced via sd-notify (socat in Exec) # Ensure we have output.
run journalctl "--since=$STARTED_TIME" --unit="$QUADLET_SERVICE_NAME" wait_for_output "STARTED CONTAINER" $pod_name-$container_name
is "$output" '.*Started.*\.service.*'
# Opportunistic test: confirm that the Propagation field got set. # Opportunistic test: confirm that the Propagation field got set.
# This is racy, because the container is short-lived and quadlet # This is racy, because the container is short-lived and quadlet