From 4188c40bebe1ab50e7b029584ab8a0fee8d5725e Mon Sep 17 00:00:00 2001 From: ricolin Date: Thu, 14 Jan 2016 09:45:14 +0800 Subject: [PATCH] Remove warnings in heat Use warning in oslo_log instead. Change-Id: I7c2cfe3cbd7ac8b1a5870cd53633342c5622ef0b --- bin/heat-api | 13 +++++++++---- bin/heat-api-cfn | 13 +++++++++---- bin/heat-api-cloudwatch | 13 +++++++++---- bin/heat-engine | 13 +++++++++---- bin/heat-manage | 11 ++++++++--- heat/engine/constraints.py | 9 ++++++--- heat/engine/environment.py | 3 +-- heat/engine/rsrc_defn.py | 15 ++++++++------- heat/engine/service.py | 12 +++++------- heat/tests/test_constraints.py | 17 ----------------- heat/tests/test_rsrc_defn.py | 16 +++------------- 11 files changed, 67 insertions(+), 68 deletions(-) diff --git a/bin/heat-api b/bin/heat-api index f08228f137..85dafb2bfa 100755 --- a/bin/heat-api +++ b/bin/heat-api @@ -18,10 +18,15 @@ An OpenStack REST API to Heat. """ -import warnings -warnings.warn("DEPRECATED: This script is deprecated. Please use the " - "system level heat binaries installed to start " - "any of the heat services.", DeprecationWarning) +from oslo_log import log as logging + +from heat.common.i18n import _LW + +LOG = logging.getLogger(__name__) + +LOG.warning(_LW('DEPRECATED: `heat-api` script is deprecated. Please use the ' + 'system level heat binaries installed to start ' + 'any of the heat services.')) import os import sys diff --git a/bin/heat-api-cfn b/bin/heat-api-cfn index 8e6571c680..810f1184d1 100755 --- a/bin/heat-api-cfn +++ b/bin/heat-api-cfn @@ -20,10 +20,15 @@ translates it into a native representation. It then calls the heat-engine via AMQP RPC to implement them. """ -import warnings -warnings.warn("DEPRECATED: This script is deprecated. Please use the " - "system level heat binaries installed to start " - "any of the heat services.", DeprecationWarning) +from oslo_log import log as logging + +from heat.common.i18n import _LW + +LOG = logging.getLogger(__name__) + +LOG.warning(_LW('DEPRECATED: `heat-api-cfn` script is deprecated. Please use ' + 'the system level heat binaries installed to start ' + 'any of the heat services.')) import os import sys diff --git a/bin/heat-api-cloudwatch b/bin/heat-api-cloudwatch index 2cd5dcaf0e..01c55ee04a 100755 --- a/bin/heat-api-cloudwatch +++ b/bin/heat-api-cloudwatch @@ -20,10 +20,15 @@ into a native representation. It then calls the heat-engine via AMQP RPC to implement them. """ -import warnings -warnings.warn("DEPRECATED: This script is deprecated. Please use the " - "system level heat binaries installed to start " - "any of the heat services.", DeprecationWarning) +from oslo_log import log as logging + +from heat.common.i18n import _LW + +LOG = logging.getLogger(__name__) + +LOG.warning(_LW('DEPRECATED: `heat-api-cloudwatch` script is deprecated. ' + 'Please use the system level heat binaries installed to ' + 'start any of the heat services.')) import os import sys diff --git a/bin/heat-engine b/bin/heat-engine index 9f1c577c86..f4d9cb0bcc 100755 --- a/bin/heat-engine +++ b/bin/heat-engine @@ -20,10 +20,15 @@ Normal communications is done via the heat API which then calls into this engine. """ -import warnings -warnings.warn("DEPRECATED: This script is deprecated. Please use the " - "system level heat binaries installed to start " - "any of the heat services.", DeprecationWarning) +from oslo_log import log as logging + +from heat.common.i18n import _LW + +LOG = logging.getLogger(__name__) + +LOG.warning(_LW('DEPRECATED: `heat-engine` script is deprecated. ' + 'Please use the system level heat binaries installed to ' + 'start any of the heat services.')) import os import sys diff --git a/bin/heat-manage b/bin/heat-manage index 3a7f42f576..ccf970d970 100755 --- a/bin/heat-manage +++ b/bin/heat-manage @@ -13,9 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -import warnings -warnings.warn("DEPRECATED: This script is deprecated. Please use the " - "system level heat-manage binary", DeprecationWarning) +from oslo_log import log as logging + +from heat.common.i18n import _LW + +LOG = logging.getLogger(__name__) + +LOG.warning(_LW('DEPRECATED: `heat-manage` script is deprecated. Please use ' + 'the system level heat-manage binary.')) import os import sys diff --git a/heat/engine/constraints.py b/heat/engine/constraints.py index f5a61e8762..619a52872b 100644 --- a/heat/engine/constraints.py +++ b/heat/engine/constraints.py @@ -14,16 +14,17 @@ import collections import numbers import re -import warnings from oslo_cache import core from oslo_config import cfg +from oslo_log import log from oslo_utils import strutils import six from heat.common import cache from heat.common import exception from heat.common.i18n import _ +from heat.common.i18n import _LW from heat.engine import resources # decorator that allows to cache the value @@ -32,6 +33,8 @@ MEMOIZE = core.get_memoization_decorator(conf=cfg.CONF, region=cache.get_cache_region(), group="constraint_validation_cache") +LOG = log.getLogger(__name__) + class Schema(collections.Mapping): """Schema base class for validating properties or parameters. @@ -94,8 +97,8 @@ class Schema(collections.Mapping): message=_('Invalid type (%s)') % self.type) if required and default is not None: - warnings.warn("Option 'required=True' should not be used with " - "any 'default' value ({0})".format(default)) + LOG.warning(_LW("Option 'required=True' should not be used with " + "any 'default' value (%s)") % default) self.description = description self.required = required diff --git a/heat/engine/environment.py b/heat/engine/environment.py index 717d4cd24d..e60e5c0dd2 100644 --- a/heat/engine/environment.py +++ b/heat/engine/environment.py @@ -17,7 +17,6 @@ import glob import itertools import os.path import re -import warnings from oslo_config import cfg from oslo_log import log @@ -293,7 +292,7 @@ class ResourceRegistry(object): if isinstance(info, ClassResourceInfo): if info.value.support_status.status != support.SUPPORTED: if info.value.support_status.message is not None: - warnings.warn(six.text_type( + LOG.warning(_LW("%s"), six.text_type( info.value.support_status.message)) info.user_resource = (self.global_registry is not None) diff --git a/heat/engine/rsrc_defn.py b/heat/engine/rsrc_defn.py index 4b6084f872..be5bfa353b 100644 --- a/heat/engine/rsrc_defn.py +++ b/heat/engine/rsrc_defn.py @@ -14,14 +14,15 @@ import collections import copy import itertools import operator -import warnings - +from oslo_log import log import six from heat.common import exception +from heat.common.i18n import _LW from heat.engine import function from heat.engine import properties +LOG = log.getLogger(__name__) __all__ = ['ResourceDefinition'] @@ -292,7 +293,7 @@ class ResourceDefinition(ResourceDefinitionCore, collections.Mapping): ResourceDefinitionCore as soon as M release. """ - _deprecation_msg = ( + _deprecation_msg = _LW( 'Reading the ResourceDefinition as if it were a snippet of a ' 'CloudFormation template is deprecated, and the ability to treat it ' 'as such will be removed in the future. Resource plugins should use ' @@ -325,7 +326,7 @@ class ResourceDefinition(ResourceDefinitionCore, collections.Mapping): This is for backwards compatibility with existing code that expects a parsed-JSON template snippet. """ - warnings.warn(self._deprecation_msg, DeprecationWarning) + LOG.warning(self._deprecation_msg) yield TYPE if self._properties is not None: @@ -347,7 +348,7 @@ class ResourceDefinition(ResourceDefinitionCore, collections.Mapping): This is for backwards compatibility with existing code that expects a parsed-JSON template snippet. """ - warnings.warn(self._deprecation_msg, DeprecationWarning) + LOG.warning(self._deprecation_msg) if key == TYPE: return self.resource_type @@ -376,7 +377,7 @@ class ResourceDefinition(ResourceDefinitionCore, collections.Mapping): def __hash__(self): """Return a hash of the ResourceDefinition object.""" - warnings.warn(self._deprecation_msg, DeprecationWarning) + LOG.warning(self._deprecation_msg) return super(ResourceDefinition, self).__hash__() def __len__(self): @@ -385,7 +386,7 @@ class ResourceDefinition(ResourceDefinitionCore, collections.Mapping): This is for backwards compatibility with existing code that expects a parsed-JSON template snippet. """ - warnings.warn(self._deprecation_msg, DeprecationWarning) + LOG.warning(self._deprecation_msg) return len(list(iter(self))) diff --git a/heat/engine/service.py b/heat/engine/service.py index 6f25a6025b..f42c9db4ef 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -16,7 +16,6 @@ import datetime import itertools import os import socket -import warnings import eventlet from oslo_config import cfg @@ -318,12 +317,11 @@ class EngineService(service.Service): self.resource_enforcer = policy.ResourceEnforcer() if cfg.CONF.trusts_delegated_roles: - warnings.warn('The default value of "trusts_delegated_roles" ' - 'option in heat.conf is changed to [] in Kilo ' - 'and heat will delegate all roles of trustor. ' - 'Please keep the same if you do not want to ' - 'delegate subset roles when upgrading.', - Warning) + LOG.warning(_LW('The default value of "trusts_delegated_roles" ' + 'option in heat.conf is changed to [] in Kilo ' + 'and heat will delegate all roles of trustor. ' + 'Please keep the same if you do not want to ' + 'delegate subset roles when upgrading.')) def create_periodic_tasks(self): LOG.debug("Starting periodic watch tasks pid=%s" % os.getpid()) diff --git a/heat/tests/test_constraints.py b/heat/tests/test_constraints.py index 292b544c71..00280199b2 100644 --- a/heat/tests/test_constraints.py +++ b/heat/tests/test_constraints.py @@ -20,23 +20,6 @@ from heat.tests import common class SchemaTest(common.HeatTestCase): - def test_warn_required_with_default(self): - msg = ("Option 'required=True' should not be used with any 'default' " - "value \(wibble\)") - with self.assertWarnsRegex(UserWarning, msg): - constraints.Schema(constraints.Schema.STRING, 'A string', - default='wibble', required=True) - - def test_without_warn_only_default(self): - constraints.Schema(constraints.Schema.STRING, 'A string', - default='wibble') - self.assertEqual(0, len(self.warnings.captures)) - - def test_without_warn_only_required(self): - constraints.Schema(constraints.Schema.STRING, 'A string', - required=True) - self.assertEqual(0, len(self.warnings.captures)) - def test_range_schema(self): d = {'range': {'min': 5, 'max': 10}, 'description': 'a range'} r = constraints.Range(5, 10, description='a range') diff --git a/heat/tests/test_rsrc_defn.py b/heat/tests/test_rsrc_defn.py index 140f3e4787..5a5573d5d9 100644 --- a/heat/tests/test_rsrc_defn.py +++ b/heat/tests/test_rsrc_defn.py @@ -12,7 +12,6 @@ # under the License. import six -import warnings from heat.common import exception from heat.engine.cfn import functions as cfn_funcs @@ -212,17 +211,8 @@ class ResourceDefinitionSnippetTest(common.HeatTestCase): def test_resource_snippet(self): rd = rsrc_defn.ResourceDefinition('rsrc', 'SomeType', **self.defn) - with warnings.catch_warnings(record=True) as ws: - warnings.filterwarnings('always') - # Work around http://bugs.python.org/issue4180 - getattr(rsrc_defn, '__warningregistry__', {}).clear() + exp_result = {'Type': 'SomeType'} + exp_result.update(self.expected) - exp_result = {'Type': 'SomeType'} - exp_result.update(self.expected) - - self.assertEqual(exp_result, rd) - - self.assertTrue(ws) - for warn in ws: - self.assertTrue(issubclass(warn.category, DeprecationWarning)) + self.assertEqual(exp_result, rd)