1
0
Fork 0

Merge pull request #26 from olysonek/profile_dir_func

Introduce ${i:PROFILE_DIR} function
This commit is contained in:
Jaroslav Škarvada 2017-03-14 21:15:22 +01:00 committed by GitHub
commit 893024a66a
15 changed files with 22 additions and 30 deletions

View file

@ -37,7 +37,7 @@ cpu_affinity=${not_isolated_cores_expanded}
[script]
priority=5
script=script.sh
script=${i:PROFILE_DIR}/script.sh
[bootloader]
priority=10

View file

@ -7,4 +7,4 @@ summary=Optimize for laptop with power savings
include=desktop-powersave
[script]
script=script.sh
script=${i:PROFILE_DIR}/script.sh

View file

@ -36,4 +36,4 @@ vm.dirty_writeback_centisecs=1500
kernel.nmi_watchdog=0
[script]
script=script.sh
script=${i:PROFILE_DIR}/script.sh

View file

@ -16,7 +16,7 @@ isolated_cores_present_expanded=${f:cpulist_present:${isolated_cores}}
assert=${f:assertion:isolated_cores contains present CPU(s):${isolated_cores_expanded}:${isolated_cores_present_expanded}}
[script]
script=script.sh
script=${i:PROFILE_DIR}/script.sh
[bootloader]
cmdline=isolcpus=${isolated_cores} nohz=on nohz_full=${isolated_cores} rcu_nocbs=${isolated_cores} intel_pstate=disable nosoftlockup

View file

@ -44,7 +44,7 @@ group.rcuc=0:f:3:*:rcuc.*
group.rcub=0:f:3:*:rcub.*
[script]
script=script.sh
script=${i:PROFILE_DIR}/script.sh
[bootloader]
cmdline=isolcpus=${isolated_cores} nohz=on nohz_full=${isolated_cores} rcu_nocbs=${isolated_cores} intel_pstate=disable nosoftlockup

View file

@ -38,4 +38,4 @@ kernel.timer_migration = 0
cmdline=isolcpus=${isolated_cores} intel_pstate=disable nosoftlockup
[script]
script = script.sh
script = ${i:PROFILE_DIR}/script.sh

View file

@ -18,4 +18,4 @@ kernel.sem = 1250 256000 100 8192
kernel.numa_balancing = 0
[script]
script=script.sh
script=${i:PROFILE_DIR}/script.sh

View file

@ -11,4 +11,4 @@ kernel.sem = 1250 256000 100 8192
vm.max_map_count = 2000000
[script]
script=script.sh
script=${i:PROFILE_DIR}/script.sh

View file

@ -34,4 +34,4 @@ vm.laptop_mode=5
vm.swappiness=30
[script]
script=script.sh
script=${i:PROFILE_DIR}/script.sh

View file

@ -12,7 +12,6 @@ DEFAULT_STORAGE_FILE = "/run/tuned/save.pickle"
LOAD_DIRECTORIES = ["/usr/lib/tuned", "/etc/tuned"]
PERSISTENT_STORAGE_DIR = "/var/lib/tuned"
PLUGIN_MAIN_UNIT_NAME = "main"
PLUGIN_WORKDIR_OPTION_NAME = "workdir"
TMP_FILE_SUFFIX = ".tmp"
# max. number of consecutive errors to give up

View file

@ -81,13 +81,13 @@ class Plugin(object):
# Interface for manipulation with instances of the plugin.
#
def create_instance(self, name, devices_expression, devices_udev_regex, workdir, options):
def create_instance(self, name, devices_expression, devices_udev_regex, options):
"""Create new instance of the plugin and seize the devices."""
if name in self._instances:
raise Exception("Plugin instance with name '%s' already exists." % name)
effective_options = self._get_effective_options(options)
instance = self._instance_factory.create(self, name, devices_expression, devices_udev_regex, workdir, effective_options)
instance = self._instance_factory.create(self, name, devices_expression, devices_udev_regex, effective_options)
self._instances[name] = instance
return instance

