Improvement of the systemd unit files test

Make the systemd unit files test more robus, to avoid false positives in
case there are non-unit files in the sytemd directory.
This commit is contained in:
Jan Kurik 2021-11-10 16:11:00 +01:00
parent 9daf757d8e
commit b263d4070b

View File

@ -31,6 +31,7 @@
PACKAGE="pcp" PACKAGE="pcp"
PKGS="pcp pcp-zeroconf" PKGS="pcp pcp-zeroconf"
UNITS="" UNITS=""
UNITFILESDIR="/usr/lib/systemd/system/"
rlJournalStart rlJournalStart
rlPhaseStartSetup rlPhaseStartSetup
@ -42,20 +43,24 @@ rlJournalStart
rlAssertRpm "${P}" rlAssertRpm "${P}"
done done
# Generate list of unit files # Generate list of unit files
UNITS="$(rpm -ql ${PKGS} | grep /usr/lib/systemd/system/)" UNITS=$(rpm -ql ${PKGS} | grep "${UNITFILESDIR}")
rlLog "Available unit files: ${UNITS}" rlLog "Available unit files: ${UNITS}"
rlPhaseEnd rlPhaseEnd
rlPhaseStartTest rlPhaseStartTest
FAILEDU="" FAILEDU=""
for U in ${UNITS}; do for U in ${UNITS}; do
if ! rlRun -s "systemd-analyze --no-pager verify ${U}"; then if [[ -f ${U} ]] && [[ "$(dirname ${U})" == "${UNITFILESDIR%/}" ]]; then
rlFail "Error in ${U}: $(cat ${rlRun_LOG})" if ! rlRun -s "systemd-analyze --no-pager verify ${U}"; then
FAILEDU="${FAILEDU} $(basename ${U})" rlFail "Error in ${U}: $(cat ${rlRun_LOG})"
fi FAILEDU="${FAILEDU} $(basename ${U})"
if grep -q 'is deprecated' ${rlRun_LOG}; then fi
rlFail "Error in ${U}: $(cat ${rlRun_LOG})" if grep -q 'is deprecated' ${rlRun_LOG}; then
FAILEDU="${FAILEDU} $(basename ${U})" rlFail "Error in ${U}: $(cat ${rlRun_LOG})"
FAILEDU="${FAILEDU} $(basename ${U})"
fi
else
rlLog "${U} is not a regular unit file ... skipping"
fi fi
done done
[[ -n "${FAILEDU}" ]] && rlLog "List of failed units: ${FAILEDU}" [[ -n "${FAILEDU}" ]] && rlLog "List of failed units: ${FAILEDU}"