1. In the raise statement of the check_positive() function, the error message conflicts with the if condition.
2. If the value of val is 0, it passes the if condition but raises an error message stating [0 has to be >= 0].
3. This PR removes the = from the raise statement, so when val is 0,
it will correctly prompt that the value of val [has to be > 0].
Signed-off-by: dufuhang <dufuhang@kylinos.cn>
If TuneD was simply off before the restart, we can then
switch the profile using the dbus method. Otherwise we
fallback to a profile switch via setting the active_profile
file (where we do not check for success).
Resolves: RHEL-15137
Appropriate commands are added to tuned-adm as well.
`get_instances`: Retrieves a list of active instances of a given
plugin or all active instances.
`instance_get_devices`: Retrieves a list of devices assigned
to a given instance.
Unfortunately non-required subcommands are not supported by argparse
module on python2, so selection between plugins and profiles must be
done by new positional non-required arguments "profiles" and
"plugins"
Examples of usage:
$ tuned-adm list -- will list tuned profiles like before
$ tuned-adm list profiles -- new command which has the same function
as tuned-adm list
$ tuned-adm list plugins -- will list tuned accessible plugins
$ tuned-adm list plugins [-v|--verbose] -- will list tuned accessible
plugins + their configuration options and hints how to use them
Signed-off-by: Tomas Korbar <tkorbar@redhat.com>
The previous fix was not sufficient, tuned-adm still tracebacks
in cases when options are specified, but an action is not, e.g.:
$ python3 ./tuned-adm.py -a
Traceback (most recent call last):
File "./tuned-adm.py", line 106, in <module>
action_name = options.pop("action")
KeyError: 'action'
The object returned by ArgumentParser.add_subparsers recognizes
a 'required' attribute (at least in Python 3), which is probably
meant to allow to make specifying an action required, but I wasn't
able to make it work properly, I get errors such as
Traceback (most recent call last):
File "./tuned-adm.py", line 98, in <module>
args = parser.parse_args(sys.argv[1:])
File "/usr/lib64/python3.6/argparse.py", line 1730, in parse_args
args, argv = self.parse_known_args(args, namespace)
File "/usr/lib64/python3.6/argparse.py", line 1762, in parse_known_args
namespace, args = self._parse_known_args(args, namespace)
File "/usr/lib64/python3.6/argparse.py", line 1997, in _parse_known_args
', '.join(required_actions))
TypeError: sequence item 0: expected str instance, NoneType found
which I think is not expected. The error is raised here:
6ceab46a60/Lib/argparse.py (L2001)
Signed-off-by: Ondřej Lysoněk <olysonek@redhat.com>
Running tuned-adm without arguments using Python 3 results in
a traceback. This is because in this case parse_args does not
exit with a usage message in Python 3 and the 'action' option
is then undefined. So let's check for this case and print the
usage message ourselves. There may be a better solution to this,
but I wasn't able to come up with anything in a reasonable amount
of time.
Signed-off-by: Ondřej Lysoněk <olysonek@redhat.com>
Print messages logged during a profile switch to stderr (this affects
the "profile" and "auto_profile" commands). By default messages with
log level ERROR and higher are printed. This can be changed using the
--loglevel command line option. Valid values are debug, info, warn,
error, console, none ('none' can be used to disable the log printing).
E.g.:
tuned-adm --loglevel info profile powersave
Log printing cannot be used when --async is used.
Resolves: rhbz#1538745
Signed-off-by: Ondřej Lysoněk <olysonek@redhat.com>
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 <olysonek@redhat.com>
A profile can now be set in two modes: automatic and manual.
When the automatic mode is active, Tuned always activates the
recommended profile upon startup. This mode can be set using
the following command:
tuned-adm auto_profile
When the manual mode is active, the previously applied profile
is activated upon startup. This mode can be set by switching
to the desired profile, e.g.
tuned-adm profile throughput-performance
The mode is saved on the second line of /etc/tuned/active_profile.
When the file /etc/tuned/active_profile does not exist, or is
empty, automatic mode is enabled. When the file has only one line,
i.e. it was generated by a previous Tuned version, manual mode
is enabled so that the upgrade doesn't cause unexpected active profile
changes.
Related: rhbz#1459146
Signed-off-by: Ondřej Lysoněk <olysonek@redhat.com>
List available profiles when 'tuned-adm profile' is run
without a profile name.
Resolves: rhbz#988433
Signed-off-by: Ondřej Lysoněk <olysonek@redhat.com>
In no_daemon mode it doesn't try to query DBus, so it doesn't
output DBus error.
Resolves: rhbz#1351536
Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
The glib/dbus doesn't like multithreading which is not handled
by them, thus the code may segfault. According to
https://bugzilla.redhat.com/show_bug.cgi?id=1330127#c2
it is not supportd and dbus-glib/dbus-python are not thread safe.
This commit moves multithreading under glib and handles all
in the glib mainloop, thus it may no longer segfaults.
It also adds --timeout, -t command line parameter which may
specify timeout for the sync operations, e.g.:
# tuned-adm --timeout 200 profile balanced
wil use 200 seconds timeout when waiting for the profile to
load.
The default timeout was increased to 90 seconds to match
systemd default timeouts.
Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
The verify command can now be run in ignore-missing mode. In this mode
missing/non-supported settings (i.e. those which current value is None)
are ignored and not treated as errors.
The tuned-adm got new verify options -i and --ignore-missing which
enables the ignore-missing mode, usage:
tuned-adm verify -i
or:
tuned-adm verify --ignore-missing
The DBus interface got new method 'verify_profile_ignore_missing' which
does the verification in ignore-missing mode.
Resolves: rhbz#1243807
Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
By default tuned-adm now synchronously switch profiles, i.e it waits untill
the profile is applied and then returns to the shell. It returns with
exitcode 0 if profile is correctly applied. If there is an error it uses
exitcode > 0 (currently only 1 is used) and displays error. For reverting
to old behaviour (i.e. asynchronous profile switching) when the tuned-adm
returns immediately there is an tuned-adm command line option -a (or --async).
D-Bus API was extended to allow synchronous profile switching. Now the
"profile_changed" D-Bus signal is sent when the profile is applied. The
signal contains the following data:
profile_name:string - the name of the profile which was applied
result:boolean - status of the operation, true if OK, false on error
errstr:string - string containing description of the error (if result is
false)
Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
Added new tuned-adm functionality 'profile_info'. It has optional parameter
'profile_name'. If called without parameter, active profile is used.
It outputs name of the profile it is querying, profile summary, and profile
description. If there is no profile summary or description available it
outputs empty string(s).
Extended tuned-adm 'list' functionality. It now displays profile summary
in the list (if available).
Added summary to profiles.
Extended D-Bus API to support the new feature and for better Cockpit support:
- Added 'profile_info' method. It gets profile_name argument and it queries
the requested profile for information. If profile_name is empty string it
queries the active/selected profile. It returns tuple of the following
format (status, profile_name, summary, description), where status is
boolean. If it is False, the query mechanism failed and the other fields
don't contain valid data
- Added 'profiles2' method. It's extension of 'profiles' method. It returns
list of tuples. Tuples have following format:
(profile_name, profile_summary)
Related: rhbz#1228356
Fixes: #46
Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
Most of the functionality don' work in this mode, it just
applies the settings, no rollback possible.
Disable daemon by setting 'daemon = 0' in /etc/tuned/tuned-main.conf
This settings can be overridden if running tuned with '-d' command line
option. In such case daemon mode will be used.
Resolves: rhbz#1068663
Also fixed interpretation of booleans in main config.
Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
On some platforms the 'recommend' functionality doens't make sense
as there is only one product variant. On such platforms the recommend
functionality can be disabled by adding/changing the following in
the global config (/etc/tuned/tuned-main.conf):
recommend_command = 0
Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
The verify command verifies whether the current system settings matches
activated profile. It also writes all settings from the active profile
with the current / expected values to the log. It is good for checking
what is exactly set and what changed during the run.
Currently custom commands and plugin_scheduler are not supported.
Resolves: rhbz#1150047
Fixes: #34
Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
Made tuned error messages less verbose, but more descriptive if running without
debug option. Also made class from the tuned.utils.commands helper functions.
Its logging can be enabled / disabled.
Resolves: rhbz#1068699
Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
GPL license does not require all files to have the copyright notice
and header. To save some space, I removed the headers from all files
except the executables and the main Python module.