Beispiel #1
0
 def wrapper(obj, *args, **kwargs):
     args = [
         utils.strtime(arg) if isinstance(arg, datetime.datetime) else arg
         for arg in args
     ]
     for k, v in kwargs.items():
         if k == 'exc_val' and v:
             try:
                 # NOTE(danms): When we run this for a remotable method,
                 # we need to attempt to format_message() the exception to
                 # get the sanitized message, and if it's not a
                 # NovaException, fall back to just the exception class
                 # name. However, a remotable will end up calling this again
                 # on the other side of the RPC call, so we must not try
                 # to do that again, otherwise we will always end up with
                 # just str. So, only do that if exc_val is an Exception
                 # class.
                 kwargs[k] = (v.format_message() if isinstance(
                     v, Exception) else v)
             except Exception:
                 kwargs[k] = v.__class__.__name__
         elif k == 'exc_tb' and v and not isinstance(v, str):
             kwargs[k] = ''.join(traceback.format_tb(v))
         elif isinstance(v, datetime.datetime):
             kwargs[k] = utils.strtime(v)
     if hasattr(fn, '__call__'):
         return fn(obj, *args, **kwargs)
     # NOTE(danms): We wrap a descriptor, so use that protocol
     return fn.__get__(None, obj)(*args, **kwargs)
Beispiel #2
0
 def wrapper(obj, *args, **kwargs):
     args = [utils.strtime(arg) if isinstance(arg, datetime.datetime) else arg for arg in args]
     for k, v in six.iteritems(kwargs):
         if k == "exc_val" and v:
             kwargs[k] = six.text_type(v)
         elif k == "exc_tb" and v and not isinstance(v, six.string_types):
             kwargs[k] = "".join(traceback.format_tb(v))
         elif isinstance(v, datetime.datetime):
             kwargs[k] = utils.strtime(v)
     if hasattr(fn, "__call__"):
         return fn(obj, *args, **kwargs)
     # NOTE(danms): We wrap a descriptor, so use that protocol
     return fn.__get__(None, obj)(*args, **kwargs)
 def wrapper(obj, *args, **kwargs):
     args = [utils.strtime(arg) if isinstance(arg, datetime.datetime)
             else arg for arg in args]
     for k, v in kwargs.items():
         if k == 'exc_val' and v:
             kwargs[k] = six.text_type(v)
         elif k == 'exc_tb' and v and not isinstance(v, six.string_types):
             kwargs[k] = ''.join(traceback.format_tb(v))
         elif isinstance(v, datetime.datetime):
             kwargs[k] = utils.strtime(v)
     if hasattr(fn, '__call__'):
         return fn(obj, *args, **kwargs)
     # NOTE(danms): We wrap a descriptor, so use that protocol
     return fn.__get__(None, obj)(*args, **kwargs)
 def test_get(self, mock_get):
     task_log = objects.TaskLog.get(self.context,
                                    fake_task_log['task_name'],
                                    fake_task_log['period_beginning'],
                                    fake_task_log['period_ending'],
                                    fake_task_log['host'],
                                    state=fake_task_log['state'])
     mock_get.assert_called_once_with(
         self.context,
         fake_task_log['task_name'],
         utils.strtime(fake_task_log['period_beginning']),
         utils.strtime(fake_task_log['period_ending']),
         fake_task_log['host'],
         state=fake_task_log['state'])
     self.compare_obj(task_log, fake_task_log)
Beispiel #5
0
 def test_get(self, mock_get):
     task_log = objects.TaskLog.get(self.context,
                                    fake_task_log['task_name'],
                                    fake_task_log['period_beginning'],
                                    fake_task_log['period_ending'],
                                    fake_task_log['host'],
                                    state=fake_task_log['state'])
     mock_get.assert_called_once_with(
         self.context,
         fake_task_log['task_name'],
         utils.strtime(fake_task_log['period_beginning']),
         utils.strtime(fake_task_log['period_ending']),
         fake_task_log['host'],
         state=fake_task_log['state'])
     self.compare_obj(task_log, fake_task_log)
