Skip to contentSkip to conversation

Automatically cache expected IPs for t_client.sh on the first run

PATCH In review [email protected]... 3 participants 3 messages Oct 3, 2016 – Oct 4, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Automatically cache expected IPs for t_client.sh on the first run

From: Samuli Seppänen <[email protected]...>

Previously one had to manually define correct values for the EXPECT_IFCONFIG* variables based on what IPv4 and IPv6 addresses the test VPN server handed out. This was a tedious process especially with large number of tests, as the IPs changed for every test client and for every test. With this patch t_client.sh figures out the correct IP addresses using an --up script and caches them to a separate file for later use.

---
 .gitignore                   |  1 +
 tests/t_client.rc-sample     | 12 ++++++++----
 tests/t_client.sh.in         |  8 +++++++-
 tests/update_t_client_ips.sh |  7 +++++++
 4 files changed, 23 insertions(+), 5 deletions(-)
 create mode 100755 tests/update_t_client_ips.sh
.gitignore +1 -0
index 0eea06e..fc1e223 100644
@@ -55,6 +55,7 @@ distro/rpm/openvpn.spec
 tests/t_client.sh
 tests/t_client-*-20??????-??????/
 t_client.rc
+t_client_ips.rc
 
 src/openvpn/openvpn
 include/openvpn-plugin.h
tests/t_client.rc-sample +8 -4
index 6e66607..fb2abfa 100644
@@ -11,6 +11,14 @@ top_srcdir="${top_srcdir:-..}"
 CA_CERT="${top_srcdir}/sample/sample-keys/ca.crt"
 CLIENT_KEY="${top_srcdir}/sample/sample-keys/client.key"
 CLIENT_CERT="${top_srcdir}/sample/sample-keys/client.crt"
+
+# Load EXPECT_IFCONFIG* parameters from cache
+if [ -r "${top_srcdir}/t_client_ips.rc" ]; then
+    . "${top_srcdir}/t_client_ips.rc"
+else
+    echo "NOTICE: missing t_client_ips.rc will be auto-generated"
+fi
+
 #
 # remote host (used as macro below)
 #
@@ -58,8 +66,6 @@ OPENVPN_BASE_P2P="..."
 #
 RUN_TITLE_1="testing tun/udp/ipv4+ipv6"
 OPENVPN_CONF_1="$OPENVPN_BASE_P2MP --dev tun --proto udp --remote $REMOTE --port 51194"
-EXPECT_IFCONFIG4_1="10.100.50.6"
-EXPECT_IFCONFIG6_1="2001:db8:a050::1:0"
 PING4_HOSTS_1="10.100.50.1 10.100.0.1"
 PING6_HOSTS_1="2001:db8::1 2001:db8:a050::1"
 
@@ -67,8 +73,6 @@ PING6_HOSTS_1="2001:db8::1 2001:db8:a050::1"
 #
 RUN_TITLE_2="testing tun/tcp/ipv4+ipv6"
 OPENVPN_CONF_2="$OPENVPN_BASE_P2MP --dev tun --proto tcp --remote $REMOTE --port 51194"
-EXPECT_IFCONFIG4_2="10.100.51.6"
-EXPECT_IFCONFIG6_2="2001:db8:a051::1:0"
 PING4_HOSTS_2="10.100.51.1 10.100.0.1"
 PING6_HOSTS_2="2001:db8::1 2001:db8:a051::1"
 
tests/t_client.sh.in +7 -1
index 2b9bacf..d1c5d87 100755
@@ -271,6 +271,12 @@ do
     eval ping4_hosts=\"\$PING4_HOSTS_$SUF\"
     eval ping6_hosts=\"\$PING6_HOSTS_$SUF\"
 
+    # If EXCEPT_IFCONFIG* variables for this test are missing, run an --up
+    # script to generate them dynamically.
+    if [ -z "$expect_ifconfig4" ] || [ -z "$expect_ifconfig6" ]; then
+        up="--setenv TESTNUM $SUF --setenv TOP_BUILDDIR ${top_builddir} --script-security 2 --up ${top_builddir}/tests/update_t_client_ips.sh"
+    fi
+
     echo -e "\n### test run $SUF: '$test_run_title' ###\n"
     fail_count=0
 
@@ -294,7 +300,7 @@ do
     fi
 
     pidfile="${top_builddir}/tests/$LOGDIR/openvpn-$SUF.pid"
-    openvpn_conf="$openvpn_conf --writepid $pidfile"
+    openvpn_conf="$openvpn_conf --writepid $pidfile $up"
     echo " run openvpn $openvpn_conf"
     echo "# src/openvpn/openvpn $openvpn_conf" >$LOGDIR/$SUF:openvpn.log
     umask 022
tests/update_t_client_ips.sh new file +7 -0
new file mode 100755
index 0000000..e7b58ba
@@ -0,0 +1,7 @@
+#!/bin/sh
+#
+# This --up script caches the IPs handed out by the test VPN server to a file
+# for later use.
+
+echo "EXPECT_IFCONFIG4_$TESTNUM=$ifconfig_local" >> $TOP_BUILDDIR/t_client_ips.rc
+echo "EXPECT_IFCONFIG6_$TESTNUM=$ifconfig_ipv6_local" >> $TOP_BUILDDIR/t_client_ips.rc
Signature · 1 line
2.1.4
#1 lore raw

Am 03.10.16 um 12:51 schrieb [email protected]...:

Quoted 10 lines

From: Samuli Seppänen <[email protected]...>

Previously one had to manually define correct values for the EXPECT_IFCONFIG* variables based on what IPv4 and IPv6 addresses the test VPN server handed out. This was a tedious process especially with large number of tests, as the IPs changed for every test client and for every test. With this patch t_client.sh figures out the correct IP addresses using an --up script and caches them to a separate file for later use.

I removed all EXPECT_IFCONFIG for test 1-6 from my config and it worked. Also the code looks fine, so ack from me.

(If we later add a test with --up we can figure that out later. Currently the added comfort is great)

Arne

#2 lore raw
In reply to [email protected]...

Your patch has been applied to the following branches

commit df0b00c253e41cce9567be79dbd3faa14c60473b (master) commit beca355525fd250f660b5c400edd3ba83d25f171 (release/2.3)

Author: Samuli Sepp�nen
Date:   Mon Oct 3 13:51:27 2016 +0300
     Automatically cache expected IPs for t_client.sh on the first run

     Signed-off-by: Samuli Sepp�nen <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg12587.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering