Skip to contentSkip to conversation

t_net.sh: drop hard dependency on t_client.rc

PATCH Superseded Antonio Quartulli 2 participants 5 messages Jul 17, 2020 – Jul 22, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 t_net.sh: drop hard dependency on t_client.rc

Right now t_net.sh depends on t_client.rc in order to source the RUN_SUDO variable only.
However, t_client.rc is something that a few people only have configured and thus this would result in t_net.sh almost never executed even if it just could.

Drop dependency on t_client.rc by falling back to RUN_SUDO=sudo when the file is missing.

The assignment is made as conditional so that a user can still override RUN_SUDO by speciying an alternate string on the command line.

While at it, reword the error message to better match the current logic flow.

---
 tests/t_net.sh | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
tests/t_net.sh +2 -5
index c67c3df2..63732db9 100755
@@ -77,9 +77,7 @@ if [ -r "${top_builddir}"/t_client.rc ]; then
 elif [ -r "${srcdir}"/t_client.rc ]; then
     . "${srcdir}"/t_client.rc
 else
-    echo "$0: cannot find 't_client.rc' in build dir ('${top_builddir}')" >&2
-    echo "$0: or source directory ('${srcdir}'). SKIPPING TEST." >&2
-    exit 77
+    RUN_SUDO="${RUN_SUDO:-sudo}"
 fi
 
 if [ ! -x "$openvpn" ]; then
@@ -117,8 +115,7 @@ else
 
     if [ -z "$RUN_SUDO" ]
     then
-        echo "$0: this test must run be as root, or RUN_SUDO=... " >&2
-        echo "      must be set correctly in 't_client.rc'. SKIP." >&2
+        echo "$0: using t_client.rc, but RUN_SUDO=... is not defined correctly. SKIP. " >&2
         exit 77
     else
         # check that we can run the unit-test binary with sudo
Signature · 1 line
2.27.0
#1 lore raw

Hi,

Quoted 2 lines · Antonio Quartulli

Right now t_net.sh depends on t_client.rc in order to source the RUN_SUDO variable only.

I was about to merge this ("nice and easy") but I think it's just complicated.

tests/t_net.sh if [ -r "${top_builddir}"/t_client.rc ]; then · line 81

Quoted 13 lines
tests/t_net.sh +1 -3
index c67c3df2..63732db9 100755
@@ -77,9 +77,7 @@ if [ -r "${top_builddir}"/t_client.rc ]; then
 elif [ -r "${srcdir}"/t_client.rc ]; then
     . "${srcdir}"/t_client.rc
 else
-    echo "$0: cannot find 't_client.rc' in build dir ('${top_builddir}')" >&2
-    echo "$0: or source directory ('${srcdir}'). SKIPPING TEST." >&2
-    exit 77
+    RUN_SUDO="${RUN_SUDO:-sudo}"
 fi

Leave off the whole else clause.

tests/t_net.sh else · line 119

Quoted 9 lines
tests/t_net.sh +1 -2
 if [ ! -x "$openvpn" ]; then
@@ -117,8 +115,7 @@ else
 
     if [ -z "$RUN_SUDO" ]
     then
-        echo "$0: this test must run be as root, or RUN_SUDO=... " >&2
-        echo "      must be set correctly in 't_client.rc'. SKIP." >&2
+        echo "$0: using t_client.rc, but RUN_SUDO=... is not defined correctly. SKIP. " >&2
         exit 77

In here, print & set

      if [ -z "$RUN_SUDO" ]
      then
 +        echo "$0: no RUN_SUDO=... in t_client.rc or environment, defaulting to 'sudo'." >&2
 +        echo "      if that does not work, set RUN_SUDO= correctly for your system." >&2
 +        RUN_SUDO=sudo"

fi

done - less code, message conveyed if needed.

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#2 lore raw

Hi,

Quoted 11 lines · Gert Doering

In here, print & set

      if [ -z "$RUN_SUDO" ]
      then
 +        echo "$0: no RUN_SUDO=... in t_client.rc or environment, defaulting to 'sudo'." >&2
 +        echo "      if that does not work, set RUN_SUDO= correctly for your system." >&2
 +        RUN_SUDO=sudo"

fi

done - less code, message conveyed if needed.

hmhmhmh makes sense. v2 incoming!

Signature · 1 line
Antonio Quartulli
#3 lore raw

PATCH v2 1/1 t_net.sh: drop hard dependency on t_client.rc

Right now t_net.sh depends on t_client.rc in order to source the RUN_SUDO variable only.
However, t_client.rc is something that a few people only have configured and thus this would result in t_net.sh almost never executed even if it just could.

Drop dependency on t_client.rc by falling back to RUN_SUDO=sudo when the file is missing and no RUN_SUDO is passed via env.

While at it, reword the error message to better match the current logic flow.

---

Changes from v1:
* default to sudo when no RUN_SUDO is set externally
* change warning message

 tests/t_net.sh | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)
tests/t_net.sh +11 -15
index c67c3df2..eef3c5d1 100755
@@ -76,10 +76,6 @@ if [ -r "${top_builddir}"/t_client.rc ]; then
     . "${top_builddir}"/t_client.rc
 elif [ -r "${srcdir}"/t_client.rc ]; then
     . "${srcdir}"/t_client.rc
-else
-    echo "$0: cannot find 't_client.rc' in build dir ('${top_builddir}')" >&2
-    echo "$0: or source directory ('${srcdir}'). SKIPPING TEST." >&2
-    exit 77
 fi
 
 if [ ! -x "$openvpn" ]; then
@@ -117,18 +113,18 @@ else
 
     if [ -z "$RUN_SUDO" ]
     then
-        echo "$0: this test must run be as root, or RUN_SUDO=... " >&2
-        echo "      must be set correctly in 't_client.rc'. SKIP." >&2
-        exit 77
+        echo "$0: no RUN_SUDO=... in t_client.rc or environment, defaulting to 'sudo'." >&2
+        echo "      if that does not work, set RUN_SUDO= correctly for your system." >&2
+        RUN_SUDO="sudo"
+    fi
+
+    # check that we can run the unit-test binary with sudo
+	if $RUN_SUDO $UNIT_TEST test
+    then
+	    echo "$0: $RUN_SUDO $UNIT_TEST succeeded, good."
     else
-        # check that we can run the unit-test binary with sudo
-	    if $RUN_SUDO $UNIT_TEST test
-        then
-	        echo "$0: $RUN_SUDO $UNIT_TEST succeeded, good."
-        else
-	        echo "$0: $RUN_SUDO $UNIT_TEST failed, cannot go on. SKIP." >&2
-	        exit 77
-        fi
+	    echo "$0: $RUN_SUDO $UNIT_TEST failed, cannot go on. SKIP." >&2
+	    exit 77
     fi
 fi
 
Signature · 1 line
2.27.0
Acked-by on v2 1/1
#4 lore raw

"Works!"

Fixed whitespace (indent) while at it...

Your patch has been applied to the master branch.

commit e6c86b24dbe8b001dfc8b9e9c4fad95e0f5973d4

Author: Antonio Quartulli
Date:   Tue Jul 21 21:55:18 2020 +0200
     t_net.sh: drop hard dependency on t_client.rc

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg20533.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering