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>
(cherry picked from commit df0b00c253e41cce9567be79dbd3faa14c60473b)

Samuli Seppänen authored on 2016/10/03 19:51:27
Showing 4 changed files
... ...
@@ -53,5 +53,7 @@ doc/openvpn.8.html
53 53
 distro/rpm/openvpn.spec
54 54
 tests/t_client.sh
55 55
 tests/t_client-*-20??????-??????/
56
+t_client.rc
57
+t_client_ips.rc
56 58
 src/openvpn/openvpn
57 59
 config-version.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
 
... ...
@@ -263,6 +263,12 @@ do
263 263
     eval ping4_hosts=\"\$PING4_HOSTS_$SUF\"
264 264
     eval ping6_hosts=\"\$PING6_HOSTS_$SUF\"
265 265
 
266
+    # If EXCEPT_IFCONFIG* variables for this test are missing, run an --up
267
+    # script to generate them dynamically.
268
+    if [ -z "$expect_ifconfig4" ] || [ -z "$expect_ifconfig6" ]; then
269
+        up="--setenv TESTNUM $SUF --setenv TOP_BUILDDIR ${top_builddir} --script-security 2 --up ${top_builddir}/tests/update_t_client_ips.sh"
270
+    fi
271
+
266 272
     echo -e "\n### test run $SUF: '$test_run_title' ###\n"
267 273
     fail_count=0
268 274
 
... ...
@@ -281,7 +287,7 @@ do
281 281
     fi
282 282
 
283 283
     pidfile="${top_builddir}/tests/$LOGDIR/openvpn-$SUF.pid"
284
-    openvpn_conf="$openvpn_conf --writepid $pidfile"
284
+    openvpn_conf="$openvpn_conf --writepid $pidfile $up"
285 285
     echo " run openvpn $openvpn_conf"
286 286
     echo "# src/openvpn/openvpn $openvpn_conf" >$LOGDIR/$SUF:openvpn.log
287 287
     umask 022
288 288
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