Merge "Use oslo.utils.reflection to extract class name"

This commit is contained in:
Jenkins 2016-03-06 05:01:47 +00:00 committed by Gerrit Code Review
commit 9345e1648f
11 changed files with 38 additions and 18 deletions

View File

@ -14,6 +14,7 @@
import uuid import uuid
import mock import mock
from oslo_utils import reflection
import six import six
from heat.common import exception from heat.common import exception
@ -103,8 +104,9 @@ class CloudNetworkTest(common.HeatTestCase):
cloudnetworks.CloudNetwork) cloudnetworks.CloudNetwork)
def _parse_stack(self): def _parse_stack(self):
class_name = reflection.get_class_name(self, fully_qualified=False)
self.stack = utils.parse_stack(self._template, self.stack = utils.parse_stack(self._template,
stack_name=self.__class__.__name__) stack_name=class_name)
def _setup_stack(self, mock_client, *args): def _setup_stack(self, mock_client, *args):
self.fake_cnw = FakeClient(*args) self.fake_cnw = FakeClient(*args)

View File

@ -16,6 +16,7 @@
"""Heat API exception subclasses - maps API response errors to AWS Errors.""" """Heat API exception subclasses - maps API response errors to AWS Errors."""
from oslo_utils import reflection
import six import six
import webob.exc import webob.exc
@ -317,7 +318,7 @@ def map_remote_error(ex):
invalid_action_errors = ('ActionInProgress',) invalid_action_errors = ('ActionInProgress',)
request_limit_exceeded = ('RequestLimitExceeded') request_limit_exceeded = ('RequestLimitExceeded')
ex_type = ex.__class__.__name__ ex_type = reflection.get_class_name(ex, fully_qualified=False)
if ex_type.endswith('_Remote'): if ex_type.endswith('_Remote'):
ex_type = ex_type[:-len('_Remote')] ex_type = ex_type[:-len('_Remote')]

View File

@ -18,12 +18,13 @@
Inspired by Cinder's faultwrapper. Inspired by Cinder's faultwrapper.
""" """
import six
import sys import sys
import traceback import traceback
from oslo_config import cfg from oslo_config import cfg
from oslo_utils import reflection
import six
import webob import webob
from heat.common import exception from heat.common import exception
@ -116,7 +117,7 @@ class FaultWrapper(wsgi.Middleware):
ex = ex.exc ex = ex.exc
webob_exc = ex webob_exc = ex
ex_type = ex.__class__.__name__ ex_type = reflection.get_class_name(ex, fully_qualified=False)
is_remote = ex_type.endswith('_Remote') is_remote = ex_type.endswith('_Remote')
if is_remote: if is_remote:

View File

@ -18,6 +18,7 @@ import re
from oslo_cache import core from oslo_cache import core
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log from oslo_log import log
from oslo_utils import reflection
from oslo_utils import strutils from oslo_utils import strutils
import six import six
@ -616,8 +617,8 @@ class BaseCustomConstraint(object):
return False return False
else: else:
return True return True
class_name = reflection.get_class_name(self, fully_qualified=False)
cache_value_prefix = "{0}:{1}".format(self.__class__.__name__, cache_value_prefix = "{0}:{1}".format(class_name,
six.text_type(context.tenant_id)) six.text_type(context.tenant_id))
validation_result = check_cache_or_validate_value( validation_result = check_cache_or_validate_value(
cache_value_prefix, value) cache_value_prefix, value)

View File

@ -19,6 +19,7 @@ import weakref
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
from oslo_utils import reflection
import six import six
from heat.common import exception 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) return dict((k, after_props.get(k)) for k in changed_properties_set)
def __str__(self): def __str__(self):
class_name = reflection.get_class_name(self, fully_qualified=False)
if self.stack.id: if self.stack.id:
if self.resource_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, self.resource_id,
six.text_type(self.stack)) six.text_type(self.stack))
else: else:
text = '%s "%s" %s' % (self.__class__.__name__, self.name, text = '%s "%s" %s' % (class_name, self.name,
six.text_type(self.stack)) six.text_type(self.stack))
else: else:
text = '%s "%s"' % (self.__class__.__name__, self.name) text = '%s "%s"' % (class_name, self.name)
return six.text_type(text) return six.text_type(text)
def dep_attrs(self, resource_name): def dep_attrs(self, resource_name):

