From cf75acf877940135dea97af2aff9206e335b4736 Mon Sep 17 00:00:00 2001 From: Shachar Sharon Date: Wed, 5 Feb 2025 16:20:10 +0200 Subject: [PATCH] selftest: Add test for smb_prometheus_endpoint utility Basic test for smb_prometheus_endpoint utility. Requires valid metrics output using 'curl'. Start/stop the endpoint utility from within the test script itself. Signed-off-by: Shachar Sharon Reviewed-by: Ralph Boehme Reviewed-by: Guenther Deschner --- selftest/selftesthelpers.py | 1 + .../tests/test_smb_prometheus_endpoint.sh | 189 ++++++++++++++++++ source3/selftest/tests.py | 5 + 3 files changed, 195 insertions(+) create mode 100755 source3/script/tests/test_smb_prometheus_endpoint.sh diff --git a/selftest/selftesthelpers.py b/selftest/selftesthelpers.py index 908fe79cb19..54f007addbe 100644 --- a/selftest/selftesthelpers.py +++ b/selftest/selftesthelpers.py @@ -237,3 +237,4 @@ smbcacls = binpath('smbcacls') smbcontrol = binpath('smbcontrol') smbstatus = binpath('smbstatus') timelimit = binpath('timelimit') +smb_prometheus_endpoint = binpath('smb_prometheus_endpoint') diff --git a/source3/script/tests/test_smb_prometheus_endpoint.sh b/source3/script/tests/test_smb_prometheus_endpoint.sh new file mode 100755 index 00000000000..e7057f4b50a --- /dev/null +++ b/source3/script/tests/test_smb_prometheus_endpoint.sh @@ -0,0 +1,189 @@ +#!/bin/sh + +# This runs smbstatus tests + +if [ $# -lt 10 ]; then + echo "Usage: $0 SERVER SERVER_IP USERNAME PASSWORD LOCK_DIR PREFIX SMBPROMETHEUS SMBCLIENT CONFIGURATION PROTOCOL" + exit 1 +fi + +SERVER="${1}" +SERVER_IP="${2}" +USERNAME="${3}" +PASSWORD="${4}" +LOCK_DIR="${5}" +PREFIX="${6}" +SMBPROMETHEUS="${7}" +SMBCLIENT="${8}" +CONFIGURATION="${9}" +PROTOCOL="${10}" + +shift 10 + +RAWARGS="${CONFIGURATION} -m${PROTOCOL}" +ADDARGS="${RAWARGS} $*" +SMBPROFILE_TDB="${LOCK_DIR}/smbprofile.tdb" +SMBPROMETHEUS_PORT=9922 +SMBPROMETHEUS_PID=0 + +incdir=$(dirname $0)/../../../testprogs/blackbox +. $incdir/subunit.sh + +failed=0 + +start_smbprometheus() +{ + if [ ! -f "${SMBPROFILE_TDB}" ]; then + printf "'%s' doesn't exist\n" "${SMBPROFILE_TDB}" + return 1 + fi + + if [ ! -x "${SMBPROMETHEUS}" ]; then + printf "'%s' is not executable\n" "${SMBPROMETHEUS}" + return 1 + fi + + ${SMBPROMETHEUS} -a "${SERVER_IP}" -p "${SMBPROMETHEUS_PORT}" "${SMBPROFILE_TDB}" & + SMBPROMETHEUS_PID=$! + sleep 1 + + cmd='ps -p ${SMBPROMETHEUS_PID} --no-headers' + eval "$cmd" + ret=$? + if [ $ret != 0 ]; then + printf "failed to start: '%s' is not running\n" "${SMBPROMETHEUS}" + return 1 + fi + + sleep 1 + + return 0 +} + +stop_smbprometheus() +{ + cmd='ps -p ${SMBPROMETHEUS_PID} --no-headers' + eval "$cmd" + ret=$? + if [ $ret != 0 ]; then + printf "failed to stop: '%s' is not running\n" "${SMBPROMETHEUS}" + return 1 + fi + kill $SMBPROMETHEUS_PID + return 0 +} + +make_some_smb_ops() +{ + tmpfile=$PREFIX/test_smb_prometheus + + cat >$tmpfile < /dev/null; then exit 0; fi + +# Start smb_prometheus_endpoint from within test script +start_smbprometheus || exit 1 +trap "stop_smbprometheus" EXIT + +# Actual tests +testit "test_smbprometheus_tcon" \ + test_smbprometheus_tcon || + failed=$(expr $failed + 1) + +testit "test_smbprometheus_info" \ + test_smbprometheus_info || + failed=$(expr $failed + 1) + +testit "test_smbprometheus_many" \ + test_smbprometheus_many || + failed=$(expr $failed + 1) + +testok $0 $failed diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py index 437a4a8ee13..98d7084048f 100755 --- a/source3/selftest/tests.py +++ b/source3/selftest/tests.py @@ -35,6 +35,7 @@ from selftesthelpers import smbtorture4_options from selftesthelpers import smbcontrol from selftesthelpers import smbstatus from selftesthelpers import timelimit +from selftesthelpers import smb_prometheus_endpoint smbtorture4_options.extend([ '--option=torture:sharedelay=100000', '--option=torture:writetimeupdatedelay=500000', @@ -955,6 +956,10 @@ for env in ["fileserver:local"]: plantestsuite("samba3.blackbox.smbstatus", env, [os.path.join(samba3srcdir, "script/tests/test_smbstatus.sh"), '$SERVER', '$SERVER_IP', '$DOMAIN', '$USERNAME', '$PASSWORD', '$USERID', '$LOCAL_PATH', '$PREFIX', smbclient3, smbstatus, configuration, "SMB3"]) plantestsuite("samba3.blackbox.net_registry_import", env, [os.path.join(samba3srcdir, "script/tests/test_net_registry_import.sh"), '$SERVER', '$LOCAL_PATH', '$USERNAME', '$PASSWORD']) + plantestsuite("samba3.blackbox.smb_prometheus_endpoint", env, + [os.path.join(samba3srcdir, "script/tests/test_smb_prometheus_endpoint.sh"), + '$SERVER', '$SERVER_IP', '$USERNAME', '$PASSWORD', '$LOCK_DIR', '$PREFIX', + smb_prometheus_endpoint, smbclient3, configuration, "SMB3"]) env = 'ad_member' plantestsuite("samba3.blackbox.smbget", -- 2.47.3