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