BACKPORT: Tests: fix: test_relayd_working_directory fails as root
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 3 Feb 2020 20:56:43 +0000 (15:56 -0500)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 26 May 2020 18:29:42 +0000 (14:29 -0400)
From the original bug report:

This test succeeds as user, but fails as root:
not ok 23 - Warning about missing write permission is present

    Failed test 'Warning about missing write permission is present'
    in tools/working-directory/test_relayd_working_directory:test_relayd_debug_permission() at line 182.

The warning does not trigger because root always has access.

Skip this test since the permission check will succeed and the relay
daemon won't produce the expected error message.

Reported-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I4eb29958aaca78405e1fdd2392d73472af0d5912

tests/regression/tools/working-directory/test_relayd_working_directory

index 956cb780a6e368c7239aa51cff73b03f757bce65..91f2e5eea6f32a23c7e417584c654ab86967d28f 100755 (executable)
@@ -156,35 +156,46 @@ function test_relayd_background_no_working_dir()
 
 function test_relayd_debug_permission()
 {
-       local output_pattern='Working directory \".*\" is not writable'
-       local working_dir
-       local cwd
-       local pid
-
-       working_dir=$(realpath "$(mktemp -d)")
+       local is_user
 
        diag "Test lttng-relayd change working directory on non writable directory"
 
-       # Removing write access to working dir
-       okx chmod -w "$working_dir"
+       if [ "$(id -u)" == "0" ]; then
+           is_user=0
+       else
+           is_user=1
+       fi
 
-       # Redirect the error output to a temporary file
-       ERROR_OUTPUT_DEST=$(mktemp)
-       start_lttng_relayd_opt 1 "-b" "-v --working-dir $working_dir"
+       skip $is_user "Skipping permission debug output test; operation can't fail as root" 6 ||
+       {
+               local output_pattern='Working directory \".*\" is not writable'
+               local working_dir
+               local cwd
+               local pid
 
-       pid=$(pgrep "$RELAYD_MATCH")
-       ok $? "Found lttng-relayd"
+               working_dir=$(realpath "$(mktemp -d)")
 
-       cwd=$(readlink "/proc/${pid}/cwd")
-       is "$cwd" "$working_dir" "Working directory changed"
+               # Removing write access to working dir
+               okx chmod -w "$working_dir"
 
-       grep -q "$output_pattern" "$ERROR_OUTPUT_DEST"
-       ok $? "Warning about missing write permission is present"
+               # Redirect the error output to a temporary file
 
-       stop_lttng_relayd
-       rm "$ERROR_OUTPUT_DEST"
-       rm -rf "$working_dir" "$ERROR_OUTPUT_DEST"
-       ERROR_OUTPUT_DEST=/dev/null
+               ERROR_OUTPUT_DEST=$(mktemp) start_lttng_relayd_opt 1 "-b" "-v --working-dir $working_dir"
+
+               pid=$(pgrep "$RELAYD_MATCH")
+               ok $? "Found lttng-relayd"
+
+               cwd=$(readlink "/proc/${pid}/cwd")
+               is "$cwd" "$working_dir" "Working directory changed"
+
+               grep -q "$output_pattern" "$ERROR_OUTPUT_DEST"
+               ok $? "Warning about missing write permission is present"
+
+               stop_lttng_relayd
+               rm "$ERROR_OUTPUT_DEST"
+               rm -rf "$working_dir" "$ERROR_OUTPUT_DEST"
+               ERROR_OUTPUT_DEST=/dev/null
+       }
 }
 
 function test_relayd_failure()
This page took 0.027279 seconds and 5 git commands to generate.