wordpress招商平台,seo网站技术培训,阿里指数app下载,网站设计风格介绍测试shell脚本文件testing/do-tests#xff0c;测试配置文件testing/testing.conf。do-tests脚本不加参数#xff0c;将依次执行testing/tests/目录下的所有测试用例。do-tests脚本有两个参数-v和-t#xff0c;前者在测试中记录详细信息#xff0c;后者在输出信息中增加时间…测试shell脚本文件testing/do-tests测试配置文件testing/testing.conf。do-tests脚本不加参数将依次执行testing/tests/目录下的所有测试用例。do-tests脚本有两个参数-v和-t前者在测试中记录详细信息后者在输出信息中增加时间戳。另外可以指定单个或者多个测试用例来执行。
# cd strongswan-5.9.14/testing
# ./make-testing
# ./start-testing
# ./do-tests$ ls -l /srv/strongswan-testing/testing
lrwxrwxrwx 1 root root 40 11月 8 18:15 /srv/strongswan-testing/testing - /home/kai/work/strongswan-5.9.14/testing全局配置testing.conf
定义测试的目录TESTDIR以及测试所用的虚机的默认IPv4地址HOSTNAMEIPV4等全局信息。需要某个虚机的IPv4地址的时候需要由 HOSTNAMEIPV4变量中取得之后将会看到这种定义IPv4地址的方式看起来不太方便。
# Root directory of testing
: ${TESTDIR/srv/strongswan-testing}: ${HOSTNAMEIPV4\
alice,10.1.0.10,192.168.0.50 \
venus,10.1.0.20 \
moon,192.168.0.1,10.1.0.1 \
carol,192.168.0.100,10.3.0.1 \
winnetou,192.168.0.150 \
dave,192.168.0.200,10.3.0.2 \
sun,192.168.0.2,10.2.0.1 \
bob,10.2.0.10}定义默认的主机/VPN网关列表STRONGSWANHOSTS等.
# VPN gateways / clients
# The hosts stated here will be created. Possible values
# are sun, moon, dave, carol, alice, venus, bob, winnetou.
#
: ${STRONGSWANHOSTSalice bob carol dave moon sun venus winnetou}单个用例配置test.conf
每个具体的测试用例的配置文件为test.conf如testing/tests/af-alg/alg-camellia/test.conf其中指定测试过程用到的虚机、拓扑图、需要运行tcpdump命令的主机列表运行IPSec进程的虚机列表以及是否使用swanctl命令配置charon进程。
# All guest instances that are required for this test
VIRTHOSTSalice moon carol winnetou# Corresponding block diagram
DIAGRAMa-m-c-w.png# Guest instances on which tcpdump is to be started
TCPDUMPHOSTSmoon# Guest instances on which IPsec is started. Used for IPsec logging purposes
IPSECHOSTSmoon carol# charon controlled by swanctl
SWANCTL1加载测试load-testconfig
do-tests脚本调用load-testconfig来加载测试用例的配置参数为测试用例的名称。此脚本位于scripts/load-testconfig其将测试用例的配置发送到参与测试的主机上。
首先将strongswan代码目录中的测试用例如testnameaf-alg/alg-camellia文件夹下所有内容拷贝到测试目录测试目录为/srv/strongswan-testing/build/tests/af-alg/alg-camellia
TESTSDIR$BUILDDIR/tests
[ -d $TESTSDIR ] || mkdir $TESTSDIRTESTDIR$TESTSDIR/${testname}
rm -rf $TESTDIR
mkdir -p $TESTDIR
cp -rfp $DEFAULTTESTSDIR/${testname}/* $TESTDIR拷贝完成之后测试目录内容如下。由于测试过程可能修改测试用例中的文件需要执行此拷贝。
/srv/strongswan-testing/build/tests/af-alg/alg-camellia/
├── description.txt
├── evaltest.dat
├── hosts
│ ├── carol
│ │ └── etc
│ │ ├── strongswan.conf
│ │ └── swanctl
│ │ └── swanctl.conf
│ └── moon
│ └── etc
│ ├── strongswan.conf
│ └── swanctl
│ └── swanctl.conf
├── posttest.dat
├── pretest.dat
└── test.conf7 directories, 9 files以下语句处理testing.conf文件中定义的HOSTNAMEIPV4和HOSTNAMEIPV6变量取出各个测试虚机的IPv4和IPv6地址。
for host in $STRONGSWANHOSTS
doeval ipv4_${host}echo $HOSTNAMEIPV4 | sed -n -e s/^.*${host},//gp | awk -F, { print $1 } | awk { print $1 }eval ipv6_${host}echo $HOSTNAMEIPV6 | sed -n -e s/^.*${host},//gp | awk -F, { print $1 } | awk { print $1 }case $host inmoon)eval ipv4_moon1echo $HOSTNAMEIPV4 | sed -n -e s/^.*${host},//gp | awk -F, { print $2 } | awk { print $1 }eval ipv6_moon1echo $HOSTNAMEIPV6 | sed -n -e s/^.*${host},//gp | awk -F, { print $2 } | awk { print $1 };;sun)eval ipv4_sun1echo $HOSTNAMEIPV4 | sed -n -e s/^.*${host},//gp | awk -F, { print $2 } | awk { print $1 }eval ipv6_sun1echo $HOSTNAMEIPV6 | sed -n -e s/^.*${host},//gp | awk -F, { print $2 } | awk { print $1 };;...在测试用例目录查找文件中使用IP变量如PH_IP_MOON1PH_IP_MOON等的地方替换为真正的IP地址由以上变量ipv4_moon1和ipv4_moon等指定。
for host in $STRONGSWANHOSTS
docase $host inmoon)searchandreplace PH_IP_MOON1 $ipv4_moon1 $TESTDIRsearchandreplace PH_IP_MOON $ipv4_moon $TESTDIRsearchandreplace PH_IP6_MOON1 $ipv6_moon1 $TESTDIRsearchandreplace PH_IP6_MOON $ipv6_moon $TESTDIR;;sun)searchandreplace PH_IP_SUN1 $ipv4_sun1 $TESTDIRsearchandreplace PH_IP_SUN $ipv4_sun $TESTDIRsearchandreplace PH_IP6_SUN1 $ipv6_sun1 $TESTDIRsearchandreplace PH_IP6_SUN $ipv6_sun $TESTDIR;;...例如evaltest.dat文件中的PH_IP_ALICE变量替换成IP地址之后为10.1.0.10。如下
$ cat tests/af-alg/alg-camellia/evaltest.dat
carol::ping -c 1 -s 120 -p deadbeef PH_IP_ALICE::128 bytes from PH_IP_ALICE: icmp_.eq1::YES//替换IP地址修改之后。$ cat /srv/strongswan-testing/build/tests/af-alg/alg-camellia/evaltest.dat
carol::ping -c 1 -s 120 -p deadbeef 10.1.0.10::128 bytes from 10.1.0.10: icmp_.eq1::YES使用scp命令将测试所需的文件发送到测试主机上。
if [ -d $TESTDIR/hosts ]
thenfor host in ls $TESTDIR/hostsdoeval HOSTLOGINroot\$ipv4_${host}scp $SSHCONF -r $TESTDIR/hosts/$host/etc $HOSTLOGIN:/ /dev/null 21done
fi例如将测试目录中的用例alg-camellia的位于hosts子目录下的主机配置包括carol主机和moon网关的测试配置发送到测试机carol的IP为192.168.0.100moon的IP为192.168.0.1。
以上可见对于alg-camellia测试用例carol和moon的etc目录下的配置文件有两个分别为strongswan.conf和swanctl/swanctl.conf。
scp $SSHCONF -r /srv/strongswan-testing/build/tests/af-alg/alg-camellia/hosts/carol/etc root192.168.0.100:/
scp $SSHCONF -r /srv/strongswan-testing/build/tests/af-alg/alg-camellia/hosts/moon/etc root192.168.0.1:/此脚本文件中也会执行一些清理工作。如下清除了运行ipsec进程的虚机上的日志文件删除了虚机上的文件/var/log/auth.log和/var/log/daemon.log停止rsyslogd日志进程。
for host in $IPSECHOSTS
doeval HOSTLOGINroot\$ipv4_${host}ssh $SSHCONF $HOSTLOGIN rm -f /var/log/auth.log /var/log/daemon.log; \pkill -SIGHUP rsyslogd /dev/null 21
done删除radius服务虚机上的日志文件/var/log/daemon.log和/var/log/freeradius/radius.log并且停掉rsyslogd进程。
for host in $RADIUSHOSTS
doeval HOSTLOGINroot\$ipv4_${host}ssh $SSHCONF $HOSTLOGIN rm -f /var/log/daemon.log /var/log/freeradius/radius.log; \pkill -SIGHUP rsyslogd /dev/null 21
done准备tcpdump
根据测试用例的test.conf中配置的TCPDUMPHOSTS主机列表在相应主机上启动tcpdump命令后台方式运行。可在TCPDUMPHOSTS中通过冒号(:)指定主机上tcpdump使用的接口默认为eth0。 # run tcpdump in the backgroundif [ $TCPDUMPHOSTS ! ]thenecho -e TCPDUMP\n $CONSOLE_LOG 21for host_iface in $TCPDUMPHOSTSdohostecho $host_iface | awk -F : {print $1}ifaceecho $host_iface | awk -F : {if ($2 ! ) { print $2 } else { printf(eth0) }}tcpdump_cmdtcpdump -l $TCPDUMP_IM -i $iface not port ssh and not port domain /tmp/tcpdump.log 2/tmp/tcpdump.err.log echo $(print_time)${host}# $tcpdump_cmd $CONSOLE_LOGssh $SSHCONF rooteval echo \\\$ipv4_$host $tcpdump_cmdeval TDUP_${host}truedonefitcpdump抓取报文的过滤条件中去掉ssh和dns协议报文结果保存到文件/tmp/tcpdump.log。设置变量TDUP_KaTeX parse error: Expected group after _ at position 63: …cpdump抓包变量TDUP_̲{host}设置为false。 function stop_tcpdump {# wait for packets to get processed, but dont wait longer than 1seval ssh $SSHCONF root\$ipv4_${1} \i100; while [ \\\$i -gt 0 ]; do pkill -USR1 tcpdump; tail -1 /tmp/tcpdump.err.lo g | perl -n -e /(\\d).*?(\\d)/; exit (\\\$1 \\\$2) || break; sleep 0.01; i\\\$((\\\$i-1)); done;\echo $(print_time)${1}# killall tcpdump $CONSOLE_LOGeval ssh $SSHCONF root\$ipv4_${1} \killall tcpdump; while true; do killall -q -0 tcpdump || break; sleep 0.01; done; \eval TDUP_${1}falseecho $CONSOLE_LOG}测试预备阶段
do-tests脚本在此阶段执行写在测试用例pretest.dat文件中的命令。 echo -n pre..echo -e \nPRE-TEST\n $CONSOLE_LOG 21eval awk -F :: {if ($0 ~ /^#.*/){printf(echo \%s\; , $0);}else if ($2 ! ){printf(echo \$(print_time)%s# %s\; , $1, $2)printf(ssh \044SSHCONF root\044ipv4_%s \%s\; , $1, $2)printf(echo;\n)}} $TESTDIR/pretest.dat $CONSOLE_LOG 21例如af-alg/alg-camellia的pretest.dat文件。双冒号前后分别为虚机名和要执行的命令。如下设置iptables规则启动strongswan进程分别在主机moon和carol上启动名称为net和home的连接。在carol主机上发起home连接。
$ cat af-alg/alg-camellia/pretest.dat
moon::iptables-restore /etc/iptables.rules
carol::iptables-restore /etc/iptables.rules
moon::systemctl start strongswan
carol::systemctl start strongswan
moon::expect-connection net
carol::expect-connection home
carol::swanctl --initiate --child home 2 /dev/null测试用例af-alg/alg-camellia中moon虚机的swanctl.conf配置文件如下配置了名称为rw的连接和net子连接。
$ cat /srv/strongswan-testing/build/tests/af-alg/alg-camellia/hosts/moon/etc/swanctl/swanctl.conf
connections {rw {local_addrs 192.168.0.1local {auth pubkeycerts moonCert.pemid moon.strongswan.org}remote {auth pubkey}children {net {local_ts 10.1.0.0/16 updown /usr/local/libexec/ipsec/_updown iptablesesp_proposals camellia192-sha384}}version 2proposals camellia256-sha512-modp3072}
}语句moon::expect-connection net检查net子连接是否正常加载。expect-connection脚本调用了swanctl命令如下显示。
# ssh root192.168.0.1
moon:~#
moon:/etc/swanctl# swanctl --list-conns
rw: IKEv2, no reauthentication, rekeying every 14400slocal: 192.168.0.1remote: %anylocal public key authentication:id: moon.strongswan.orgcerts: CCH, OstrongSwan Project, CNmoon.strongswan.orgremote public key authentication:net: TUNNEL, rekeying every 3600slocal: 10.1.0.0/16remote: dynamic
No leaks detected, 172 suppressed by whitelistcarol虚机的swanctl.conf文件如下其中配置的连接和子连接名称都为home。
$ cat /srv/strongswan-testing/build/tests/af-alg/alg-camellia/hosts/carol/etc/swanctl/swanctl.conf
connections {home {local_addrs 192.168.0.100remote_addrs 192.168.0.1 local {auth pubkeycerts carolCert.pemid carolstrongswan.org}remote {auth pubkeyid moon.strongswan.org }children {home {remote_ts 10.1.0.0/16 updown /usr/local/libexec/ipsec/_updown iptablesesp_proposals camellia192-sha384}}version 2proposals camellia256-sha512-modp3072}
}在carol虚机上发起连接。carol::swanctl --initiate --child home。测试预备阶段完成。
测试预备阶段日志日志文件/srv/strongswan-testing/testresults/202xxxxx-1607-20/af-alg/alg-camellia/console.log。tcpdump需要在测试之前开启。
TCPDUMPmoon# tcpdump -l --immediate-mode -i eth0 not port ssh and not port domain /tmp/tcpdump.log 2/tmp/tcpdump.err.log PRE-TESTmoon# iptables-restore /etc/iptables.rules
carol# iptables-restore /etc/iptables.rules
moon# systemctl start strongswan
carol# systemctl start strongswan
moon# expect-connection net
carol# expect-connection home发起IPSec连接的日志。
carol# swanctl --initiate --child home 2 /dev/null
[IKE] initiating IKE_SA home[1] to 192.168.0.1
[NET] sending packet: from 192.168.0.100[500] to 192.168.0.1[500] (590 bytes)
[NET] received packet: from 192.168.0.1[500] to 192.168.0.100[500] (623 bytes)
...
[IKE] IKE_SA home[1] established between 192.168.0.100[carolstrongswan.org]...192.168.0.1[moon.strongswan.org]
[IKE] CHILD_SA home{1} established with SPIs c834da8a_i c0de5763_o and TS 192.168.0.100/32 10.1.0.0/16
initiate completed successfullycat testing/hosts/default/usr/local/bin/expect-connection
#!/bin/bash
# Wait until a given IPsec connection becomes available
# Params:
# $1 - connection name
# $2 - maximum time to wait in seconds, default is 5 secondssecs$2
[ ! $secs ] secs5cmdswanctl --list-conns
grep load.*stroke /etc/strongswan.conf /dev/null
if [ $? -eq 0 -o -n $DAEMON_NAME ]; thencmdipsec statusall
filet steps$secs*10
for i in seq 1 $steps
do$cmd 21 | grep ^[[:space:]]*$1: /dev/null[ $? -eq 0 ] exit 0sleep 0.1测试阶段
do-tests脚本在此阶段执行写在测试用例的evaltest.dat文件中的命令。每一行包括四个部分虚机名、执行命令、判断条件和期望结果。以下为af-alg/alg-camellia测试用例的evaltest.data文件省略了部分内容使用…表示。
kailogging:/srv/strongswan-testing/build/tests$ cat af-alg/alg-camellia/evaltest.dat
carol::ping -c 1 -s 120 -p deadbeef 10.1.0.10::128 bytes from 10.1.0.10: icmp_.eq1::YES
carol::swanctl --list-sas --raw 2 /dev/null::home.*version2 ... integ-algHMAC_SHA2_384_192.*local-ts\[192.168.0.100/32] remote-ts\[10.1.0.0/16]::YES
moon:: swanctl --list-sas --raw 2 /dev/null::rw.*version2 ... integ-algHMAC_SHA2_384_192.*local-ts\[10.1.0.0/16] remote-ts\[192.168.0.100/32]::YES
moon:: ip xfrm state::enc cbc(camellia)::YES
carol::ip xfrm state::enc cbc(camellia)::YES
moon::tcpdump::IP carol.strongswan.org moon.strongswan.org: ESP.*length 208::YES
moon::tcpdump::IP moon.strongswan.org carol.strongswan.org: ESP.*length 208::YESdo-test文件中测试代码如下。evaltest.dat文件中每行的四个部分为变量(-F指定::为分隔符)$1,$2,$3和$4分别赋值与hostcommandpattern和hit。变量$0表示当前行的所有内容。以井号#开头的行或者command为空的行不处理跳到下一行。 echo -n test..echo -e \nTEST\n $CONSOLE_LOG 21STATUSpassedeval awk -F :: {host$1command$2pattern$3hit$4if ($0 ~ /^#.*/){printf(echo \%s\; , $0);next}else if (command ){next}使用命令mktemp创建两个临时文件保存测试过程中的错误日志和正常输出日志例如文件test.PhfKyt.err和test.bSCZq4.out中间为6个随机字符mktemp命令参数中XXXXXX表示随机字符的数量。文件目录为当前目录例如strongswan-5.9.14/testing/。对于evaltest.dat中的每一行测试命令都会生成这两个文件。
SSH登录到虚机执行定义的命令命令输出重定向到cmd_out错误输出定向到cmd_err。对于tcpdump命令先停止tcpdump运行之后cat日志文件/tmp/tcpdump.log的内容到cmd_out文件中。
八进制\044表示美元符$。 printf(cmd_err\044(mktemp --suff .err test.XXXXXX); )printf(cmd_out\044(mktemp --suff .out test.XXXXXX); )printf(start_time\044(print_time); )if (command tcpdump){printf(if [ \044TDUP_%s \true\ ]; then stop_tcpdump %s; fi; \n, host, host)printf(ssh \044SSHCONF root\044ipv4_%s cat /tmp/tcpdump.log \044cmd_out; , host)}else{printf(ssh \044SSHCONF root\044ipv4_%s %s \044cmd_out 2\044cmd_err; , host, command)}在cmd_out文件中查找定义的匹配pattern命令输出保存在cmd_res变量命令执行结果保存在cmd_exit中$?表示执行结果。hit的取值为YESNOESP字符串或者数字或者为空。
正则表达式/1 / 表示数字开头 ( ) 并且结尾 ( /表示数字开头(^)并且结尾( /表示数字开头()并且结尾()表示一个或者多个数字。即如果hit为数字判断cmd_res与hit是否相等。否则根据命令执行结果cmd_exit的值为零或者非零以及hit值是否等于NO或者YES这里-a为与运算符AND需要两个条件同时成立。
例如cmd_exit等于0并且hit等于NO条件不符合STATUS设置为failedcmd_fail置1。 printf(cmd_res\044(cat \044cmd_out | grep \%s\); , pattern)printf(cmd_exit\044?; )printf(cmd_fail0; )if (hit ~ /^[0-9]$/){printf(if [ \044(echo \\044cmd_res\ | wc -l) -ne %d ] , hit)}else{printf(if [ \044cmd_exit -eq 0 -a \%s\ \NO\ ] , hit)printf(|| [ \044cmd_exit -ne 0 -a \%s\ \YES\ ] , hit)}printf(; then STATUS\failed\; cmd_fail1; fi; \n)printf(if [ \044cmd_fail -ne 0 ]; then echo \~~~~~~~ FAIL ~~~~~~~\; fi; \n)八进制\047为ASCII的单引号字符。当cmd_res非空(-n)时打印其值。接下来打印错误输出文件cmd_err的值。如果命令失败cmd_fail非零打印输出文件cmd_out的内容在设置verbose的情况下打印cmd_out的全部内容否则打印头部几行的内容head命令。
最后删除两个临时文件cmd_out和cmd_err。此过程中的输出内容重定向到了控制台文件$CONSOLE_LOG。
如果在执行do-test脚本时指定了-t选项变量start_time会被赋予当前的时间戳默认其为空。 if (command tcpdump){printf(echo \\044{start_time}%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\; , host, pattern, hit) /* 打印信息参见(B) */}else{printf(echo \\044{start_time}%s# %s | grep \047%s\047 [%s]\; , host, command, pattern, hit) /* 打印信息参见(A) */}printf(if [ -n \\044cmd_res\ ]; then echo \\044cmd_res\; fi; \n)printf(cat \044cmd_err; \n)printf(if [ \044cmd_fail -ne 0 ]; then \n)printf(if [ -s \044cmd_out ]; then echo \~~ output ~~~~~~~~~~\; \n)printf(if [ \\044verbose\ \YES\ ]; then cat \044cmd_out;\n)printf(else cat \044cmd_out | head; fi; fi; \n)printf(echo \~~~~~~~~~~~~~~~~~~~~\; fi; \n)printf(rm -f -- \044cmd_out \044cmd_err; \n)printf(echo; )} $TESTDIR/evaltest.dat $CONSOLE_LOG 21此阶段的测试日志
TESTcarol# ping -c 1 -s 120 -p deadbeef 10.1.0.10 | grep 128 bytes from 10.1.0.10: icmp_.eq1 [YES] /* 以上语句(A)的打印*/
128 bytes from 10.1.0.10: icmp_seq1 ttl63 time2.51 mscarol# swanctl --list-sas --raw 2 /dev/null | grep home.*version2 ... integ-algHMAC_SHA2_384_192.*local-ts\[192.168.0.100/32] remote-ts\[10.1.0.0/16] [YES] /* 以上语句(A)的打印*/
list-sa event {home {uniqueid1 version2 ... integ-algHMAC_SHA2_384_192 bytes-in148 packets-in1 use-in0 bytes-out148 packets-out1 use-out0 rekey-time3460 life-time3960 install-time0 local-ts[192.168.0.100/32] remote-ts[10.1.0.0/16]}}}}moon# swanctl --list-sas --raw 2 /dev/null | grep rw.*version2 ... integ-algHMAC_SHA2_384_192.*local-ts\[10.1.0.0/16] remote-ts\[192.168.0.100/32] [YES] /* 以上语句(A)的打印*/
list-sa event {rw {uniqueid1 version2 ... integ-algHMAC_SHA2_384_192 bytes-in148 packets-in1 use-in0 bytes-out148 packets-out1 use-out0 rekey-time3386 life-time3960 install-time0 local-ts[10.1.0.0/16] remote-ts[192.168.0.100/32]}}}}moon# ip xfrm state | grep enc cbc(camellia) [YES] /* 以上语句(A)的打印*/enc cbc(camellia) 0xb821b5ea62a441a642d064d2bd1537768af53bc6277c1c27enc cbc(camellia) 0xc5c34e3931ce3a64781fdbebc5cb0793bb1c8a0c238f58d6
carol# ip xfrm state | grep enc cbc(camellia) [YES] /* 以上语句(A)的打印*/enc cbc(camellia) 0xc5c34e3931ce3a64781fdbebc5cb0793bb1c8a0c238f58d6enc cbc(camellia) 0xb821b5ea62a441a642d064d2bd1537768af53bc6277c1c27moon# killall tcpdump /* stop_tcpdump函数打印。 */moon# cat /tmp/tcpdump.log | grep IP carol.strongswan.org moon.strongswan.org: ESP.*length 208 [YES] /* 以上语句(B)的打印*/
08:07:12.188904 IP carol.strongswan.org moon.strongswan.org: ESP(spi0xc0de5763,seq0x1), length 208
moon# cat /tmp/tcpdump.log | grep IP moon.strongswan.org carol.strongswan.org: ESP.*length 208 [YES] /* 以上语句(B)的打印*/
08:07:12.190869 IP moon.strongswan.org carol.strongswan.org: ESP(spi0xc834da8a,seq0x1), length 208测试后期处理
此阶段的命令写在测试用例的posttest.dat文件中。每一行包括两个部分虚机名和执行命令。这里和测试预备节点相对于顺序相反。依次为在carol虚机上停止IKE连接home在carol和moon虚机上停止strongswan进程。最后恢复iptables规则。
$ cat tests/af-alg/alg-camellia/posttest.dat
carol::swanctl --terminate --ike home
carol::systemctl stop strongswan
moon::systemctl stop strongswan
moon::iptables-restore /etc/iptables.flush
carol::iptables-restore /etc/iptables.flushdo-test文件中测试后期处理代码如下。SSH登录到相应虚机上执行指定命令。 # execute post-test commandsecho -n postecho -e \nPOST-TEST\n $CONSOLE_LOG 21eval awk -F :: {if ($0 ~ /^#.*/){printf(echo \%s\; , $0);}else if ($2 ! ){printf(echo \$(print_time)%s# %s\; , $1, $2)printf(ssh \044SSHCONF root\044ipv4_%s \%s\; , $1, $2)printf(echo;\n)}} $TESTDIR/posttest.dat $CONSOLE_LOG 21此阶段的日志如下。
POST-TESTcarol# swanctl --terminate --ike home
[IKE] deleting IKE_SA home[1] between 192.168.0.100[carolstrongswan.org]...192.168.0.1[moon.strongswan.org]
[IKE] sending DELETE for IKE_SA home[1]
[ENC] generating INFORMATIONAL request 2 [ D ]
[NET] sending packet: from 192.168.0.100[4500] to 192.168.0.1[4500] (96 bytes)
[NET] received packet: from 192.168.0.1[4500] to 192.168.0.100[4500] (96 bytes)
[ENC] parsed INFORMATIONAL response 2 [ ]
[IKE] IKE_SA deleted
terminate completed successfullycarol# systemctl stop strongswan
moon# systemctl stop strongswan
moon# iptables-restore /etc/iptables.flush
carol# iptables-restore /etc/iptables.flush恢复配置脚本restore-defaults
测试结束之后do-tests执行一系列的记录和清理工作比如停止tcpdump运行等。 # copy default host config back if necessary#$DIR/scripts/restore-defaults $testname将strongswan-5.9.14/testing/hosts/目录下的default/etc子目录内存scp到测试虚机并且将${host}/etc子目录scp到测试虚机。
if [ -d $TESTSDIR/${testname}/hosts ]
thenfor host in ls $TESTSDIR/${testname}/hostsdoeval HOSTLOGINrootecho $HOSTNAMEIPV4 | sed -n -e s/^.*${host},//gp | awk -F, { print $1 } | awk { print $1 }scp $SSHCONF -r $HOSTCONFIGDIR/default/etc $HOSTLOGIN:/ /dev/null 21scp $SSHCONF -r $HOSTCONFIGDIR/${host}/etc $HOSTLOGIN:/ /dev/null 21done
fi0-9 ↩︎