Beispiel #6
0
 def to_dict(self):
     values = super(RequestContext, self).to_dict()
     # FIXME(dims): defensive hasattr() checks need to be
     # removed once we figure out why we are seeing stack
     # traces
     values.update({
         'user_id': getattr(self, 'user_id', None),
         'project_id': getattr(self, 'project_id', None),
         'is_admin': getattr(self, 'is_admin', None),
         'read_deleted': getattr(self, 'read_deleted', 'no'),
         'remote_address': getattr(self, 'remote_address', None),
         'timestamp': utils.strtime(self.timestamp) if hasattr(
             self, 'timestamp') else None,
         'request_id': getattr(self, 'request_id', None),
         'quota_class': getattr(self, 'quota_class', None),
         'user_name': getattr(self, 'user_name', None),
         'service_catalog': getattr(self, 'service_catalog', None),
         'project_name': getattr(self, 'project_name', None),
     })
     # NOTE(tonyb): This can be removed once we're certain to have a
     # RequestContext contains 'is_admin_project', We can only get away with
     # this because we "know" the default value of 'is_admin_project' which
     # is very fragile.
     values.update({
         'is_admin_project': getattr(self, 'is_admin_project', True),
     })
     return values
 def to_dict(self):
     values = super(RequestContext, self).to_dict()
     # FIXME(dims): defensive hasattr() checks need to be
     # removed once we figure out why we are seeing stack
     # traces
     values.update({
         'user_id':
         getattr(self, 'user_id', None),
         'project_id':
         getattr(self, 'project_id', None),
         'is_admin':
         getattr(self, 'is_admin', None),
         'read_deleted':
         getattr(self, 'read_deleted', 'no'),
         'roles':
         getattr(self, 'roles', None),
         'remote_address':
         getattr(self, 'remote_address', None),
         'timestamp':
         utils.strtime(self.timestamp)
         if hasattr(self, 'timestamp') else None,
         'request_id':
         getattr(self, 'request_id', None),
         'quota_class':
         getattr(self, 'quota_class', None),
         'user_name':
         getattr(self, 'user_name', None),
         'service_catalog':
         getattr(self, 'service_catalog', None),
         'project_name':
         getattr(self, 'project_name', None),
         'instance_lock_checked':
         getattr(self, 'instance_lock_checked', False)
     })
     return values
Beispiel #8
0
 def to_dict(self):
     values = super(RequestContext, self).to_dict()
     # FIXME(dims): defensive hasattr() checks need to be
     # removed once we figure out why we are seeing stack
     # traces
     values.update({
         'user_id': getattr(self, 'user_id', None),
         'project_id': getattr(self, 'project_id', None),
         'is_admin': getattr(self, 'is_admin', None),
         'read_deleted': getattr(self, 'read_deleted', 'no'),
         'remote_address': getattr(self, 'remote_address', None),
         'timestamp': utils.strtime(self.timestamp) if hasattr(
             self, 'timestamp') else None,
         'request_id': getattr(self, 'request_id', None),
         'quota_class': getattr(self, 'quota_class', None),
         'user_name': getattr(self, 'user_name', None),
         'service_catalog': getattr(self, 'service_catalog', None),
         'project_name': getattr(self, 'project_name', None),
     })
     # NOTE(tonyb): This can be removed once we're certain to have a
     # RequestContext contains 'is_admin_project', We can only get away with
     # this because we "know" the default value of 'is_admin_project' which
     # is very fragile.
     values.update({
         'is_admin_project': getattr(self, 'is_admin_project', True),
     })
     return values
Beispiel #9
0
 def to_dict(self):
     return {'user_id': self.user_id,
             'project_id': self.project_id,
             'is_admin': self.is_admin,
             'read_deleted': self.read_deleted,
             'roles': self.roles,
             'remote_address': self.remote_address,
             'timestamp': utils.strtime(self.timestamp),
             'request_id': self.request_id}
