From 0b5b77c974e80757a030bb633a64b78e073c86bb Mon Sep 17 00:00:00 2001 From: Doug Szumski Date: Thu, 2 May 2019 13:38:39 +0100 Subject: [PATCH] Remove deprecated YAML config This was marked for removal after the Pike release. Updating Docker file is leftover and will done in a separate change. Story: 2003180 Task: 23326 Change-Id: I583eab7b3ea2efd5d9bcd3ef433e68b49684e343 --- monasca_notification/conf/__init__.py | 84 ------- monasca_notification/conf/cli.py | 41 ---- monasca_notification/config.py | 16 +- .../drop-yaml-config-9eb8f5e68a40ba14.yaml | 6 + tests/base.py | 3 +- tests/test_config.py | 227 ------------------ 6 files changed, 8 insertions(+), 369 deletions(-) delete mode 100644 monasca_notification/conf/cli.py create mode 100644 releasenotes/notes/drop-yaml-config-9eb8f5e68a40ba14.yaml delete mode 100644 tests/test_config.py diff --git a/monasca_notification/conf/__init__.py b/monasca_notification/conf/__init__.py index 43f59f2..4f07b1e 100644 --- a/monasca_notification/conf/__init__.py +++ b/monasca_notification/conf/__init__.py @@ -19,7 +19,6 @@ from oslo_config import cfg from oslo_log import log from oslo_utils import importutils -from monasca_notification.conf import cli from monasca_notification.conf import database from monasca_notification.conf import kafka from monasca_notification.conf import keystone @@ -40,7 +39,6 @@ LOG = log.getLogger(__name__) CONF = cfg.CONF CONF_OPTS = [ - cli, database, kafka, keystone, @@ -81,88 +79,6 @@ def list_opts(): return _tupleize(opts) -def load_from_yaml(yaml_config, conf=None): - # build named BACKWARD_MAP to modules set_defaults - - if conf is None: - conf = CONF - - def _noop(*arg, **kwargs): - pass - - def _plain_override(g=None, **opts): - for k, v in opts.items(): - conf.set_override(group=g, name=k, override=v) - - def _load_plugin_settings(**notifiers_cfg): - notifiers_cfg = {t.lower(): v for t, v in notifiers_cfg.items()} - enabled_plugins = notifiers_cfg.pop('plugins', []) - - _plain_override(g='notification_types', enabled=enabled_plugins) - if not enabled_plugins: - return - - for ep in enabled_plugins: - ep_module = importutils.import_module(ep.split(':')[0]) - ep_clazz = importutils.import_class(ep.replace(':', '.')) - - if not hasattr(ep_module, 'register_opts'): - LOG.debug('%s does not have \'register_opts\' method') - continue - if not hasattr(ep_clazz, 'type'): - LOG.debug('%s does not have \'type\' class variable') - continue - - ep_r_opt = getattr(ep_module, 'register_opts') - ep_type = getattr(ep_clazz, 'type') - - ep_r_opt(conf) # register options - _plain_override(g='%s_notifier' % ep_type, - **notifiers_cfg.get(ep_type)) - - LOG.debug('Registered options and values of the %s notifier', - ep_type) - - def _configure_and_warn_the_logging(logging_config): - LOG.warning('Configuration of the logging system from ' - '\'notification.yml\' has been deprecated and ' - 'Please check how to configure logging with ' - 'oslo.log library.') - import logging.config - logging.config.dictConfig(logging_config) - - mappper = { - 'statsd': [lambda d: _plain_override(g='statsd', **d)], - 'retry': [lambda d: _plain_override(g='retry_engine', **d)], - 'database': [ - lambda d: _plain_override(g='database', repo_driver=d['repo_driver']), - lambda d: _plain_override(g='orm', url=d['orm']['url']) - ], - 'postgresql': [lambda d: _plain_override(g='postgresql', **d)], - 'mysql': [lambda d: _plain_override(g='mysql', **d)], - 'processors': [ - lambda d: _plain_override(g='alarm_processor', - number=d['alarm']['number'], - ttl=d['alarm']['ttl']), - lambda d: _plain_override(g='notification_processor', - number=d['notification']['number']) - ], - 'queues': [lambda d: _plain_override(g='queues', **d)], - 'kafka': [lambda d: _plain_override(g='kafka', **d)], - 'keystone': [lambda d: _plain_override(g='keystone', **d)], - 'zookeeper': [lambda d: _plain_override(g='zookeeper', **d)], - 'notification_types': [lambda d: _load_plugin_settings(**d)], - 'logging': [_configure_and_warn_the_logging] - } - - for key, opts in yaml_config.items(): - LOG.debug('Loading group %s from deprecated yaml configuration', key) - handlers = mappper.get(key, [_noop]) - if len(handlers) == 1 and handlers[0] == _noop: - LOG.warning('Unmapped configuration group %s from YAML file', key) - [handler(opts) for handler in handlers] - - def _tupleize(d): """Convert a dict of options to the 2-tuple format.""" return [(key, value) for key, value in d.items()] diff --git a/monasca_notification/conf/cli.py b/monasca_notification/conf/cli.py deleted file mode 100644 index 57ab741..0000000 --- a/monasca_notification/conf/cli.py +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright 2017 FUJITSU LIMITED -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from oslo_config import cfg - -cli_opts = [ - cfg.StrOpt(name='yaml_config', default=None, - positional=True, - help='Backward compatible option that allows to pass path ' - 'to YAML file containing configuration ' - 'of monasca-notitifcation.', - deprecated_for_removal=True, - deprecated_since='1.9.0', - deprecated_reason='monasca-notification has moved to ' - 'oslo.conf henceusing YAML based ' - 'configuration will be removed ' - 'after PIKE release.', - required=False) -] - - -def register_opts(conf): - for opt in cli_opts: - conf.register_cli_opt(opt=opt) - - -def list_opts(): - return { - 'default': cli_opts - } diff --git a/monasca_notification/config.py b/monasca_notification/config.py index 2d7d5df..d7e31c2 100644 --- a/monasca_notification/config.py +++ b/monasca_notification/config.py @@ -15,7 +15,6 @@ from oslo_config import cfg from oslo_log import log import sys -import yaml from monasca_notification import conf from monasca_notification import version @@ -25,7 +24,7 @@ CONF = conf.CONF _CONF_LOADED = False -def parse_args(argv, no_yaml=False): +def parse_args(argv): """Sets up configuration of monasca-notification.""" global _CONF_LOADED @@ -55,11 +54,6 @@ def parse_args(argv, no_yaml=False): product_name='monasca-notification', version=version.version_string) - if not no_yaml: - # note(trebskit) used only in test cases as the notification.yml - # will be dropped eventually - set_from_yaml() - _CONF_LOADED = True @@ -80,11 +74,3 @@ def _get_config_files(): 'of main configuration file'.format(old_conf_files)) conf_files += old_conf_files return conf_files - - -def set_from_yaml(): - if CONF.yaml_config: - LOG.info('Detected usage of deprecated YAML configuration') - with open(CONF.yaml_config, 'rb') as ycf: - yaml_cfg = yaml.safe_load(ycf.read()) - conf.load_from_yaml(yaml_cfg) diff --git a/releasenotes/notes/drop-yaml-config-9eb8f5e68a40ba14.yaml b/releasenotes/notes/drop-yaml-config-9eb8f5e68a40ba14.yaml new file mode 100644 index 0000000..22ed04d --- /dev/null +++ b/releasenotes/notes/drop-yaml-config-9eb8f5e68a40ba14.yaml @@ -0,0 +1,6 @@ +--- +upgrade: + - | + Support for YAML configuration file has been removed. Last release of + monasca-notification to support YAML configuration is OpenStack Train. + Please use oslo.config configuration file instead. diff --git a/tests/base.py b/tests/base.py index 944ee59..7397c8c 100644 --- a/tests/base.py +++ b/tests/base.py @@ -45,8 +45,7 @@ class ConfigFixture(oo_cfg.Config): self.addCleanup(self._clean_config_loaded_flag) conf.register_opts() - # prevent test from trying to load the yaml file - config.parse_args(argv=[], no_yaml=True) + config.parse_args(argv=[]) @staticmethod def _clean_config_loaded_flag(): diff --git a/tests/test_config.py b/tests/test_config.py deleted file mode 100644 index c9095bf..0000000 --- a/tests/test_config.py +++ /dev/null @@ -1,227 +0,0 @@ -# Copyright 2017 FUJITSU LIMITED -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from unittest import mock - -from oslo_config import cfg -from oslo_utils import importutils -import yaml - -from monasca_notification import conf -from monasca_notification import config -from tests import base - - -class TestConfig(base.BaseTestCase): - @mock.patch('monasca_notification.config.conf') - def test_should_load_deprecated_yaml(self, conf): - fake_config = """ - sayians: - - goku - - vegeta - """ - yaml_config = self.create_tempfiles( - files=[('notification', fake_config)], - ext='.yml' - )[0] - - self.conf_override(yaml_config=yaml_config) - - config.set_from_yaml() - - fake_yaml_config = { - 'sayians': ['goku', 'vegeta'] - } - conf.load_from_yaml.assert_called_once_with(fake_yaml_config) - - @mock.patch('monasca_notification.config.conf') - def test_should_not_load_deprecated_yaml(self, conf): - config.set_from_yaml() - conf.load_from_yaml.assert_not_called() - - -class TestYamlOverriding(base.BaseTestCase): - # TOP_LEVEL keys represents old groups in YAML file - VERIFIERS = { - 'statsd': { - 'groups': [ - ('statsd', { - 'host': 'localhost', - 'port': 8125 - }) - ] - }, - 'retry': { - 'groups': [ - ('retry_engine', { - 'interval': 300, - 'max_attempts': 500 - }) - ] - }, - 'queues': { - 'groups': [ - ('queues', { - 'alarms_size': 1024, - 'finished_size': 1024, - 'notifications_size': 1024, - 'sent_notifications_size': 1024 - }) - ] - }, - 'zookeeper': { - 'groups': [ - ('zookeeper', { - 'url': ['127.0.0.1:2181'], - 'notification_path': '/foo/bar', - 'periodic_path': { - 666: '/bu/666_bubu' - }, - }) - ] - }, - 'kafka': { - 'groups': [ - ('kafka', { - 'url': ['127.0.0.1:9092'], - 'group': 'a', - 'alarm_topic': 'b', - 'notification_topic': 'c', - 'notification_retry_topic': 'd', - 'periodic': { - 60: 'e' - }, - 'max_offset_lag': 666 - }) - ] - }, - 'processors': { - 'groups': [ - ('alarm_processor', {'number': 666, 'ttl': 666}), - ('notification_processor', {'number': 666}) - ] - }, - 'postgresql': { - 'groups': [ - ('postgresql', { - 'host': '100.10.100.10', - 'port': 9999, - 'user': 'goku', - 'password': 'kame-ha-me-ha', - 'database': 'planet_vegeta' - }) - ] - }, - 'mysql': { - 'groups': [ - ('mysql', { - 'host': '100.99.100.99', - 'port': 3306, - 'user': 'goku', - 'passwd': 'kame-ha-me-ha', - 'db': 'planet_vegeta', - 'ssl': {} - }) - ] - }, - 'database': { - 'groups': [ - ('database', {'repo_driver': importutils.import_class( - 'monasca_notification.common.repositories.mysql.' - 'mysql_repo.MysqlRepo')}), - ('orm', {'url': 'postgres://a:b@127.0.0.1:9999/goo'}) - ] - }, - 'notification_types': { - 'groups': [ - ('notification_types', { - 'enabled': [ - 'monasca_notification.plugins.hipchat_notifier:HipChatNotifier', - 'monasca_notification.plugins.slack_notifier:SlackNotifier', - 'monasca_notification.plugins.jira_notifier:JiraNotifier', - 'monasca_notification.plugins.email_notifier:EmailNotifier', - 'monasca_notification.plugins.pagerduty_notifier:PagerdutyNotifier', - 'monasca_notification.plugins.webhook_notifier:WebhookNotifier', - ] - }), - ('email_notifier', { - 'server': '127.0.0.1', - 'port': 25, - 'user': None, - 'password': None, - 'timeout': 60, - 'from_addr': 'root@localhost', - 'grafana_url': 'http://127.0.0.1:3000' - }), - ('webhook_notifier', {'timeout': 123}), - ('pagerduty_notifier', { - 'timeout': 231, - 'url': 'https://a.b.c/d/e/f.json' - }), - ('hipchat_notifier', { - 'timeout': 512, - 'ca_certs': "/a.crt", - 'insecure': True, - 'proxy': 'https://myproxy.corp.invalid:9999' - }), - ('slack_notifier', { - 'timeout': 512, - 'ca_certs': "/a.crt", - 'insecure': True, - 'proxy': 'https://myproxy.corp.invalid:9999' - }), - ('jira_notifier', { - 'user': 'username', - 'password': 'password', - 'timeout': 666, - 'custom_formatter': '/some_yml.yml', - 'proxy': 'www.example.org' - }) - ] - } - } - - def setUp(self): - super(TestYamlOverriding, self).setUp() - self.yaml_config = yaml.safe_load( - open('tests/resources/notification.yaml', 'rb') - ) - - def test_overriding(self): - - conf.load_from_yaml(yaml_config=self.yaml_config, conf=config.CONF) - opts = config.CONF - - for group in self.VERIFIERS.keys(): - verifier_details = self.VERIFIERS[group] - groups = verifier_details['groups'] - - for opt_group, opt_values in groups: - - for key, value in opt_values.items(): - try: - opt_value = opts[opt_group][key] - except (cfg.NoSuchOptError, cfg.NoSuchGroupError) as ex: - self.fail(str(ex)) - else: - msg = ('%s not overridden in group %s' - % (key, opt_group)) - - if (isinstance(value, list) and - isinstance(opt_value, list)): - for v in value: - self.assertIn(v, opt_value, msg) - continue - - self.assertEqual(value, opt_value, msg)