Skip to content

Commit e5ddeb1

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

4 files changed

Lines changed: 154 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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
29+
continue: false
30+
- enabled: false
31+
when: distro > rhel-8
32+
continue: false
33+
- enabled: false
34+
when: distro > f-20
35+
continue: false
36+
extra-nitrate: TC#0496876
37+
extra-summary: /CoreOS/tuned/Sanity/built-in-functions
38+
extra-task: /CoreOS/tuned/Sanity/built-in-functions
39+
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: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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'; then
38+
TEST_SCRIPT="rhel8_function_testfunc.py"
39+
elif rlIsFedora; then
40+
TEST_SCRIPT="rhel8_function_testfunc.py"
41+
fi
42+
rlRun "cp -v ${TEST_SCRIPT} ${PSITE_PATH}/tuned/profiles/functions/function_testfunc.py"
43+
44+
# Prepare balanced profile
45+
rlRun "mkdir $TUNED_DIR/$PROFILE"
46+
rlRun -l "echo '[main]
47+
summary=My testing profile
48+
49+
[variables]
50+
VAR1 = \${f:testfunc:/var/tmp/test1:IamTestingThis1}
51+
VAR2 = \${f:testfunc:/var/tmp/test2:\${VAR1}}
52+
cmd = echo
53+
cmd_out = \${f:exec:\${cmd}:output}
54+
VAR3 = \${f:testfunc:/var/tmp/test3:\${cmd_out}}
55+
56+
' >> $TUNED_DIR/$PROFILE/tuned.conf"
57+
rlRun -l "cat $TUNED_DIR/$PROFILE/tuned.conf"
58+
59+
echo > /var/log/tuned/tuned.log
60+
rlRun "tuned-adm profile $PROFILE"
61+
rlRun -l "cat /var/log/tuned/tuned.log"
62+
rlPhaseEnd
63+
64+
rlPhaseStartTest
65+
rlLog "Custom function and variable propagation"
66+
rlAssertGrep "IamTestingThis1" "/var/tmp/test1"
67+
rlAssertGrep "IamTestingThis1returned" "/var/tmp/test2"
68+
69+
rlLog "Built in 'exec' function"
70+
rlAssertGrep "output" "/var/tmp/test3"
71+
rlPhaseEnd
72+
73+
rlPhaseStartCleanup
74+
rlFileRestore
75+
tunedProfileRestore
76+
rlServiceRestore "tuned"
77+
rlRun "rm -rf $TUNED_DIR/$PROFILE"
78+
rlRun "rm ${PSITE_PATH}/tuned/profiles/functions/function_testfunc.py"
79+
rlRun "rm /var/tmp/test1 /var/tmp/test2"
80+
rlPhaseEnd
81+
82+
rlJournalPrintText
83+
rlJournalEnd

0 commit comments

Comments
 (0)