View file

@ -2,12 +2,11 @@ class Instance(object):
"""
"""
def __init__(self, plugin, name, devices_expression, devices_udev_regex, workdir, options):
def __init__(self, plugin, name, devices_expression, devices_udev_regex, options):
self._plugin = plugin
self._name = name
self._devices_expression = devices_expression
self._devices_udev_regex = devices_udev_regex
self._workdir = workdir
self._options = options
self._active = True
@ -46,10 +45,6 @@ class Instance(object):
def devices_udev_regex(self):
return self._devices_udev_regex
@property
def workdir(self):
return self._workdir
@property
def options(self):
return self._options

View file

@ -34,7 +34,6 @@ class BootloaderPlugin(base.Plugin):
self._initrd_dst_img_val = None
self._cmdline_val = ""
self._initrd_val = ""
self._workdir = instance.workdir
self._grub2_cfg_file_name = self._get_grub2_cfg_file()
def _instance_cleanup(self, instance):
@ -185,11 +184,6 @@ class BootloaderPlugin(base.Plugin):
self.update_grub2_cfg = True
self._initrd_val = "/" + img_name
def _build_abs_path(self, path):
if path is None or len(path) == 0 or path[0] == "/":
return path
return os.path.normpath(os.path.join(self._workdir, path))
@command_custom("grub2_cfg_file")
def _grub2_cfg_file(self, enabling, value, verify, ignore_missing):
# nothing to verify
@ -228,7 +222,6 @@ class BootloaderPlugin(base.Plugin):
self._init_initrd_dst_img(src_img)
if src_img == "":
return False
src_img = self._build_abs_path(src_img)
self._install_initrd(src_img)
@command_custom("initrd_add_dir", per_device = False, priority = 10)
@ -241,7 +234,6 @@ class BootloaderPlugin(base.Plugin):
self._init_initrd_dst_img(src_dir)
if src_dir == "":
return False
src_dir = self._build_abs_path(src_dir)
if not os.path.isdir(src_dir):
log.error("error: cannot create initrd image, source directory '%s' doesn't exist" % src_dir)
return False

View file

@ -74,6 +74,9 @@ class Loader(object):
profiles.append(profile)
def _expand_profile_dir(self, profile_dir, string):
return re.sub(r'(?<!\\)\$\{i:PROFILE_DIR\}', profile_dir, string)
def _load_config_data(self, file_name):
try:
config_obj = ConfigObj(file_name, raise_errors = True, list_values = False, interpolation = False)
@ -93,13 +96,16 @@ class Loader(object):
for option in keys:
config[section][option] = config_obj[section][option]
# TODO: HACK, this needs to be solved in a better way (better config parser)
dir_name = os.path.dirname(file_name)
# TODO: Could we do this in the same place as the expansion of other functions?
for section in config:
for option in config[section]:
config[section][option] = self._expand_profile_dir(dir_name, config[section][option])
# TODO: HACK, this needs to be solved in a better way (better config parser)
for unit_name in config:
if "script" in config[unit_name] and config[unit_name].get("script", None) is not None:
script_path = os.path.join(dir_name, config[unit_name]["script"])
config[unit_name]["script"] = [os.path.normpath(script_path)]
if config[unit_name].get(consts.PLUGIN_WORKDIR_OPTION_NAME, None) is None:
config[unit_name][consts.PLUGIN_WORKDIR_OPTION_NAME] = dir_name
return config

View file

@ -64,7 +64,7 @@ class Manager(object):
continue
log.debug("creating '%s' (%s)" % (instance_info.name, instance_info.type))
new_instance = plugin.create_instance(instance_info.name, instance_info.devices, instance_info.devices_udev_regex, \
instance_info.options.pop(consts.PLUGIN_WORKDIR_OPTION_NAME, "."), instance_info.options)
instance_info.options)
plugin.assign_free_devices(new_instance)
plugin.initialize_instance(new_instance)
self._instances.append(new_instance)