From fe47baae9b1f6850fbd9991ff51d37bba6a0700b Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Thu, 12 May 2016 17:11:47 +0200 Subject: [PATCH] Avoid hardcoding version numbers in the settings The version number can be extracted from the package's filename. Change-Id: I0fd3cf86a3a299898027b5e6be07c6ec47e0271c --- .../elasticsearch_kibana/plugin_settings.py | 3 ++- stacklight_tests/helpers/helpers.py | 19 +++++++++++++++++++ .../influxdb_grafana/plugin_settings.py | 3 ++- .../lma_collector/plugin_settings.py | 3 ++- .../plugin_settings.py | 3 ++- 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/stacklight_tests/elasticsearch_kibana/plugin_settings.py b/stacklight_tests/elasticsearch_kibana/plugin_settings.py index f60703e..efe24a1 100644 --- a/stacklight_tests/elasticsearch_kibana/plugin_settings.py +++ b/stacklight_tests/elasticsearch_kibana/plugin_settings.py @@ -12,11 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. +from stacklight_tests.helpers import helpers from stacklight_tests import settings name = 'elasticsearch_kibana' -version = '0.9.0' role_name = ['elasticsearch_kibana'] vip_name = 'es_vip_mgmt' plugin_path = settings.ELASTICSEARCH_KIBANA_PLUGIN_PATH +version = helpers.get_plugin_version(plugin_path) diff --git a/stacklight_tests/helpers/helpers.py b/stacklight_tests/helpers/helpers.py index 103cc1b..b85036e 100644 --- a/stacklight_tests/helpers/helpers.py +++ b/stacklight_tests/helpers/helpers.py @@ -13,6 +13,7 @@ # under the License. import os +import re import time import urllib2 @@ -23,12 +24,30 @@ from proboscis import asserts from stacklight_tests import settings +PACKAGE_VERSION_RE = re.compile(r'(\d+\.\d+\.\d+)') + + def create_cluster( env, name, cluster_settings=None, mode=settings.DEPLOYMENT_MODE): return env.fuel_web.create_cluster( name=name, settings=cluster_settings, mode=mode) +def get_plugin_version(filename): + """Extract the plugin version from the package filename. + + :param filename: the plugin's filename. + :type filename: str + :returns: the plugin's version or None if not found + :rtype: str + """ + m = PACKAGE_VERSION_RE.search(filename) + if m: + return m.group(1) + else: + return None + + class PluginHelper(object): """Class for common help functions.""" diff --git a/stacklight_tests/influxdb_grafana/plugin_settings.py b/stacklight_tests/influxdb_grafana/plugin_settings.py index 24db337..e5c3b09 100644 --- a/stacklight_tests/influxdb_grafana/plugin_settings.py +++ b/stacklight_tests/influxdb_grafana/plugin_settings.py @@ -12,14 +12,15 @@ # License for the specific language governing permissions and limitations # under the License. +from stacklight_tests.helpers import helpers from stacklight_tests import settings name = 'influxdb_grafana' -version = '0.9.0' role_name = ['influxdb_grafana'] vip_name = 'influxdb' plugin_path = settings.INFLUXDB_GRAFANA_PLUGIN_PATH +version = helpers.get_plugin_version(plugin_path) influxdb_db_name = "lma" influxdb_user = 'influxdb' diff --git a/stacklight_tests/lma_collector/plugin_settings.py b/stacklight_tests/lma_collector/plugin_settings.py index d4ad252..6caacdb 100644 --- a/stacklight_tests/lma_collector/plugin_settings.py +++ b/stacklight_tests/lma_collector/plugin_settings.py @@ -12,14 +12,15 @@ # License for the specific language governing permissions and limitations # under the License. +from stacklight_tests.helpers import helpers from stacklight_tests import settings name = 'lma_collector' -version = '0.9.0' role_name = [] # NOTE(rpromyshlennikov): there is no role name # because lma collector is installed on all nodes in cluster plugin_path = settings.LMA_COLLECTOR_PLUGIN_PATH +version = helpers.get_plugin_version(plugin_path) options = { 'environment_label/value': 'deploy_lma_toolchain', diff --git a/stacklight_tests/lma_infrastructure_alerting/plugin_settings.py b/stacklight_tests/lma_infrastructure_alerting/plugin_settings.py index df1077c..074ebed 100644 --- a/stacklight_tests/lma_infrastructure_alerting/plugin_settings.py +++ b/stacklight_tests/lma_infrastructure_alerting/plugin_settings.py @@ -12,13 +12,14 @@ # License for the specific language governing permissions and limitations # under the License. +from stacklight_tests.helpers import helpers from stacklight_tests import settings name = 'lma_infrastructure_alerting' -version = '0.10.0' role_name = ['infrastructure_alerting'] vip_name = 'infrastructure_alerting_mgmt_vip' plugin_path = settings.LMA_INFRA_ALERTING_PLUGIN_PATH +version = helpers.get_plugin_version(plugin_path) nagios_user = 'nagiosadmin' nagios_password = 'r00tme'