Replace 'format_time' with 'isotime'

After switching to interacting with DB via versioned objects, we have
datetime fields stored in ISO8601 format string. These strings, when
deserialized, contain an annoying timezone suffix which is not needed
most of the time because we are using UTC. This patch proposes to
replace format_time() calls with isotime() calls and thus remove the
former completely. For UTC date time values, the uniform representation
would be 'yyyy-mm-ddThh:MM:ssZ'.

Change-Id: I38b4d819640dff9426aa7771086a5606a0fd6219
This commit is contained in:
tengqm 2016-06-06 22:53:20 -04:00
parent 30a609a706
commit e8d7a8ac4f
8 changed files with 19 additions and 27 deletions

View File

@ -168,14 +168,6 @@ def random_name(length=8):
return lead + tail
def format_time(value):
"""Cut microsecond and format to isoformat string."""
if value:
value = value.replace(microsecond=0)
value = value.isoformat()
return value
def isotime(at):
"""Stringify time in ISO 8601 format.

View File

@ -208,9 +208,9 @@ class Cluster(object):
'user': self.user,
'project': self.project,
'domain': self.domain,
'init_at': utils.format_time(self.init_at),
'created_at': utils.format_time(self.created_at),
'updated_at': utils.format_time(self.updated_at),
'init_at': utils.isotime(self.init_at),
'created_at': utils.isotime(self.created_at),
'updated_at': utils.isotime(self.updated_at),
'min_size': self.min_size,
'max_size': self.max_size,
'desired_capacity': self.desired_capacity,

View File

@ -197,9 +197,9 @@ class Node(object):
'domain': self.domain,
'index': self.index,
'role': self.role,
'init_at': utils.format_time(self.init_at),
'created_at': utils.format_time(self.created_at),
'updated_at': utils.format_time(self.updated_at),
'init_at': utils.isotime(self.init_at),
'created_at': utils.isotime(self.created_at),
'updated_at': utils.isotime(self.updated_at),
'status': self.status,
'status_reason': self.status_reason,
'data': self.data,

View File

@ -175,8 +175,8 @@ class Receiver(object):
'user': self.user,
'project': self.project,
'domain': self.domain,
'created_at': utils.format_time(self.created_at),
'updated_at': utils.format_time(self.updated_at),
'created_at': utils.isotime(self.created_at),
'updated_at': utils.isotime(self.updated_at),
'cluster_id': self.cluster_id,
'actor': self.actor,
'action': self.action,

View File

@ -338,8 +338,8 @@ class Profile(object):
'domain': self.domain,
'spec': self.spec,
'metadata': self.metadata,
'created_at': utils.format_time(self.created_at),
'updated_at': utils.format_time(self.updated_at),
'created_at': utils.isotime(self.created_at),
'updated_at': utils.isotime(self.updated_at),
}
return pb_dict

View File

@ -182,9 +182,9 @@ class TestNode(base.SenlinTestCase):
'domain': node.domain,
'index': node.index,
'role': node.role,
'init_at': common_utils.format_time(node.init_at),
'created_at': common_utils.format_time(node.created_at),
'updated_at': common_utils.format_time(node.updated_at),
'init_at': common_utils.isotime(node.init_at),
'created_at': common_utils.isotime(node.created_at),
'updated_at': common_utils.isotime(node.updated_at),
'status': node.status,
'status_reason': node.status_reason,
'data': node.data,
@ -212,9 +212,9 @@ class TestNode(base.SenlinTestCase):
'domain': node.domain,
'index': node.index,
'role': node.role,
'init_at': common_utils.format_time(node.init_at),
'created_at': common_utils.format_time(node.created_at),
'updated_at': common_utils.format_time(node.updated_at),
'init_at': common_utils.isotime(node.init_at),
'created_at': common_utils.isotime(node.created_at),
'updated_at': common_utils.isotime(node.updated_at),
'status': node.status,
'status_reason': node.status_reason,
'data': node.data,

View File

@ -236,8 +236,8 @@ class TestReceiver(base.SenlinTestCase):
'action': receiver.action,
'actor': receiver.actor,
'params': receiver.params,
'created_at': common_utils.format_time(receiver.created_at),
'updated_at': receiver.updated_at,
'created_at': common_utils.isotime(receiver.created_at),
'updated_at': common_utils.isotime(receiver.updated_at),
'channel': None,
}

View File

@ -672,7 +672,7 @@ class TestProfileBase(base.SenlinTestCase):
'domain': profile.domain,
'spec': profile.spec,
'metadata': profile.metadata,
'created_at': common_utils.format_time(profile.created_at),
'created_at': common_utils.isotime(profile.created_at),
'updated_at': None,
}