diff --git a/tuned/admin/admin.py b/tuned/admin/admin.py index aadd084..8b5f7bd 100644 --- a/tuned/admin/admin.py +++ b/tuned/admin/admin.py @@ -42,7 +42,7 @@ class Admin(object): if profile_name == "": return False try: - ret = self._controller.switch_profile(profile_name) + (ret, msg) = self._controller.switch_profile(profile_name) except TunedAdminDBusException as e: self._error(e) if profile_name in profiles_locator(consts.LOAD_DIRECTORIES).get_known_names(): @@ -60,7 +60,7 @@ class Admin(object): self._error("Cannot enable the tuning.") ret = False else: - self._error("Cannot switch the profile.") + self._error(msg) return ret diff --git a/tuned/admin/dbus_controller.py b/tuned/admin/dbus_controller.py index 191b606..f2a2d11 100644 --- a/tuned/admin/dbus_controller.py +++ b/tuned/admin/dbus_controller.py @@ -49,7 +49,7 @@ class DBusController(object): def switch_profile(self, new_profile): if new_profile == "": - return False + return (False, "No profile specified") return self._call("switch_profile", new_profile) def recommend_profile(self): diff --git a/tuned/daemon/controller.py b/tuned/daemon/controller.py index a52f7b8..a7a015b 100644 --- a/tuned/daemon/controller.py +++ b/tuned/daemon/controller.py @@ -61,21 +61,23 @@ class Controller(tuned.exports.interfaces.ExportableInterface): else: return self.stop() and self.start() - @exports.export("s", "b") + @exports.export("s", "(bs)") def switch_profile(self, profile_name): was_running = self._daemon.is_running() + msg = "OK" success = True try: if was_running: self._daemon.stop() self._daemon.set_profile(profile_name) - except tuned.exceptions.TunedException: + except tuned.exceptions.TunedException as e: success = False + msg = str(e) finally: if was_running: self._daemon.start() - return success + return (success, msg) @exports.export("", "s") def active_profile(self): diff --git a/tuned/daemon/daemon.py b/tuned/daemon/daemon.py index 6c0c2f1..7acbc35 100644 --- a/tuned/daemon/daemon.py +++ b/tuned/daemon/daemon.py @@ -57,6 +57,8 @@ class Daemon(object): if profile_name == "" or profile_name is None: self._profile = None + elif profile_name not in self.profile_loader.profile_locator.get_known_names(): + raise TunedException("Requested profile '%s' doesn't exist." % profile_name) else: try: self._profile = self._profile_loader.load(profile_name)