tuned: improved error handling of switch_profile
Now the D-Bus method "switch_profile" returns record (bool, string), where in case of error, the string describes the error. The string is also displayed by tuned-adm, so the user has better overview what's going there. Related: rhbz#1068699 Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
This commit is contained in:
parent
56ecbd362e
commit
cd506bdf57
4 changed files with 10 additions and 6 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue