Skip to content

Commit

Permalink
Fix some failing tests
Browse files Browse the repository at this point in the history
Added a new broctl option, called StopWait, to force the stop command
to wait for the post-terminate script to finish.  This is needed
because some tests were failing due to background log-archive processes
creating logs after "broctl stop" finished, which was preventing the
test directory from being deleted.
  • Loading branch information
Daniel Thayer committed Jan 19, 2017
1 parent a721ed1 commit 982e378
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 37 deletions.
2 changes: 2 additions & 0 deletions BroControl/options.py
Expand Up @@ -120,6 +120,8 @@ def __init__(self, name, default, type, category, dontinit, description):

Option("StatusCmdShowAll", 0, "bool", Option.USER, False,
"True to have the status command show all output, or False to show only some of the output (peer information will not be collected or shown, so the command will run faster)."),
Option("StopWait", 0, "bool", Option.USER, False,
"True to force the stop command to wait for the post-terminate script to finish, or False to let post-terminate finish in the background."),

Option("CronCmd", "", "string", Option.USER, False,
"A custom command to run everytime the cron command has finished."),
Expand Down
74 changes: 41 additions & 33 deletions bin/post-terminate
Expand Up @@ -162,6 +162,8 @@ parse_filename()

archivelogs()
{
startuptime=`cat .startup | tail -1`

# Attempt to archive all log files. Although stdout.log/stderr.log are
# not really Bro logs, we try to archive them anyway, because they might
# contain useful info, especially if Bro crashes.
Expand Down Expand Up @@ -213,44 +215,50 @@ archivelogs()
done
}

# Execute the remaining part of this script in the background so that broctl
# doesn't need to wait for it to finish. Stdout/stderr is redirected to a
# file to capture error messages.
(
postterminate()
{
# Wait until all running archive-log processes have terminated.
wait_for_archivelog

# Wait until all running archive-log processes have terminated.
wait_for_archivelog
flags=
failed=0

startuptime=`cat .startup | tail -1`
flags=
failed=0
if [ $crash -eq 1 ]; then
# If Bro crashed, then we tell archive-log to not delete the log file
# (however, in this case the log file will be renamed to indicate it
# was successfully archived).
flags=-c
fi

if [ $crash -eq 1 ]; then
# If Bro crashed, then we tell archive-log to not delete the log file
# (however, in this case the log file will be renamed to indicate it
# was successfully archived).
flags=-c
fi
# Archive all logs.
archivelogs

# Archive all logs.
archivelogs
# If one or more logs failed to be archived, then try to send an email.
if [ $failed -ne 0 ]; then
sendfailuremail
fi

# If one or more logs failed to be archived, then try to send an email.
if [ $failed -ne 0 ]; then
sendfailuremail
fi
# If Bro crashed, then we don't need to do anything else, because we don't
# want to remove the directory.
if [ $crash -eq 1 ]; then
exit 0
fi

# If Bro crashed, then we don't need to do anything else, because we don't
# want to remove the directory.
if [ $crash -eq 1 ]; then
exit 0
fi
# If no archive-log processes started from this script failed, then remove
# the directory. If the directory is not removed, then an email was sent
# to notify the user to look in this directory for logs.
if [ $failed -eq 0 ]; then
rm -rf "$postdir"
fi
}

# If no archive-log processes started from this script failed, then remove
# the directory. If the directory is not removed, then an email was sent
# to notify the user to look in this directory for logs.
if [ $failed -eq 0 ]; then
rm -rf "$postdir"
fi
# Execute the remaining part of this script in the background so that broctl
# doesn't need to wait for it to finish. Stdout/stderr is redirected to a
# file to capture error messages.
postterminate >post-terminate.out 2>&1 &

) >post-terminate.out 2>&1 &
# In some situations (such as testing), we may want the broctl stop command to
# wait for the post-terminate script to finish.
if [ "${stopwait}" = "1" ]; then
wait
fi
5 changes: 5 additions & 0 deletions testing/Cfg/etc/broctl.cfg__stopwait
@@ -0,0 +1,5 @@
# Don't send emails or summary reports
sendmail=
tracesummary=
# stop command will wait for post-terminate to finish
stopwait=1
2 changes: 1 addition & 1 deletion testing/command/start-state-cluster.test
Expand Up @@ -8,7 +8,7 @@
. broctl-test-setup

while read line; do installcfgfile "$line"; done << EOF
etc/broctl.cfg__no_email
etc/broctl.cfg__stopwait
etc/node.cfg__cluster
bin/bro__test
EOF
Expand Down
2 changes: 1 addition & 1 deletion testing/command/start-state-standalone.test
Expand Up @@ -8,7 +8,7 @@
. broctl-test-setup

while read line; do installcfgfile "$line"; done << EOF
etc/broctl.cfg__no_email
etc/broctl.cfg__stopwait
bin/bro__test
EOF

Expand Down
2 changes: 1 addition & 1 deletion testing/command/stop-state-cluster.test
Expand Up @@ -8,7 +8,7 @@
. broctl-test-setup

while read line; do installcfgfile "$line"; done << EOF
etc/broctl.cfg__no_email
etc/broctl.cfg__stopwait
etc/node.cfg__cluster
bin/bro__test
EOF
Expand Down
2 changes: 1 addition & 1 deletion testing/command/stop-state-standalone.test
Expand Up @@ -8,7 +8,7 @@
. broctl-test-setup

while read line; do installcfgfile "$line"; done << EOF
etc/broctl.cfg__no_email
etc/broctl.cfg__stopwait
bin/bro__test
EOF

Expand Down

0 comments on commit 982e378

Please sign in to comment.