Browse code

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

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.

Signed-off-by: Samuli Seppänen <samuli@openvpn.net>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <1475491887-740-1-git-send-email-samuli@openvpn.net>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg12587.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Samuli Seppänen authored on 2016/10/03 19:51:27
Showing 4 changed files
... ...
@@ -55,6 +55,7 @@ distro/rpm/openvpn.spec
55 55
 tests/t_client.sh
56 56
 tests/t_client-*-20??????-??????/
57 57
 t_client.rc
58
+t_client_ips.rc
58 59
 
59 60
 src/openvpn/openvpn
60 61
 include/openvpn-plugin.h
... ...
@@ -11,6 +11,14 @@ top_srcdir="${top_srcdir:-..}"
11 11
 CA_CERT="${top_srcdir}/sample/sample-keys/ca.crt"
12 12
 CLIENT_KEY="${top_srcdir}/sample/sample-keys/client.key"
13 13
 CLIENT_CERT="${top_srcdir}/sample/sample-keys/client.crt"
14
+
15
+# Load EXPECT_IFCONFIG* parameters from cache
16
+if [ -r "${top_srcdir}/t_client_ips.rc" ]; then
17
+    . "${top_srcdir}/t_client_ips.rc"
18
+else
19
+    echo "NOTICE: missing t_client_ips.rc will be auto-generated"
20
+fi
21
+
14 22
 #
15 23
 # remote host (used as macro below)
16 24
 #
... ...
@@ -58,8 +66,6 @@ OPENVPN_BASE_P2P="..."
58 58
 #
59 59
 RUN_TITLE_1="testing tun/udp/ipv4+ipv6"
60 60
 OPENVPN_CONF_1="$OPENVPN_BASE_P2MP --dev tun --proto udp --remote $REMOTE --port 51194"
61
-EXPECT_IFCONFIG4_1="10.100.50.6"
62
-EXPECT_IFCONFIG6_1="2001:db8:a050::1:0"
63 61
 PING4_HOSTS_1="10.100.50.1 10.100.0.1"
64 62
 PING6_HOSTS_1="2001:db8::1 2001:db8:a050::1"
65 63
 
... ...
@@ -67,8 +73,6 @@ PING6_HOSTS_1="2001:db8::1 2001:db8:a050::1"
67 67
 #
68 68
 RUN_TITLE_2="testing tun/tcp/ipv4+ipv6"
69 69
 OPENVPN_CONF_2="$OPENVPN_BASE_P2MP --dev tun --proto tcp --remote $REMOTE --port 51194"
70
-EXPECT_IFCONFIG4_2="10.100.51.6"
71
-EXPECT_IFCONFIG6_2="2001:db8:a051::1:0"
72 70
 PING4_HOSTS_2="10.100.51.1 10.100.0.1"
73 71
 PING6_HOSTS_2="2001:db8::1 2001:db8:a051::1"
74 72
 
... ...
@@ -271,6 +271,12 @@ do
271 271
     eval ping4_hosts=\"\$PING4_HOSTS_$SUF\"
272 272
     eval ping6_hosts=\"\$PING6_HOSTS_$SUF\"
273 273
 
274
+    # If EXCEPT_IFCONFIG* variables for this test are missing, run an --up
275
+    # script to generate them dynamically.
276
+    if [ -z "$expect_ifconfig4" ] || [ -z "$expect_ifconfig6" ]; then
277
+        up="--setenv TESTNUM $SUF --setenv TOP_BUILDDIR ${top_builddir} --script-security 2 --up ${top_builddir}/tests/update_t_client_ips.sh"
278
+    fi
279
+
274 280
     echo -e "\n### test run $SUF: '$test_run_title' ###\n"
275 281
     fail_count=0
276 282
 
... ...
@@ -294,7 +300,7 @@ do
294 294
     fi
295 295
 
296 296
     pidfile="${top_builddir}/tests/$LOGDIR/openvpn-$SUF.pid"
297
-    openvpn_conf="$openvpn_conf --writepid $pidfile"
297
+    openvpn_conf="$openvpn_conf --writepid $pidfile $up"
298 298
     echo " run openvpn $openvpn_conf"
299 299
     echo "# src/openvpn/openvpn $openvpn_conf" >$LOGDIR/$SUF:openvpn.log
300 300
     umask 022
301 301
new file mode 100755
... ...
@@ -0,0 +1,7 @@
0
+#!/bin/sh
1
+#
2
+# This --up script caches the IPs handed out by the test VPN server to a file
3
+# for later use.
4
+
5
+echo "EXPECT_IFCONFIG4_$TESTNUM=$ifconfig_local" >> $TOP_BUILDDIR/t_client_ips.rc
6
+echo "EXPECT_IFCONFIG6_$TESTNUM=$ifconfig_ipv6_local" >> $TOP_BUILDDIR/t_client_ips.rc