From 1a7f3a59d6441a50b96b78a3c17d20a8f692ad8b Mon Sep 17 00:00:00 2001 From: Jan Kurik Date: Wed, 31 Mar 2021 14:38:16 +0200 Subject: [PATCH] Initial implementation of a start/stop test of PCP services --- tests/Sanity/pcp-services/Makefile | 64 +++++++++++++++++++++ tests/Sanity/pcp-services/PURPOSE | 5 ++ tests/Sanity/pcp-services/runtest.sh | 86 ++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 tests/Sanity/pcp-services/Makefile create mode 100644 tests/Sanity/pcp-services/PURPOSE create mode 100755 tests/Sanity/pcp-services/runtest.sh diff --git a/tests/Sanity/pcp-services/Makefile b/tests/Sanity/pcp-services/Makefile new file mode 100644 index 0000000..fd2590e --- /dev/null +++ b/tests/Sanity/pcp-services/Makefile @@ -0,0 +1,64 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /tools/pcp/Sanity/pcp-services +# Description: Test of pcp services +# Author: Jan Kuřík +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2021 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TEST=/tools/pcp/Sanity/pcp-services +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE + +.PHONY: all install download clean + +run: $(FILES) build + ./runtest.sh + +build: $(BUILT_FILES) + test -x runtest.sh || chmod a+x runtest.sh + +clean: + rm -f *~ $(BUILT_FILES) + + +include /usr/share/rhts/lib/rhts-make.include + +$(METADATA): Makefile + @echo "Owner: Jan Kuřík " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Test for BZ#1944150 (Job for pmlogger.service failed because the)" >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 15m" >> $(METADATA) + @echo "RunFor: pcp" >> $(METADATA) + @echo "Requires: pcp pcp-zeroconf" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2+" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + @echo "Bug: 1929556 1944150" >> $(METADATA) + @echo "Releases: -RHEL4 -RHEL6 -RHELClient5 -RHELServer5" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/Sanity/pcp-services/PURPOSE b/tests/Sanity/pcp-services/PURPOSE new file mode 100644 index 0000000..012e5d8 --- /dev/null +++ b/tests/Sanity/pcp-services/PURPOSE @@ -0,0 +1,5 @@ +PURPOSE of /tools/pcp/Sanity/pcp-services +Description: Test of pcp services (start / stop) +Author: Jan Kuřík +Bug summary: Job for pmlogger.service failed because the service did not take the steps required by its unit configuration. +Bugzilla link: https://bugzilla.redhat.com/show_bug.cgi?id=1944150 diff --git a/tests/Sanity/pcp-services/runtest.sh b/tests/Sanity/pcp-services/runtest.sh new file mode 100755 index 0000000..53bdb2c --- /dev/null +++ b/tests/Sanity/pcp-services/runtest.sh @@ -0,0 +1,86 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /tools/pcp/Sanity/pcp-services +# Description: Test of pcp services +# Author: Jan Kuřík +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2021 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/bin/rhts-environment.sh || exit 1 +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="pcp" +PCPSERVICES="pmlogger pmie pmproxy pmcd" +TOUT="90" # Timeout to wait for a service to start / stop + +function service_action() { + local service=$1 + local status=$2 + local ss= + local t=${TOUT} + + rlRun -s "systemctl show -p ActiveState --no-pager ${service}" 0 \ + "Check if ${service} service is in expected state" + + # Wait for the service to get into a proper state + while [[ "${ss}" != "${status}" ]]; do + [[ $(( t-- )) -le 0 ]] && break + sleep 1 + ss=$(sed -n 's/^ActiveState=//g p' < ${rlRun_LOG}) + done + if [[ "${ss}" != "${status}" ]]; then + rlFail "The ${service} service is in unexpected state '${ss}'" + return 1 + else + rlPass "${service} state is OK '${ss}'" + return 0 + fi +} + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + rlRun "systemctl --no-pager stop ${PCPSERVICES}" 0-255 + rlPhaseEnd + + rlPhaseStartTest + for s in ${PCPSERVICES}; do + # All services should be stopped + service_action ${s} inactive + done + + for s in ${PCPSERVICES}; do + # Start a service and check it runs + rlRun "systemctl start --no-pager ${s}" + service_action ${s} active + + # Stop a service and check it is stopped + rlRun "systemctl stop --no-pager ${s}" + service_action ${s} inactive + done + rlPhaseEnd + + rlPhaseStartCleanup + rlPhaseEnd +rlJournalPrintText +rlJournalEnd