From 9efd6d77283324ed8b8802431522a7a4eabd9aa0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= <olysonek@redhat.com>
Date: Fri, 10 Aug 2018 16:17:47 +0200
Subject: [PATCH 2/2] Support syspurpose role matching in recommend.conf
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Resolves: rhbz#1565598
Signed-off-by: Ondřej Lysoněk <olysonek@redhat.com>
---
tuned.spec | 3 +++
tuned/utils/commands.py | 22 ++++++++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/tuned.spec b/tuned.spec
index 2b4f039..3bf0db2 100644
--- a/tuned.spec
+++ b/tuned.spec
@@ -67,6 +67,9 @@ Requires: util-linux, dbus, polkit
%if 0%{?fedora} > 22 || 0%{?rhel} > 7
Recommends: kernel-tools
%endif
+%if 0%{?rhel} > 7
+Requires: python3-syspurpose
+%endif
%description
The tuned package contains a daemon that tunes system settings dynamically.
diff --git a/tuned/utils/commands.py b/tuned/utils/commands.py
index 8bb31a3..9a81baf 100644
--- a/tuned/utils/commands.py
+++ b/tuned/utils/commands.py
@@ -10,6 +10,11 @@ import procfs
from subprocess import *
from tuned.exceptions import TunedException
import dmidecode
+try:
+ import syspurpose.files
+ have_syspurpose = True
+except:
+ have_syspurpose = False
log = tuned.logs.get()
@@ -421,6 +426,23 @@ class commands:
break
else:
match = False
+ elif option == "syspurpose_role":
+ if have_syspurpose:
+ s = syspurpose.files.SyspurposeStore(
+ syspurpose.files.USER_SYSPURPOSE,
+ raise_on_error = True)
+ role = ""
+ try:
+ s.read_file()
+ role = s.contents["role"]
+ except (IOError, OSError, KeyError) as e:
+ if hasattr(e, "errno") and e.errno != errno.ENOENT:
+ log.error("Failed to load the syspurpose file: %s" % e)
+ if re.match(value, role, re.IGNORECASE) is None:
+ match = False
+ else:
+ log.error("Failed to process 'syspurpose_role' in '%s', the syspurpose module is not available" % fname)
+
if match:
# remove the ",.*" suffix
r = re.compile(r",[^,]*$")
--
2.17.1