Commit 984b64c9 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_cloud: Add reference and portal_type on access status

   The access status is now widely used and often fetch in bulk (list of software instances of a computer). Include reference and portal_type gives a hind of which object the message is from, which helps on gadgets and APIs (by reducing the number of fetches for example).
parent 62d6f6cf
...@@ -78,7 +78,9 @@ class SlapOSCacheMixin: ...@@ -78,7 +78,9 @@ class SlapOSCacheMixin:
'since': '%s' % last_modified, 'since': '%s' % last_modified,
'state': "", 'state': "",
"text": "#error no data found for %s" % self.getReference(), "text": "#error no data found for %s" % self.getReference(),
"no_data": 1 "no_data": 1,
'reference': self.getReference(),
'portal_type': self.getPortalType()
} }
# Prepare for xml marshalling # Prepare for xml marshalling
#data_dict["text"] = data_dict["text"].decode("UTF-8") #data_dict["text"] = data_dict["text"].decode("UTF-8")
...@@ -128,7 +130,9 @@ class SlapOSCacheMixin: ...@@ -128,7 +130,9 @@ class SlapOSCacheMixin:
'created_at': '%s' % created_at, 'created_at': '%s' % created_at,
'text': '%s' % text, 'text': '%s' % text,
'since': '%s' % since, 'since': '%s' % since,
'state': state 'state': state,
'reference': self.getReference(),
'portal_type': self.getPortalType()
}) })
cache_duration = self._getAccessStatusCacheFactory().cache_duration cache_duration = self._getAccessStatusCacheFactory().cache_duration
......
...@@ -6,12 +6,6 @@ ...@@ -6,12 +6,6 @@
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item> <item>
<key> <string>default_reference</string> </key> <key> <string>default_reference</string> </key>
<value> <string>SlapOSCacheMixin</string> </value> <value> <string>SlapOSCacheMixin</string> </value>
...@@ -61,28 +55,13 @@ ...@@ -61,28 +55,13 @@
<item> <item>
<key> <string>workflow_history</string> </key> <key> <string>workflow_history</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="2" aka="AAAAAAAAAAI="> <record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="PersistentMapping" module="Persistence.mapping"/> <global name="PersistentMapping" module="Persistence.mapping"/>
</pickle> </pickle>
...@@ -95,7 +74,7 @@ ...@@ -95,7 +74,7 @@
<item> <item>
<key> <string>component_validation_workflow</string> </key> <key> <string>component_validation_workflow</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
...@@ -104,7 +83,7 @@ ...@@ -104,7 +83,7 @@
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
......
...@@ -27,6 +27,10 @@ ...@@ -27,6 +27,10 @@
############################################################################## ##############################################################################
def _decode_with_json(value):
# Ensure value is serisalisable as json
return json.loads(json.dumps(value))
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin
from DateTime import DateTime from DateTime import DateTime
from App.Common import rfc1123_date from App.Common import rfc1123_date
...@@ -67,6 +71,8 @@ class TestSlapOSCloudSlapOSCacheMixin( ...@@ -67,6 +71,8 @@ class TestSlapOSCloudSlapOSCacheMixin(
created_at = since created_at = since
def getBaseExpectedDict(doc): def getBaseExpectedDict(doc):
return { return {
"portal_type": doc.getPortalType(),
"reference": doc.getReference(),
"user": "SlapOS Master", "user": "SlapOS Master",
'created_at': '%s' % created_at, 'created_at': '%s' % created_at,
'since': '%s' % since, 'since': '%s' % since,
...@@ -102,6 +108,8 @@ class TestSlapOSCloudSlapOSCacheMixin( ...@@ -102,6 +108,8 @@ class TestSlapOSCloudSlapOSCacheMixin(
def getExpectedCacheDict(doc): def getExpectedCacheDict(doc):
return json.dumps({ return json.dumps({
"portal_type": doc.getPortalType(),
"reference": doc.getReference(),
"user": "ERP5TypeTestCase", "user": "ERP5TypeTestCase",
'created_at': '%s' % created_at, 'created_at': '%s' % created_at,
'since': '%s' % since, 'since': '%s' % since,
...@@ -109,22 +117,24 @@ class TestSlapOSCloudSlapOSCacheMixin( ...@@ -109,22 +117,24 @@ class TestSlapOSCloudSlapOSCacheMixin(
"text": "#access TEST123 %s" % doc.getUid() "text": "#access TEST123 %s" % doc.getUid()
}) })
def getBaseExpectedDict(doc): def getBaseExpectedDict(doc):
return { return _decode_with_json({
"portal_type": doc.getPortalType(),
"reference": doc.getReference(),
"user": "ERP5TypeTestCase", "user": "ERP5TypeTestCase",
'created_at': '%s' % created_at, 'created_at': '%s' % created_at,
u'since': u'%s' % since, 'since': '%s' % since,
u'state': u"", 'state': "",
u"text": u"#access TEST123 %s" % doc.getUid(), "text": "#access TEST123 %s" % doc.getUid(),
'no_data_since_15_minutes': 0, 'no_data_since_15_minutes': 0,
'no_data_since_5_minutes': 0 'no_data_since_5_minutes': 0
} })
# Check Compute Node # Check Compute Node
self.assertEqual(True, self.assertEqual(True,
self.compute_node.setAccessStatus("TEST123 %s" % self.compute_node.getUid())) self.compute_node.setAccessStatus("TEST123 %s" % self.compute_node.getUid()))
self.assertEqual(self.compute_node._getCachedAccessInfo(), self.assertEqual(self.compute_node._getCachedAccessInfo(),
getExpectedCacheDict(self.compute_node)) getExpectedCacheDict(self.compute_node))
self.assertEqual(self.compute_node.getAccessStatus(), self.assertEqual(_decode_with_json(self.compute_node.getAccessStatus()),
getBaseExpectedDict(self.compute_node)) getBaseExpectedDict(self.compute_node))
self.assertEqual(False, self.assertEqual(False,
self.compute_node.setAccessStatus("TEST123 %s" % self.compute_node.getUid())) self.compute_node.setAccessStatus("TEST123 %s" % self.compute_node.getUid()))
...@@ -135,7 +145,7 @@ class TestSlapOSCloudSlapOSCacheMixin( ...@@ -135,7 +145,7 @@ class TestSlapOSCloudSlapOSCacheMixin(
installation.setAccessStatus("TEST123 %s" % installation.getUid())) installation.setAccessStatus("TEST123 %s" % installation.getUid()))
self.assertEqual(installation._getCachedAccessInfo(), self.assertEqual(installation._getCachedAccessInfo(),
getExpectedCacheDict(installation)) getExpectedCacheDict(installation))
self.assertEqual(installation.getAccessStatus(), self.assertEqual(_decode_with_json(installation.getAccessStatus()),
getBaseExpectedDict(installation)) getBaseExpectedDict(installation))
self.assertEqual(False, self.assertEqual(False,
installation.setAccessStatus("TEST123 %s" % installation.getUid())) installation.setAccessStatus("TEST123 %s" % installation.getUid()))
...@@ -146,7 +156,7 @@ class TestSlapOSCloudSlapOSCacheMixin( ...@@ -146,7 +156,7 @@ class TestSlapOSCloudSlapOSCacheMixin(
partition.setAccessStatus("TEST123 %s" % partition.getUid())) partition.setAccessStatus("TEST123 %s" % partition.getUid()))
self.assertEqual(partition._getCachedAccessInfo(), self.assertEqual(partition._getCachedAccessInfo(),
getExpectedCacheDict(partition)) getExpectedCacheDict(partition))
self.assertEqual(partition.getAccessStatus(), self.assertEqual(_decode_with_json(partition.getAccessStatus()),
getBaseExpectedDict(partition)) getBaseExpectedDict(partition))
self.assertEqual(False, self.assertEqual(False,
partition.setAccessStatus("TEST123 %s" % partition.getUid())) partition.setAccessStatus("TEST123 %s" % partition.getUid()))
...@@ -158,7 +168,7 @@ class TestSlapOSCloudSlapOSCacheMixin( ...@@ -158,7 +168,7 @@ class TestSlapOSCloudSlapOSCacheMixin(
instance.setAccessStatus("TEST123 %s" % instance.getUid())) instance.setAccessStatus("TEST123 %s" % instance.getUid()))
self.assertEqual(instance._getCachedAccessInfo(), self.assertEqual(instance._getCachedAccessInfo(),
getExpectedCacheDict(instance)) getExpectedCacheDict(instance))
self.assertEqual(instance.getAccessStatus(), self.assertEqual(_decode_with_json(instance.getAccessStatus()),
getBaseExpectedDict(instance)) getBaseExpectedDict(instance))
self.assertEqual(False, self.assertEqual(False,
instance.setAccessStatus("TEST123 %s" % instance.getUid())) instance.setAccessStatus("TEST123 %s" % instance.getUid()))
...@@ -170,6 +180,8 @@ class TestSlapOSCloudSlapOSCacheMixin( ...@@ -170,6 +180,8 @@ class TestSlapOSCloudSlapOSCacheMixin(
def getExpectedCacheDict(doc): def getExpectedCacheDict(doc):
return json.dumps({ return json.dumps({
"portal_type": doc.getPortalType(),
"reference": doc.getReference(),
"user": "ERP5TypeTestCase", "user": "ERP5TypeTestCase",
'created_at': '%s' % created_at, 'created_at': '%s' % created_at,
'since': '%s' % since, 'since': '%s' % since,
...@@ -177,15 +189,17 @@ class TestSlapOSCloudSlapOSCacheMixin( ...@@ -177,15 +189,17 @@ class TestSlapOSCloudSlapOSCacheMixin(
"text": "#access TEST123 %s" % doc.getUid() "text": "#access TEST123 %s" % doc.getUid()
}) })
def getBaseExpectedDict(doc): def getBaseExpectedDict(doc):
return { return _decode_with_json({
"portal_type": doc.getPortalType(),
"reference": doc.getReference(),
"user": "ERP5TypeTestCase", "user": "ERP5TypeTestCase",
'created_at': '%s' % created_at, 'created_at': '%s' % created_at,
u'since': u'%s' % since, 'since': '%s' % since,
u'state': u"", 'state': "",
u"text": u"#access TEST123 %s" % doc.getUid(), "text": "#access TEST123 %s" % doc.getUid(),
'no_data_since_15_minutes': 0, 'no_data_since_15_minutes': 0,
'no_data_since_5_minutes': 0 'no_data_since_5_minutes': 0
} })
self.tic() self.tic()
...@@ -202,7 +216,7 @@ class TestSlapOSCloudSlapOSCacheMixin( ...@@ -202,7 +216,7 @@ class TestSlapOSCloudSlapOSCacheMixin(
instance.setAccessStatus("TEST123 %s" % instance.getUid())) instance.setAccessStatus("TEST123 %s" % instance.getUid()))
self.assertEqual(instance._getCachedAccessInfo(), self.assertEqual(instance._getCachedAccessInfo(),
getExpectedCacheDict(instance)) getExpectedCacheDict(instance))
self.assertEqual(instance.getAccessStatus(), self.assertEqual(_decode_with_json(instance.getAccessStatus()),
getBaseExpectedDict(instance)) getBaseExpectedDict(instance))
self.tic() self.tic()
new_indexation_timestamp = self.portal.portal_catalog( new_indexation_timestamp = self.portal.portal_catalog(
...@@ -246,6 +260,8 @@ class TestSlapOSCloudSlapOSCacheMixin( ...@@ -246,6 +260,8 @@ class TestSlapOSCloudSlapOSCacheMixin(
def getExpectedCacheDict(doc): def getExpectedCacheDict(doc):
return json.dumps({ return json.dumps({
"portal_type": doc.getPortalType(),
"reference": doc.getReference(),
"user": "ERP5TypeTestCase", "user": "ERP5TypeTestCase",
'created_at': '%s' % created_at, 'created_at': '%s' % created_at,
'since': '%s' % since, 'since': '%s' % since,
...@@ -253,22 +269,24 @@ class TestSlapOSCloudSlapOSCacheMixin( ...@@ -253,22 +269,24 @@ class TestSlapOSCloudSlapOSCacheMixin(
"text": "#error TEST123 %s" % doc.getUid() "text": "#error TEST123 %s" % doc.getUid()
}) })
def getBaseExpectedDict(doc): def getBaseExpectedDict(doc):
return { return _decode_with_json({
"portal_type": doc.getPortalType(),
"reference": doc.getReference(),
"user": "ERP5TypeTestCase", "user": "ERP5TypeTestCase",
'created_at': '%s' % created_at, 'created_at': '%s' % created_at,
u'since': u'%s' % since, 'since': '%s' % since,
u'state': u"", 'state': "",
u"text": u"#error TEST123 %s" % doc.getUid(), "text": "#error TEST123 %s" % doc.getUid(),
'no_data_since_15_minutes': 0, 'no_data_since_15_minutes': 0,
'no_data_since_5_minutes': 0 'no_data_since_5_minutes': 0
} })
# Check Compute Node # Check Compute Node
self.assertEqual(True, self.assertEqual(True,
self.compute_node.setErrorStatus("TEST123 %s" % self.compute_node.getUid())) self.compute_node.setErrorStatus("TEST123 %s" % self.compute_node.getUid()))
self.assertEqual(self.compute_node._getCachedAccessInfo(), self.assertEqual(self.compute_node._getCachedAccessInfo(),
getExpectedCacheDict(self.compute_node)) getExpectedCacheDict(self.compute_node))
self.assertEqual(self.compute_node.getAccessStatus(), self.assertEqual(_decode_with_json(self.compute_node.getAccessStatus()),
getBaseExpectedDict(self.compute_node)) getBaseExpectedDict(self.compute_node))
self.assertEqual(False, self.assertEqual(False,
self.compute_node.setErrorStatus("TEST123 %s" % self.compute_node.getUid())) self.compute_node.setErrorStatus("TEST123 %s" % self.compute_node.getUid()))
...@@ -279,7 +297,7 @@ class TestSlapOSCloudSlapOSCacheMixin( ...@@ -279,7 +297,7 @@ class TestSlapOSCloudSlapOSCacheMixin(
installation.setErrorStatus("TEST123 %s" % installation.getUid())) installation.setErrorStatus("TEST123 %s" % installation.getUid()))
self.assertEqual(installation._getCachedAccessInfo(), self.assertEqual(installation._getCachedAccessInfo(),
getExpectedCacheDict(installation)) getExpectedCacheDict(installation))
self.assertEqual(installation.getAccessStatus(), self.assertEqual(_decode_with_json(installation.getAccessStatus()),
getBaseExpectedDict(installation)) getBaseExpectedDict(installation))
self.assertEqual(False, self.assertEqual(False,
installation.setErrorStatus("TEST123 %s" % installation.getUid())) installation.setErrorStatus("TEST123 %s" % installation.getUid()))
...@@ -290,7 +308,7 @@ class TestSlapOSCloudSlapOSCacheMixin( ...@@ -290,7 +308,7 @@ class TestSlapOSCloudSlapOSCacheMixin(
partition.setErrorStatus("TEST123 %s" % partition.getUid())) partition.setErrorStatus("TEST123 %s" % partition.getUid()))
self.assertEqual(partition._getCachedAccessInfo(), self.assertEqual(partition._getCachedAccessInfo(),
getExpectedCacheDict(partition)) getExpectedCacheDict(partition))
self.assertEqual(partition.getAccessStatus(), self.assertEqual(_decode_with_json(partition.getAccessStatus()),
getBaseExpectedDict(partition)) getBaseExpectedDict(partition))
self.assertEqual(False, self.assertEqual(False,
partition.setErrorStatus("TEST123 %s" % partition.getUid())) partition.setErrorStatus("TEST123 %s" % partition.getUid()))
...@@ -301,7 +319,7 @@ class TestSlapOSCloudSlapOSCacheMixin( ...@@ -301,7 +319,7 @@ class TestSlapOSCloudSlapOSCacheMixin(
instance.setErrorStatus("TEST123 %s" % instance.getUid())) instance.setErrorStatus("TEST123 %s" % instance.getUid()))
self.assertEqual(instance._getCachedAccessInfo(), self.assertEqual(instance._getCachedAccessInfo(),
getExpectedCacheDict(instance)) getExpectedCacheDict(instance))
self.assertEqual(instance.getAccessStatus(), self.assertEqual(_decode_with_json(instance.getAccessStatus()),
getBaseExpectedDict(instance)) getBaseExpectedDict(instance))
self.assertEqual(False, self.assertEqual(False,
instance.setErrorStatus("TEST123 %s" % instance.getUid())) instance.setErrorStatus("TEST123 %s" % instance.getUid()))
...@@ -313,6 +331,8 @@ class TestSlapOSCloudSlapOSCacheMixin( ...@@ -313,6 +331,8 @@ class TestSlapOSCloudSlapOSCacheMixin(
def getExpectedCacheDict(doc): def getExpectedCacheDict(doc):
return json.dumps({ return json.dumps({
"portal_type": doc.getPortalType(),
"reference": doc.getReference(),
"user": "ERP5TypeTestCase", "user": "ERP5TypeTestCase",
'created_at': '%s' % created_at, 'created_at': '%s' % created_at,
'since': '%s' % since, 'since': '%s' % since,
...@@ -320,15 +340,17 @@ class TestSlapOSCloudSlapOSCacheMixin( ...@@ -320,15 +340,17 @@ class TestSlapOSCloudSlapOSCacheMixin(
"text": "#building TEST123 %s" % doc.getUid() "text": "#building TEST123 %s" % doc.getUid()
}) })
def getBaseExpectedDict(doc): def getBaseExpectedDict(doc):
return { return _decode_with_json({
"portal_type": doc.getPortalType(),
"reference": doc.getReference(),
"user": "ERP5TypeTestCase", "user": "ERP5TypeTestCase",
'created_at': '%s' % created_at, 'created_at': '%s' % created_at,
u'since': u'%s' % since, 'since': '%s' % since,
u'state': u"", 'state': "",
u"text": u"#building TEST123 %s" % doc.getUid(), "text": "#building TEST123 %s" % doc.getUid(),
'no_data_since_15_minutes': 0, 'no_data_since_15_minutes': 0,
'no_data_since_5_minutes': 0 'no_data_since_5_minutes': 0
} })
# Check Software Installation # Check Software Installation
installation = self.start_requested_software_installation installation = self.start_requested_software_installation
...@@ -336,7 +358,7 @@ class TestSlapOSCloudSlapOSCacheMixin( ...@@ -336,7 +358,7 @@ class TestSlapOSCloudSlapOSCacheMixin(
installation.setBuildingStatus("TEST123 %s" % installation.getUid())) installation.setBuildingStatus("TEST123 %s" % installation.getUid()))
self.assertEqual(installation._getCachedAccessInfo(), self.assertEqual(installation._getCachedAccessInfo(),
getExpectedCacheDict(installation)) getExpectedCacheDict(installation))
self.assertEqual(installation.getAccessStatus(), self.assertEqual(_decode_with_json(installation.getAccessStatus()),
getBaseExpectedDict(installation)) getBaseExpectedDict(installation))
self.assertEqual(False, self.assertEqual(False,
installation.setBuildingStatus("TEST123 %s" % installation.getUid())) installation.setBuildingStatus("TEST123 %s" % installation.getUid()))
......
...@@ -11,7 +11,9 @@ def get_compute_partition_dict(reference): ...@@ -11,7 +11,9 @@ def get_compute_partition_dict(reference):
compute_partition_dict[compute_partition.getTitle()] = software_instance.getAccessStatus() compute_partition_dict[compute_partition.getTitle()] = software_instance.getAccessStatus()
return {"compute_node": compute_node_dict, return {"compute_node": compute_node_dict,
"partition": compute_partition_dict} "partition": compute_partition_dict,
"portal_type": compute_node_dict['portal_type'],
"reference": compute_node_dict['reference']}
# Use Cache here, at least transactional one. # Use Cache here, at least transactional one.
return get_compute_partition_dict(context.getReference()) return get_compute_partition_dict(context.getReference())
news_dict = {"instance" : []} news_dict = {"instance" : []}
news_dict = {
"portal_type": context.getPortalType(),
"reference": context.getReference(),
"title": context.getTitle(),
"instance" : []}
if context.getSlapState() == 'stop_requested': if context.getSlapState() == 'stop_requested':
news_dict["is_stopped"] = 1 news_dict["is_stopped"] = 1
......
...@@ -28,6 +28,10 @@ from Products.ERP5Type.Cache import DEFAULT_CACHE_SCOPE ...@@ -28,6 +28,10 @@ from Products.ERP5Type.Cache import DEFAULT_CACHE_SCOPE
from DateTime import DateTime from DateTime import DateTime
import json import json
def _decode_with_json(value):
# Ensure value is serisalisable as json
return json.loads(json.dumps(value))
def fakeStopRequestedSlapState(): def fakeStopRequestedSlapState():
return "stop_requested" return "stop_requested"
...@@ -56,7 +60,9 @@ class TestSlapOSHalJsonStyleMixin(SlapOSTestCaseMixinWithAbort): ...@@ -56,7 +60,9 @@ class TestSlapOSHalJsonStyleMixin(SlapOSTestCaseMixinWithAbort):
'created_at': '%s' % self.created_at, 'created_at': '%s' % self.created_at,
'text': '%s' % text, 'text': '%s' % text,
'since': '%s' % self.created_at, 'since': '%s' % self.created_at,
'state': state 'state': state,
'reference': document.getReference(),
'portal_type': document.getPortalType()
}) })
cache_duration = document._getAccessStatusCacheFactory().cache_duration cache_duration = document._getAccessStatusCacheFactory().cache_duration
document._getAccessStatusPlugin().set(document._getAccessStatusCacheKey(), document._getAccessStatusPlugin().set(document._getAccessStatusCacheKey(),
...@@ -151,37 +157,53 @@ class TestInstanceTree_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -151,37 +157,53 @@ class TestInstanceTree_getNewsDict(TestSlapOSHalJsonStyleMixin):
def test(self): def test(self):
instance_tree = self._makeInstanceTree() instance_tree = self._makeInstanceTree()
news_dict = instance_tree.InstanceTree_getNewsDict() news_dict = instance_tree.InstanceTree_getNewsDict()
expected_news_dict = {'instance': []} expected_news_dict = {
self.assertEqual(news_dict, expected_news_dict) 'instance': [],
# Ensure it don't raise error when converting to JSON 'portal_type': instance_tree.getPortalType(),
json.dumps(news_dict) 'reference': instance_tree.getReference(),
'title': instance_tree.getTitle()
}
self.assertEqual(_decode_with_json(news_dict),
_decode_with_json(expected_news_dict))
def test_slave(self): def test_slave(self):
instance_tree = self._makeInstanceTree() instance_tree = self._makeInstanceTree()
instance_tree.setRootSlave(1) instance_tree.setRootSlave(1)
news_dict = instance_tree.InstanceTree_getNewsDict() news_dict = instance_tree.InstanceTree_getNewsDict()
expected_news_dict = {'instance': [], 'is_slave': 1} expected_news_dict = {'instance': [],
self.assertEqual(news_dict, expected_news_dict) 'portal_type': instance_tree.getPortalType(),
# Ensure it don't raise error when converting to JSON 'reference': instance_tree.getReference(),
json.dumps(news_dict) 'title': instance_tree.getTitle(),
'is_slave': 1
}
self.assertEqual(news_dict,
_decode_with_json(expected_news_dict))
def test_stopped(self): def test_stopped(self):
instance_tree = self._makeInstanceTree() instance_tree = self._makeInstanceTree()
instance_tree.getSlapState = fakeStopRequestedSlapState instance_tree.getSlapState = fakeStopRequestedSlapState
news_dict = instance_tree.InstanceTree_getNewsDict() news_dict = instance_tree.InstanceTree_getNewsDict()
expected_news_dict = {'instance': [], 'is_stopped': 1} expected_news_dict = {'instance': [],
self.assertEqual(news_dict, expected_news_dict) 'portal_type': instance_tree.getPortalType(),
# Ensure it don't raise error when converting to JSON 'reference': instance_tree.getReference(),
json.dumps(news_dict) 'title': instance_tree.getTitle(),
'is_stopped': 1
}
self.assertEqual(_decode_with_json(news_dict),
_decode_with_json(expected_news_dict))
def test_destroyed(self): def test_destroyed(self):
instance_tree = self._makeInstanceTree() instance_tree = self._makeInstanceTree()
instance_tree.getSlapState = fakeDestroyRequestedSlapState instance_tree.getSlapState = fakeDestroyRequestedSlapState
news_dict = instance_tree.InstanceTree_getNewsDict() news_dict = instance_tree.InstanceTree_getNewsDict()
expected_news_dict = {'instance': [], 'is_destroyed': 1} expected_news_dict = {'instance': [],
self.assertEqual(news_dict, expected_news_dict) 'portal_type': instance_tree.getPortalType(),
# Ensure it don't raise error when converting to JSON 'reference': instance_tree.getReference(),
json.dumps(news_dict) 'title': instance_tree.getTitle(),
'is_destroyed': 1
}
self.assertEqual(_decode_with_json(news_dict),
_decode_with_json(expected_news_dict))
def test_with_instance(self): def test_with_instance(self):
instance_tree = self._makeInstanceTree() instance_tree = self._makeInstanceTree()
...@@ -190,15 +212,21 @@ class TestInstanceTree_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -190,15 +212,21 @@ class TestInstanceTree_getNewsDict(TestSlapOSHalJsonStyleMixin):
self.tic() self.tic()
self.changeSkin('Hal') self.changeSkin('Hal')
news_dict = instance_tree.InstanceTree_getNewsDict() news_dict = instance_tree.InstanceTree_getNewsDict()
expected_news_dict = {'instance': [{'created_at': self.created_at, expected_news_dict = {
'portal_type': instance_tree.getPortalType(),
'reference': instance_tree.getReference(),
'title': instance_tree.getTitle(),
'instance': [{'created_at': self.created_at,
'no_data': 1, 'no_data': 1,
'portal_type': instance.getPortalType(),
'reference': instance.getReference(),
'since': self.created_at, 'since': self.created_at,
'state': '', 'state': '',
'text': '#error no data found for %s' % instance.getReference(), 'text': '#error no data found for %s' % instance.getReference(),
'user': 'SlapOS Master'}]} 'user': 'SlapOS Master'}]
self.assertEqual(news_dict, expected_news_dict) }
# Ensure it don't raise error when converting to JSON self.assertEqual(_decode_with_json(news_dict),
json.dumps(news_dict) _decode_with_json(expected_news_dict))
def test_with_slave_instance(self): def test_with_slave_instance(self):
instance_tree = self._makeInstanceTree() instance_tree = self._makeInstanceTree()
...@@ -207,10 +235,14 @@ class TestInstanceTree_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -207,10 +235,14 @@ class TestInstanceTree_getNewsDict(TestSlapOSHalJsonStyleMixin):
self.tic() self.tic()
self.changeSkin('Hal') self.changeSkin('Hal')
news_dict = instance_tree.InstanceTree_getNewsDict() news_dict = instance_tree.InstanceTree_getNewsDict()
expected_news_dict = {'instance': []} expected_news_dict = {
self.assertEqual(news_dict, expected_news_dict) 'portal_type': instance_tree.getPortalType(),
# Ensure it don't raise error when converting to JSON 'reference': instance_tree.getReference(),
json.dumps(news_dict) 'title': instance_tree.getTitle(),
'instance': []
}
self.assertEqual(_decode_with_json(news_dict),
_decode_with_json(expected_news_dict))
def test_with_two_instance(self): def test_with_two_instance(self):
instance_tree = self._makeInstanceTree() instance_tree = self._makeInstanceTree()
...@@ -222,21 +254,30 @@ class TestInstanceTree_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -222,21 +254,30 @@ class TestInstanceTree_getNewsDict(TestSlapOSHalJsonStyleMixin):
self.tic() self.tic()
self.changeSkin('Hal') self.changeSkin('Hal')
news_dict = instance_tree.InstanceTree_getNewsDict() news_dict = instance_tree.InstanceTree_getNewsDict()
expected_news_dict = {'instance': [{'created_at': self.created_at, expected_news_dict = {
'no_data': 1, 'portal_type': instance_tree.getPortalType(),
'since': self.created_at, 'reference': instance_tree.getReference(),
'state': '', 'title': instance_tree.getTitle(),
'text': '#error no data found for %s' % instance0.getReference(), 'instance': [
'user': 'SlapOS Master'}, {'created_at': self.created_at,
{'created_at': self.created_at, 'no_data': 1,
'no_data': 1, 'portal_type': instance0.getPortalType(),
'since': self.created_at, 'reference': instance0.getReference(),
'state': '', 'since': self.created_at,
'text': '#error no data found for %s' % instance.getReference(), 'state': '',
'user': 'SlapOS Master'}]} 'text': '#error no data found for %s' % instance0.getReference(),
self.assertEqual(news_dict["instance"], expected_news_dict["instance"]) 'user': 'SlapOS Master'},
# Ensure it don't raise error when converting to JSON {'created_at': self.created_at,
json.dumps(news_dict) 'no_data': 1,
'portal_type': instance.getPortalType(),
'reference': instance.getReference(),
'since': self.created_at,
'state': '',
'text': '#error no data found for %s' % instance.getReference(),
'user': 'SlapOS Master'}]}
self.assertEqual(_decode_with_json(news_dict["instance"]),
_decode_with_json(expected_news_dict["instance"]))
class TestSoftwareInstance_getNewsDict(TestSlapOSHalJsonStyleMixin): class TestSoftwareInstance_getNewsDict(TestSlapOSHalJsonStyleMixin):
...@@ -247,13 +288,14 @@ class TestSoftwareInstance_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -247,13 +288,14 @@ class TestSoftwareInstance_getNewsDict(TestSlapOSHalJsonStyleMixin):
expected_news_dict = {'created_at': self.created_at, expected_news_dict = {'created_at': self.created_at,
'no_data_since_15_minutes': 0, 'no_data_since_15_minutes': 0,
'no_data_since_5_minutes': 0, 'no_data_since_5_minutes': 0,
'portal_type': instance.getPortalType(),
'reference': instance.getReference(),
'since': self.created_at, 'since': self.created_at,
'state': 'start_requested', 'state': 'start_requested',
'text': '#access OK', 'text': '#access OK',
'user': 'SlapOS Master'} 'user': 'SlapOS Master'}
self.assertEqual(news_dict, expected_news_dict) self.assertEqual(_decode_with_json(news_dict),
# Ensure it don't raise error when converting to JSON _decode_with_json(expected_news_dict))
json.dumps(news_dict)
def test_no_data(self): def test_no_data(self):
...@@ -263,49 +305,56 @@ class TestSoftwareInstance_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -263,49 +305,56 @@ class TestSoftwareInstance_getNewsDict(TestSlapOSHalJsonStyleMixin):
news_dict = instance.SoftwareInstance_getNewsDict() news_dict = instance.SoftwareInstance_getNewsDict()
expected_news_dict = {'created_at': self.created_at, expected_news_dict = {'created_at': self.created_at,
'no_data': 1, 'no_data': 1,
'portal_type': instance.getPortalType(),
'reference': instance.getReference(),
'since': self.created_at, 'since': self.created_at,
'state': '', 'state': '',
'text': '#error no data found for %s' % instance.getReference(), 'text': '#error no data found for %s' % instance.getReference(),
'user': 'SlapOS Master'} 'user': 'SlapOS Master'}
self.assertEqual(news_dict, expected_news_dict)
# Ensure it don't raise error when converting to JSON self.assertEqual(_decode_with_json(news_dict),
json.dumps(news_dict) _decode_with_json(expected_news_dict))
def test_slave(self): def test_slave(self):
instance = self._makeSlaveInstance() instance = self._makeSlaveInstance()
news_dict = instance.SoftwareInstance_getNewsDict() news_dict = instance.SoftwareInstance_getNewsDict()
expected_news_dict = {'is_slave': 1, expected_news_dict = {
'portal_type': instance.getPortalType(),
'reference': instance.getReference(),
'is_slave': 1,
'text': '#nodata is a slave %s' % instance.getReference(), 'text': '#nodata is a slave %s' % instance.getReference(),
'user': 'SlapOS Master'} 'user': 'SlapOS Master'}
self.assertEqual(news_dict, expected_news_dict) self.assertEqual(_decode_with_json(news_dict),
# Ensure it don't raise error when converting to JSON _decode_with_json(expected_news_dict))
json.dumps(news_dict)
def test_stopped(self): def test_stopped(self):
instance = self._makeInstance() instance = self._makeInstance()
instance.getSlapState = fakeStopRequestedSlapState instance.getSlapState = fakeStopRequestedSlapState
news_dict = instance.SoftwareInstance_getNewsDict() news_dict = instance.SoftwareInstance_getNewsDict()
expected_news_dict = { expected_news_dict = {
"portal_type": instance.getPortalType(),
"reference": instance.getReference(),
"user": "SlapOS Master", "user": "SlapOS Master",
"text": "#nodata is an stopped instance %s" % instance.getReference(), "text": "#nodata is an stopped instance %s" % instance.getReference(),
"is_stopped": 1 "is_stopped": 1
} }
self.assertEqual(news_dict, expected_news_dict) self.assertEqual(_decode_with_json(news_dict),
# Ensure it don't raise error when converting to JSON _decode_with_json(expected_news_dict))
json.dumps(news_dict)
def test_destroyed(self): def test_destroyed(self):
instance = self._makeInstance() instance = self._makeInstance()
instance.getSlapState = fakeDestroyRequestedSlapState instance.getSlapState = fakeDestroyRequestedSlapState
news_dict = instance.SoftwareInstance_getNewsDict() news_dict = instance.SoftwareInstance_getNewsDict()
expected_news_dict = { expected_news_dict = {
"portal_type": instance.getPortalType(),
"reference": instance.getReference(),
"user": "SlapOS Master", "user": "SlapOS Master",
"text": "#nodata is an destroyed instance %s" % instance.getReference(), "text": "#nodata is an destroyed instance %s" % instance.getReference(),
"is_destroyed": 1 "is_destroyed": 1
} }
self.assertEqual(news_dict, expected_news_dict) self.assertEqual(_decode_with_json(news_dict),
# Ensure it don't raise error when converting to JSON _decode_with_json(expected_news_dict))
json.dumps(news_dict)
class TestSoftwareInstallation_getNewsDict(TestSlapOSHalJsonStyleMixin): class TestSoftwareInstallation_getNewsDict(TestSlapOSHalJsonStyleMixin):
def test(self): def test(self):
...@@ -315,13 +364,15 @@ class TestSoftwareInstallation_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -315,13 +364,15 @@ class TestSoftwareInstallation_getNewsDict(TestSlapOSHalJsonStyleMixin):
expected_news_dict = {'created_at': self.created_at, expected_news_dict = {'created_at': self.created_at,
'no_data_since_15_minutes': 0, 'no_data_since_15_minutes': 0,
'no_data_since_5_minutes': 0, 'no_data_since_5_minutes': 0,
'portal_type': installation.getPortalType(),
'reference': installation.getReference(),
'since': self.created_at, 'since': self.created_at,
'state': 'start_requested', 'state': 'start_requested',
'text': '#access OK', 'text': '#access OK',
'user': 'SlapOS Master'} 'user': 'SlapOS Master'}
self.assertEqual(news_dict, expected_news_dict) self.assertEqual(_decode_with_json(news_dict),
# Ensure it don't raise error when converting to JSON _decode_with_json(expected_news_dict))
json.dumps(news_dict)
def test_stopped(self): def test_stopped(self):
installation = self._makeSoftwareInstallation() installation = self._makeSoftwareInstallation()
...@@ -333,13 +384,15 @@ class TestSoftwareInstallation_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -333,13 +384,15 @@ class TestSoftwareInstallation_getNewsDict(TestSlapOSHalJsonStyleMixin):
expected_news_dict = {'created_at': self.created_at, expected_news_dict = {'created_at': self.created_at,
'no_data_since_15_minutes': 0, 'no_data_since_15_minutes': 0,
'no_data_since_5_minutes': 0, 'no_data_since_5_minutes': 0,
'portal_type': installation.getPortalType(),
'reference': installation.getReference(),
'since': self.created_at, 'since': self.created_at,
'state': 'stop_requested', 'state': 'stop_requested',
'text': '#access OK', 'text': '#access OK',
'user': 'SlapOS Master'} 'user': 'SlapOS Master'}
self.assertEqual(news_dict, expected_news_dict) self.assertEqual(_decode_with_json(news_dict),
# Ensure it don't raise error when converting to JSON _decode_with_json(expected_news_dict))
json.dumps(news_dict)
def test_destroyed(self): def test_destroyed(self):
installation = self._makeSoftwareInstallation() installation = self._makeSoftwareInstallation()
...@@ -351,26 +404,30 @@ class TestSoftwareInstallation_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -351,26 +404,30 @@ class TestSoftwareInstallation_getNewsDict(TestSlapOSHalJsonStyleMixin):
expected_news_dict = {'created_at': self.created_at, expected_news_dict = {'created_at': self.created_at,
'no_data_since_15_minutes': 0, 'no_data_since_15_minutes': 0,
'no_data_since_5_minutes': 0, 'no_data_since_5_minutes': 0,
'portal_type': installation.getPortalType(),
'reference': installation.getReference(),
'since': self.created_at, 'since': self.created_at,
'state': 'destroy_requested', 'state': 'destroy_requested',
'text': '#access OK', 'text': '#access OK',
'user': 'SlapOS Master'} 'user': 'SlapOS Master'}
self.assertEqual(news_dict, expected_news_dict) self.assertEqual(_decode_with_json(news_dict),
# Ensure it don't raise error when converting to JSON _decode_with_json(expected_news_dict))
json.dumps(news_dict)
def test_no_data(self): def test_no_data(self):
installation = self._makeSoftwareInstallation() installation = self._makeSoftwareInstallation()
news_dict = installation.SoftwareInstallation_getNewsDict() news_dict = installation.SoftwareInstallation_getNewsDict()
expected_news_dict = {'created_at': self.created_at, expected_news_dict = {'created_at': self.created_at,
'no_data': 1, 'no_data': 1,
'portal_type': installation.getPortalType(),
'reference': installation.getReference(),
'since': self.created_at, 'since': self.created_at,
'state': '', 'state': '',
'text': '#error no data found for %s' % installation.getReference(), 'text': '#error no data found for %s' % installation.getReference(),
'user': 'SlapOS Master'} 'user': 'SlapOS Master'}
self.assertEqual(news_dict, expected_news_dict) self.assertEqual(_decode_with_json(news_dict),
# Ensure it don't raise error when converting to JSON _decode_with_json(expected_news_dict))
json.dumps(news_dict)
class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin): class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin):
...@@ -382,15 +439,18 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -382,15 +439,18 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin):
{'created_at': self.created_at, {'created_at': self.created_at,
'no_data_since_15_minutes': 0, 'no_data_since_15_minutes': 0,
'no_data_since_5_minutes': 0, 'no_data_since_5_minutes': 0,
'portal_type': compute_node.getPortalType(),
'reference': compute_node.getReference(),
'since': self.created_at, 'since': self.created_at,
'state': 'start_requested', 'state': 'start_requested',
'text': '#access OK', 'text': '#access OK',
'user': 'SlapOS Master'}, 'user': 'SlapOS Master'},
'partition': {} 'partition': {},
'portal_type': compute_node.getPortalType(),
'reference': compute_node.getReference()
} }
self.assertEqual(news_dict, expected_news_dict) self.assertEqual(_decode_with_json(news_dict),
# Ensure it don't raise error when converting to JSON _decode_with_json(expected_news_dict))
json.dumps(news_dict)
def test_stopped(self): def test_stopped(self):
compute_node = self._makeComputeNode() compute_node = self._makeComputeNode()
...@@ -403,15 +463,18 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -403,15 +463,18 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin):
{'created_at': self.created_at, {'created_at': self.created_at,
'no_data_since_15_minutes': 0, 'no_data_since_15_minutes': 0,
'no_data_since_5_minutes': 0, 'no_data_since_5_minutes': 0,
'portal_type': compute_node.getPortalType(),
'reference': compute_node.getReference(),
'since': self.created_at, 'since': self.created_at,
'state': 'stop_requested', 'state': 'stop_requested',
'text': '#access OK', 'text': '#access OK',
'user': 'SlapOS Master'}, 'user': 'SlapOS Master'},
'partition': {} 'partition': {},
'portal_type': compute_node.getPortalType(),
'reference': compute_node.getReference()
} }
self.assertEqual(news_dict, expected_news_dict) self.assertEqual(_decode_with_json(news_dict),
# Ensure it don't raise error when converting to JSON _decode_with_json(expected_news_dict))
json.dumps(news_dict)
def test_destroyed(self): def test_destroyed(self):
compute_node = self._makeComputeNode() compute_node = self._makeComputeNode()
...@@ -424,15 +487,18 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -424,15 +487,18 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin):
{'created_at': self.created_at, {'created_at': self.created_at,
'no_data_since_15_minutes': 0, 'no_data_since_15_minutes': 0,
'no_data_since_5_minutes': 0, 'no_data_since_5_minutes': 0,
'portal_type': compute_node.getPortalType(),
'reference': compute_node.getReference(),
'since': self.created_at, 'since': self.created_at,
'state': 'destroy_requested', 'state': 'destroy_requested',
'text': '#access OK', 'text': '#access OK',
'user': 'SlapOS Master'}, 'user': 'SlapOS Master'},
'partition': {} 'partition': {},
'portal_type': compute_node.getPortalType(),
'reference': compute_node.getReference()
} }
self.assertEqual(news_dict, expected_news_dict) self.assertEqual(_decode_with_json(news_dict),
# Ensure it don't raise error when converting to JSON _decode_with_json(expected_news_dict))
json.dumps(news_dict)
def test_no_data(self): def test_no_data(self):
compute_node = self._makeComputeNode() compute_node = self._makeComputeNode()
...@@ -440,15 +506,18 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -440,15 +506,18 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin):
expected_news_dict = {'compute_node': expected_news_dict = {'compute_node':
{'created_at': self.created_at, {'created_at': self.created_at,
'no_data': 1, 'no_data': 1,
'portal_type': compute_node.getPortalType(),
'reference': compute_node.getReference(),
'since': self.created_at, 'since': self.created_at,
'state': '', 'state': '',
'text': '#error no data found for %s' % compute_node.getReference(), 'text': '#error no data found for %s' % compute_node.getReference(),
'user': 'SlapOS Master'}, 'user': 'SlapOS Master'},
'partition': {} 'partition': {},
'portal_type': compute_node.getPortalType(),
'reference': compute_node.getReference()
} }
self.assertEqual(news_dict, expected_news_dict) self.assertEqual(_decode_with_json(news_dict),
# Ensure it don't raise error when converting to JSON _decode_with_json(expected_news_dict))
json.dumps(news_dict)
def test_with_instance(self): def test_with_instance(self):
compute_node = self._makeComputeNode() compute_node = self._makeComputeNode()
...@@ -462,20 +531,25 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -462,20 +531,25 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin):
{u'created_at': u'%s' % self.created_at, {u'created_at': u'%s' % self.created_at,
'no_data_since_15_minutes': 0, 'no_data_since_15_minutes': 0,
'no_data_since_5_minutes': 0, 'no_data_since_5_minutes': 0,
'portal_type': compute_node.getPortalType(),
'reference': compute_node.getReference(),
u'since': u'%s' % self.created_at, u'since': u'%s' % self.created_at,
u'state': u'start_requested', u'state': u'start_requested',
u'text': u'#access OK', u'text': u'#access OK',
u'user': u'SlapOS Master'}, u'user': u'SlapOS Master'},
'partition': {'slappart0': {'created_at': self.created_at, 'partition': {'slappart0': {'created_at': self.created_at,
'no_data': 1, 'no_data': 1,
'portal_type': instance.getPortalType(),
'reference': instance.getReference(),
'since': self.created_at, 'since': self.created_at,
'state': '', 'state': '',
'text': '#error no data found for %s' % (instance.getReference()), 'text': '#error no data found for %s' % (instance.getReference()),
'user': 'SlapOS Master'}} 'user': 'SlapOS Master'}},
'portal_type': compute_node.getPortalType(),
'reference': compute_node.getReference()
} }
self.assertEqual(news_dict, expected_news_dict) self.assertEqual(_decode_with_json(news_dict),
# Ensure it don't raise error when converting to JSON _decode_with_json(expected_news_dict))
json.dumps(news_dict)
class TestComputerNetwork_getNewsDict(TestSlapOSHalJsonStyleMixin): class TestComputerNetwork_getNewsDict(TestSlapOSHalJsonStyleMixin):
...@@ -494,6 +568,8 @@ class TestComputerNetwork_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -494,6 +568,8 @@ class TestComputerNetwork_getNewsDict(TestSlapOSHalJsonStyleMixin):
{u'created_at': u'%s' % self.created_at, {u'created_at': u'%s' % self.created_at,
'no_data_since_15_minutes': 0, 'no_data_since_15_minutes': 0,
'no_data_since_5_minutes': 0, 'no_data_since_5_minutes': 0,
'portal_type': compute_node.getPortalType(),
'reference': compute_node.getReference(),
u'since': u'%s' % self.created_at, u'since': u'%s' % self.created_at,
u'state': u'start_requested', u'state': u'start_requested',
u'text': u'#access OK', u'text': u'#access OK',
...@@ -502,6 +578,8 @@ class TestComputerNetwork_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -502,6 +578,8 @@ class TestComputerNetwork_getNewsDict(TestSlapOSHalJsonStyleMixin):
{ compute_node.getReference(): { compute_node.getReference():
{'slappart0': {'created_at': self.created_at, {'slappart0': {'created_at': self.created_at,
'no_data': 1, 'no_data': 1,
'portal_type': instance.getPortalType(),
'reference': instance.getReference(),
'since': self.created_at, 'since': self.created_at,
'state': '', 'state': '',
'text': '#error no data found for %s' % (instance.getReference()), 'text': '#error no data found for %s' % (instance.getReference()),
...@@ -511,17 +589,15 @@ class TestComputerNetwork_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -511,17 +589,15 @@ class TestComputerNetwork_getNewsDict(TestSlapOSHalJsonStyleMixin):
} }
self.assertEqual(news_dict, expected_news_dict) self.assertEqual(_decode_with_json(news_dict),
# Ensure it don't raise error when converting to JSON _decode_with_json(expected_news_dict))
json.dumps(news_dict)
def test_no_data(self): def test_no_data(self):
network = self._makeComputerNetwork() network = self._makeComputerNetwork()
news_dict = network.ComputerNetwork_getNewsDict() news_dict = network.ComputerNetwork_getNewsDict()
expected_news_dict = {'compute_node': {}, 'partition': {}} expected_news_dict = {'compute_node': {}, 'partition': {}}
self.assertEqual(news_dict, expected_news_dict) self.assertEqual(_decode_with_json(news_dict),
# Ensure it don't raise error when converting to JSON _decode_with_json(expected_news_dict))
json.dumps(news_dict)
class TestOrganisation_getNewsDict(TestSlapOSHalJsonStyleMixin): class TestOrganisation_getNewsDict(TestSlapOSHalJsonStyleMixin):
...@@ -542,6 +618,8 @@ class TestOrganisation_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -542,6 +618,8 @@ class TestOrganisation_getNewsDict(TestSlapOSHalJsonStyleMixin):
{u'created_at': u'%s' % self.created_at, {u'created_at': u'%s' % self.created_at,
'no_data_since_15_minutes': 0, 'no_data_since_15_minutes': 0,
'no_data_since_5_minutes': 0, 'no_data_since_5_minutes': 0,
'portal_type': compute_node.getPortalType(),
'reference': compute_node.getReference(),
u'since': u'%s' % self.created_at, u'since': u'%s' % self.created_at,
u'state': u'start_requested', u'state': u'start_requested',
u'text': u'#access OK', u'text': u'#access OK',
...@@ -550,6 +628,8 @@ class TestOrganisation_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -550,6 +628,8 @@ class TestOrganisation_getNewsDict(TestSlapOSHalJsonStyleMixin):
{ compute_node.getReference(): { compute_node.getReference():
{'slappart0': {'created_at': self.created_at, {'slappart0': {'created_at': self.created_at,
'no_data': 1, 'no_data': 1,
'portal_type': instance.getPortalType(),
'reference': instance.getReference(),
'since': self.created_at, 'since': self.created_at,
'state': '', 'state': '',
'text': '#error no data found for %s' % (instance.getReference()), 'text': '#error no data found for %s' % (instance.getReference()),
...@@ -559,17 +639,15 @@ class TestOrganisation_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -559,17 +639,15 @@ class TestOrganisation_getNewsDict(TestSlapOSHalJsonStyleMixin):
} }
self.assertEqual(news_dict, expected_news_dict) self.assertEqual(_decode_with_json(news_dict),
# Ensure it don't raise error when converting to JSON _decode_with_json(expected_news_dict))
json.dumps(news_dict)
def test_no_data(self): def test_no_data(self):
organisation = self._makeOrganisation() organisation = self._makeOrganisation()
news_dict = organisation.Organisation_getNewsDict() news_dict = organisation.Organisation_getNewsDict()
expected_news_dict = {'compute_node': {}, 'partition': {}} expected_news_dict = {'compute_node': {}, 'partition': {}}
self.assertEqual(news_dict, expected_news_dict) self.assertEqual(_decode_with_json(news_dict),
# Ensure it don't raise error when converting to JSON _decode_with_json(expected_news_dict))
json.dumps(news_dict)
class TestProject_getNewsDict(TestSlapOSHalJsonStyleMixin): class TestProject_getNewsDict(TestSlapOSHalJsonStyleMixin):
...@@ -590,6 +668,8 @@ class TestProject_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -590,6 +668,8 @@ class TestProject_getNewsDict(TestSlapOSHalJsonStyleMixin):
{u'created_at': u'%s' % self.created_at, {u'created_at': u'%s' % self.created_at,
'no_data_since_15_minutes': 0, 'no_data_since_15_minutes': 0,
'no_data_since_5_minutes': 0, 'no_data_since_5_minutes': 0,
'portal_type': compute_node.getPortalType(),
'reference': compute_node.getReference(),
u'since': u'%s' % self.created_at, u'since': u'%s' % self.created_at,
u'state': u'start_requested', u'state': u'start_requested',
u'text': u'#access OK', u'text': u'#access OK',
...@@ -598,6 +678,8 @@ class TestProject_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -598,6 +678,8 @@ class TestProject_getNewsDict(TestSlapOSHalJsonStyleMixin):
{ compute_node.getReference(): { compute_node.getReference():
{'slappart0': {'created_at': self.created_at, {'slappart0': {'created_at': self.created_at,
'no_data': 1, 'no_data': 1,
'portal_type': instance.getPortalType(),
'reference': instance.getReference(),
'since': self.created_at, 'since': self.created_at,
'state': '', 'state': '',
'text': '#error no data found for %s' % (instance.getReference()), 'text': '#error no data found for %s' % (instance.getReference()),
...@@ -607,17 +689,15 @@ class TestProject_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -607,17 +689,15 @@ class TestProject_getNewsDict(TestSlapOSHalJsonStyleMixin):
} }
self.assertEqual(news_dict, expected_news_dict) self.assertEqual(_decode_with_json(news_dict),
# Ensure it don't raise error when converting to JSON _decode_with_json(expected_news_dict))
json.dumps(news_dict)
def test_no_data(self): def test_no_data(self):
project = self._makeProject() project = self._makeProject()
news_dict = project.Project_getNewsDict() news_dict = project.Project_getNewsDict()
expected_news_dict = {'compute_node': {}, 'partition': {}} expected_news_dict = {'compute_node': {}, 'partition': {}}
self.assertEqual(news_dict, expected_news_dict) self.assertEqual(_decode_with_json(news_dict),
# Ensure it don't raise error when converting to JSON _decode_with_json(expected_news_dict))
json.dumps(news_dict)
class TestPerson_newLogin(TestSlapOSHalJsonStyleMixin): class TestPerson_newLogin(TestSlapOSHalJsonStyleMixin):
def test_Person_newLogin_as_superuser(self): def test_Person_newLogin_as_superuser(self):
...@@ -819,10 +899,18 @@ class TestComputerNetwork_hasComputeNode(TestSlapOSHalJsonStyleMixin): ...@@ -819,10 +899,18 @@ class TestComputerNetwork_hasComputeNode(TestSlapOSHalJsonStyleMixin):
compute_node = self._makeComputeNode() compute_node = self._makeComputeNode()
compute_node.setSubordinationValue(network) compute_node.setSubordinationValue(network)
compute_node.setAllocationScopeValue(
self.portal.portal_categories.allocation_scope.open.public)
self.tic() self.tic()
self.changeSkin("Hal") self.changeSkin("Hal")
self.assertEqual(json.loads(network.ComputerNetwork_hasComputeNode()), 1) self.assertEqual(json.loads(network.ComputerNetwork_hasComputeNode()), 1)
compute_node.setAllocationScopeValue(
self.portal.portal_categories.allocation_scope.close.forever)
self.tic()
self.changeSkin("Hal")
self.assertEqual(json.loads(network.ComputerNetwork_hasComputeNode()), 0)
class TestBase_getCredentialToken(TestSlapOSHalJsonStyleMixin): class TestBase_getCredentialToken(TestSlapOSHalJsonStyleMixin):
......
...@@ -651,6 +651,10 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin): ...@@ -651,6 +651,10 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string> <string>%(created_at)s</string>
<string>no_data</string> <string>no_data</string>
<int>1</int> <int>1</int>
<string>portal_type</string>
<string>Compute Node</string>
<string>reference</string>
<string>%(compute_node_id)s</string>
<string>since</string> <string>since</string>
<string>%(since)s</string> <string>%(since)s</string>
<string>state</string> <string>state</string>
...@@ -703,6 +707,10 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin): ...@@ -703,6 +707,10 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin):
<int>0</int> <int>0</int>
<string>no_data_since_5_minutes</string> <string>no_data_since_5_minutes</string>
<int>0</int> <int>0</int>
<string>portal_type</string>
<string>Compute Node</string>
<string>reference</string>
<string>%(compute_node_id)s</string>
<string>since</string> <string>since</string>
<string>%(since)s</string> <string>%(since)s</string>
<string>state</string> <string>state</string>
...@@ -815,6 +823,10 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin): ...@@ -815,6 +823,10 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string> <string>%(created_at)s</string>
<string>no_data</string> <string>no_data</string>
<int>1</int> <int>1</int>
<string>portal_type</string>
<string>Software Installation</string>
<string>reference</string>
<string>%(reference)s</string>
<string>since</string> <string>since</string>
<string>%(since)s</string> <string>%(since)s</string>
<string>state</string> <string>state</string>
...@@ -887,6 +899,10 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin): ...@@ -887,6 +899,10 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin):
<int>0</int> <int>0</int>
<string>no_data_since_5_minutes</string> <string>no_data_since_5_minutes</string>
<int>0</int> <int>0</int>
<string>portal_type</string>
<string>Software Installation</string>
<string>reference</string>
<string>%(reference)s</string>
<string>since</string> <string>since</string>
<string>%(since)s</string> <string>%(since)s</string>
<string>state</string> <string>state</string>
...@@ -902,6 +918,7 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin): ...@@ -902,6 +918,7 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin):
since=since, since=since,
url_string=url_string, url_string=url_string,
compute_node_id=self.compute_node_id, compute_node_id=self.compute_node_id,
reference=software_installation.getReference()
) )
self.assertEqual(expected_xml, got_xml, self.assertEqual(expected_xml, got_xml,
'\n'.join([q for q in difflib.unified_diff(expected_xml.split('\n'), got_xml.split('\n'))])) '\n'.join([q for q in difflib.unified_diff(expected_xml.split('\n'), got_xml.split('\n'))]))
...@@ -936,6 +953,10 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin): ...@@ -936,6 +953,10 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin):
<int>0</int> <int>0</int>
<string>no_data_since_5_minutes</string> <string>no_data_since_5_minutes</string>
<int>0</int> <int>0</int>
<string>portal_type</string>
<string>Software Installation</string>
<string>reference</string>
<string>%(reference)s</string>
<string>since</string> <string>since</string>
<string>%(since)s</string> <string>%(since)s</string>
<string>state</string> <string>state</string>
...@@ -951,6 +972,7 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin): ...@@ -951,6 +972,7 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin):
since=since, since=since,
url_string=url_string, url_string=url_string,
compute_node_id=self.compute_node_id, compute_node_id=self.compute_node_id,
reference=software_installation.getReference()
) )
self.assertEqual(expected_xml, got_xml, self.assertEqual(expected_xml, got_xml,
'\n'.join([q for q in difflib.unified_diff(expected_xml.split('\n'), got_xml.split('\n'))])) '\n'.join([q for q in difflib.unified_diff(expected_xml.split('\n'), got_xml.split('\n'))]))
...@@ -985,6 +1007,10 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin): ...@@ -985,6 +1007,10 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin):
<int>0</int> <int>0</int>
<string>no_data_since_5_minutes</string> <string>no_data_since_5_minutes</string>
<int>0</int> <int>0</int>
<string>portal_type</string>
<string>Software Installation</string>
<string>reference</string>
<string>%(reference)s</string>
<string>since</string> <string>since</string>
<string>%(since)s</string> <string>%(since)s</string>
<string>state</string> <string>state</string>
...@@ -1000,6 +1026,7 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin): ...@@ -1000,6 +1026,7 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSSlapToolMixin):
since=since, since=since,
url_string=url_string, url_string=url_string,
compute_node_id=self.compute_node_id, compute_node_id=self.compute_node_id,
reference=software_installation.getReference()
) )
self.assertEqual(expected_xml, got_xml, self.assertEqual(expected_xml, got_xml,
'\n'.join([q for q in difflib.unified_diff(expected_xml.split('\n'), got_xml.split('\n'))])) '\n'.join([q for q in difflib.unified_diff(expected_xml.split('\n'), got_xml.split('\n'))]))
...@@ -1324,6 +1351,10 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin): ...@@ -1324,6 +1351,10 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string> <string>%(created_at)s</string>
<string>no_data</string> <string>no_data</string>
<int>1</int> <int>1</int>
<string>portal_type</string>
<string>Software Instance</string>
<string>reference</string>
<string>%(instance_guid)s</string>
<string>since</string> <string>since</string>
<string>%(since)s</string> <string>%(since)s</string>
<string>state</string> <string>state</string>
...@@ -1375,6 +1406,10 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin): ...@@ -1375,6 +1406,10 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string> <string>%(created_at)s</string>
<string>no_data</string> <string>no_data</string>
<int>1</int> <int>1</int>
<string>portal_type</string>
<string>Software Instance</string>
<string>reference</string>
<string>%(instance_guid)s</string>
<string>since</string> <string>since</string>
<string>%(since)s</string> <string>%(since)s</string>
<string>state</string> <string>state</string>
...@@ -1749,6 +1784,10 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin): ...@@ -1749,6 +1784,10 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<int>0</int> <int>0</int>
<string>no_data_since_5_minutes</string> <string>no_data_since_5_minutes</string>
<int>0</int> <int>0</int>
<string>portal_type</string>
<string>Software Instance</string>
<string>reference</string>
<string>%(instance_guid)s</string>
<string>since</string> <string>since</string>
<string>%(since)s</string> <string>%(since)s</string>
<string>state</string> <string>state</string>
...@@ -1797,6 +1836,10 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin): ...@@ -1797,6 +1836,10 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<int>0</int> <int>0</int>
<string>no_data_since_5_minutes</string> <string>no_data_since_5_minutes</string>
<int>0</int> <int>0</int>
<string>portal_type</string>
<string>Software Instance</string>
<string>reference</string>
<string>%(instance_guid)s</string>
<string>since</string> <string>since</string>
<string>%(since)s</string> <string>%(since)s</string>
<string>state</string> <string>state</string>
...@@ -1847,6 +1890,10 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin): ...@@ -1847,6 +1890,10 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<int>0</int> <int>0</int>
<string>no_data_since_5_minutes</string> <string>no_data_since_5_minutes</string>
<int>0</int> <int>0</int>
<string>portal_type</string>
<string>Software Instance</string>
<string>reference</string>
<string>%(instance_guid)s</string>
<string>since</string> <string>since</string>
<string>%(since)s</string> <string>%(since)s</string>
<string>state</string> <string>state</string>
...@@ -1907,6 +1954,10 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin): ...@@ -1907,6 +1954,10 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<int>0</int> <int>0</int>
<string>no_data_since_5_minutes</string> <string>no_data_since_5_minutes</string>
<int>0</int> <int>0</int>
<string>portal_type</string>
<string>Software Instance</string>
<string>reference</string>
<string>%(instance_guid)s</string>
<string>since</string> <string>since</string>
<string>%(since)s</string> <string>%(since)s</string>
<string>state</string> <string>state</string>
...@@ -2227,6 +2278,10 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin): ...@@ -2227,6 +2278,10 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<int>0</int> <int>0</int>
<string>no_data_since_5_minutes</string> <string>no_data_since_5_minutes</string>
<int>0</int> <int>0</int>
<string>portal_type</string>
<string>Software Instance</string>
<string>reference</string>
<string>%(instance_guid)s</string>
<string>since</string> <string>since</string>
<string>%(since)s</string> <string>%(since)s</string>
<string>state</string> <string>state</string>
...@@ -2274,6 +2329,10 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin): ...@@ -2274,6 +2329,10 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<int>0</int> <int>0</int>
<string>no_data_since_5_minutes</string> <string>no_data_since_5_minutes</string>
<int>0</int> <int>0</int>
<string>portal_type</string>
<string>Software Instance</string>
<string>reference</string>
<string>%(instance_guid)s</string>
<string>since</string> <string>since</string>
<string>%(since)s</string> <string>%(since)s</string>
<string>state</string> <string>state</string>
...@@ -2520,6 +2579,10 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin): ...@@ -2520,6 +2579,10 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string> <string>%(created_at)s</string>
<string>no_data</string> <string>no_data</string>
<int>1</int> <int>1</int>
<string>portal_type</string>
<string>Compute Node</string>
<string>reference</string>
<string>%(compute_node_id)s</string>
<string>since</string> <string>since</string>
<string>%(since)s</string> <string>%(since)s</string>
<string>state</string> <string>state</string>
...@@ -2572,6 +2635,10 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin): ...@@ -2572,6 +2635,10 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
<int>0</int> <int>0</int>
<string>no_data_since_5_minutes</string> <string>no_data_since_5_minutes</string>
<int>0</int> <int>0</int>
<string>portal_type</string>
<string>Compute Node</string>
<string>reference</string>
<string>%(compute_node_id)s</string>
<string>since</string> <string>since</string>
<string>%(since)s</string> <string>%(since)s</string>
<string>state</string> <string>state</string>
...@@ -2649,6 +2716,10 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin): ...@@ -2649,6 +2716,10 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string> <string>%(created_at)s</string>
<string>no_data</string> <string>no_data</string>
<int>1</int> <int>1</int>
<string>portal_type</string>
<string>Software Instance</string>
<string>reference</string>
<string>%(instance_guid)s</string>
<string>since</string> <string>since</string>
<string>%(since)s</string> <string>%(since)s</string>
<string>state</string> <string>state</string>
...@@ -2702,6 +2773,10 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin): ...@@ -2702,6 +2773,10 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string> <string>%(created_at)s</string>
<string>no_data</string> <string>no_data</string>
<int>1</int> <int>1</int>
<string>portal_type</string>
<string>Software Instance</string>
<string>reference</string>
<string>%(instance_guid)s</string>
<string>since</string> <string>since</string>
<string>%(since)s</string> <string>%(since)s</string>
<string>state</string> <string>state</string>
...@@ -3013,6 +3088,10 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin): ...@@ -3013,6 +3088,10 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
<int>0</int> <int>0</int>
<string>no_data_since_5_minutes</string> <string>no_data_since_5_minutes</string>
<int>0</int> <int>0</int>
<string>portal_type</string>
<string>Software Instance</string>
<string>reference</string>
<string>%(instance_guid)s</string>
<string>since</string> <string>since</string>
<string>%(since)s</string> <string>%(since)s</string>
<string>state</string> <string>state</string>
...@@ -3027,6 +3106,7 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin): ...@@ -3027,6 +3106,7 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
created_at=created_at, created_at=created_at,
since=since, since=since,
person_reference=self.person_reference, person_reference=self.person_reference,
instance_guid=self.start_requested_software_instance.getReference()
) )
self.assertEqual(expected_xml, got_xml, self.assertEqual(expected_xml, got_xml,
'\n'.join([q for q in difflib.unified_diff(expected_xml.split('\n'), got_xml.split('\n'))])) '\n'.join([q for q in difflib.unified_diff(expected_xml.split('\n'), got_xml.split('\n'))]))
......
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