From cd655df597d7c10171036f4788530cd86821b766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Thu, 3 Aug 2017 15:18:21 +0200 Subject: [PATCH] Add 'tuned-adm profile_mode' command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement a new 'tuned-adm profile_mode' command, which prints the current profile mode - automatic vs. manual. Related: rhbz#1459146 Signed-off-by: Ondřej Lysoněk --- com.redhat.tuned.policy | 10 ++++++++++ tuned-adm.py | 3 +++ tuned/admin/admin.py | 26 +++++++++++++++++++++++++- tuned/admin/dbus_controller.py | 3 +++ tuned/daemon/controller.py | 11 ++++++++++- tuned/daemon/daemon.py | 5 +++++ 6 files changed, 56 insertions(+), 2 deletions(-) diff --git a/com.redhat.tuned.policy b/com.redhat.tuned.policy index 1db1bf2..b34fdab 100644 --- a/com.redhat.tuned.policy +++ b/com.redhat.tuned.policy @@ -17,6 +17,16 @@ + + Show current profile selection mode + Authentication is required to show current profile selection mode + + yes + yes + yes + + + Disable Tuned Authentication is required to disable Tuned diff --git a/tuned-adm.py b/tuned-adm.py index c56dc68..a5b6b39 100755 --- a/tuned-adm.py +++ b/tuned-adm.py @@ -74,6 +74,9 @@ if __name__ == "__main__": parser_auto_profile = subparsers.add_parser("auto_profile", help="enable automatic profile selection mode, switch to the recommended profile") parser_auto_profile.set_defaults(action="auto_profile") + parser_profile_mode = subparsers.add_parser("profile_mode", help="show current profile selection mode") + parser_profile_mode.set_defaults(action="profile_mode") + args = parser.parse_args(sys.argv[1:]) options = vars(args) diff --git a/tuned/admin/admin.py b/tuned/admin/admin.py index b751ff0..fd96b0a 100644 --- a/tuned/admin/admin.py +++ b/tuned/admin/admin.py @@ -122,6 +122,19 @@ class Admin(object): profile_name = None return profile_name + def _get_profile_mode(self): + contents = str.strip(self._cmd.read_file(consts.ACTIVE_PROFILE_FILE)) + if contents == '': + mode = consts.ACTIVE_PROFILE_AUTO + else: + arr = contents.split('\n') + if len(arr) == 1: + # The file was generated by old Tuned -> manual mode + mode = consts.ACTIVE_PROFILE_MANUAL + else: + mode = arr[1] + return mode + def _print_profile_info(self, profile, profile_info): if profile_info[0] == True: print("Profile name:") @@ -166,7 +179,18 @@ class Admin(object): return True return self._print_profile_name(profile_name) - # TODO action profile mode - auto/manual + def _print_profile_mode(self, mode): + print("Profile selection mode: " + mode) + + def _action_dbus_profile_mode(self): + mode = self._controller.profile_mode() + self._print_profile_mode(mode) + return self._controller.exit(True) + + def _action_profile_mode(self): + mode = self._get_profile_mode() + self._print_profile_mode(mode) + return True def _profile_print_status(self, ret, msg): if ret: diff --git a/tuned/admin/dbus_controller.py b/tuned/admin/dbus_controller.py index 322b8c0..fa46a0d 100644 --- a/tuned/admin/dbus_controller.py +++ b/tuned/admin/dbus_controller.py @@ -99,6 +99,9 @@ class DBusController(object): def active_profile(self): return self._call("active_profile") + def profile_mode(self): + return self._call("profile_mode") + def switch_profile(self, new_profile): if new_profile == "": return (False, "No profile specified") diff --git a/tuned/daemon/controller.py b/tuned/daemon/controller.py index d626bf5..087380b 100644 --- a/tuned/daemon/controller.py +++ b/tuned/daemon/controller.py @@ -128,6 +128,15 @@ class Controller(tuned.exports.interfaces.ExportableInterface): else: return "" + @exports.export("", "s") + def profile_mode(self, caller = None): + if caller == "": + return "" + if self._daemon.manual: + return consts.ACTIVE_PROFILE_MANUAL + else: + return consts.ACTIVE_PROFILE_AUTO + @exports.export("", "b") def disable(self, caller = None): if caller == "": @@ -135,7 +144,7 @@ class Controller(tuned.exports.interfaces.ExportableInterface): if self._daemon.is_running(): self._daemon.stop() if self._daemon.is_enabled(): - self._daemon.set_profile(None, True, save_instantly=True) + self._daemon.set_profile(None, None, save_instantly=True) return True @exports.export("", "b") diff --git a/tuned/daemon/daemon.py b/tuned/daemon/daemon.py index 55f66d8..4292575 100644 --- a/tuned/daemon/daemon.py +++ b/tuned/daemon/daemon.py @@ -90,6 +90,11 @@ class Daemon(object): def profile(self): return self._profile + @property + def manual(self): + # manual == None means /etc/tuned/active_profile is empty -> automatic mode + return self._manual == True or self._manual is None + @property def profile_loader(self): return self._profile_loader