From 579e8b2d7a5c33c5a6f68864af59b6349497f46e Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Wed, 4 Sep 2024 08:24:16 -0600 Subject: [PATCH] e2e: flake fix: SIGPIPE in hook test One-off flake, easy to fix. And, as long as I'm fixing it, add a few more checks to it. Signed-off-by: Ed Santiago --- test/e2e/run_test.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go index 07c4751f54..53d51f7098 100644 --- a/test/e2e/run_test.go +++ b/test/e2e/run_test.go @@ -957,7 +957,29 @@ USER bin`, BB) random := stringid.GenerateRandomID() hookScript := fmt.Sprintf(`#!/bin/sh -echo -n %s >%s +teststring="%s" +tmpfile="%s" + +# Hook gets invoked with config.json in stdin. +# Flush it, otherwise caller may get SIGPIPE. +cat >$tmpfile.json + +# Check for required fields in our given json. +# Hooks have no visibility -- our output goes nowhere -- so +# use unique exit codes to give test code reader a hint as +# to what went wrong. Podman will exit 126, but will emit +# "crun: error executing hook .... (exit code: X)" +rc=1 +for s in ociVersion id pid root bundle status annotations io.container.manager; do + grep -w $s $tmpfile.json || exit $rc + rc=$((rc + 1)) +done +rm -f $tmpfile.json + +# json contains all required keys. We're good so far. +# Now write a modified teststring to our tmpfile. Our +# caller will confirm. +echo -n madeit-$teststring >$tmpfile `, random, targetFile) err = os.WriteFile(hookScriptPath, []byte(hookScript), 0755) Expect(err).ToNot(HaveOccurred()) @@ -968,7 +990,7 @@ echo -n %s >%s b, err := os.ReadFile(targetFile) Expect(err).ToNot(HaveOccurred()) - Expect(string(b)).To(Equal(random)) + Expect(string(b)).To(Equal("madeit-" + random)) }) It("podman run with subscription secrets", func() {