Skip to content

Commit

Permalink
tuned: Call right tuned.disable() function when stopping tuned
Browse files Browse the repository at this point in the history
In addition disable the tuned service when the user has chosen
the "none" option. Enable the tuned service only when the user
has chosen an actual profile.

Add tests for this.

Closes #4623
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
  • Loading branch information
stefwalter authored and mvollmer committed Jun 27, 2016
1 parent 4084a91 commit 0462c71
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 18 deletions.
65 changes: 47 additions & 18 deletions pkg/tuned/dialog.js
Expand Up @@ -125,31 +125,63 @@ define([
function set_profile() {
// no need to check input here, all states are valid
var profile = dialog_selected;
var promise;

if (profile == "none") {
return tuned.call('/Tuned', 'com.redhat.tuned.control', 'stop', [])
.then(function() {
promise = tuned.call("/Tuned", 'com.redhat.tuned.control', 'disable', [])
.then(function(results) {
/* Yup this is how tuned returns failures */
if (!results[0]) {
console.warn("Failed to disable tuned profile:", results);
return cockpit.reject(_("Failed to disable tuned profile"));
}

update_button();
return null;
});
} else {
return tuned.call('/Tuned', 'com.redhat.tuned.control', 'switch_profile', [ profile ])
promise = tuned.call('/Tuned', 'com.redhat.tuned.control', 'switch_profile', [ profile ])
.then(function(results) {

/* Yup this is how tuned returns failures */
if (!results[0][0]) {
console.warn("Failed to switch profile:", results);
return cockpit.reject(results[0][1] || _("Failed to switch profile"));
} else {
return tuned.call('/Tuned', 'com.redhat.tuned.control', 'start', [])
.then(function(results) {
if (!results[0]) {
console.warn("tuned set_profile failed: " + JSON.stringify(results));
return cockpit.reject(results[1] || _("Failed to activate profile"));
} else {
update_button();
return null;
}
});
}

update_button();
});
}

return promise.then(set_service);
}

function set_service() {
/* When the profile is none we disable tuned */
var enable = (dialog_selected != "none");
var action = enable ? "start" : "stop";
return tuned.call('/Tuned', 'com.redhat.tuned.control', action, [])
.then(function(results) {
var msg;

/* Yup this is how tuned returns failures */
if (!results[0]) {
console.warn("Failed to " + action + " tuned:", results);
if (results[1])
return cockpit.reject(results[1]);
else if (enable)
return cockpit.reject(cockpit.format(_("Failed to enable tuned")));
else
return cockpit.reject(cockpit.format(_("Failed to disable tuned")));
}

/* Now tell systemd about this change */
if (enable && !tuned_service.enabled)
return tuned_service.enable();
else if (!enable && tuned_service.enabled)
return tuned_service.disable();
else
return null;
});
}

function update_selected_item(selected) {
Expand Down Expand Up @@ -247,9 +279,6 @@ define([
with_tuned();
})
.fail(show_error);

if (!tuned_service.enabled)
tuned_service.enable();
}

button.on('click', open_dialog);
Expand Down
33 changes: 33 additions & 0 deletions test/verify/check-tuned
Expand Up @@ -37,6 +37,7 @@ class TestTuned(MachineCase):
# Stop tuned in case it is running by default, as on RHEL.

m.execute("systemctl stop tuned")
m.execute("systemctl disable tuned")

# Login and check initial state

Expand Down Expand Up @@ -78,5 +79,37 @@ class TestTuned(MachineCase):
b.wait_attr('#system-info-performance [data-toggle="popover"]', 'data-content',
"This system is using a custom profile")

# Check the status of tuned, it should show the profile
output = m.execute("tuned-adm active 2>&1 || true")
self.assertIn("balanced", output)
output = m.execute("systemctl status tuned")
self.assertIn("enabled;", output)

# Now disable tuned
b.click('#system-info-performance button')
b.wait_present(title_selector)
b.wait_present("{0} .list-group-item.active p".format(body_selector))

b.click("{0} .list-group-item p:contains('None')".format(body_selector))
b.wait_present("{0} .list-group-item.active p:contains('None')".format(body_selector))
b.click("{0} button.apply".format(body_selector))
b.wait_not_present(title_selector)

b.wait_text('#system-info-performance button', "none")

# Check the status of tuned, it should show disabled
output = m.execute("tuned-adm active 2>&1 || true")
self.assertIn("No current active profile", output)
output = m.execute("systemctl status tuned")
self.assertIn("disabled;", output)

# Click on the button again
b.click('#system-info-performance button')
b.wait_present(title_selector)

# Tuned should still be disabled
output = m.execute("systemctl status tuned")
self.assertIn("disabled;", output)

if __name__ == '__main__':
test_main()

0 comments on commit 0462c71

Please sign in to comment.