forked from fortinet-solutions-cse/40ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_test.sh
executable file
·122 lines (94 loc) · 2.74 KB
/
run_test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env bash
set -x
cd $( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )
trap ctrl_c SIGINT
trap ctrl_c SIGTERM
FGT_IP="192.168.122.40"
if [ ! -e license_file.lic ]; then
echo "Need 'license_file.lic' in this directory in order to perform all tests."
exit -1
fi
ssh-keygen -f "${HOME}/.ssh/known_hosts" -R "${FGT_IP}"
function remove_waste_files()
{
rm -f $(pwd)/*.retry
rm -f $(pwd)/*.https
rm -f backup_config_001
}
function ctrl_c() {
echo "** Interrupted by user **"
echo -e "\n\n Results: \n Success: "${success}" Failed: "${failed}"\n"
remove_waste_files
exit -1
}
if [ ! -z $1 ] && [ "$1"="--https" ]; then
https=true
fi
remove_waste_files
success=0
failed=0
function wait_until_fgt_is_up() {
sleep 3
until wget ${FGT_IP} -T1 -t1 -q -O /dev/null --no-check-certificate
do
sleep 1
echo Waiting for FGT to get up
done
}
function wait_until_fgt_validates_license() {
until ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null admin@${FGT_IP} get system status|grep "License Status: Valid"
do
sleep 1
echo Waiting for FGT to validate license
done
}
function modify_playbook_for_https() {
cat $1 |sed 's/https: False/https: True/g' > $1.https
}
function run_example( ) {
export ANSIBLE_LIBRARY=$(pwd)/library
filename=$1
cp ./examples/$1 .
if [ "$https" = true ]; then
modify_playbook_for_https ${filename}
ansible-playbook ${filename}.https
if [ $? == 0 ]; then
success=$(($success+1))
else
failed=$(($failed+1))
fi
rm -f ${filename}.https
else
ansible-playbook ${filename}
if [ $? == 0 ]; then
success=$(($success+1))
else
failed=$(($failed+1))
fi
fi
rm -f ${filename}
}
run_example fortigate_create_firewall_policy.yml
run_example fortigate_delete_firewall_policy.yml
run_example fortigate_create_firewall_vip.yml
run_example fortigate_mix.yml
run_example fortigate_monitor_system_resource_usage.yml
run_example fortigate_ssh.yml
run_example fortigate_backup_config.yml
run_example fortigate_restore_config.yml
wait_until_fgt_is_up
run_example fortigate_upload_license.yml
wait_until_fgt_is_up
https=true
wait_until_fgt_validates_license
run_example fortigate_disable_https_redirect.yml
run_example fortigate_create_firewall_policy.yml
run_example fortigate_delete_firewall_policy.yml
# Uncomment after 6.2.1 release, when vpn certificate is fixed in REST API
#run_example fortigate_vpn_certificate_csr_generate.yml
#run_example fortigate_vpn_certificate_csr_delete.yml
remove_waste_files
echo -e "\n\n Results: \n Success: "${success}" Failed: "${failed}"\n"
if [ ${failed} -ne 0 ]; then
exit -1
fi