summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Waldon <bcwaldon@gmail.com>2012-07-29 23:25:55 -0700
committerBrian Waldon <bcwaldon@gmail.com>2012-07-30 09:44:50 -0700
commit9b61fdf34bee6ad9d8e28a32c4c30df243b02443 (patch)
tree2ea0936c7c340db8ea23893be7df8879141e9dc9
parent8f0d8e26d09ff6de3065864d6d62d124bcc85737 (diff)
downloadnova-9b61fdf34bee6ad9d8e28a32c4c30df243b02443.tar.gz
nova-9b61fdf34bee6ad9d8e28a32c4c30df243b02443.tar.xz
nova-9b61fdf34bee6ad9d8e28a32c4c30df243b02443.zip
Use common parse_isotime in GlanceImageService
Rather than reimplement openstack-common's isotime functionality, just use what's provided for us! Change-Id: Id44eab3c34ae2c682d27d1563c6baaf68b979d2b
-rw-r--r--nova/image/glance.py18
-rw-r--r--nova/tests/image/test_glance.py8
2 files changed, 8 insertions, 18 deletions
diff --git a/nova/image/glance.py b/nova/image/glance.py
index 4bebd2c64..0b2d29c7d 100644
--- a/nova/image/glance.py
+++ b/nova/image/glance.py
@@ -338,30 +338,14 @@ class GlanceImageService(object):
return str(user_id) == str(context.user_id)
-# utility functions
def _convert_timestamps_to_datetimes(image_meta):
"""Returns image with timestamp fields converted to datetime objects."""
for attr in ['created_at', 'updated_at', 'deleted_at']:
if image_meta.get(attr):
- image_meta[attr] = _parse_glance_iso8601_timestamp(
- image_meta[attr])
+ image_meta[attr] = timeutils.parse_isotime(image_meta[attr])
return image_meta
-def _parse_glance_iso8601_timestamp(timestamp):
- """Parse a subset of iso8601 timestamps into datetime objects."""
- iso_formats = ['%Y-%m-%dT%H:%M:%S.%f', '%Y-%m-%dT%H:%M:%S']
-
- for iso_format in iso_formats:
- try:
- return timeutils.parse_strtime(timestamp, iso_format)
- except ValueError:
- pass
-
- raise ValueError(_('%(timestamp)s does not follow any of the '
- 'signatures: %(iso_formats)s') % locals())
-
-
# NOTE(bcwaldon): used to store non-string data in glance metadata
def _json_loads(properties, attr):
prop = properties[attr]
diff --git a/nova/tests/image/test_glance.py b/nova/tests/image/test_glance.py
index 4616f0949..4d866bb7b 100644
--- a/nova/tests/image/test_glance.py
+++ b/nova/tests/image/test_glance.py
@@ -88,7 +88,13 @@ class TestGlanceImageService(test.TestCase):
"""
NOW_GLANCE_OLD_FORMAT = "2010-10-11T10:30:22"
NOW_GLANCE_FORMAT = "2010-10-11T10:30:22.000000"
- NOW_DATETIME = datetime.datetime(2010, 10, 11, 10, 30, 22)
+
+ class tzinfo(datetime.tzinfo):
+ @staticmethod
+ def utcoffset(*args, **kwargs):
+ return datetime.timedelta()
+
+ NOW_DATETIME = datetime.datetime(2010, 10, 11, 10, 30, 22, tzinfo=tzinfo())
def setUp(self):
super(TestGlanceImageService, self).setUp()