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): ...@@ -177,17 +177,19 @@ class SoftwareInstance(Item):
software_instance_dict['_instance_guid'] = instance_guid software_instance_dict['_instance_guid'] = instance_guid
return software_instance_dict return software_instance_dict
def _getModificationDateAsTimestamp(self, document):
return int(float(document.getModificationDate()) * 1e6)
@UnrestrictedMethod @UnrestrictedMethod
def _asParameterDict(self, shared_instance_sql_list=None): def _asParameterDict(self, shared_instance_sql_list=None):
portal = self.getPortalObject() portal = self.getPortalObject()
compute_partition = self.getAggregateValue(portal_type="Compute Partition") compute_partition = self.getAggregateValue(portal_type="Compute Partition")
if compute_partition is None: if compute_partition is None:
raise ValueError("Instance isn't allocated to call _asParamterDict") 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))) timestamp = max(
if (newtimestamp > timestamp): self._getModificationDateAsTimestamp(compute_partition),
timestamp = newtimestamp int(self.getBangTimestamp(self._getModificationDateAsTimestamp(self))))
instance_tree = self.getSpecialiseValue() instance_tree = self.getSpecialiseValue()
...@@ -222,18 +224,19 @@ class SoftwareInstance(Item): ...@@ -222,18 +224,19 @@ class SoftwareInstance(Item):
shared_instance = _assertACI(shared_instance.getObject()) shared_instance = _assertACI(shared_instance.getObject())
# XXX Use catalog to filter more efficiently # XXX Use catalog to filter more efficiently
if shared_instance.getSlapState() == "start_requested": 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({ append({
'slave_title': shared_instance.getTitle().decode("UTF-8"), 'slave_title': shared_instance.getTitle().decode("UTF-8"),
'slap_software_type': \ 'slap_software_type': \
shared_instance.getSourceReference().decode("UTF-8"), shared_instance.getSourceReference().decode("UTF-8"),
'slave_reference': shared_instance.getReference().decode("UTF-8"), 'slave_reference': shared_instance.getReference().decode("UTF-8"),
'timestamp': newtimestamp, 'timestamp': shared_timestamp,
'xml': shared_instance.getTextContent(), 'xml': shared_instance.getTextContent(),
'connection_xml': shared_instance.getConnectionXml(), 'connection_xml': shared_instance.getConnectionXml(),
}) })
if (newtimestamp > timestamp): timestamp = max(timestamp, shared_timestamp)
timestamp = newtimestamp
return { return {
'instance_guid': self.getReference().decode("UTF-8"), 'instance_guid': self.getReference().decode("UTF-8"),
'instance_title': self.getTitle().decode("UTF-8"), 'instance_title': self.getTitle().decode("UTF-8"),
...@@ -253,7 +256,7 @@ class SoftwareInstance(Item): ...@@ -253,7 +256,7 @@ class SoftwareInstance(Item):
'slave_instance_list': shared_instance_list, 'slave_instance_list': shared_instance_list,
'ip_list': ip_list, 'ip_list': ip_list,
'full_ip_list': full_ip_list, 'full_ip_list': full_ip_list,
'timestamp': "%i" % timestamp, 'timestamp': timestamp,
} }
@UnrestrictedMethod @UnrestrictedMethod
......
...@@ -363,7 +363,7 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin): ...@@ -363,7 +363,7 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin):
<string>slave_instance_list</string> <string>slave_instance_list</string>
<list id="i14"/> <list id="i14"/>
<string>timestamp</string> <string>timestamp</string>
<string>%(partition_3_timestamp)s</string> <int>%(partition_3_timestamp)s</int>
</dictionary> </dictionary>
<string>_partition_id</string> <string>_partition_id</string>
<string>partition3</string> <string>partition3</string>
...@@ -440,7 +440,7 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin): ...@@ -440,7 +440,7 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin):
<string>slave_instance_list</string> <string>slave_instance_list</string>
<list id="i25"/> <list id="i25"/>
<string>timestamp</string> <string>timestamp</string>
<string>%(partition_2_timestamp)s</string> <int>%(partition_2_timestamp)s</int>
</dictionary> </dictionary>
<string>_partition_id</string> <string>_partition_id</string>
<string>partition2</string> <string>partition2</string>
...@@ -530,7 +530,7 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin): ...@@ -530,7 +530,7 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin):
</dictionary> </dictionary>
</list> </list>
<string>timestamp</string> <string>timestamp</string>
<string>%(partition_1_timestamp)s</string> <int>%(partition_1_timestamp)s</int>
</dictionary> </dictionary>
<string>_partition_id</string> <string>_partition_id</string>
<string>partition1</string> <string>partition1</string>
...@@ -1247,7 +1247,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin): ...@@ -1247,7 +1247,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
</dictionary> </dictionary>
</list> </list>
<string>timestamp</string> <string>timestamp</string>
<string>%(timestamp)s</string> <int>%(timestamp)s</int>
</dictionary> </dictionary>
<string>_partition_id</string> <string>_partition_id</string>
<string>partition1</string> <string>partition1</string>
...@@ -1482,7 +1482,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin): ...@@ -1482,7 +1482,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
</dictionary> </dictionary>
</list> </list>
<string>timestamp</string> <string>timestamp</string>
<string>%(timestamp)s</string> <int>%(timestamp)s</int>
</dictionary> </dictionary>
<string>_partition_id</string> <string>_partition_id</string>
<string>partition1</string> <string>partition1</string>
...@@ -1597,7 +1597,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin): ...@@ -1597,7 +1597,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<string>slave_instance_list</string> <string>slave_instance_list</string>
<list id="i9"/> <list id="i9"/>
<string>timestamp</string> <string>timestamp</string>
<string>%(timestamp)s</string> <int>%(timestamp)s</int>
</dictionary> </dictionary>
<string>_partition_id</string> <string>_partition_id</string>
<string>partition1</string> <string>partition1</string>
...@@ -2775,7 +2775,7 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin): ...@@ -2775,7 +2775,7 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
</dictionary> </dictionary>
</list> </list>
<string>timestamp</string> <string>timestamp</string>
<string>%(timestamp)s</string> <int>%(timestamp)s</int>
</dictionary> </dictionary>
<string>_partition_id</string> <string>_partition_id</string>
<string>partition1</string> <string>partition1</string>
...@@ -2890,7 +2890,7 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin): ...@@ -2890,7 +2890,7 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
<string>slave_instance_list</string> <string>slave_instance_list</string>
<list id="i9"/> <list id="i9"/>
<string>timestamp</string> <string>timestamp</string>
<string>%(timestamp)s</string> <int>%(timestamp)s</int>
</dictionary> </dictionary>
<string>_partition_id</string> <string>_partition_id</string>
<string>partition1</string> <string>partition1</string>
...@@ -3195,7 +3195,7 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin): ...@@ -3195,7 +3195,7 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
<string>slave_instance_list</string> <string>slave_instance_list</string>
<list id="i9"/> <list id="i9"/>
<string>timestamp</string> <string>timestamp</string>
<string>%(timestamp)s</string> <int>%(timestamp)s</int>
</dictionary> </dictionary>
</object> </object>
</marshal> </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