From 2317e2865487f7d44685feced691be73f4bad613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Tue, 12 Mar 2019 12:48:33 +0100 Subject: [PATCH 1/4] net: Rename local variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename local variables to make the code more readable. Signed-off-by: Ondřej Lysoněk --- tuned/plugins/plugin_net.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tuned/plugins/plugin_net.py b/tuned/plugins/plugin_net.py index 3010c3c..e0a0447 100644 --- a/tuned/plugins/plugin_net.py +++ b/tuned/plugins/plugin_net.py @@ -376,15 +376,18 @@ class NetTuningPlugin(base.Plugin): command_name = context, device_name = device) if start: - cd = self._get_device_parameters(context, device) - d = self._set_device_parameters(context, value, device, verify, - dev_params = cd) + params_current = self._get_device_parameters(context, + device) + params_set = self._set_device_parameters(context, + value, device, verify, + dev_params = params_current) # if none of parameters passed checks then the command completely # failed - if len(d) == 0: + if len(params_set) == 0: return False # saved are only those parameters which passed checks - self._storage.set(storage_key," ".join(self._cmd.dict2list(d))) + self._storage.set(storage_key, " ".join( + self._cmd.dict2list(params_set))) else: original_value = self._storage.get(storage_key) # in storage are only those parameters which were already tested From 59c1282c0ee95502806c8630402da654a7954a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Tue, 12 Mar 2019 13:04:19 +0100 Subject: [PATCH 2/4] net: Fix rollback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Starting with commit 0d28f9e63ee44558ec9, values that have been applied were stored instead of the original values, which broke rollback. Fix it by storing the actual original values. Fixes #135 Signed-off-by: Ondřej Lysoněk --- tuned/plugins/plugin_net.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tuned/plugins/plugin_net.py b/tuned/plugins/plugin_net.py index e0a0447..3e14287 100644 --- a/tuned/plugins/plugin_net.py +++ b/tuned/plugins/plugin_net.py @@ -385,9 +385,13 @@ class NetTuningPlugin(base.Plugin): # failed if len(params_set) == 0: return False + relevant_params_current = [(param, value) for param, value + in params_current.items() + if param in params_set] + relevant_params_current = dict(relevant_params_current) # saved are only those parameters which passed checks self._storage.set(storage_key, " ".join( - self._cmd.dict2list(params_set))) + self._cmd.dict2list(relevant_params_current))) else: original_value = self._storage.get(storage_key) # in storage are only those parameters which were already tested From e88c72d5b60796e124b6202cc4782f541311e5c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Tue, 12 Mar 2019 13:37:48 +0100 Subject: [PATCH 3/4] Refactor verification result logging into a separate method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The method is useful for plugins that do their own verification. Signed-off-by: Ondřej Lysoněk --- tuned/plugins/base.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tuned/plugins/base.py b/tuned/plugins/base.py index f8c74c1..784d44d 100644 --- a/tuned/plugins/base.py +++ b/tuned/plugins/base.py @@ -547,7 +547,13 @@ class Plugin(object): ret = val == current_value if ret: break - if ret: + self._log_verification_result(name, ret, new_value, + current_value, device = device) + return ret + + def _log_verification_result(self, name, success, new_value, + current_value, device = None): + if success: if device is None: log.info(consts.STR_VERIFY_PROFILE_VALUE_OK % (name, str(current_value).strip())) else: From 4d12eeff819592af61c14ced7106a81c5f88191d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Tue, 12 Mar 2019 13:57:50 +0100 Subject: [PATCH 4/4] net: Fix verification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In commit 0d28f9e63ee44558ec9, verification has been accidentally dropped from the _custom_parameters method. Fix it. Fixes #135 Signed-off-by: Ondřej Lysoněk --- tuned/plugins/plugin_net.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tuned/plugins/plugin_net.py b/tuned/plugins/plugin_net.py index 3e14287..4d4c19e 100644 --- a/tuned/plugins/plugin_net.py +++ b/tuned/plugins/plugin_net.py @@ -389,6 +389,14 @@ class NetTuningPlugin(base.Plugin): in params_current.items() if param in params_set] relevant_params_current = dict(relevant_params_current) + if verify: + res = (self._cmd.dict2list(params_set) + == self._cmd.dict2list(relevant_params_current)) + self._log_verification_result(context, res, + params_set, + relevant_params_current, + device = device) + return res # saved are only those parameters which passed checks self._storage.set(storage_key, " ".join( self._cmd.dict2list(relevant_params_current)))