Replaced deprecated timeutils methods
Since oslo 1.6.0 timeutils.isotime() and timeutils.strtime() methods are deprecated. DeprecationWarning: Using function/method 'oslo_utils.timeutils.strtime()' is deprecated in version '1.6' and will be removed in a future version: use either datetime.datetime.isoformat() or datetime.datetime.strftime() instead Change-Id: If69bd8a6bee052556ba8853afef3941bcd1e7b13 Closes-Bug: 1479056 Co-Authored-By: Diana Clarke <diana.joan.clarke@gmail.com>
This commit is contained in:
parent
3be51f19ae
commit
630aad025e
@ -1802,7 +1802,7 @@ class CloudController(object):
|
||||
raise exception.InternalError(message=err)
|
||||
|
||||
# meaningful image name
|
||||
name_map = dict(instance=instance_uuid, now=timeutils.isotime())
|
||||
name_map = dict(instance=instance_uuid, now=utils.isotime())
|
||||
name = name or _('image of %(instance)s at %(now)s') % name_map
|
||||
|
||||
new_image = self.compute_api.snapshot_volume_backed(context,
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import fileutils
|
||||
from oslo_utils import timeutils
|
||||
from webob import exc
|
||||
|
||||
from nova.api.openstack.compute.schemas import cloudpipe
|
||||
@ -77,7 +76,7 @@ class CloudpipeController(wsgi.Controller):
|
||||
rv['state'] = 'pending'
|
||||
return rv
|
||||
rv['instance_id'] = instance.uuid
|
||||
rv['created_at'] = timeutils.isotime(instance.created_at)
|
||||
rv['created_at'] = utils.isotime(instance.created_at)
|
||||
nw_info = compute_utils.get_nw_info_for_instance(instance)
|
||||
if not nw_info:
|
||||
return rv
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import fileutils
|
||||
from oslo_utils import timeutils
|
||||
from webob import exc
|
||||
|
||||
from nova.api.openstack import extensions
|
||||
@ -72,7 +71,7 @@ class CloudpipeController(object):
|
||||
rv['state'] = 'pending'
|
||||
return rv
|
||||
rv['instance_id'] = instance.uuid
|
||||
rv['created_at'] = timeutils.isotime(instance.created_at)
|
||||
rv['created_at'] = utils.isotime(instance.created_at)
|
||||
nw_info = compute_utils.get_nw_info_for_instance(instance)
|
||||
if not nw_info:
|
||||
return rv
|
||||
|
@ -231,7 +231,7 @@ class SimpleTenantUsageController(object):
|
||||
except exception.InvalidStrTime as e:
|
||||
raise exc.HTTPBadRequest(explanation=e.format_message())
|
||||
|
||||
now = timeutils.parse_isotime(timeutils.strtime())
|
||||
now = timeutils.parse_isotime(timeutils.utcnow().isoformat())
|
||||
if period_stop > now:
|
||||
period_stop = now
|
||||
usages = self._tenant_usages_for_period(context,
|
||||
@ -253,7 +253,7 @@ class SimpleTenantUsageController(object):
|
||||
except exception.InvalidStrTime as e:
|
||||
raise exc.HTTPBadRequest(explanation=e.format_message())
|
||||
|
||||
now = timeutils.parse_isotime(timeutils.strtime())
|
||||
now = timeutils.parse_isotime(timeutils.utcnow().isoformat())
|
||||
if period_stop > now:
|
||||
period_stop = now
|
||||
usage = self._tenant_usages_for_period(context,
|
||||
|
@ -231,7 +231,7 @@ class SimpleTenantUsageController(wsgi.Controller):
|
||||
except exception.InvalidStrTime as e:
|
||||
raise exc.HTTPBadRequest(explanation=e.format_message())
|
||||
|
||||
now = timeutils.parse_isotime(timeutils.strtime())
|
||||
now = timeutils.parse_isotime(timeutils.utcnow().isoformat())
|
||||
if period_stop > now:
|
||||
period_stop = now
|
||||
usages = self._tenant_usages_for_period(context,
|
||||
@ -254,7 +254,7 @@ class SimpleTenantUsageController(wsgi.Controller):
|
||||
except exception.InvalidStrTime as e:
|
||||
raise exc.HTTPBadRequest(explanation=e.format_message())
|
||||
|
||||
now = timeutils.parse_isotime(timeutils.strtime())
|
||||
now = timeutils.parse_isotime(timeutils.utcnow().isoformat())
|
||||
if period_stop > now:
|
||||
period_stop = now
|
||||
usage = self._tenant_usages_for_period(context,
|
||||
|
@ -14,10 +14,9 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_utils import timeutils
|
||||
|
||||
from nova.api.openstack import common
|
||||
from nova.image import glance
|
||||
from nova import utils
|
||||
|
||||
|
||||
class ViewBuilder(common.ViewBuilder):
|
||||
@ -135,7 +134,7 @@ class ViewBuilder(common.ViewBuilder):
|
||||
def _format_date(dt):
|
||||
"""Return standard format for a given datetime object."""
|
||||
if dt is not None:
|
||||
return timeutils.isotime(dt)
|
||||
return utils.isotime(dt)
|
||||
|
||||
@staticmethod
|
||||
def _get_status(image):
|
||||
|
@ -14,10 +14,10 @@
|
||||
# under the License.
|
||||
|
||||
import datetime
|
||||
|
||||
from oslo_utils import timeutils
|
||||
import six
|
||||
|
||||
from nova import utils
|
||||
|
||||
|
||||
class ViewBuilder(object):
|
||||
"""OpenStack API base limits view builder."""
|
||||
@ -99,7 +99,7 @@ class ViewBuilder(object):
|
||||
"value": rate_limit["value"],
|
||||
"remaining": int(rate_limit["remaining"]),
|
||||
"unit": rate_limit["unit"],
|
||||
"next-available": timeutils.isotime(at=next_avail),
|
||||
"next-available": utils.isotime(next_avail),
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,7 +17,6 @@
|
||||
import hashlib
|
||||
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import timeutils
|
||||
|
||||
from nova.api.openstack import api_version_request
|
||||
from nova.api.openstack import common
|
||||
@ -120,8 +119,8 @@ class ViewBuilder(common.ViewBuilder):
|
||||
"hostId": self._get_host_id(instance) or "",
|
||||
"image": self._get_image(request, instance),
|
||||
"flavor": self._get_flavor(request, instance),
|
||||
"created": timeutils.isotime(instance["created_at"]),
|
||||
"updated": timeutils.isotime(instance["updated_at"]),
|
||||
"created": utils.isotime(instance["created_at"]),
|
||||
"updated": utils.isotime(instance["updated_at"]),
|
||||
"addresses": self._get_addresses(request, instance),
|
||||
"accessIPv4": str(ip_v4) if ip_v4 is not None else '',
|
||||
"accessIPv6": str(ip_v6) if ip_v6 is not None else '',
|
||||
@ -246,7 +245,7 @@ class ViewBuilder(common.ViewBuilder):
|
||||
|
||||
fault_dict = {
|
||||
"code": fault["code"],
|
||||
"created": timeutils.isotime(fault["created_at"]),
|
||||
"created": utils.isotime(fault["created_at"]),
|
||||
"message": fault["message"],
|
||||
}
|
||||
|
||||
@ -289,8 +288,8 @@ class ViewBuilderV21(ViewBuilder):
|
||||
# V2.1.
|
||||
"image": self._get_image(request, instance),
|
||||
"flavor": self._get_flavor(request, instance),
|
||||
"created": timeutils.isotime(instance["created_at"]),
|
||||
"updated": timeutils.isotime(instance["updated_at"]),
|
||||
"created": utils.isotime(instance["created_at"]),
|
||||
"updated": utils.isotime(instance["updated_at"]),
|
||||
"addresses": self._get_addresses(request, instance,
|
||||
extend_address),
|
||||
"links": self._get_links(request,
|
||||
|
@ -4191,7 +4191,7 @@ class ComputeManager(manager.Manager):
|
||||
self._power_off_instance(context, instance, clean_shutdown)
|
||||
self.driver.snapshot(context, instance, image_id, update_task_state)
|
||||
|
||||
instance.system_metadata['shelved_at'] = timeutils.strtime()
|
||||
instance.system_metadata['shelved_at'] = timeutils.utcnow().isoformat()
|
||||
instance.system_metadata['shelved_image_id'] = image_id
|
||||
instance.system_metadata['shelved_host'] = self.host
|
||||
instance.vm_state = vm_states.SHELVED
|
||||
|
@ -30,7 +30,7 @@ import six
|
||||
from nova import exception
|
||||
from nova.i18n import _, _LW
|
||||
from nova import policy
|
||||
|
||||
from nova import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -179,7 +179,7 @@ class RequestContext(context.RequestContext):
|
||||
'read_deleted': getattr(self, 'read_deleted', 'no'),
|
||||
'roles': getattr(self, 'roles', None),
|
||||
'remote_address': getattr(self, 'remote_address', None),
|
||||
'timestamp': timeutils.strtime(self.timestamp) if hasattr(
|
||||
'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),
|
||||
|
@ -37,7 +37,6 @@ from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import excutils
|
||||
from oslo_utils import fileutils
|
||||
from oslo_utils import timeutils
|
||||
import paramiko
|
||||
import six
|
||||
|
||||
@ -253,12 +252,12 @@ def revoke_certs_by_user_and_project(user_id, project_id):
|
||||
|
||||
def _project_cert_subject(project_id):
|
||||
"""Helper to generate user cert subject."""
|
||||
return CONF.project_cert_subject % (project_id, timeutils.isotime())
|
||||
return CONF.project_cert_subject % (project_id, utils.isotime())
|
||||
|
||||
|
||||
def _user_cert_subject(user_id, project_id):
|
||||
"""Helper to generate user cert subject."""
|
||||
return CONF.user_cert_subject % (project_id, user_id, timeutils.isotime())
|
||||
return CONF.user_cert_subject % (project_id, user_id, utils.isotime())
|
||||
|
||||
|
||||
def generate_x509_cert(user_id, project_id, bits=2048):
|
||||
|
@ -377,7 +377,7 @@ def info_from_instance(context, instance, network_info,
|
||||
|
||||
def null_safe_isotime(s):
|
||||
if isinstance(s, datetime.datetime):
|
||||
return timeutils.strtime(s)
|
||||
return utils.strtime(s)
|
||||
else:
|
||||
return str(s) if s else ''
|
||||
|
||||
|
@ -22,7 +22,6 @@ import traceback
|
||||
import netaddr
|
||||
from oslo_log import log as logging
|
||||
import oslo_messaging as messaging
|
||||
from oslo_utils import timeutils
|
||||
from oslo_versionedobjects import base as ovoo_base
|
||||
from oslo_versionedobjects import exception as ovoo_exc
|
||||
import six
|
||||
@ -334,7 +333,7 @@ def obj_make_list(context, list_obj, item_cls, db_list, **extra_args):
|
||||
def serialize_args(fn):
|
||||
"""Decorator that will do the arguments serialization before remoting."""
|
||||
def wrapper(obj, *args, **kwargs):
|
||||
args = [timeutils.strtime(at=arg) if isinstance(arg, datetime.datetime)
|
||||
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:
|
||||
@ -342,7 +341,7 @@ def serialize_args(fn):
|
||||
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] = timeutils.strtime(at=v)
|
||||
kwargs[k] = utils.strtime(v)
|
||||
if hasattr(fn, '__call__'):
|
||||
return fn(obj, *args, **kwargs)
|
||||
# NOTE(danms): We wrap a descriptor, so use that protocol
|
||||
|
@ -171,7 +171,7 @@ class FixedIP(obj_base.NovaPersistentObject, obj_base.NovaObject,
|
||||
@classmethod
|
||||
def disassociate_all_by_timeout(cls, context, host, time):
|
||||
return cls._disassociate_all_by_timeout(context, host,
|
||||
timeutils.isotime(time))
|
||||
utils.isotime(time))
|
||||
|
||||
@obj_base.remotable
|
||||
def create(self):
|
||||
|
@ -1076,8 +1076,8 @@ class InstanceList(base.ObjectListBase, base.NovaObject):
|
||||
"""
|
||||
# NOTE(mriedem): We have to convert the datetime objects to string
|
||||
# primitives for the remote call.
|
||||
begin = timeutils.isotime(begin)
|
||||
end = timeutils.isotime(end) if end else None
|
||||
begin = utils.isotime(begin)
|
||||
end = utils.isotime(end) if end else None
|
||||
return cls._get_active_by_window_joined(context, begin, end,
|
||||
project_id, host,
|
||||
expected_attrs,
|
||||
|
@ -11,7 +11,6 @@
|
||||
# under the License.
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import timeutils
|
||||
|
||||
from nova.objects import base
|
||||
from nova.objects import fields
|
||||
@ -60,7 +59,7 @@ class MonitorMetric(base.NovaObject):
|
||||
# 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': timeutils.strtime(self.timestamp),
|
||||
'timestamp': utils.strtime(self.timestamp),
|
||||
'source': self.source,
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ from nova.tests.unit import cast_as_call
|
||||
from nova.tests.unit import fake_network
|
||||
from nova.tests.unit import fake_notifier
|
||||
from nova.tests.unit.image import fake
|
||||
from nova import utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.import_opt('compute_driver', 'nova.virt.driver')
|
||||
@ -227,20 +228,18 @@ class EC2TimestampValidationTestCase(test.NoDBTestCase):
|
||||
|
||||
# EC2 request with Timestamp in advanced time
|
||||
timestamp = timeutils.utcnow() + datetime.timedelta(seconds=250)
|
||||
params = {'Timestamp': timeutils.strtime(timestamp,
|
||||
"%Y-%m-%dT%H:%M:%SZ")}
|
||||
params = {'Timestamp': utils.isotime(timestamp)}
|
||||
expired = ec2utils.is_ec2_timestamp_expired(params, expires=300)
|
||||
self.assertFalse(expired)
|
||||
|
||||
def test_validate_ec2_timestamp_advanced_time_expired(self):
|
||||
timestamp = timeutils.utcnow() + datetime.timedelta(seconds=350)
|
||||
params = {'Timestamp': timeutils.strtime(timestamp,
|
||||
"%Y-%m-%dT%H:%M:%SZ")}
|
||||
params = {'Timestamp': utils.isotime(timestamp)}
|
||||
expired = ec2utils.is_ec2_timestamp_expired(params, expires=300)
|
||||
self.assertTrue(expired)
|
||||
|
||||
def test_validate_ec2_req_timestamp_not_expired(self):
|
||||
params = {'Timestamp': timeutils.isotime()}
|
||||
params = {'Timestamp': utils.isotime()}
|
||||
expired = ec2utils.is_ec2_timestamp_expired(params, expires=15)
|
||||
self.assertFalse(expired)
|
||||
|
||||
@ -250,13 +249,13 @@ class EC2TimestampValidationTestCase(test.NoDBTestCase):
|
||||
self.assertTrue(compare)
|
||||
|
||||
def test_validate_ec2_req_expired(self):
|
||||
params = {'Expires': timeutils.isotime()}
|
||||
params = {'Expires': utils.isotime()}
|
||||
expired = ec2utils.is_ec2_timestamp_expired(params)
|
||||
self.assertTrue(expired)
|
||||
|
||||
def test_validate_ec2_req_not_expired(self):
|
||||
expire = timeutils.utcnow() + datetime.timedelta(seconds=350)
|
||||
params = {'Expires': timeutils.strtime(expire, "%Y-%m-%dT%H:%M:%SZ")}
|
||||
params = {'Expires': utils.isotime(expire)}
|
||||
expired = ec2utils.is_ec2_timestamp_expired(params)
|
||||
self.assertFalse(expired)
|
||||
|
||||
@ -271,7 +270,7 @@ class EC2TimestampValidationTestCase(test.NoDBTestCase):
|
||||
|
||||
# EC2 request with both Timestamp and Expires
|
||||
params = {'Timestamp': '2011-04-22T11:29:49Z',
|
||||
'Expires': timeutils.isotime()}
|
||||
'Expires': utils.isotime()}
|
||||
self.assertRaises(exception.InvalidRequest,
|
||||
ec2utils.is_ec2_timestamp_expired,
|
||||
params)
|
||||
|
@ -2047,7 +2047,7 @@ class ComputeTestCase(BaseTestCase):
|
||||
instance = self._create_fake_instance_obj()
|
||||
image = {'id': 'fake_id'}
|
||||
# Adding shelved information to instance system metadata.
|
||||
shelved_time = timeutils.strtime(at=timeutils.utcnow())
|
||||
shelved_time = timeutils.utcnow().isoformat()
|
||||
instance.system_metadata['shelved_at'] = shelved_time
|
||||
instance.system_metadata['shelved_image_id'] = image['id']
|
||||
instance.system_metadata['shelved_host'] = 'fake-mini'
|
||||
@ -3958,8 +3958,8 @@ class ComputeTestCase(BaseTestCase):
|
||||
self.assertIn('launched_at', payload)
|
||||
self.assertIn('terminated_at', payload)
|
||||
self.assertIn('deleted_at', payload)
|
||||
self.assertEqual(payload['terminated_at'], timeutils.strtime(cur_time))
|
||||
self.assertEqual(payload['deleted_at'], timeutils.strtime(cur_time))
|
||||
self.assertEqual(payload['terminated_at'], utils.strtime(cur_time))
|
||||
self.assertEqual(payload['deleted_at'], utils.strtime(cur_time))
|
||||
image_ref_url = glance.generate_image_url(FAKE_IMAGE_REF)
|
||||
self.assertEqual(payload['image_ref_url'], image_ref_url)
|
||||
|
||||
@ -4882,7 +4882,7 @@ class ComputeTestCase(BaseTestCase):
|
||||
self.assertIn('display_name', payload)
|
||||
self.assertIn('created_at', payload)
|
||||
self.assertIn('launched_at', payload)
|
||||
self.assertEqual(payload['launched_at'], timeutils.strtime(cur_time))
|
||||
self.assertEqual(payload['launched_at'], utils.strtime(cur_time))
|
||||
self.assertEqual(payload['image_ref_url'], new_image_ref_url)
|
||||
self.compute.terminate_instance(self.context, inst_ref, [], [])
|
||||
|
||||
@ -4940,7 +4940,7 @@ class ComputeTestCase(BaseTestCase):
|
||||
self.assertIn('display_name', payload)
|
||||
self.assertIn('created_at', payload)
|
||||
self.assertIn('launched_at', payload)
|
||||
self.assertEqual(payload['launched_at'], timeutils.strtime(cur_time))
|
||||
self.assertEqual(payload['launched_at'], utils.strtime(cur_time))
|
||||
image_ref_url = glance.generate_image_url(FAKE_IMAGE_REF)
|
||||
self.assertEqual(payload['image_ref_url'], image_ref_url)
|
||||
self.compute.terminate_instance(self.context, instance, [], [])
|
||||
|
@ -1194,8 +1194,7 @@ class ComputeMonitorTestCase(BaseTestCase):
|
||||
|
||||
expected_metrics = [
|
||||
{
|
||||
'timestamp': timeutils.strtime(
|
||||
FakeCPUMonitor.NOW_TS),
|
||||
'timestamp': FakeCPUMonitor.NOW_TS.isoformat(),
|
||||
'name': 'cpu.frequency',
|
||||
'value': 100,
|
||||
'source': 'FakeCPUMonitor'
|
||||
|
@ -191,7 +191,7 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
|
||||
# Adding shelved_* keys in system metadata to verify
|
||||
# whether those are deleted after unshelve call.
|
||||
sys_meta = dict(instance.system_metadata)
|
||||
sys_meta['shelved_at'] = timeutils.strtime(at=cur_time)
|
||||
sys_meta['shelved_at'] = cur_time.isoformat()
|
||||
sys_meta['shelved_image_id'] = image['id']
|
||||
sys_meta['shelved_host'] = host
|
||||
instance.system_metadata = sys_meta
|
||||
@ -360,7 +360,7 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
|
||||
instance.task_state = None
|
||||
instance.host = self.compute.host
|
||||
sys_meta = instance.system_metadata
|
||||
sys_meta['shelved_at'] = timeutils.strtime(at=shelved_time)
|
||||
sys_meta['shelved_at'] = shelved_time.isoformat()
|
||||
instance.save()
|
||||
|
||||
with mock.patch.object(self.compute, 'shelve_offload_instance') as soi:
|
||||
@ -378,7 +378,7 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
|
||||
instance.task_state = None
|
||||
instance.host = self.compute.host
|
||||
sys_meta = instance.system_metadata
|
||||
sys_meta['shelved_at'] = timeutils.strtime(at=shelved_time)
|
||||
sys_meta['shelved_at'] = shelved_time.isoformat()
|
||||
instance.save()
|
||||
|
||||
data = []
|
||||
|
@ -3654,7 +3654,7 @@ class InstanceActionTestCase(test.TestCase, ModelsObjectComparatorMixin):
|
||||
|
||||
action = db.action_start(self.ctxt, self._create_action_values(uuid))
|
||||
|
||||
event_values = {'start_time': timeutils.strtime(timeutils.utcnow())}
|
||||
event_values = {'start_time': timeutils.utcnow().isoformat()}
|
||||
event_values = self._create_event_values(uuid, extra=event_values)
|
||||
event = db.action_event_start(self.ctxt, event_values)
|
||||
|
||||
@ -5762,8 +5762,8 @@ class TaskLogTestCase(test.TestCase):
|
||||
super(TaskLogTestCase, self).setUp()
|
||||
self.context = context.get_admin_context()
|
||||
now = timeutils.utcnow()
|
||||
self.begin = timeutils.strtime(now - datetime.timedelta(seconds=10))
|
||||
self.end = timeutils.strtime(now - datetime.timedelta(seconds=5))
|
||||
self.begin = (now - datetime.timedelta(seconds=10)).isoformat()
|
||||
self.end = (now - datetime.timedelta(seconds=5)).isoformat()
|
||||
self.task_name = 'fake-task-name'
|
||||
self.host = 'fake-host'
|
||||
self.message = 'Fake task message'
|
||||
@ -7859,9 +7859,9 @@ class BwUsageTestCase(test.TestCase, ModelsObjectComparatorMixin):
|
||||
def test_bw_usage_get_by_uuids(self):
|
||||
now = timeutils.utcnow()
|
||||
start_period = now - datetime.timedelta(seconds=10)
|
||||
start_period_str = timeutils.strtime(start_period)
|
||||
start_period_str = start_period.isoformat()
|
||||
uuid3_refreshed = now - datetime.timedelta(seconds=5)
|
||||
uuid3_refreshed_str = timeutils.strtime(uuid3_refreshed)
|
||||
uuid3_refreshed_str = uuid3_refreshed.isoformat()
|
||||
|
||||
expected_bw_usages = {
|
||||
'fake_uuid1': {'uuid': 'fake_uuid1',
|
||||
@ -7934,7 +7934,7 @@ class BwUsageTestCase(test.TestCase, ModelsObjectComparatorMixin):
|
||||
def test_bw_usage_get(self):
|
||||
now = timeutils.utcnow()
|
||||
start_period = now - datetime.timedelta(seconds=10)
|
||||
start_period_str = timeutils.strtime(start_period)
|
||||
start_period_str = start_period.isoformat()
|
||||
|
||||
expected_bw_usage = {'uuid': 'fake_uuid1',
|
||||
'mac': 'fake_mac1',
|
||||
|
@ -16,13 +16,13 @@ import datetime
|
||||
|
||||
import iso8601
|
||||
import netaddr
|
||||
from oslo_utils import timeutils
|
||||
from oslo_versionedobjects import exception as ovo_exc
|
||||
import six
|
||||
|
||||
from nova.network import model as network_model
|
||||
from nova.objects import fields
|
||||
from nova import test
|
||||
from nova import utils
|
||||
|
||||
|
||||
class FakeFieldType(fields.FieldType):
|
||||
@ -662,10 +662,10 @@ class TestDateTime(TestField):
|
||||
self.dt = datetime.datetime(1955, 11, 5, tzinfo=iso8601.iso8601.Utc())
|
||||
self.field = fields.DateTimeField()
|
||||
self.coerce_good_values = [(self.dt, self.dt),
|
||||
(timeutils.isotime(self.dt), self.dt)]
|
||||
(utils.isotime(self.dt), self.dt)]
|
||||
self.coerce_bad_values = [1, 'foo']
|
||||
self.to_primitive_values = [(self.dt, timeutils.isotime(self.dt))]
|
||||
self.from_primitive_values = [(timeutils.isotime(self.dt), self.dt)]
|
||||
self.to_primitive_values = [(self.dt, utils.isotime(self.dt))]
|
||||
self.from_primitive_values = [(utils.isotime(self.dt), self.dt)]
|
||||
|
||||
def test_stringify(self):
|
||||
self.assertEqual(
|
||||
|
@ -25,7 +25,7 @@ from nova.objects import fixed_ip
|
||||
from nova.tests.unit import fake_instance
|
||||
from nova.tests.unit.objects import test_network
|
||||
from nova.tests.unit.objects import test_objects
|
||||
|
||||
from nova import utils
|
||||
|
||||
fake_fixed_ip = {
|
||||
'created_at': None,
|
||||
@ -210,7 +210,7 @@ class _TestFixedIPObject(object):
|
||||
def test_disassociate_all_by_timeout(self, disassociate):
|
||||
now = timeutils.utcnow()
|
||||
now_tz = timeutils.parse_isotime(
|
||||
timeutils.isotime(now)).replace(
|
||||
utils.isotime(now)).replace(
|
||||
tzinfo=iso8601.iso8601.Utc())
|
||||
disassociate.return_value = 123
|
||||
result = fixed_ip.FixedIP.disassociate_all_by_timeout(self.context,
|
||||
|
@ -44,6 +44,7 @@ from nova.tests.unit.objects import test_migration_context as test_mig_ctxt
|
||||
from nova.tests.unit.objects import test_objects
|
||||
from nova.tests.unit.objects import test_security_group
|
||||
from nova.tests.unit.objects import test_vcpu_model
|
||||
from nova import utils
|
||||
|
||||
|
||||
class _TestInstanceObject(object):
|
||||
@ -74,7 +75,7 @@ class _TestInstanceObject(object):
|
||||
|
||||
def test_datetime_deserialization(self):
|
||||
red_letter_date = timeutils.parse_isotime(
|
||||
timeutils.isotime(datetime.datetime(1955, 11, 5)))
|
||||
utils.isotime(datetime.datetime(1955, 11, 5)))
|
||||
inst = objects.Instance(uuid='fake-uuid', launched_at=red_letter_date)
|
||||
primitive = inst.obj_to_primitive()
|
||||
expected = {'nova_object.name': 'Instance',
|
||||
@ -1479,7 +1480,7 @@ class _TestInstanceListObject(object):
|
||||
def test_get_hung_in_rebooting(self):
|
||||
fakes = [self.fake_instance(1),
|
||||
self.fake_instance(2)]
|
||||
dt = timeutils.isotime()
|
||||
dt = utils.isotime()
|
||||
self.mox.StubOutWithMock(db, 'instance_get_all_hung_in_rebooting')
|
||||
db.instance_get_all_hung_in_rebooting(self.context, dt).AndReturn(
|
||||
fakes)
|
||||
|
@ -21,21 +21,21 @@ _ts_now = timeutils.utcnow()
|
||||
_monitor_metric_spec = {
|
||||
'name': fields.MonitorMetricType.CPU_FREQUENCY,
|
||||
'value': 1000,
|
||||
'timestamp': timeutils.strtime(_ts_now),
|
||||
'timestamp': _ts_now.isoformat(),
|
||||
'source': 'nova.virt.libvirt.driver'
|
||||
}
|
||||
|
||||
_monitor_metric_perc_spec = {
|
||||
'name': fields.MonitorMetricType.CPU_PERCENT,
|
||||
'value': 0.17,
|
||||
'timestamp': timeutils.strtime(_ts_now),
|
||||
'timestamp': _ts_now.isoformat(),
|
||||
'source': 'nova.virt.libvirt.driver'
|
||||
}
|
||||
|
||||
_monitor_numa_metric_spec = {
|
||||
'name': fields.MonitorMetricType.NUMA_MEM_BW_CURRENT,
|
||||
'numa_membw_values': {"0": 10, "1": 43},
|
||||
'timestamp': timeutils.strtime(_ts_now),
|
||||
'timestamp': _ts_now.isoformat(),
|
||||
'source': 'nova.virt.libvirt.driver'
|
||||
}
|
||||
|
||||
|
@ -588,8 +588,8 @@ class _TestObject(object):
|
||||
'nova_object.changes':
|
||||
['deleted', 'created_at', 'deleted_at', 'updated_at'],
|
||||
'nova_object.data':
|
||||
{'created_at': timeutils.isotime(dt),
|
||||
'updated_at': timeutils.isotime(dt),
|
||||
{'created_at': utils.isotime(dt),
|
||||
'updated_at': utils.isotime(dt),
|
||||
'deleted_at': None,
|
||||
'deleted': False,
|
||||
}
|
||||
@ -1103,7 +1103,7 @@ class TestArgsSerializer(test.NoDBTestCase):
|
||||
def setUp(self):
|
||||
super(TestArgsSerializer, self).setUp()
|
||||
self.now = timeutils.utcnow()
|
||||
self.str_now = timeutils.strtime(at=self.now)
|
||||
self.str_now = utils.strtime(self.now)
|
||||
self.unicode_str = u'\xF0\x9F\x92\xA9'
|
||||
|
||||
@base.serialize_args
|
||||
|
@ -18,7 +18,7 @@ from oslo_utils import timeutils
|
||||
|
||||
from nova import objects
|
||||
from nova.tests.unit.objects import test_objects
|
||||
|
||||
from nova import utils
|
||||
|
||||
NOW = timeutils.utcnow().replace(microsecond=0)
|
||||
|
||||
@ -51,8 +51,8 @@ class _TestTaskLog(object):
|
||||
mock_get.assert_called_once_with(
|
||||
self.context,
|
||||
fake_task_log['task_name'],
|
||||
timeutils.strtime(at=fake_task_log['period_beginning']),
|
||||
timeutils.strtime(at=fake_task_log['period_ending']),
|
||||
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)
|
||||
@ -123,8 +123,8 @@ class _TestTaskLogList(object):
|
||||
mock_get_all.assert_called_once_with(
|
||||
self.context,
|
||||
fake_task_log['task_name'],
|
||||
timeutils.strtime(at=fake_task_log['period_beginning']),
|
||||
timeutils.strtime(at=fake_task_log['period_ending']),
|
||||
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):
|
||||
|
@ -20,6 +20,7 @@ from nova import objects
|
||||
from nova.scheduler.filters import trusted_filter
|
||||
from nova import test
|
||||
from nova.tests.unit.scheduler import fakes
|
||||
from nova import utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
@ -113,7 +114,7 @@ class TestTrustedFilter(test.NoDBTestCase):
|
||||
def test_trusted_filter_trusted_and_trusted_passes(self, req_mock):
|
||||
oat_data = {"hosts": [{"host_name": "node1",
|
||||
"trust_lvl": "trusted",
|
||||
"vtime": timeutils.isotime()}]}
|
||||
"vtime": utils.isotime()}]}
|
||||
req_mock.return_value = requests.codes.OK, oat_data
|
||||
|
||||
extra_specs = {'trust:trusted_host': 'trusted'}
|
||||
@ -127,7 +128,7 @@ class TestTrustedFilter(test.NoDBTestCase):
|
||||
def test_trusted_filter_trusted_and_untrusted_fails(self, req_mock):
|
||||
oat_data = {"hosts": [{"host_name": "node1",
|
||||
"trust_lvl": "untrusted",
|
||||
"vtime": timeutils.isotime()}]}
|
||||
"vtime": utils.isotime()}]}
|
||||
req_mock.return_value = requests.codes.OK, oat_data
|
||||
extra_specs = {'trust:trusted_host': 'trusted'}
|
||||
filter_properties = {'context': mock.sentinel.ctx,
|
||||
@ -139,7 +140,7 @@ class TestTrustedFilter(test.NoDBTestCase):
|
||||
def test_trusted_filter_untrusted_and_trusted_fails(self, req_mock):
|
||||
oat_data = {"hosts": [{"host_name": "node",
|
||||
"trust_lvl": "trusted",
|
||||
"vtime": timeutils.isotime()}]}
|
||||
"vtime": utils.isotime()}]}
|
||||
req_mock.return_value = requests.codes.OK, oat_data
|
||||
extra_specs = {'trust:trusted_host': 'untrusted'}
|
||||
filter_properties = {'context': mock.sentinel.ctx,
|
||||
@ -151,7 +152,7 @@ class TestTrustedFilter(test.NoDBTestCase):
|
||||
def test_trusted_filter_untrusted_and_untrusted_passes(self, req_mock):
|
||||
oat_data = {"hosts": [{"host_name": "node1",
|
||||
"trust_lvl": "untrusted",
|
||||
"vtime": timeutils.isotime()}]}
|
||||
"vtime": utils.isotime()}]}
|
||||
req_mock.return_value = requests.codes.OK, oat_data
|
||||
extra_specs = {'trust:trusted_host': 'untrusted'}
|
||||
filter_properties = {'context': mock.sentinel.ctx,
|
||||
@ -163,7 +164,7 @@ class TestTrustedFilter(test.NoDBTestCase):
|
||||
def test_trusted_filter_update_cache(self, req_mock):
|
||||
oat_data = {"hosts": [{"host_name": "node1",
|
||||
"trust_lvl": "untrusted",
|
||||
"vtime": timeutils.isotime()}]}
|
||||
"vtime": utils.isotime()}]}
|
||||
|
||||
req_mock.return_value = requests.codes.OK, oat_data
|
||||
extra_specs = {'trust:trusted_host': 'untrusted'}
|
||||
@ -247,10 +248,12 @@ class TestTrustedFilter(test.NoDBTestCase):
|
||||
req_mock):
|
||||
oat_data = {"hosts": [{"host_name": "host1",
|
||||
"trust_lvl": "trusted",
|
||||
"vtime": timeutils.strtime(fmt="%c")},
|
||||
"vtime": timeutils.utcnow().strftime(
|
||||
"%c")},
|
||||
{"host_name": "host2",
|
||||
"trust_lvl": "trusted",
|
||||
"vtime": timeutils.strtime(fmt="%D")},
|
||||
"vtime": timeutils.utcnow().strftime(
|
||||
"%D")},
|
||||
# This is just a broken date to ensure that
|
||||
# we're not just arbitrarily accepting any
|
||||
# date format.
|
||||
|
@ -1870,8 +1870,7 @@ class VMwareAPIVMTestCase(test.NoDBTestCase):
|
||||
|
||||
def _get_timestamp_filename(self):
|
||||
return '%s%s' % (imagecache.TIMESTAMP_PREFIX,
|
||||
timeutils.strtime(at=self.old_time,
|
||||
fmt=imagecache.TIMESTAMP_FORMAT))
|
||||
self.old_time.strftime(imagecache.TIMESTAMP_FORMAT))
|
||||
|
||||
def _override_time(self):
|
||||
self.old_time = datetime.datetime(2012, 11, 22, 12, 00, 00)
|
||||
|
@ -54,8 +54,7 @@ class ImageCacheManagerTestCase(test.NoDBTestCase):
|
||||
if not self.exists:
|
||||
return
|
||||
ts = '%s%s' % (imagecache.TIMESTAMP_PREFIX,
|
||||
timeutils.strtime(at=self._time,
|
||||
fmt=imagecache.TIMESTAMP_FORMAT))
|
||||
self._time.strftime(imagecache.TIMESTAMP_FORMAT))
|
||||
return ts
|
||||
|
||||
with test.nested(
|
||||
|
@ -1539,3 +1539,21 @@ def delete_cached_file(filename):
|
||||
|
||||
if filename in _FILE_CACHE:
|
||||
del _FILE_CACHE[filename]
|
||||
|
||||
|
||||
def isotime(at=None):
|
||||
"""Current time as ISO string,
|
||||
as timeutils.isotime() is deprecated
|
||||
|
||||
:returns: Current time in ISO format
|
||||
"""
|
||||
if not at:
|
||||
at = timeutils.utcnow()
|
||||
date_string = at.strftime("%Y-%m-%dT%H:%M:%S")
|
||||
tz = at.tzinfo.tzname(None) if at.tzinfo else 'UTC'
|
||||
date_string += ('Z' if tz == 'UTC' else tz)
|
||||
return date_string
|
||||
|
||||
|
||||
def strtime(at):
|
||||
return at.strftime("%Y-%m-%dT%H:%M:%S.%f")
|
||||
|
@ -112,7 +112,7 @@ class ImageCacheManager(imagecache.ImageCacheManager):
|
||||
|
||||
def _get_timestamp_filename(self):
|
||||
return '%s%s' % (TIMESTAMP_PREFIX,
|
||||
timeutils.strtime(fmt=TIMESTAMP_FORMAT))
|
||||
timeutils.utcnow().strftime(TIMESTAMP_FORMAT))
|
||||
|
||||
def _get_datetime_from_filename(self, timestamp_filename):
|
||||
ts = timestamp_filename.lstrip(TIMESTAMP_PREFIX)
|
||||
|
Loading…
x
Reference in New Issue
Block a user