Commit b9929aeb authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_cloud: Normalize type for timestamp and Use max rather them if

   All timestamps parameters should be int, and be consistent accross
   the parameters.

   The client compare previous/fetched as float, so use string can break
   later on if we introduce a non-numeric value on returned dict.
parent d5f7a311
......@@ -177,17 +177,19 @@ class SoftwareInstance(Item):
software_instance_dict['_instance_guid'] = instance_guid
return software_instance_dict
def _getModificationDateAsTimestamp(self, document):
return int(float(document.getModificationDate()) * 1e6)
@UnrestrictedMethod
def _asParameterDict(self, shared_instance_sql_list=None):
portal = self.getPortalObject()
compute_partition = self.getAggregateValue(portal_type="Compute Partition")
if compute_partition is None:
raise ValueError("Instance isn't allocated to call _asParamterDict")
timestamp = int(float(compute_partition.getModificationDate()) * 1e6)
newtimestamp = int(self.getBangTimestamp(int(float(self.getModificationDate()) * 1e6)))
if (newtimestamp > timestamp):
timestamp = newtimestamp
timestamp = max(
self._getModificationDateAsTimestamp(compute_partition),
int(self.getBangTimestamp(self._getModificationDateAsTimestamp(self))))
instance_tree = self.getSpecialiseValue()
......@@ -222,18 +224,19 @@ class SoftwareInstance(Item):
shared_instance = _assertACI(shared_instance.getObject())
# XXX Use catalog to filter more efficiently
if shared_instance.getSlapState() == "start_requested":
newtimestamp = int(shared_instance.getBangTimestamp(int(shared_instance.getModificationDate())))
shared_timestamp = int(shared_instance.getBangTimestamp(
self._getModificationDateAsTimestamp(shared_instance)))
append({
'slave_title': shared_instance.getTitle().decode("UTF-8"),
'slap_software_type': \
shared_instance.getSourceReference().decode("UTF-8"),
'slave_reference': shared_instance.getReference().decode("UTF-8"),
'timestamp': newtimestamp,
'timestamp': shared_timestamp,
'xml': shared_instance.getTextContent(),
'connection_xml': shared_instance.getConnectionXml(),
})
if (newtimestamp > timestamp):
timestamp = newtimestamp
timestamp = max(timestamp, shared_timestamp)
return {
'instance_guid': self.getReference().decode("UTF-8"),
'instance_title': self.getTitle().decode("UTF-8"),
......@@ -253,7 +256,7 @@ class SoftwareInstance(Item):
'slave_instance_list': shared_instance_list,
'ip_list': ip_list,
'full_ip_list': full_ip_list,
'timestamp': "%i" % timestamp,
'timestamp': timestamp,
}
@UnrestrictedMethod
......
......@@ -363,7 +363,7 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin):
<string>slave_instance_list</string>
<list id="i14"/>
<string>timestamp</string>
<string>%(partition_3_timestamp)s</string>
<int>%(partition_3_timestamp)s</int>
</dictionary>
<string>_partition_id</string>
<string>partition3</string>
......@@ -440,7 +440,7 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin):
<string>slave_instance_list</string>
<list id="i25"/>
<string>timestamp</string>
<string>%(partition_2_timestamp)s</string>
<int>%(partition_2_timestamp)s</int>
</dictionary>
<string>_partition_id</string>
<string>partition2</string>
......@@ -530,7 +530,7 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin):
</dictionary>
</list>
<string>timestamp</string>
<string>%(partition_1_timestamp)s</string>
<int>%(partition_1_timestamp)s</int>
</dictionary>
<string>_partition_id</string>
<string>partition1</string>
......@@ -1247,7 +1247,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
</dictionary>
</list>
<string>timestamp</string>
<string>%(timestamp)s</string>
<int>%(timestamp)s</int>
</dictionary>
<string>_partition_id</string>
<string>partition1</string>
......@@ -1482,7 +1482,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
</dictionary>
</list>
<string>timestamp</string>
<string>%(timestamp)s</string>
<int>%(timestamp)s</int>
</dictionary>
<string>_partition_id</string>
<string>partition1</string>
......@@ -1597,7 +1597,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<string>slave_instance_list</string>
<list id="i9"/>
<string>timestamp</string>
<string>%(timestamp)s</string>
<int>%(timestamp)s</int>
</dictionary>
<string>_partition_id</string>
<string>partition1</string>
......@@ -2775,7 +2775,7 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
</dictionary>
</list>
<string>timestamp</string>
<string>%(timestamp)s</string>
<int>%(timestamp)s</int>
</dictionary>
<string>_partition_id</string>
<string>partition1</string>
......@@ -2890,7 +2890,7 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
<string>slave_instance_list</string>
<list id="i9"/>
<string>timestamp</string>
<string>%(timestamp)s</string>
<int>%(timestamp)s</int>
</dictionary>
<string>_partition_id</string>
<string>partition1</string>
......@@ -3195,7 +3195,7 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
<string>slave_instance_list</string>
<list id="i9"/>
<string>timestamp</string>
<string>%(timestamp)s</string>
<int>%(timestamp)s</int>
</dictionary>
</object>
</marshal>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment