Skip to content

Commit

Permalink
spec: used macro for profiles path and other fixes
Browse files Browse the repository at this point in the history
- improved conditionals for better readability
- fixed tuned-ppd not to run install twice
- used macro for profiles path
- consolidated names of related variables
- updated Makefile to update the current profile paths during
  installation
- fixed tests to use correct profile directory on RHEL/CentOS
- consolidated whitespaces and variable names in fixed tests

Signed-off-by: Jaroslav Škarvada <[email protected]>
  • Loading branch information
yarda committed Oct 15, 2024
1 parent c082797 commit 5580fbc
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 109 deletions.
54 changes: 33 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ $(error Failed to determine python library directory)
endif
KERNELINSTALLHOOKDIR = /usr/lib/kernel/install.d
TUNED_SYSTEM_DIR = /usr/lib/tuned
TUNED_PROFILES_DIR = $(TUNED_SYSTEM_DIR)/profiles
TUNED_SYSTEM_PROFILES_DIR = $(TUNED_SYSTEM_DIR)/profiles
TUNED_CFG_DIR = $(SYSCONFDIR)/tuned
TUNED_USER_PROFILES_DIR = $(TUNED_CFG_DIR)/profiles
TUNED_RECOMMEND_DIR = $(TUNED_SYSTEM_DIR)/recommend.d
TUNED_USER_RECOMMEND_DIR = $(SYSCONFDIR)/tuned/recommend.d
TUNED_USER_RECOMMEND_DIR = $(TUNED_CFG_DIR)/recommend.d
BASH_COMPLETIONS = $(DATADIR)/bash-completion/completions

copy_executable = install -Dm 0755 $(1) $(2)
Expand Down Expand Up @@ -129,13 +131,13 @@ clean-html:

install-dirs:
mkdir -p $(DESTDIR)$(PYTHON_SITELIB)
mkdir -p $(DESTDIR)$(TUNED_PROFILES_DIR)
mkdir -p $(DESTDIR)$(TUNED_SYSTEM_PROFILES_DIR)
mkdir -p $(DESTDIR)/var/lib/tuned
mkdir -p $(DESTDIR)/var/log/tuned
mkdir -p $(DESTDIR)/run/tuned
mkdir -p $(DESTDIR)$(DOCDIR)
mkdir -p $(DESTDIR)$(SYSCONFDIR)
mkdir -p $(DESTDIR)$(SYSCONFDIR)/tuned/profiles
mkdir -p $(DESTDIR)$(TUNED_USER_PROFILES_DIR)
mkdir -p $(DESTDIR)$(TUNED_RECOMMEND_DIR)
mkdir -p $(DESTDIR)$(TUNED_USER_RECOMMEND_DIR)

Expand All @@ -161,26 +163,36 @@ install: install-dirs
experiments/powertop2tuned.py, $(DESTDIR)/usr/bin/powertop2tuned)

# configuration files
install -Dpm 0644 tuned-main.conf $(DESTDIR)$(SYSCONFDIR)/tuned/tuned-main.conf
# Update profiles location
sed '/^\s*#\?\s*profile_dirs\s*=\s*/ s|\(profile_dirs\s*=\s*\).*$$|\1$(TUNED_SYSTEM_PROFILES_DIR),$(TUNED_USER_PROFILES_DIR)|' \
tuned-main.conf > tuned-main.conf.tmp
touch -r tuned-main.conf tuned-main.conf.tmp
sed -i '/^\s*USER_PROFILES_DIR\s*=\s*/ s|\(USER_PROFILES_DIR\s*=\s*\).*$$|\1"$(TUNED_USER_PROFILES_DIR)"|' \
$(DESTDIR)$(PYTHON_SITELIB)/tuned/consts.py
sed -i '/^\s*SYSTEM_PROFILES_DIR\s*=\s*/ s|\(SYSTEM_PROFILES_DIR\s*=\s*\).*$$|\1"$(TUNED_SYSTEM_PROFILES_DIR)"|' \
$(DESTDIR)$(PYTHON_SITELIB)/tuned/consts.py
install -Dpm 0644 tuned-main.conf.tmp $(DESTDIR)$(TUNED_CFG_DIR)/tuned-main.conf
rm -f tuned-main.conf.tmp

# None profile in the moment, autodetection will be used
echo -n > $(DESTDIR)$(SYSCONFDIR)/tuned/active_profile
echo -n > $(DESTDIR)$(SYSCONFDIR)/tuned/profile_mode
echo -n > $(DESTDIR)$(SYSCONFDIR)/tuned/post_loaded_profile
install -Dpm 0644 bootcmdline $(DESTDIR)$(SYSCONFDIR)/tuned/bootcmdline
echo -n > $(DESTDIR)$(TUNED_CFG_DIR)/active_profile
echo -n > $(DESTDIR)$(TUNED_CFG_DIR)/profile_mode
echo -n > $(DESTDIR)$(TUNED_CFG_DIR)/post_loaded_profile
install -Dpm 0644 bootcmdline $(DESTDIR)$(TUNED_CFG_DIR)/bootcmdline
install -Dpm 0644 modules.conf $(DESTDIR)$(SYSCONFDIR)/modprobe.d/tuned.conf

