File: cron-disk.test

package info (click to toggle)
broctl 1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 2,220 kB
  • sloc: python: 4,931; sh: 1,188; makefile: 70; awk: 24
file content (89 lines) | stat: -rw-r--r-- 1,896 bytes parent folder | download
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
# Test that the broctl cron command sends an email warning on low disk free
# space only when the amount of free disk space crosses the threshold
# specified by the mindiskspace broctl option.
#
# @TEST-EXEC: bash %INPUT

. broctl-test-setup

while read line; do installcfgfile "$line"; done << EOF
etc/broctl.cfg__test_sendmail
bin/df__test --new
bin/sendmail__test --new
EOF

replaceprefix etc/broctl.cfg

# Check if a low disk space email was received.  Return 0 if yes, and 1 if no.
function check_email() {
    email=$BROCTL_INSTALL_PREFIX/sendmail.out
    test ! -e $email && return 1

    grep -q "Disk space low on localhost:/dev/sda6" $email
    test $? -ne 0 && return 1
    rm $email
    return 0
}

ret=0
broctl install

# Verify the default value of mindiskspace
broctl config 2>&1 | sed 's/ //g' | grep -q mindiskspace=5
test $? -ne 0 && exit 1

################
# Test with lots of free disk space (no email warning)

broctl cron

check_email && ret=1

################
# Test with a disk that is almost full (email warning)

export BROCTL_TEST_DISK_FULL=1
broctl cron

check_email || ret=1

################
# Test again with same disk usage as before (no duplicate warning is sent)

broctl cron

check_email && ret=1

################
# Test with lots of free disk space (no email warning)

BROCTL_TEST_DISK_FULL=
broctl cron

check_email && ret=1

################
# Test with a disk that is almost full (another warning is sent)

BROCTL_TEST_DISK_FULL=1
broctl cron

check_email || ret=1

################
# Test with lots of free disk space, but different mindiskspace (email warning)

# Remove previous free disk space records (otherwise we won't get an email)
rm $BROCTL_INSTALL_PREFIX/spool/state.db

# Update configuration
echo "mindiskspace=50" >> $BROCTL_INSTALL_PREFIX/etc/broctl.cfg
broctl install

BROCTL_TEST_DISK_FULL=
broctl cron

check_email || ret=1

exit $ret