Beispiel #10
0
 def test_null_safe_isotime(self):
     dt = None
     self.assertEqual('', base.null_safe_isotime(dt))
     dt = datetime.datetime(second=1,
                           minute=1,
                           hour=1,
                           day=1,
                           month=1,
                           year=2017)
     self.assertEqual(utils.strtime(dt), base.null_safe_isotime(dt))
Beispiel #11
0
 def test_null_safe_isotime(self):
     dt = None
     self.assertEqual('', base.null_safe_isotime(dt))
     dt = datetime.datetime(second=1,
                            minute=1,
                            hour=1,
                            day=1,
                            month=1,
                            year=2017)
     self.assertEqual(utils.strtime(dt), base.null_safe_isotime(dt))
Beispiel #12
0
 def test_get_all(self, mock_get_all):
     fake_task_logs = [dict(fake_task_log, id=1), dict(fake_task_log, id=2)]
     mock_get_all.return_value = fake_task_logs
     task_logs = objects.TaskLogList.get_all(
         self.context,
         fake_task_log['task_name'],
         fake_task_log['period_beginning'],
         fake_task_log['period_ending'],
         host=fake_task_log['host'],
         state=fake_task_log['state'])
     mock_get_all.assert_called_once_with(
         self.context,
         fake_task_log['task_name'],
         utils.strtime(fake_task_log['period_beginning']),
         utils.strtime(fake_task_log['period_ending']),
         host=fake_task_log['host'],
         state=fake_task_log['state'])
     for index, task_log in enumerate(task_logs):
         self.compare_obj(task_log, fake_task_logs[index])
 def test_get_all(self, mock_get_all):
     fake_task_logs = [dict(fake_task_log, id=1), dict(fake_task_log, id=2)]
     mock_get_all.return_value = fake_task_logs
     task_logs = objects.TaskLogList.get_all(
         self.context,
         fake_task_log['task_name'],
         fake_task_log['period_beginning'],
         fake_task_log['period_ending'],
         host=fake_task_log['host'],
         state=fake_task_log['state'])
     mock_get_all.assert_called_once_with(
         self.context,
         fake_task_log['task_name'],
         utils.strtime(fake_task_log['period_beginning']),
         utils.strtime(fake_task_log['period_ending']),
         host=fake_task_log['host'],
         state=fake_task_log['state'])
     for index, task_log in enumerate(task_logs):
         self.compare_obj(task_log, fake_task_logs[index])
Beispiel #14
0
 def to_dict(self):
     return {
         'user_id': self.user_id,
         'project_id': self.project_id,
         'is_admin': self.is_admin,
         'read_deleted': self.read_deleted,
         'roles': self.roles,
         'remote_address': self.remote_address,
         'timestamp': utils.strtime(self.timestamp),
         'request_id': self.request_id
     }
Beispiel #15
0
 def to_dict(self):
     return {
         "user_id": self.user_id,
         "project_id": self.project_id,
         "is_admin": self.is_admin,
         "read_deleted": self.read_deleted,
         "roles": self.roles,
         "remote_address": self.remote_address,
         "timestamp": utils.strtime(self.timestamp),
         "request_id": self.request_id,
         "auth_token": self.auth_token,
     }
Beispiel #16
0
 def to_dict(self):
     return {'user_id': self.user_id,
             'project_id': self.project_id,
             'is_admin': self.is_admin,
             'read_deleted': self.read_deleted,
             'roles': self.roles,
             'remote_address': self.remote_address,
             'timestamp': utils.strtime(self.timestamp),
             'request_id': self.request_id,
             'auth_token': self.auth_token,
             'quota_class': self.quota_class,
             'user_name': self.user_name,
             'project_name': self.project_name}
Beispiel #17
0
 def to_dict(self):
     return {
         'user_id': self.user_id,
         'project_id': self.project_id,
         'is_admin': self.is_admin,
         'read_deleted': self.read_deleted,
         'roles': self.roles,
         'remote_address': self.remote_address,
         'timestamp': utils.strtime(self.timestamp),
         'request_id': self.request_id,
         'auth_token': self.auth_token,
         'quota_class': self.quota_class,
         'user_name': self.user_name,
         'project_name': self.project_name
     }
