diff --git a/tests/beakerlib/built-in-functions/main.fmf b/tests/beakerlib/built-in-functions/main.fmf new file mode 100644 index 000000000..999c4eccc --- /dev/null +++ b/tests/beakerlib/built-in-functions/main.fmf @@ -0,0 +1,39 @@ +summary: built-in functions for various conversions. New functionality according to + BZ#1225135. +description: '' +contact: rhack@redhat.com +component: + - tuned +test: ./runtest.sh +framework: beakerlib +require: + - library(tuned/basic) +recommend: + - tuned +duration: 5m +enabled: true +tag: + - FedoraReady + - NoRHEL4 + - NoRHEL5 + - NoRHEL6 + - TIPfail_infra + - TIPpass + - Tier1 +tier: '1' +link: + - relates: https://bugzilla.redhat.com/show_bug.cgi?id=1225135 +adjust: + - enabled: false + when: distro == rhel-4, rhel-5, rhel-6, rhel-7 + continue: false + - enabled: false + when: distro > rhel-8 + continue: false + - enabled: false + when: distro > f-20 + continue: false +extra-nitrate: TC#0496876 +extra-summary: /CoreOS/tuned/Sanity/built-in-functions +extra-task: /CoreOS/tuned/Sanity/built-in-functions +id: b04c6dd3-4412-4bd9-b4c7-a5cc44172574 diff --git a/tests/beakerlib/built-in-functions/rhel7_function_testfunc.py b/tests/beakerlib/built-in-functions/rhel7_function_testfunc.py new file mode 100644 index 000000000..1741e1ae2 --- /dev/null +++ b/tests/beakerlib/built-in-functions/rhel7_function_testfunc.py @@ -0,0 +1,16 @@ +import base +from tuned.utils.commands import commands + +class testfunc(base.Function): + """ + Test function + """ + def __init__(self): + super(self.__class__, self).__init__("testfunc", 2) + + def execute(self, args): + f = open(str(args[0]),'w') + f.write(str(args[1])) + f.close() + return str(args[1]) + 'returned' + diff --git a/tests/beakerlib/built-in-functions/rhel8_function_testfunc.py b/tests/beakerlib/built-in-functions/rhel8_function_testfunc.py new file mode 100644 index 000000000..f6ced632c --- /dev/null +++ b/tests/beakerlib/built-in-functions/rhel8_function_testfunc.py @@ -0,0 +1,16 @@ +from . import base +from tuned.utils.commands import commands + +class testfunc(base.Function): + """ + Test function + """ + def __init__(self): + super(self.__class__, self).__init__("testfunc", 2) + + def execute(self, args): + f = open(str(args[0]),'w') + f.write(str(args[1])) + f.close() + return str(args[1]) + 'returned' + diff --git a/tests/beakerlib/built-in-functions/runtest.sh b/tests/beakerlib/built-in-functions/runtest.sh new file mode 100755 index 000000000..d5575e331 --- /dev/null +++ b/tests/beakerlib/built-in-functions/runtest.sh @@ -0,0 +1,81 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/tuned/Sanity/built-in-functions +# Description: built-in functions for various conversions. New functionality according to BZ#1225135. +# Author: Robin Hack +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright Red Hat +# +# SPDX-License-Identifier: GPL-2.0-or-later WITH GPL-CC-1.0 +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="tuned" +TUNED_DIR="/usr/lib/tuned" +PROFILE="myprofile" + + +rlJournalStart + + rlPhaseStartSetup + rlAssertRpm $PACKAGE + rlImport "tuned/basic" + rlServiceStart "tuned" + tunedProfileBackup + + + PSITE_PATH=$(python3 -c "import site; print(site.getsitepackages()[3])") + + # RHEL7 is not supported + if rlIsRHEL '>=8' || rlIsCentOS >= 8 || rlIsFedora; then + TEST_SCRIPT="rhel8_function_testfunc.py" + fi + rlRun "cp -v ${TEST_SCRIPT} ${PSITE_PATH}/tuned/profiles/functions/function_testfunc.py" + + # Prepare balanced profile + rlRun "mkdir $TUNED_DIR/$PROFILE" + rlRun -l "echo '[main] +summary=My testing profile + +[variables] +VAR1 = \${f:testfunc:/var/tmp/test1:IamTestingThis1} +VAR2 = \${f:testfunc:/var/tmp/test2:\${VAR1}} +cmd = echo +cmd_out = \${f:exec:\${cmd}:output} +VAR3 = \${f:testfunc:/var/tmp/test3:\${cmd_out}} + +' >> $TUNED_DIR/$PROFILE/tuned.conf" + rlRun -l "cat $TUNED_DIR/$PROFILE/tuned.conf" + + echo > /var/log/tuned/tuned.log + rlRun "tuned-adm profile $PROFILE" + rlRun -l "cat /var/log/tuned/tuned.log" + rlPhaseEnd + + rlPhaseStartTest + rlLog "Custom function and variable propagation" + rlAssertGrep "IamTestingThis1" "/var/tmp/test1" + rlAssertGrep "IamTestingThis1returned" "/var/tmp/test2" + + rlLog "Built in 'exec' function" + rlAssertGrep "output" "/var/tmp/test3" + rlPhaseEnd + + rlPhaseStartCleanup + rlFileRestore + tunedProfileRestore + rlServiceRestore "tuned" + rlRun "rm -rf $TUNED_DIR/$PROFILE" + rlRun "rm ${PSITE_PATH}/tuned/profiles/functions/function_testfunc.py" + rlRun "rm /var/tmp/test1 /var/tmp/test2" + rlPhaseEnd + +rlJournalPrintText +rlJournalEnd