# profiles & system config
cp -a profiles/* $(DESTDIR)$(TUNED_PROFILES_DIR)/
mv $(DESTDIR)$(TUNED_PROFILES_DIR)/realtime/realtime-variables.conf \
$(DESTDIR)$(SYSCONFDIR)/tuned/realtime-variables.conf
mv $(DESTDIR)$(TUNED_PROFILES_DIR)/realtime-virtual-guest/realtime-virtual-guest-variables.conf \
$(DESTDIR)$(SYSCONFDIR)/tuned/realtime-virtual-guest-variables.conf
mv $(DESTDIR)$(TUNED_PROFILES_DIR)/realtime-virtual-host/realtime-virtual-host-variables.conf \
$(DESTDIR)$(SYSCONFDIR)/tuned/realtime-virtual-host-variables.conf
mv $(DESTDIR)$(TUNED_PROFILES_DIR)/cpu-partitioning/cpu-partitioning-variables.conf \
$(DESTDIR)$(SYSCONFDIR)/tuned/cpu-partitioning-variables.conf
mv $(DESTDIR)$(TUNED_PROFILES_DIR)/cpu-partitioning-powersave/cpu-partitioning-powersave-variables.conf \
$(DESTDIR)$(SYSCONFDIR)/tuned/cpu-partitioning-powersave-variables.conf
cp -a profiles/* $(DESTDIR)$(TUNED_SYSTEM_PROFILES_DIR)/
mv $(DESTDIR)$(TUNED_SYSTEM_PROFILES_DIR)/realtime/realtime-variables.conf \
$(DESTDIR)$(TUNED_CFG_DIR)/realtime-variables.conf
mv $(DESTDIR)$(TUNED_SYSTEM_PROFILES_DIR)/realtime-virtual-guest/realtime-virtual-guest-variables.conf \
$(DESTDIR)$(TUNED_CFG_DIR)/realtime-virtual-guest-variables.conf
mv $(DESTDIR)$(TUNED_SYSTEM_PROFILES_DIR)/realtime-virtual-host/realtime-virtual-host-variables.conf \
$(DESTDIR)$(TUNED_CFG_DIR)/realtime-virtual-host-variables.conf
mv $(DESTDIR)$(TUNED_SYSTEM_PROFILES_DIR)/cpu-partitioning/cpu-partitioning-variables.conf \
$(DESTDIR)$(TUNED_CFG_DIR)/cpu-partitioning-variables.conf
mv $(DESTDIR)$(TUNED_SYSTEM_PROFILES_DIR)/cpu-partitioning-powersave/cpu-partitioning-powersave-variables.conf \
$(DESTDIR)$(TUNED_CFG_DIR)/cpu-partitioning-powersave-variables.conf
install -pm 0644 recommend.conf $(DESTDIR)$(TUNED_RECOMMEND_DIR)/50-tuned.conf

# bash functions used by profile scripts
Expand Down Expand Up @@ -228,7 +240,7 @@ install: install-dirs
install -dD $(DESTDIR)$(DATADIR)/applications
desktop-file-install --dir=$(DESTDIR)$(DATADIR)/applications tuned-gui.desktop

install-ppd: install
install-ppd:
$(call install_python_script,tuned-ppd.py,$(DESTDIR)/usr/sbin/tuned-ppd)
install -Dpm 0644 tuned/ppd/tuned-ppd.service $(DESTDIR)$(UNITDIR)/tuned-ppd.service
install -Dpm 0644 tuned/ppd/tuned-ppd.dbus.service $(DESTDIR)$(DATADIR)/dbus-1/system-services/net.hadess.PowerProfiles.service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
. /usr/share/beakerlib/beakerlib.sh || exit 1

PACKAGE="tuned"
PROFILE_DIR="/etc/tuned/profiles"

rlJournalStart
rlPhaseStartSetup
Expand All @@ -29,33 +28,36 @@ rlJournalStart
rlServiceStart "tuned"
rlImport "tuned/basic"
tunedProfileBackup
rlFileBackup "/etc/tuned/active_profile"
rlFileBackup "/etc/tuned/active_profile"
rlFileBackup "/etc/tuned/profile_mode"

rlRun "mkdir $PROFILE_DIR/test-profile"
rlServiceStart "tuned"
PROFILE_DIR=$(tunedGetProfilesBaseDir)

rlRun "mkdir -p ${PROFILE_DIR}/test-profile"
rlServiceStop "tuned"
sleep 1
rlFileBackup "/var/log/tuned/tuned.log"
rlRun "rm -rf /var/log/tuned/tuned.log"
rlFileBackup "/var/log/tuned/tuned.log"
rlRun "rm -rf /var/log/tuned/tuned.log"
rlServiceStart "tuned"
rlPhaseEnd

rlPhaseStartTest
rlRun "pushd $PROFILE_DIR/test-profile"
cat << EOF > tuned.conf
rlRun "pushd $PROFILE_DIR/test-profile"
cat << EOF > tuned.conf
[scheduler]
runtime=0
EOF
rlRun "popd"
rlRun "popd"

rlRun "tuned-adm profile test-profile"
rlRun "tuned-adm profile test-profile"
rlServiceStop "tuned"
sleep 3
sleep 3
rlServiceStart "tuned"
sleep 3
sleep 3
rlServiceStop "tuned"

rlAssertNotGrep "Traceback" "/var/log/tuned/tuned.log"
rlAssertNotGrep "object has no attribute '_evlist'" "/var/log/tuned/tuned.log"
rlAssertNotGrep "Traceback" "/var/log/tuned/tuned.log"
rlAssertNotGrep "object has no attribute '_evlist'" "/var/log/tuned/tuned.log"
rlPhaseEnd

rlPhaseStartCleanup
Expand All @@ -65,10 +67,10 @@ EOF

tunedProfileRestore
rlServiceStop "tuned"
rlFileRestore
rlFileRestore

rlServiceRestore "tuned"
rlRun "rm -rf $PROFILE_DIR/test-profile"
rlRun "rm -rf $PROFILE_DIR/test-profile"
rlPhaseEnd

rlJournalPrintText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
. /usr/share/beakerlib/beakerlib.sh || exit 1

PACKAGE="tuned"
SYSCONF_DIR=/etc/tuned
PROFILE_DIR=$SYSCONF_DIR/profiles
ACTIVE_PROFILE=$SYSCONF_DIR/active_profile
PROFILE_MODE=$SYSCONF_DIR/profile_mode
POST_LOADED_PROFILE=$SYSCONF_DIR/post_loaded_profile
ACTIVE_PROFILE=/etc/tuned/active_profile
POST_LOADED_PROFILE="/etc/tuned/post_loaded_profile"
PROFILE_MODE=/etc/tuned/profile_mode
SWAPPINESS=vm.swappiness
DIRTY_RATIO=vm.dirty_ratio
PID_FILE=/run/tuned/tuned.pid
Expand Down Expand Up @@ -62,10 +60,11 @@ function wait_for_tuned_stop()
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE

rlImport "tuned/basic"
tunedDisableSystemdRateLimitingStart
rlRun "for PYTHON in $PYTHON_CHECK; do \$PYTHON --version 2>/dev/null && break; done" 0 "Detect python"
rlRun "rlFileBackup --clean $SYSCONF_DIR"
PROFILE_DIR=$(tunedGetProfilesBaseDir)

rlRun "rlFileBackup --clean $PROFILE_DIR"
rlRun "cp -r parent $PROFILE_DIR"
rlRun "cp -r parent2 $PROFILE_DIR"
rlRun "cp -r parent-vars $PROFILE_DIR"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
. /usr/share/beakerlib/beakerlib.sh || exit 1

PACKAGE="tuned"
PROFILE_DIR=/etc/tuned/profiles

rlJournalStart
rlPhaseStartSetup
Expand All @@ -29,7 +28,9 @@ rlJournalStart
rlServiceStart "tuned"
tunedProfileBackup

rlRun "mkdir $PROFILE_DIR/test-profile"
PROFILE_DIR=$(tunedGetProfilesBaseDir)

rlRun "mkdir -p $PROFILE_DIR/test-profile"
rlRun "pushd $PROFILE_DIR/test-profile"
cat << EOF > tuned.conf
[sysctl]
Expand All @@ -53,8 +54,8 @@ EOF

rlAssertGrep "test-profile" "/etc/tuned/active_profile"

# last value from config is used
rlAssertGrep "16384$" /sys/fs/selinux/avc/cache_threshold
# last value from config is used
rlAssertGrep "16384$" /sys/fs/selinux/avc/cache_threshold
rlPhaseEnd

rlPhaseStartCleanup
Expand Down
4 changes: 3 additions & 1 deletion tests/beakerlib/error-messages/runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
. /usr/share/beakerlib/beakerlib.sh || exit 1

PACKAGE="tuned"
PROFILE_DIR="/usr/lib/tuned/profiles"

rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE
rlImport "tuned/basic"

PROFILE_DIR=$(tunedGetProfilesBaseDir)

tunedDisableSystemdRateLimitingStart
rlServiceStart "tuned"
tunedProfileBackup
Expand Down
9 changes: 6 additions & 3 deletions tests/beakerlib/variables-support-in-profiles/runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@
. /usr/share/beakerlib/beakerlib.sh || exit 1

PACKAGE="tuned"
PROFILE_DIR="/usr/lib/tuned/profiles"

rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE
rlImport "tuned/basic"

PROFILE_DIR=$(tunedGetProfilesBaseDir)

rlFileBackup --clean "$PROFILE_DIR/balanced"
rlRun "mkdir -p ${PROFILE_DIR}/test-profile"

tunedDisableSystemdRateLimitingStart
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "pushd $TmpDir"
rlServiceStart "tuned"
tunedProfileBackup
rlFileBackup "$PROFILE_DIR/balanced/tuned.conf"

echo "
[variables]
Expand Down
Loading

0 comments on commit 5580fbc

Please sign in to comment.