From 850ec0a7acad96a913798b8a577390df0769fb7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= Date: Fri, 17 Aug 2018 17:26:44 +0200 Subject: [PATCH] FIXME: Use SettingPlugin to register config files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /* Incomplete version, the missing pieces are: * 1. fix symlinks location * 2. make sure LTS works well (disable vt_settings on LTS) */ Recently Avocado introduced a SettingPlugin, that allows Avocado plugins to register/modify paths to be processed by "avocado.core.settings". Let's use this instead of symlinking of our etc config files. For now we also have to keep the symlinking because the avocado 52.x (LTS) does not support this feature. Signed-off-by: Lukáš Doktor --- Makefile | 9 ++--- {etc/avocado => avocado_vt}/conf.d/vt.conf | 0 .../conf.d/vt_joblock.conf | 0 avocado_vt/plugins/vt_settings.py | 33 +++++++++++++++++++ setup.py | 7 ++-- 5 files changed, 43 insertions(+), 6 deletions(-) rename {etc/avocado => avocado_vt}/conf.d/vt.conf (100%) rename {etc/avocado => avocado_vt}/conf.d/vt_joblock.conf (100%) create mode 100644 avocado_vt/plugins/vt_settings.py diff --git a/Makefile b/Makefile index 5a4bcc0d073..2eb145ad815 100644 --- a/Makefile +++ b/Makefile @@ -57,14 +57,15 @@ develop: $(PYTHON) setup.py develop $(PYTHON_DEVELOP_ARGS) link: develop - for CONF in etc/avocado/conf.d/*; do\ - [ -d "../$(AVOCADO_DIRNAME)/avocado/etc/avocado/conf.d" ] && ln -srf $(CURDIR)/$$CONF ../$(AVOCADO_DIRNAME)/avocado/$$CONF || true;\ - [ -d "../$(AVOCADO_DIRNAME)/etc/avocado/conf.d" ] && ln -srf $(CURDIR)/$$CONF ../$(AVOCADO_DIRNAME)/$$CONF || true;\ + for NAME in $$(ls -1 avocado_vt/conf.d); do\ + [ -d "../$(AVOCADO_DIRNAME)/avocado/etc/avocado/conf.d" ] && ln -srf $(CURDIR)/avocado_vt/conf.d/$$NAME ../$(AVOCADO_DIRNAME)/avocado/etc/avocado/conf.d/$$NAME || true;\ + [ -d "../$(AVOCADO_DIRNAME)/etc/avocado/conf.d" ] && ln -srf $(CURDIR)/avocado_vt/conf.d/$$NAME ../$(AVOCADO_DIRNAME)/avocado/etc/avocado/conf.d/$$NAME || true;\ done unlink: $(PYTHON) setup.py develop --uninstall $(PYTHON_DEVELOP_ARGS) - for CONF in etc/avocado/conf.d/*; do\ + for NAME in $$(ls -1 avocado_vt/conf.d); do\ + CONF="etc/avocado/conf.d/$$NAME";\ [ -L ../$(AVOCADO_DIRNAME)/avocado/$$CONF ] && rm -f ../$(AVOCADO_DIRNAME)/avocado/$$CONF || true;\ [ -L ../$(AVOCADO_DIRNAME)/$$CONF ] && rm -f ../$(AVOCADO_DIRNAME)/$$CONF || true;\ done diff --git a/etc/avocado/conf.d/vt.conf b/avocado_vt/conf.d/vt.conf similarity index 100% rename from etc/avocado/conf.d/vt.conf rename to avocado_vt/conf.d/vt.conf diff --git a/etc/avocado/conf.d/vt_joblock.conf b/avocado_vt/conf.d/vt_joblock.conf similarity index 100% rename from etc/avocado/conf.d/vt_joblock.conf rename to avocado_vt/conf.d/vt_joblock.conf diff --git a/avocado_vt/plugins/vt_settings.py b/avocado_vt/plugins/vt_settings.py new file mode 100644 index 00000000000..165bc8bfa65 --- /dev/null +++ b/avocado_vt/plugins/vt_settings.py @@ -0,0 +1,33 @@ +# 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 LICENSE for more details. +# +# Copyright: Red Hat Inc. 2018 +# Author: Lukas Doktor + +""" +Avocado plugin that extends the settings path of our config paths +""" + +import os +from pkg_resources import resource_filename +from pkg_resources import resource_isdir +from pkg_resources import resource_listdir + +from avocado.core.plugin_interfaces import Settings + + +class VTSettings(Settings): + def adjust_settings_paths(self, paths): + base = resource_filename('avocado_vt', 'conf.d') + paths.extend([os.path.join(base, conf) + for conf in resource_listdir('avocado_vt', 'conf.d') + if conf.endswith('.conf')]) + diff --git a/setup.py b/setup.py index 658e79e01c3..7e5fb329250 100644 --- a/setup.py +++ b/setup.py @@ -81,14 +81,14 @@ def pre_post_plugin_type(): if __name__ == "__main__": requirements = ["netifaces", "aexpect", "netaddr", "simplejson"] if sys.version_info[:2] >= (2, 7): - requirements.append("avocado-framework") + requirements.append("avocado-framework>=68.0") else: # Latest py2 supported stevedore is 1.10.0, need to limit it here # as older avocado versions were not limiting it. # Note: Avocado 70+ doesn't require stevedore and older Avocado # can use whatever version of stevedore on py3 requirements.append("stevedore>=1.8.0,<=1.10.0") - requirements.append("avocado-framework<70.0") + requirements.append("avocado-framework>=68.0,<70.0") setup(name='avocado-framework-plugins-vt', version=VERSION, @@ -100,6 +100,9 @@ def pre_post_plugin_type(): package_data={"virttest": ["*.*"]}, data_files=get_data_files(), entry_points={ + 'avocado.plugins.settings': [ + 'vt-settings = avocado_vt.plugins.vt_settings:VTSettings', + ], 'avocado.plugins.cli': [ 'vt-list = avocado_vt.plugins.vt_list:VTLister', 'vt = avocado_vt.plugins.vt:VTRun',