-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathci_test
executable file
·104 lines (88 loc) · 4.22 KB
/
ci_test
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
#!/bin/bash
FAILED_TESTS=""
assertSuccess(){
local STRATEGY="$1"
local CMD="$2"
echo "****************************************************************************"
echo "** EXECUTE: $CMD";
eval "$CMD 2>&1"
local RET="$?"
echo "**"
if [ "$RET" != "0" ];then
echo "** ERROR: execution failed (returncode $RET)"
FAILED_TESTS="$FAILED_TESTS#assertSuccess => $CMD"
echo "****************************************************************************"
if [ "$STRATEGY" = "STOP_ON_ERROR" ];then
exit 100
else
return 100
fi
fi
echo "****************************************************************************"
return 0
}
echo "*** CLEANUP"
set -x
set -e
sudo dpkg -P zabbix-agent-extensions zabbix-agent
sudo rm -rf /etc/zabbix_* /var/log/zabbix /var/run/zabbix zabbix-agent_*.deb zabbix-get_*.deb
wget -c "https://repo.zabbix.com/zabbix/7.2/release/ubuntu/pool/main/z/zabbix-release/zabbix-release_latest_7.2+ubuntu24.04_all.deb"
sudo dpkg -i zabbix-release_latest_7.2+ubuntu24.04_all.deb
sudo apt-get update -y
sudo apt-get install zabbix-agent zabbix-get -y
sudo sed -i '~s,# DebugLevel.*,DebugLevel=2,' /etc/zabbix/zabbix_agentd.conf
sudo sed -i '~s,^Server=.*,Server=127.0.0.1,' /etc/zabbix/zabbix_agentd.conf
set +e
set +x
echo "*** VALIDATIONS"
COMPILEDIR="$(mktemp -d /tmp/pycompile-XXXXXX)"
for SCRIPT in $(grep -l "#!/usr/bin/env python3" extension-files/tools/zabbix_*|sort -u|xargs);
do
cp $SCRIPT $COMPILEDIR/
assertSuccess STOP_ON_ERROR "python3 -m py_compile ${COMPILEDIR}/$(basename $SCRIPT)"
done
echo "*** TESTS"
assertSuccess STOP_ON_ERROR "sudo dpkg -i zabbix-agent-extensions_*.deb"
sleep 3
sudo tail -f /var/log/zabbix/zabbix_agentd.log &
for i in `seq 1 30`;do
nc -vvv -w 1 127.0.0.1 10050
if [ "$?" = "0" ];then
break
fi
echo -n "."
sleep 1
done
echo
pkill tail
echo '{ "{#FOO}" : "BAR" }' | sudo tee /etc/zabbix/zabbix-discovery-generic/foo-bar.json
assertSuccess STOP_ON_ERROR "ls -l /etc/zabbix/zabbix-discovery-generic/foo-bar.json"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'generic.discovery[foo,json]' | tee /dev/stderr | grep -q -P 'BAR'" # Without sudo
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k linux.dmesg | tee /dev/stderr | grep -q -P 'OK: ALL OK|ERROR:'" # Without sudo
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k linux.dmesg | tee /dev/stderr | grep -q -P 'OK: ALL OK|ERROR:'" # Without sudo
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k linux.multipath | tee /dev/stderr | grep -q 'OK:'" # With sudo
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'custom.process[zabbix_agentd,minage]'|tee /dev/stderr | grep -q -P '^\d+$'"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'custom.process[zabbix_agentd,maxage]'|tee /dev/stderr | grep -q -P '^\d+$'"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'custom.process[nosuchprocess,maxage]'|tee /dev/stderr | grep -q -P '^\d+$'"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'zabbix.agent_extensions.version'|tee /dev/stderr | grep -q -P '^\d+'"
sudo mkdir -m 755 -p /opt/puppetlabs/puppet/cache/state/
sudo cp extension-files/test/last_run_summary.yaml /opt/puppetlabs/puppet/cache/state/last_run_summary.yaml
sudo cp extension-files/test/last_run_report.yaml /opt/puppetlabs/puppet/cache/state/last_run_report.yaml
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'puppet[state]'|tee /dev/stderr | grep -q -P '^OK: puppetrun successful, no changes$'"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'puppet[changes,total]'|tee /dev/stderr | grep -q -P '^\d+$'"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'puppet[environment]'|tee /dev/stderr | grep -q -P '^production_master$'"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k vfs.dev.discovery | tee /dev/stderr | grep -q '#BLOCKDEVICE'"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k vfs.fs.discovery | grep -v /proc"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k nfs.rpc.calls|grep -P '^0$'"
assertSuccess STOP_ON_ERROR 'sudo dpkg -P zabbix-agent-extensions'
echo
echo
echo "*** SUMMARY"
if [ -z "$FAILED_TESTS" ];then
echo "ALL TESTS PASSED"
exit 0
else
echo "THE FOLLOWING TESTS FAILED"
echo "$FAILED_TESTS"|tr '#' '\n'|sed '~s,^, ,'
exit 1
fi