Skip to content

Commit c788c48

Browse files
MDBF-1159 Libvirt - collect system logs as a step LogFile
When an error occurs, displaying system logs in standard output may not be beneficial if they do not provide additional information that could help with debugging the issue. This was initially implemented as a trap, triggered whenever the scripts exit with a failure. See: MDBF-1130 (bbb5955) Sometimes, the errors of interest are located at the beginning of the log, but they are obscured by a large number of system logs. Collecting system logs could be done into a file that is uploaded at the buildbot step level. This can be implemented by defining the logfiles parameter at the step level. See: https://docs.buildbot.net/latest/manual/configuration/steps/shell_command.html
1 parent c69bcef commit c788c48

2 files changed

Lines changed: 75 additions & 14 deletions

File tree

master-libvirt/master.cfg

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ artifactsURL = os.environ["ARTIFACTS_URL"]
3434

3535

3636
####### UTILS
37+
LOGFILES = {
38+
"pam.log": "pam.log",
39+
"systemd.log": "systemd.log",
40+
"selinux.log": "selinux.log",
41+
}
42+
43+
3744
def getRpmUpgradeStep():
3845
return Test(
3946
name="upgrade",
@@ -57,6 +64,7 @@ def getRpmUpgradeStep():
5764
]
5865
),
5966
command=["./rpm-upgrade.sh"],
67+
logfiles=LOGFILES,
6068
)
6169

6270

@@ -82,6 +90,7 @@ def getRpmInstallStep():
8290
]
8391
),
8492
command=["./rpm-install.sh"],
93+
logfiles=LOGFILES,
8594
)
8695

8796

@@ -107,6 +116,7 @@ def getDebUpgradeStep():
107116
]
108117
),
109118
command=["./deb-upgrade.sh"],
119+
logfiles=LOGFILES,
110120
)
111121

112122

@@ -132,6 +142,7 @@ def getDebInstallStep():
132142
]
133143
),
134144
command=["./deb-install.sh"],
145+
logfiles=LOGFILES,
135146
)
136147

137148

@@ -157,6 +168,7 @@ def getPAMTestStep():
157168
]
158169
),
159170
command=["./pam-test.sh"],
171+
logfiles=LOGFILES,
160172
)
161173

162174

scripts/bash_lib.sh

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,77 @@ err() {
4040
exit 1
4141
}
4242

43+
WORKER_BASE_DIR="$(pwd -P)"
44+
4345
collect_logs() {
44-
exit_code=$?
45-
if ((exit_code != 0)); then
46-
set +e
47-
bb_log_info "systemd service information"
48-
sudo journalctl --boot --unit mariadb.service --unit mariadb-columnstore.service
46+
local exit_code=$?
47+
48+
# Do not let logging failures change outcome
49+
set +e
50+
51+
if (( exit_code != 0 )); then
52+
local systemd_log="${WORKER_BASE_DIR}/systemd.log"
53+
local pam_log="${WORKER_BASE_DIR}/pam.log"
54+
local selinux_log="${WORKER_BASE_DIR}/selinux.log"
55+
56+
# Create log files
57+
touch "$systemd_log"
58+
touch "$pam_log"
59+
touch "$selinux_log"
60+
61+
# -------------------------
62+
# systemd/journalctl logs
63+
# -------------------------
64+
{
65+
echo "==== systemd service information ($(date -Is)) ===="
66+
echo "-- journalctl --boot --unit mariadb.service --unit mariadb-columnstore.service"
67+
} >> "$systemd_log"
68+
69+
sudo journalctl --boot \
70+
--unit mariadb.service \
71+
--unit mariadb-columnstore.service \
72+
2>&1 | sudo tee -a "$systemd_log" >/dev/null
73+
74+
# ---------------------------------
75+
# SELinux denial logs (if present)
76+
# ---------------------------------
4977
if [ -f /etc/selinux/config ]; then
50-
bb_log_info "selinux denial information"
51-
sudo ausearch -i -m avc,user_avc,selinux_err,user_selinux_err -ts boot
78+
{
79+
echo "==== selinux denial information ($(date -Is)) ===="
80+
echo "-- ausearch -i -m avc,user_avc,selinux_err,user_selinux_err -ts boot"
81+
} >> "$selinux_log"
82+
83+
sudo ausearch -i -m avc,user_avc,selinux_err,user_selinux_err -ts boot \
84+
2>&1 | sudo tee -a "$selinux_log" >/dev/null
85+
else
86+
echo "SELinux config not present; skipping." >> "$selinux_log"
5287
fi
53-
bb_log_info "PAM information"
88+
89+
# ----------------------------------------------
90+
# PAM logs (secure/auth.log depending on distro)
91+
# ----------------------------------------------
92+
{
93+
echo "==== PAM information ($(date -Is)) ===="
94+
} >> "$pam_log"
95+
5496
if [ -f /var/log/secure ]; then
55-
sudo grep -i pam /var/log/secure
97+
echo "-- grep -i pam /var/log/secure" >> "$pam_log"
98+
sudo grep -i pam /var/log/secure 2>&1 | sudo tee -a "$pam_log" >/dev/null
99+
else
100+
echo "/var/log/secure not present." >> "$pam_log"
56101
fi
102+
57103
if [ -f /var/log/auth.log ]; then
58-
sudo grep -i pam /var/log/auth.log
104+
echo "-- grep -i pam /var/log/auth.log" >> "$pam_log"
105+
sudo grep -i pam /var/log/auth.log 2>&1 | sudo tee -a "$pam_log" >/dev/null
106+
else
107+
echo "/var/log/auth.log not present." >> "$pam_log"
59108
fi
60-
set -e
61-
else
62-
bb_log_info "Test(s) ran successfully"
63109
fi
64-
exit $exit_code
110+
111+
# Restore strict mode
112+
set -e
113+
exit "$exit_code"
65114
}
66115

67116
# mariadb < 10.4 the client binary was mysql

0 commit comments

Comments
 (0)