View File

@ -16,6 +16,7 @@ import json
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
from oslo_utils import reflection
import six import six
from heat.common import exception from heat.common import exception
@ -174,8 +175,8 @@ class StackResource(resource.Resource):
child_template = self.child_template() child_template = self.child_template()
params = self.child_params() params = self.child_params()
except NotImplementedError: except NotImplementedError:
LOG.warning(_LW("Preview of '%s' not yet implemented"), class_name = reflection.get_class_name(self, fully_qualified=False)
self.__class__.__name__) LOG.warning(_LW("Preview of '%s' not yet implemented"), class_name)
return self return self
name = "%s-%s" % (self.stack.name, self.name) name = "%s-%s" % (self.stack.name, self.name)
@ -324,7 +325,8 @@ class StackResource(resource.Resource):
# finish # finish
return 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 raise ex
full_message = six.text_type(ex) full_message = six.text_type(ex)

View File

@ -15,6 +15,8 @@
"""Client side of the heat engine RPC API.""" """Client side of the heat engine RPC API."""
from oslo_utils import reflection
from heat.common import messaging from heat.common import messaging
from heat.rpc import api as rpc_api 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. :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] return error_name.split('_Remote')[0]
def ignore_error_named(self, error, name): def ignore_error_named(self, error, name):

View File

@ -11,6 +11,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_utils import reflection
import heat.api.openstack.v1 as api_v1 import heat.api.openstack.v1 as api_v1
from heat.tests import common from heat.tests import common
@ -23,8 +25,9 @@ class RoutesTest(common.HeatTestCase):
route = mapper.match(path, {'REQUEST_METHOD': method}) route = mapper.match(path, {'REQUEST_METHOD': method})
self.assertIsNotNone(route) self.assertIsNotNone(route)
self.assertEqual(action, route['action']) self.assertEqual(action, route['action'])
self.assertEqual( class_name = reflection.get_class_name(route['controller'].controller,
controller, route['controller'].controller.__class__.__name__) fully_qualified=False)
self.assertEqual(controller, class_name)
del(route['action']) del(route['action'])
del(route['controller']) del(route['controller'])
self.assertEqual(params, route) self.assertEqual(params, route)

View File

@ -22,6 +22,7 @@ import copy
import mock import mock
from mox import stubout from mox import stubout
from oslo_messaging._drivers import common as rpc_common from oslo_messaging._drivers import common as rpc_common
from oslo_utils import reflection
from heat.common import exception from heat.common import exception
from heat.common import identifier from heat.common import identifier
@ -53,7 +54,8 @@ class EngineRpcAPITestCase(common.HeatTestCase):
self.assertEqual('NotFound', self.rpcapi.local_error_name(ex)) self.assertEqual('NotFound', self.rpcapi.local_error_name(ex))
exr = self._to_remote_error(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)) self.assertEqual('NotFound', self.rpcapi.local_error_name(exr))
def test_ignore_error_named(self): def test_ignore_error_named(self):

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_utils import reflection
from heat_integrationtests.common import test from heat_integrationtests.common import test
@ -21,7 +23,7 @@ class FunctionalTestsBase(test.HeatIntegrationTest):
self.client = self.orchestration_client self.client = self.orchestration_client
def check_skip(self): 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_method_name = '.'.join([test_cls_name, self._testMethodName])
test_skipped = (self.conf.skip_functional_test_list and ( test_skipped = (self.conf.skip_functional_test_list and (
test_cls_name in self.conf.skip_functional_test_list or test_cls_name in self.conf.skip_functional_test_list or

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_utils import reflection
from heat_integrationtests.common import test from heat_integrationtests.common import test
@ -59,7 +61,7 @@ class ScenarioTestsBase(test.HeatIntegrationTest):
return stack_id return stack_id
def check_skip(self): 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_method_name = '.'.join([test_cls_name, self._testMethodName])
test_skipped = (self.conf.skip_scenario_test_list and ( test_skipped = (self.conf.skip_scenario_test_list and (
test_cls_name in self.conf.skip_scenario_test_list or test_cls_name in self.conf.skip_scenario_test_list or