diff --git a/contrib/rackspace/rackspace/tests/test_cloudnetworks.py b/contrib/rackspace/rackspace/tests/test_cloudnetworks.py index f44e68c60f..29c36e238e 100644 --- a/contrib/rackspace/rackspace/tests/test_cloudnetworks.py +++ b/contrib/rackspace/rackspace/tests/test_cloudnetworks.py @@ -14,6 +14,7 @@ import uuid import mock +from oslo_utils import reflection import six from heat.common import exception @@ -103,8 +104,9 @@ class CloudNetworkTest(common.HeatTestCase): cloudnetworks.CloudNetwork) def _parse_stack(self): + class_name = reflection.get_class_name(self, fully_qualified=False) self.stack = utils.parse_stack(self._template, - stack_name=self.__class__.__name__) + stack_name=class_name) def _setup_stack(self, mock_client, *args): self.fake_cnw = FakeClient(*args) diff --git a/heat/api/aws/exception.py b/heat/api/aws/exception.py index 29b96206b5..4bc8389567 100644 --- a/heat/api/aws/exception.py +++ b/heat/api/aws/exception.py @@ -16,6 +16,7 @@ """Heat API exception subclasses - maps API response errors to AWS Errors.""" +from oslo_utils import reflection import six import webob.exc @@ -317,7 +318,7 @@ def map_remote_error(ex): invalid_action_errors = ('ActionInProgress',) request_limit_exceeded = ('RequestLimitExceeded') - ex_type = ex.__class__.__name__ + ex_type = reflection.get_class_name(ex, fully_qualified=False) if ex_type.endswith('_Remote'): ex_type = ex_type[:-len('_Remote')] diff --git a/heat/api/middleware/fault.py b/heat/api/middleware/fault.py index c18afa8b1f..7508f81ee0 100644 --- a/heat/api/middleware/fault.py +++ b/heat/api/middleware/fault.py @@ -18,12 +18,13 @@ Inspired by Cinder's faultwrapper. """ -import six import sys import traceback from oslo_config import cfg +from oslo_utils import reflection +import six import webob from heat.common import exception @@ -116,7 +117,7 @@ class FaultWrapper(wsgi.Middleware): ex = ex.exc webob_exc = ex - ex_type = ex.__class__.__name__ + ex_type = reflection.get_class_name(ex, fully_qualified=False) is_remote = ex_type.endswith('_Remote') if is_remote: diff --git a/heat/engine/constraints.py b/heat/engine/constraints.py index f4b948264f..e15e36000c 100644 --- a/heat/engine/constraints.py +++ b/heat/engine/constraints.py @@ -18,6 +18,7 @@ import re from oslo_cache import core from oslo_config import cfg from oslo_log import log +from oslo_utils import reflection from oslo_utils import strutils import six @@ -616,8 +617,8 @@ class BaseCustomConstraint(object): return False else: return True - - cache_value_prefix = "{0}:{1}".format(self.__class__.__name__, + class_name = reflection.get_class_name(self, fully_qualified=False) + cache_value_prefix = "{0}:{1}".format(class_name, six.text_type(context.tenant_id)) validation_result = check_cache_or_validate_value( cache_value_prefix, value) diff --git a/heat/engine/resource.py b/heat/engine/resource.py index 3eeddc6b4c..a2a4d09cdb 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -19,6 +19,7 @@ import weakref from oslo_config import cfg from oslo_log import log as logging from oslo_utils import excutils +from oslo_utils import reflection import six from heat.common import exception @@ -543,16 +544,17 @@ class Resource(object): return dict((k, after_props.get(k)) for k in changed_properties_set) def __str__(self): + class_name = reflection.get_class_name(self, fully_qualified=False) if self.stack.id: if self.resource_id: - text = '%s "%s" [%s] %s' % (self.__class__.__name__, self.name, + text = '%s "%s" [%s] %s' % (class_name, self.name, self.resource_id, six.text_type(self.stack)) else: - text = '%s "%s" %s' % (self.__class__.__name__, self.name, + text = '%s "%s" %s' % (class_name, self.name, six.text_type(self.stack)) else: - text = '%s "%s"' % (self.__class__.__name__, self.name) + text = '%s "%s"' % (class_name, self.name) return six.text_type(text) def dep_attrs(self, resource_name): diff --git a/heat/engine/resources/stack_resource.py b/heat/engine/resources/stack_resource.py index 59584e88d2..49259a6b61 100644 --- a/heat/engine/resources/stack_resource.py +++ b/heat/engine/resources/stack_resource.py @@ -16,6 +16,7 @@ import json from oslo_config import cfg from oslo_log import log as logging from oslo_utils import excutils +from oslo_utils import reflection import six from heat.common import exception @@ -174,8 +175,8 @@ class StackResource(resource.Resource): child_template = self.child_template() params = self.child_params() except NotImplementedError: - LOG.warning(_LW("Preview of '%s' not yet implemented"), - self.__class__.__name__) + class_name = reflection.get_class_name(self, fully_qualified=False) + LOG.warning(_LW("Preview of '%s' not yet implemented"), class_name) return self name = "%s-%s" % (self.stack.name, self.name) @@ -324,7 +325,8 @@ class StackResource(resource.Resource): # finish return - if not ex.__class__.__name__.endswith('_Remote'): + class_name = reflection.get_class_name(ex, fully_qualified=False) + if not class_name.endswith('_Remote'): raise ex full_message = six.text_type(ex) diff --git a/heat/rpc/client.py b/heat/rpc/client.py index e21b9bf36c..be4ece09dd 100644 --- a/heat/rpc/client.py +++ b/heat/rpc/client.py @@ -15,6 +15,8 @@ """Client side of the heat engine RPC API.""" +from oslo_utils import reflection + from heat.common import messaging from heat.rpc import api as rpc_api @@ -79,7 +81,7 @@ class EngineClient(object): :param error: Remote raised error to derive the name from. """ - error_name = error.__class__.__name__ + error_name = reflection.get_class_name(error, fully_qualified=False) return error_name.split('_Remote')[0] def ignore_error_named(self, error, name): diff --git a/heat/tests/api/openstack_v1/test_routes.py b/heat/tests/api/openstack_v1/test_routes.py index 4177f78e0f..29d1ae4a77 100644 --- a/heat/tests/api/openstack_v1/test_routes.py +++ b/heat/tests/api/openstack_v1/test_routes.py @@ -11,6 +11,8 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_utils import reflection + import heat.api.openstack.v1 as api_v1 from heat.tests import common @@ -23,8 +25,9 @@ class RoutesTest(common.HeatTestCase): route = mapper.match(path, {'REQUEST_METHOD': method}) self.assertIsNotNone(route) self.assertEqual(action, route['action']) - self.assertEqual( - controller, route['controller'].controller.__class__.__name__) + class_name = reflection.get_class_name(route['controller'].controller, + fully_qualified=False) + self.assertEqual(controller, class_name) del(route['action']) del(route['controller']) self.assertEqual(params, route) diff --git a/heat/tests/test_rpc_client.py b/heat/tests/test_rpc_client.py index 262575825d..9ad61b1b5b 100644 --- a/heat/tests/test_rpc_client.py +++ b/heat/tests/test_rpc_client.py @@ -22,6 +22,7 @@ import copy import mock from mox import stubout from oslo_messaging._drivers import common as rpc_common +from oslo_utils import reflection from heat.common import exception from heat.common import identifier @@ -53,7 +54,8 @@ class EngineRpcAPITestCase(common.HeatTestCase): self.assertEqual('NotFound', self.rpcapi.local_error_name(ex)) exr = self._to_remote_error(ex) - self.assertEqual('NotFound_Remote', exr.__class__.__name__) + self.assertEqual('NotFound_Remote', + reflection.get_class_name(exr, fully_qualified=False)) self.assertEqual('NotFound', self.rpcapi.local_error_name(exr)) def test_ignore_error_named(self): diff --git a/heat_integrationtests/functional/functional_base.py b/heat_integrationtests/functional/functional_base.py index 452e055354..9f760110c4 100644 --- a/heat_integrationtests/functional/functional_base.py +++ b/heat_integrationtests/functional/functional_base.py @@ -10,6 +10,8 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_utils import reflection + from heat_integrationtests.common import test @@ -21,7 +23,7 @@ class FunctionalTestsBase(test.HeatIntegrationTest): self.client = self.orchestration_client def check_skip(self): - test_cls_name = self.__class__.__name__ + test_cls_name = reflection.get_class_name(self, fully_qualified=False) test_method_name = '.'.join([test_cls_name, self._testMethodName]) test_skipped = (self.conf.skip_functional_test_list and ( test_cls_name in self.conf.skip_functional_test_list or diff --git a/heat_integrationtests/scenario/scenario_base.py b/heat_integrationtests/scenario/scenario_base.py index 66069ff774..d41c9a1c95 100644 --- a/heat_integrationtests/scenario/scenario_base.py +++ b/heat_integrationtests/scenario/scenario_base.py @@ -10,6 +10,8 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_utils import reflection + from heat_integrationtests.common import test @@ -59,7 +61,7 @@ class ScenarioTestsBase(test.HeatIntegrationTest): return stack_id def check_skip(self): - test_cls_name = self.__class__.__name__ + test_cls_name = reflection.get_class_name(self, fully_qualified=False) test_method_name = '.'.join([test_cls_name, self._testMethodName]) test_skipped = (self.conf.skip_scenario_test_list and ( test_cls_name in self.conf.skip_scenario_test_list or