Skip to content

Commit eb5681e

Browse files
committed
tests/beakerlib: Add new test which covers build-in functions.
1 parent b15de12 commit eb5681e

4 files changed

Lines changed: 146 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
summary: built-in functions for various conversions. New functionality according to
2+
BZ#1225135.
3+
description: ''
4+
contact: rhack@redhat.com
5+
component:
6+
- tuned
7+
test: ./runtest.sh
8+
framework: beakerlib
9+
require:
10+
- library(tuned/basic)
11+
recommend:
12+
- tuned
13+
duration: 5m
14+
enabled: true
15+
tag:
16+
- FedoraReady
17+
- NoRHEL4
18+
- NoRHEL5
19+
- NoRHEL6
20+
- TIPfail_infra
21+
- TIPpass
22+
- Tier1
23+
tier: '1'
24+
link:
25+
- relates: https://bugzilla.redhat.com/show_bug.cgi?id=1225135
26+
adjust:
27+
- enabled: false
28+
when: distro == rhel-4, rhel-5, rhel-6, rhel-7, centos-7
29+
continue: false
30+
extra-nitrate: TC#0496876
31+
extra-summary: /CoreOS/tuned/Sanity/built-in-functions
32+
extra-task: /CoreOS/tuned/Sanity/built-in-functions
33+
id: b04c6dd3-4412-4bd9-b4c7-a5cc44172574
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import base
2+
from tuned.utils.commands import commands
3+
4+
class testfunc(base.Function):
5+
"""
6+
Test function
7+
"""
8+
def __init__(self):
9+
super(self.__class__, self).__init__("testfunc", 2)
10+
11+
def execute(self, args):
12+
f = open(str(args[0]),'w')
13+
f.write(str(args[1]))
14+
f.close()
15+
return str(args[1]) + 'returned'
16+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from . import base
2+
from tuned.utils.commands import commands
3+
4+
class testfunc(base.Function):
5+
"""
6+
Test function
7+
"""
8+
def __init__(self):
9+
super(self.__class__, self).__init__("testfunc", 2)
10+
11+
def execute(self, args):
12+
f = open(str(args[0]),'w')
13+
f.write(str(args[1]))
14+
f.close()
15+
return str(args[1]) + 'returned'
16+
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
3+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4+
#
5+
# runtest.sh of /CoreOS/tuned/Sanity/built-in-functions
6+
# Description: built-in functions for various conversions. New functionality according to BZ#1225135.
7+
# Author: Robin Hack <rhack@redhat.com>
8+
#
9+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10+
#
11+
# Copyright Red Hat
12+
#
13+
# SPDX-License-Identifier: GPL-2.0-or-later WITH GPL-CC-1.0
14+
#
15+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16+
17+
# Include Beaker environment
18+
. /usr/share/beakerlib/beakerlib.sh || exit 1
19+
20+
PACKAGE="tuned"
21+
TUNED_DIR="/usr/lib/tuned"
22+
PROFILE="myprofile"
23+
24+
25+
rlJournalStart
26+
27+
rlPhaseStartSetup
28+
rlAssertRpm $PACKAGE
29+
rlImport "tuned/basic"
30+
rlServiceStart "tuned"
31+
tunedProfileBackup
32+
33+
34+
PSITE_PATH=$(python3 -c "import site; print(site.getsitepackages()[3])")
35+
36+
# RHEL7 is not supported
37+
if rlIsRHEL '>=8' || rlIsCentOS >= 8 || rlIsFedora; then
38+
TEST_SCRIPT="rhel8_function_testfunc.py"
39+
fi
40+
rlRun "cp -v ${TEST_SCRIPT} ${PSITE_PATH}/tuned/profiles/functions/function_testfunc.py"
41+
42+
# Prepare balanced profile
43+
rlRun "mkdir $TUNED_DIR/$PROFILE"
44+
rlRun -l "echo '[main]
45+
summary=My testing profile
46+
47+
[variables]
48+
VAR1 = \${f:testfunc:/var/tmp/test1:IamTestingThis1}
49+
VAR2 = \${f:testfunc:/var/tmp/test2:\${VAR1}}
50+
cmd = echo
51+
cmd_out = \${f:exec:\${cmd}:output}
52+
VAR3 = \${f:testfunc:/var/tmp/test3:\${cmd_out}}
53+
54+
' >> $TUNED_DIR/$PROFILE/tuned.conf"
55+
rlRun -l "cat $TUNED_DIR/$PROFILE/tuned.conf"
56+
57+
echo > /var/log/tuned/tuned.log
58+
rlRun "tuned-adm profile $PROFILE"
59+
rlRun -l "cat /var/log/tuned/tuned.log"
60+
rlPhaseEnd
61+
62+
rlPhaseStartTest
63+
rlLog "Custom function and variable propagation"
64+
rlAssertGrep "IamTestingThis1" "/var/tmp/test1"
65+
rlAssertGrep "IamTestingThis1returned" "/var/tmp/test2"
66+
67+
rlLog "Built in 'exec' function"
68+
rlAssertGrep "output" "/var/tmp/test3"
69+
rlPhaseEnd
70+
71+
rlPhaseStartCleanup
72+
rlFileRestore
73+
tunedProfileRestore
74+
rlServiceRestore "tuned"
75+
rlRun "rm -rf $TUNED_DIR/$PROFILE"
76+
rlRun "rm ${PSITE_PATH}/tuned/profiles/functions/function_testfunc.py"
77+
rlRun "rm /var/tmp/test1 /var/tmp/test2"
78+
rlPhaseEnd
79+
80+
rlJournalPrintText
81+
rlJournalEnd

0 commit comments

Comments
 (0)