Bug 1825882

Summary: Applying a profile with multiple inheritance where parents include a common ancestor fails
Product: Red Hat Enterprise Linux 8 Reporter: Yanir Quinn <yquinn>
Component: tunedAssignee: Jaroslav Škarvada <jskarvad>
Status: CLOSED ERRATA QA Contact: Robin Hack <rhack>
Severity: high Docs Contact:
Priority: unspecified    
Version: 8.2CC: jeder, jmencak, jorton, jskarvad, lmiksik, mapfelba, psklenar, yjoseph, yquinn
Target Milestone: rcKeywords: AutoVerified, NeedsTestCase, Patch, Triaged, Upstream
Target Release: 8.0Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: tuned-2.16.0-0.1.rc1.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-11-09 19:58:24 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1961869    
Attachments:
Description Flags
Proposed patch to address this issue.
none
Proposed fix none

Description Yanir Quinn 2020-04-20 12:44:47 UTC
Description of problem:
When applying a profile with multiple inheritance where both parent profiles include a common ancestor Tuned daemon will fail to apply it.

Version-Release number of selected component (if applicable):

NAME="Red Hat Enterprise Linux"
VERSION="8.2 (Ootpa)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="8.2"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Red Hat Enterprise Linux 8.2 (Ootpa)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:8.2:GA"
HOME_URL="https://www.redhat.com/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 8"
REDHAT_BUGZILLA_PRODUCT_VERSION=8.2
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="8.2"

How reproducible:
Always

Steps to Reproduce:

[root@b82 ~]# yum install tuned-profiles-cpu-partitioning -y
[root@b82 ~]# systemctl stop tuned --now
[root@b82 ~]# echo '[openshift-realtime]' > /etc/tuned/recommend.d/50-openshift.conf
[root@b82 ~]# rm -f /etc/tuned/{active_profile,profile_mode}
[root@b82 ~]# mkdir -p /etc/tuned/{openshift-realtime,realtime}
[root@b82 ~]# cat > /etc/tuned/openshift-realtime/tuned.conf <<EOF
[main]
summary=Custom OpenShift realtime profile
include=cpu-partitioning,realtime
EOF
[root@b82 ~]# cat > /etc/tuned/realtime/tuned.conf <<EOF
[main]
summary=Optimize for realtime workloads
include = network-latency
EOF

Actual results:
Profile with multiple inheritance fails due to:

[root@b82 ~]# tuned --no-dbus
2020-04-20 08:00:14,649 INFO     tuned.daemon.application: dynamic tuning is globally disabled
2020-04-20 08:00:14,651 INFO     tuned.daemon.daemon: using sleep interval of 1 second(s)
2020-04-20 08:00:14,652 INFO     tuned.daemon.daemon: Running in automatic mode, checking what profile is recommended for your configuration.
2020-04-20 08:00:14,652 INFO     tuned.daemon.daemon: Using 'openshift-realtime' profile
2020-04-20 08:00:14,653 INFO     tuned.profiles.loader: loading profile: openshift-realtime
2020-04-20 08:00:14,655 ERROR    tuned.daemon.daemon: Cannot set initial profile. No tunings will be enabled: Cannot load profile(s) 'openshift-realtime': Cannot find profile 'network-latency' in '['/etc/tuned', '/usr/lib/tuned']'.
2020-04-20 08:00:14,655 INFO     tuned.daemon.controller: starting controller
^C2020-04-20 08:00:17,390 INFO     tuned.daemon.controller: terminating controller[root@b82 ~]# ls -l /usr/lib/tuned/network-latency/tuned.conf 
-rw-r--r--. 1 root root 366 Dec 11 12:13 /usr/lib/tuned/network-latency/tuned.conf


Expected results:
Custom profile should be applied successfully. 

Additional info:
Possible reason for failure is mentioned in comments.

Comment 1 Yanir Quinn 2020-04-20 12:55:39 UTC
Looking at loader.py :

	def _load_profile(self, profile_names, profiles, processed_files):
		for name in profile_names:
			filename = self._profile_locator.get_config(name, processed_files)
			if filename is None:
				raise InvalidProfileException("Cannot find profile '%s' in '%s'." % (name, list(reversed(self._profile_locator._load_directories))))
			processed_files.append(filename)

			config = self._load_config_data(filename)
			profile = self._profile_factory.create(name, config)
			if "include" in profile.options:
				include_names = re.split(r"\b\s*[,;]\s*", self._variables.expand(profile.options.pop("include")))
				self._load_profile(include_names, profiles, processed_files)

			profiles.append(profile)


It seems that self._profile_locator.get_config(name, processed_files) is probably invoked twice with an ancestor profile. 
If an ancestor profile was already processed and added processed_files.append(filename) it won't be obtained again and be skipped:
locator.py :
	def get_config(self, profile_name, skip_files=None):
		for dir_name in reversed(self._load_directories):
			# basename is protection not to get out of the path
			config_file = self._get_config_filename(dir_name, os.path.basename(profile_name))

			if skip_files is not None and config_file in skip_files:
				continue

			if os.path.isfile(config_file):
				return config_file

		return None

In the bug description we use realtime and cpu-partitioning profiles that have a common ancestor : network-latency that fails to be obtained according to the log.
There is also a need to consider the case where there is a transitive inheritance , for example:
realtime-> network-latency -> latency-performance
cpu-partitioning -> network-latency -> latency-performance

latency-performance should not be also a reason for a failure in case we overcome the first ancestor.

Comment 2 Ondřej Lysoněk 2020-04-20 13:21:11 UTC
Reproduced. Thanks for the report!

Comment 13 Jiří Mencák 2021-06-03 08:09:16 UTC
Created attachment 1788804 [details]
Proposed patch to address this issue.

Proposing a patch to address this issue.  Might break some unit tests, but seems to address the problem.

Comment 14 Jaroslav Škarvada 2021-06-09 00:26:43 UTC
Created attachment 1789468 [details]
Proposed fix

I address the following:

- unit test fixes
- fix the problem (regression) when customized profile PROFILE (in /etc/tuned) uses include=PROFILE (for customizing the stock profiles from the /usr/share/tuned)

I will give you credit in the upstream git.

I am going to give it a bit more thinking whether this simplified profile loading could introduce some unexpected situations (e.g. with 'replace=true').

Comment 15 Jaroslav Škarvada 2021-06-09 08:53:26 UTC
Upstream PR:
https://github.com/redhat-performance/tuned/pull/357

Comment 24 errata-xmlrpc 2021-11-09 19:58:24 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (tuned bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2021:4476

Comment 25 Red Hat Bugzilla 2023-09-15 00:31:05 UTC
The needinfo request[s] on this closed bug have been removed as they have been unresolved for 500 days