Beispiel #18
0
    def to_dict(self):
        dict_to_return = {
            'name': self.name,
            # NOTE(jaypipes): This is what jsonutils.dumps() does to
            # datetime.datetime objects, which is what timestamp is in
            # this object as well as the original simple dict metrics
            'timestamp': utils.strtime(self.timestamp),
            'source': self.source,
        }

        if self.obj_attr_is_set('value'):
            if self.name in FIELDS_REQUIRING_CONVERSION:
                dict_to_return['value'] = self.value / 100.0
            else:
                dict_to_return['value'] = self.value
        elif self.obj_attr_is_set('numa_membw_values'):
            dict_to_return['numa_membw_values'] = self.numa_membw_values

        return dict_to_return
Beispiel #19
0
    def to_dict(self):
        dict_to_return = {
            'name': self.name,
            # NOTE(jaypipes): This is what jsonutils.dumps() does to
            # datetime.datetime objects, which is what timestamp is in
            # this object as well as the original simple dict metrics
            'timestamp': utils.strtime(self.timestamp),
            'source': self.source,
        }

        if self.obj_attr_is_set('value'):
            if self.name in FIELDS_REQUIRING_CONVERSION:
                dict_to_return['value'] = self.value / 100.0
            else:
                dict_to_return['value'] = self.value
        elif self.obj_attr_is_set('numa_membw_values'):
            dict_to_return['numa_membw_values'] = self.numa_membw_values

        return dict_to_return
Beispiel #20
0
 def to_dict(self):
     values = super(RequestContext, self).to_dict()
     # FIXME(dims): defensive hasattr() checks need to be
     # removed once we figure out why we are seeing stack
     # traces
     values.update(
         {
             "user_id": getattr(self, "user_id", None),
             "project_id": getattr(self, "project_id", None),
             "is_admin": getattr(self, "is_admin", None),
             "read_deleted": getattr(self, "read_deleted", "no"),
             "remote_address": getattr(self, "remote_address", None),
             "timestamp": utils.strtime(self.timestamp) if hasattr(self, "timestamp") else None,
             "request_id": getattr(self, "request_id", None),
             "quota_class": getattr(self, "quota_class", None),
             "user_name": getattr(self, "user_name", None),
             "service_catalog": getattr(self, "service_catalog", None),
             "project_name": getattr(self, "project_name", None),
             "instance_lock_checked": getattr(self, "instance_lock_checked", False),
         }
     )
     return values
Beispiel #21
0
 def to_dict(self):
     values = super(RequestContext, self).to_dict()
     # FIXME(dims): defensive hasattr() checks need to be
     # removed once we figure out why we are seeing stack
     # traces
     values.update({
         'user_id': getattr(self, 'user_id', None),
         'project_id': getattr(self, 'project_id', None),
         'is_admin': getattr(self, 'is_admin', None),
         'read_deleted': getattr(self, 'read_deleted', 'no'),
         'remote_address': getattr(self, 'remote_address', None),
         'timestamp': utils.strtime(self.timestamp) if hasattr(
             self, 'timestamp') else None,
         'request_id': getattr(self, 'request_id', None),
         'quota_class': getattr(self, 'quota_class', None),
         'user_name': getattr(self, 'user_name', None),
         'service_catalog': getattr(self, 'service_catalog', None),
         'project_name': getattr(self, 'project_name', None),
         'instance_lock_checked': getattr(self, 'instance_lock_checked',
                                          False)
     })
     return values
Beispiel #22
0
def null_safe_isotime(s):
    if isinstance(s, datetime.datetime):
        return utils.strtime(s)
    else:
        return str(s) if s else ''
Beispiel #23
0
 def null_safe_isotime(s):
     if isinstance(s, datetime.datetime):
         return utils.strtime(s)
     else:
         return str(s) if s else ''