use oslo.utils.reflection extract the class name
The oslo.utils reflection module/code handles more variations of where a class name may come from (on python 2 and python 3) so its usage allows getting more accurate class names so we might as well use it. Change-Id: I4b18aeec0a1b8b207c2c824b7e68dc8e51d34523
This commit is contained in:
parent
f0e9321cce
commit
eef90b081d
cloudpulse
@ -25,6 +25,7 @@ import uuid
|
||||
from keystoneclient import exceptions as keystone_exceptions
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import excutils
|
||||
from oslo_utils import reflection
|
||||
import pecan
|
||||
import six
|
||||
import wsme
|
||||
@ -221,7 +222,8 @@ class CloudpulseException(Exception):
|
||||
return self.message
|
||||
|
||||
def format_message(self):
|
||||
if self.__class__.__name__.endswith('_Remote'):
|
||||
cls_name = reflection.get_class_name(self, fully_qualified=False)
|
||||
if cls_name.endswith('_Remote'):
|
||||
return self.args[0]
|
||||
else:
|
||||
return six.text_type(self)
|
||||
|
@ -21,6 +21,7 @@ import json
|
||||
from oslo_config import cfg
|
||||
from oslo_db import options as db_options
|
||||
from oslo_db.sqlalchemy import models
|
||||
from oslo_utils import reflection
|
||||
import six.moves.urllib.parse as urlparse
|
||||
from sqlalchemy import Column
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
@ -64,13 +65,14 @@ class JsonEncodedType(TypeDecorator):
|
||||
impl = TEXT
|
||||
|
||||
def process_bind_param(self, value, dialect):
|
||||
cls_name = reflection.get_class_name(self, fully_qualified=False)
|
||||
if value is None:
|
||||
# Save default value according to current type to keep the
|
||||
# interface the consistent.
|
||||
value = self.type()
|
||||
elif not isinstance(value, self.type):
|
||||
raise TypeError("%s supposes to store %s objects, but %s given"
|
||||
% (self.__class__.__name__,
|
||||
% (cls_name,
|
||||
self.type.__name__,
|
||||
type(value).__name__))
|
||||
serialized_value = json.dumps(value)
|
||||
|
@ -17,6 +17,7 @@ import random
|
||||
import time
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import reflection
|
||||
import six
|
||||
|
||||
from cloudpulse.openstack.common._i18n import _, _LE, _LI
|
||||
@ -200,9 +201,10 @@ class PeriodicTasks(object):
|
||||
|
||||
def run_periodic_tasks(self, context, raise_on_error=False):
|
||||
"""Tasks to be run at a periodic interval."""
|
||||
cls_name = reflection.get_class_name(self, fully_qualified=False)
|
||||
idle_for = DEFAULT_INTERVAL
|
||||
for task_name, task in self._periodic_tasks:
|
||||
full_task_name = '.'.join([self.__class__.__name__, task_name])
|
||||
full_task_name = '.'.join([cls_name, task_name])
|
||||
|
||||
spacing = self._periodic_spacing[task_name]
|
||||
last_run = self._periodic_last_run[task_name]
|
||||
|
Loading…
x
Reference in New Issue
Block a user