Yeela Kaplan has uploaded a new change for review.
Change subject: [WIP]configurators: move configurator functions into conf_utils ......................................................................
[WIP]configurators: move configurator functions into conf_utils
Change-Id: Id67a0f51adb2d543c0542a48c020d34a13d1f2ed Signed-off-by: Yeela Kaplan ykaplan@redhat.com --- M lib/vdsm/tool/Makefile.am A lib/vdsm/tool/conf_utils.py M vdsm.spec.in 3 files changed, 110 insertions(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/86/44286/1
diff --git a/lib/vdsm/tool/Makefile.am b/lib/vdsm/tool/Makefile.am index c8979ca..c3ed0cc 100644 --- a/lib/vdsm/tool/Makefile.am +++ b/lib/vdsm/tool/Makefile.am @@ -35,7 +35,8 @@ dump_bonding_defaults.py \ dump_volume_chains.py \ nwfilter.py \ - configfile.py \ + conf_utils.py \ + configfile.py \ configurator.py \ register.py \ restore_nets.py \ diff --git a/lib/vdsm/tool/conf_utils.py b/lib/vdsm/tool/conf_utils.py new file mode 100644 index 0000000..1308097 --- /dev/null +++ b/lib/vdsm/tool/conf_utils.py @@ -0,0 +1,107 @@ +# Copyright 2015 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Refer to the README and COPYING files for full details of the license +# +import os + +from .. configfile import ( + ConfigFile, +) + +from ... import utils + +if utils.isOvirtNode(): + from ovirt.node.utils.fs import Config as NodeCfg + + +def get_file(fname, files): + return files[fname]['path'] + + +def remove_conf(files, version): + for cfile, content in files.items(): + content['removeConf'](content['path'], version) + + +def add_section(content, version, vdsmConfiguration={}): + """ + Add a 'configuration section by vdsm' part to a config file. + This section contains only keys not originally defined + The section headers will include the current configuration version. + """ + configuration = {} + for fragment in content['fragments']: + if vdsmConfiguration: + if is_applicable(fragment, vdsmConfiguration): + configuration.update(fragment['content']) + else: + configuration.update(fragment['content']) + if configuration: + with open_config(content['path'], version) as conff: + for key, val in configuration.items(): + conff.addEntry(key, val) + + +def remove_section(path, version): + """ + remove entire 'configuration section by vdsm' section. + section is removed regardless of it's version. + """ + if os.path.exists(path): + with open_config(path, version) as conff: + conff.removeConf() + + +def remove_file(content, vdsmConfiguration): + """ + delete a file if it exists. + """ + if utils.isOvirtNode(): + NodeCfg().delete(content['path']) + else: + try: + os.unlink(content['path']) + except OSError as e: + if e.errno != errno.ENOENT: + raise + + +def get_persisted_files(files): + """ + get files where vdsm is expected to add a section. + """ + return [ + cfile['path'] for cfile in files.values() + if cfile['persisted'] + ] + + +def open_config(path, conf_version): + return ConfigFile(path, conf_version) + + +def is_applicable(fragment, vdsmConfiguration): + """ + Return true if 'fragment' should be included for current + configuration. An applicable fragment is a fragment who's list + of conditions are met according to vdsmConfiguration. + """ + applyFragment = True + for key, booleanValue in fragment['conditions'].items(): + if vdsmConfiguration[key] != booleanValue: + applyFragment = False + return applyFragment diff --git a/vdsm.spec.in b/vdsm.spec.in index 5020d8b..21e1b50 100644 --- a/vdsm.spec.in +++ b/vdsm.spec.in @@ -1094,6 +1094,7 @@ %{python_sitelib}/%{vdsm_name}/tool/dummybr.py* %{python_sitelib}/%{vdsm_name}/tool/dump_bonding_defaults.py* %{python_sitelib}/%{vdsm_name}/tool/nwfilter.py* +%{python_sitelib}/%{vdsm_name}/tool/conf_utils.py* %{python_sitelib}/%{vdsm_name}/tool/configurator.py* %{python_sitelib}/%{vdsm_name}/tool/configurators/__init__* %{python_sitelib}/%{vdsm_name}/tool/configurators/certificates.py*
automation@ovirt.org has posted comments on this change.
Change subject: [WIP]configurators: move configurator functions into conf_utils ......................................................................
Patch Set 1:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
From Yaniv Bronhaim ybronhei@redhat.com:
Yaniv Bronhaim has restored this change.
Change subject: [WIP]configurators: move configurator functions into conf_utils ......................................................................
Restored
From Yaniv Bronhaim ybronhei@redhat.com:
Yaniv Bronhaim has posted comments on this change.
Change subject: configurators: move configurator functions into conf_utils ......................................................................
Patch Set 4:
(2 comments)
https://gerrit.ovirt.org/#/c/44286/4//COMMIT_MSG Commit Message:
PS4, Line 7: configurators
please provide more details
it only moves code to make it public
https://gerrit.ovirt.org/#/c/44286/4/lib/vdsm/tool/conf_utils.py File lib/vdsm/tool/conf_utils.py:
Line 21: import os Line 22: Line 23: from vdsm.tool.configfile import ConfigFile Line 24: Line 25:
please add some explanation on how conf files are represented - it's hard t
I don't make a util here.. this should be done separately maybe. this patch is about moving code so I'll be able to use it in following patch Line 26: def get_file(fname, files): Line 27: return files[fname]['path'] Line 28: Line 29:
From Yaniv Bronhaim ybronhei@redhat.com:
Yaniv Bronhaim has posted comments on this change.
Change subject: Add confutil to manage properties files easily ......................................................................
Patch Set 9: Verified+1
From Yaniv Bronhaim ybronhei@redhat.com:
Yaniv Bronhaim has posted comments on this change.
Change subject: Add confutil to manage properties files easily ......................................................................
Patch Set 13:
(1 comment)
https://gerrit.ovirt.org/#/c/44286/13/lib/vdsm/tool/confutils.py File lib/vdsm/tool/confutils.py:
PS13, Line 66: if vdsmConfiguration:
Do we need this check? From the code it looks like we use is_applicable to
just moved the code in this patch. but I guess this here to avoid calling is_applicable if vdsmConfiguration is empty, in your suggestion I'll need to change also is_applicable to check for keyError exception
From Dan Kenigsberg danken@redhat.com:
Dan Kenigsberg has submitted this change and it was merged.
Change subject: Add confutil to manage properties files easily ......................................................................
Add confutil to manage properties files easily
In addition to confmeta [1], this util allows easy to manage files in the format of
key = value key2 = value ..
This uses configfile and add functionality for easy add and remove sections inside the file.
Those function moved from libvirt configurator and are not introduced in this patch. configurators/libvirt.py was the first usage until abrt.conf. For later configurators this util might be useful.
See internal comments to understand usages.
[1] https://gerrit.ovirt.org/70583
Related-To: https://bugzilla.redhat.com/917062 Change-Id: Id67a0f51adb2d543c0542a48c020d34a13d1f2ed Signed-off-by: Yeela Kaplan ykaplan@redhat.com Signed-off-by: Yaniv Bronhaim ybronhei@redhat.com --- M lib/vdsm/tool/Makefile.am M lib/vdsm/tool/configurators/libvirt.py A lib/vdsm/tool/confutils.py M vdsm.spec.in 4 files changed, 145 insertions(+), 91 deletions(-)
Approvals: Piotr Kliczewski: Looks good to me, approved Yaniv Bronhaim: Verified Jenkins CI: Passed CI tests Irit Goihman: Looks good to me, but someone else must approve
vdsm-patches@lists.fedorahosted.org