Blame SOURCES/0002-Support-syspurpose-role-matching-in-recommend.conf.patch

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