Commit 41e5b43f authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_cloud: Normalize Access Status suffix

  Create specific API for status suffixes, since this is a widely used by monitoring system
parent 10d32071
...@@ -35,6 +35,10 @@ from Products.ERP5Type.Cache import DEFAULT_CACHE_SCOPE ...@@ -35,6 +35,10 @@ from Products.ERP5Type.Cache import DEFAULT_CACHE_SCOPE
import json import json
ACCESS = "#access"
ERROR = "#error"
BUILDING = "#building"
class SlapOSCacheMixin: class SlapOSCacheMixin:
# Declarative security # Declarative security
...@@ -93,7 +97,16 @@ class SlapOSCacheMixin: ...@@ -93,7 +97,16 @@ class SlapOSCacheMixin:
return data_dict return data_dict
def setAccessStatus(self, text, state=""): def setAccessStatus(self, text, state="", reindex=0):
self._setAccessStatus("%s %s" % (ACCESS, text), state, reindex)
def setErrorStatus(self, text, state="", reindex=0):
self._setAccessStatus("%s %s" % (ERROR, text), state, reindex)
def setBuildingStatus(self, text, state="", reindex=0):
self._setAccessStatus("%s %s" % (BUILDING, text), state, reindex)
def _setAccessStatus(self, text, state="", reindex=0):
user_reference = self.getPortalObject().portal_membership.getAuthenticatedMember()\ user_reference = self.getPortalObject().portal_membership.getAuthenticatedMember()\
.getUserName() .getUserName()
...@@ -121,6 +134,9 @@ class SlapOSCacheMixin: ...@@ -121,6 +134,9 @@ class SlapOSCacheMixin:
cache_duration = self._getAccessStatusCacheFactory().cache_duration cache_duration = self._getAccessStatusCacheFactory().cache_duration
self._getAccessStatusPlugin().set(self._getAccessStatusCacheKey(), self._getAccessStatusPlugin().set(self._getAccessStatusCacheKey(),
DEFAULT_CACHE_SCOPE, value, cache_duration=cache_duration) DEFAULT_CACHE_SCOPE, value, cache_duration=cache_duration)
if status_changed and reindex:
self.reindexObject()
return status_changed return status_changed
def getTextAccessStatus(self): def getTextAccessStatus(self):
...@@ -134,7 +150,6 @@ class SlapOSCacheMixin: ...@@ -134,7 +150,6 @@ class SlapOSCacheMixin:
date = DateTime(data_dict['created_at']) date = DateTime(data_dict['created_at'])
return date.strftime('%Y/%m/%d %H:%M') return date.strftime('%Y/%m/%d %H:%M')
##################### #####################
# SlapOS Last Data # SlapOS Last Data
##################### #####################
......
...@@ -814,7 +814,7 @@ class TestComputeNode_hasContactedRecently(SlapOSTestCaseMixinWithAbort): ...@@ -814,7 +814,7 @@ class TestComputeNode_hasContactedRecently(SlapOSTestCaseMixinWithAbort):
@simulate('ComputeNode_getCreationDate', '*args, **kwargs','return DateTime() - 32') @simulate('ComputeNode_getCreationDate', '*args, **kwargs','return DateTime() - 32')
def test_ComputeNode_hasContactedRecently_memcached(self): def test_ComputeNode_hasContactedRecently_memcached(self):
compute_node = self._makeComputeNode()[0] compute_node = self._makeComputeNode()[0]
compute_node.setAccessStatus("#access ") compute_node.setAccessStatus("")
self.tic() self.tic()
compute_node.getCreationDate = self.portal.ComputeNode_getCreationDate compute_node.getCreationDate = self.portal.ComputeNode_getCreationDate
...@@ -827,7 +827,7 @@ class TestComputeNode_hasContactedRecently(SlapOSTestCaseMixinWithAbort): ...@@ -827,7 +827,7 @@ class TestComputeNode_hasContactedRecently(SlapOSTestCaseMixinWithAbort):
compute_node = self._makeComputeNode()[0] compute_node = self._makeComputeNode()[0]
try: try:
self.pinDateTime(DateTime()-32) self.pinDateTime(DateTime()-32)
compute_node.setAccessStatus("#access ") compute_node.setAccessStatus("")
finally: finally:
self.unpinDateTime() self.unpinDateTime()
...@@ -843,7 +843,7 @@ class TestComputeNode_hasContactedRecently(SlapOSTestCaseMixinWithAbort): ...@@ -843,7 +843,7 @@ class TestComputeNode_hasContactedRecently(SlapOSTestCaseMixinWithAbort):
compute_node = self._makeComputeNode()[0] compute_node = self._makeComputeNode()[0]
try: try:
self.pinDateTime(DateTime()-32) self.pinDateTime(DateTime()-32)
compute_node.setAccessStatus("#access ") compute_node.setAccessStatus("")
finally: finally:
self.unpinDateTime() self.unpinDateTime()
...@@ -1008,7 +1008,7 @@ class TestSlapOSComputeNode_CheckState(TestCRMSkinsMixin): ...@@ -1008,7 +1008,7 @@ class TestSlapOSComputeNode_CheckState(TestCRMSkinsMixin):
try: try:
d = DateTime() - 1.1 d = DateTime() - 1.1
self.pinDateTime(d) self.pinDateTime(d)
compute_node.setAccessStatus("#access ") compute_node.setAccessStatus("")
finally: finally:
self.unpinDateTime() self.unpinDateTime()
...@@ -1045,7 +1045,7 @@ class TestSlapOSComputeNode_CheckState(TestCRMSkinsMixin): ...@@ -1045,7 +1045,7 @@ class TestSlapOSComputeNode_CheckState(TestCRMSkinsMixin):
try: try:
self.pinDateTime(DateTime()-1.1) self.pinDateTime(DateTime()-1.1)
compute_node.setAccessStatus("#access ") compute_node.setAccessStatus("")
finally: finally:
self.unpinDateTime() self.unpinDateTime()
...@@ -1275,7 +1275,7 @@ class TestSlapOSHasError(SlapOSTestCaseMixin): ...@@ -1275,7 +1275,7 @@ class TestSlapOSHasError(SlapOSTestCaseMixin):
self._makeComputeNode() self._makeComputeNode()
self._makeComputePartitionList() self._makeComputePartitionList()
instance.setAccessStatus("#error ") instance.setErrorStatus("")
self.assertEqual(instance.SoftwareInstance_hasReportedError(), None) self.assertEqual(instance.SoftwareInstance_hasReportedError(), None)
...@@ -1283,7 +1283,7 @@ class TestSlapOSHasError(SlapOSTestCaseMixin): ...@@ -1283,7 +1283,7 @@ class TestSlapOSHasError(SlapOSTestCaseMixin):
self.assertEqual(str(instance.SoftwareInstance_hasReportedError()), '#error ') self.assertEqual(str(instance.SoftwareInstance_hasReportedError()), '#error ')
instance.setAccessStatus("#access ") instance.setAccessStatus("")
self.assertEqual(instance.SoftwareInstance_hasReportedError(), None) self.assertEqual(instance.SoftwareInstance_hasReportedError(), None)
def test_SoftwareInstallation_hasReportedError(self): def test_SoftwareInstallation_hasReportedError(self):
...@@ -1298,14 +1298,14 @@ class TestSlapOSHasError(SlapOSTestCaseMixin): ...@@ -1298,14 +1298,14 @@ class TestSlapOSHasError(SlapOSTestCaseMixin):
error_date = DateTime() error_date = DateTime()
try: try:
self.pinDateTime(error_date) self.pinDateTime(error_date)
installation.setAccessStatus("#error ") installation.setErrorStatus("")
finally: finally:
self.unpinDateTime() self.unpinDateTime()
self.assertEqual( self.assertEqual(
rfc1123_date(installation.SoftwareInstallation_hasReportedError()), rfc1123_date(installation.SoftwareInstallation_hasReportedError()),
rfc1123_date(error_date)) rfc1123_date(error_date))
installation.setAccessStatus("#building ") installation.setBuildingStatus("")
self.assertEqual(installation.SoftwareInstallation_hasReportedError(), None) self.assertEqual(installation.SoftwareInstallation_hasReportedError(), None)
...@@ -1352,7 +1352,7 @@ class TestSlapOSHasError(SlapOSTestCaseMixin): ...@@ -1352,7 +1352,7 @@ class TestSlapOSHasError(SlapOSTestCaseMixin):
"slapos-crm-instance-tree-instance-state.notification"), "slapos-crm-instance-tree-instance-state.notification"),
instance_tree.InstanceTree_checkSoftwareInstanceState()) instance_tree.InstanceTree_checkSoftwareInstanceState())
instance.setAccessStatus("#access ") instance.setAccessStatus("")
self.assertEqual(None, self.assertEqual(None,
instance_tree.InstanceTree_checkSoftwareInstanceState()) instance_tree.InstanceTree_checkSoftwareInstanceState())
...@@ -1455,7 +1455,7 @@ class TestSlapOSHasError(SlapOSTestCaseMixin): ...@@ -1455,7 +1455,7 @@ class TestSlapOSHasError(SlapOSTestCaseMixin):
instance.requestInstance(**kw) instance.requestInstance(**kw)
self.tic() self.tic()
instance.setAccessStatus("#access ") instance.setAccessStatus("")
self.assertEqual( self.assertEqual(
'Visited by InstanceTree_createSupportRequestEvent %s %s' % \ 'Visited by InstanceTree_createSupportRequestEvent %s %s' % \
...@@ -1490,7 +1490,7 @@ class TestSlapOSHasError(SlapOSTestCaseMixin): ...@@ -1490,7 +1490,7 @@ class TestSlapOSHasError(SlapOSTestCaseMixin):
self._makeComputePartitionList() self._makeComputePartitionList()
instance.setAggregateValue(self.compute_node.partition1) instance.setAggregateValue(self.compute_node.partition1)
instance.setAccessStatus("#error ") instance.setErrorStatus("")
self.assertEqual( self.assertEqual(
None, None,
instance_tree.InstanceTree_checkSoftwareInstanceState()) instance_tree.InstanceTree_checkSoftwareInstanceState())
......
...@@ -171,7 +171,7 @@ class SlapTool(BaseTool): ...@@ -171,7 +171,7 @@ class SlapTool(BaseTool):
user = self.getPortalObject().portal_membership.getAuthenticatedMember().getUserName() user = self.getPortalObject().portal_membership.getAuthenticatedMember().getUserName()
if str(user) == computer_id: if str(user) == computer_id:
compute_node = self.getPortalObject().portal_membership.getAuthenticatedMember().getUserValue() compute_node = self.getPortalObject().portal_membership.getAuthenticatedMember().getUserValue()
compute_node.setAccessStatus('#access %s' % computer_id) compute_node.setAccessStatus(computer_id)
else: else:
compute_node = self._getComputeNodeDocument(computer_id) compute_node = self._getComputeNodeDocument(computer_id)
...@@ -609,7 +609,7 @@ class SlapTool(BaseTool): ...@@ -609,7 +609,7 @@ class SlapTool(BaseTool):
Fire up bung on Compute Node Fire up bung on Compute Node
""" """
compute_node = self._getComputeNodeDocument(compute_node_id) compute_node = self._getComputeNodeDocument(compute_node_id)
compute_node.setAccessStatus('#error bang') compute_node.setErrorStatus('bang')
return compute_node.reportComputeNodeBang(comment=message) return compute_node.reportComputeNodeBang(comment=message)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
...@@ -807,8 +807,8 @@ class SlapTool(BaseTool): ...@@ -807,8 +807,8 @@ class SlapTool(BaseTool):
compute_node_document = self._getComputeNodeDocument(compute_node_id) compute_node_document = self._getComputeNodeDocument(compute_node_id)
software_installation = self._getSoftwareInstallationForComputeNode(url, software_installation = self._getSoftwareInstallationForComputeNode(url,
compute_node_document) compute_node_document)
software_installation.setAccessStatus( software_installation.setBuildingStatus(
'#building software release %s' % url, "building") 'software release %s' % url, "building")
@convertToREST @convertToREST
def _availableSoftwareRelease(self, url, compute_node_id): def _availableSoftwareRelease(self, url, compute_node_id):
...@@ -819,7 +819,7 @@ class SlapTool(BaseTool): ...@@ -819,7 +819,7 @@ class SlapTool(BaseTool):
software_installation = self._getSoftwareInstallationForComputeNode(url, software_installation = self._getSoftwareInstallationForComputeNode(url,
compute_node_document) compute_node_document)
software_installation.setAccessStatus( software_installation.setAccessStatus(
'#access software release %s available' % url, "available") 'software release %s available' % url, "available")
@convertToREST @convertToREST
def _destroyedSoftwareRelease(self, url, compute_node_id): def _destroyedSoftwareRelease(self, url, compute_node_id):
...@@ -836,24 +836,25 @@ class SlapTool(BaseTool): ...@@ -836,24 +836,25 @@ class SlapTool(BaseTool):
software_installation.invalidate( software_installation.invalidate(
comment="Software Release destroyed report.") comment="Software Release destroyed report.")
####
@convertToREST @convertToREST
def _softwareInstanceError(self, compute_node_id, def _softwareInstanceError(self, compute_node_id,
compute_partition_id, error_log=""): compute_partition_id, error_log=""):
""" """
Add an error for the software Instance Workflow Add an error for the software Instance Workflow
""" """
if error_log is None:
error_log = ""
instance = self._getSoftwareInstanceForComputePartition( instance = self._getSoftwareInstanceForComputePartition(
compute_node_id, compute_node_id,
compute_partition_id) compute_partition_id)
status_changed = instance.setAccessStatus( if error_log is None:
'#error while instanciating: %s' % error_log[-80:]) error_log = ""
instance.setErrorStatus(
'while instanciating: %s' % error_log[-80:], reindex=1)
if status_changed: #####
instance.reindexObject()
@convertToREST @convertToREST
def _softwareInstanceRename(self, new_name, compute_node_id, def _softwareInstanceRename(self, new_name, compute_node_id,
...@@ -876,7 +877,7 @@ class SlapTool(BaseTool): ...@@ -876,7 +877,7 @@ class SlapTool(BaseTool):
compute_node_id, compute_node_id,
compute_partition_id) compute_partition_id)
software_instance.setAccessStatus('#error bang called') software_instance.setErrorStatus('bang called')
timestamp = str(int(software_instance.getModificationDate())) timestamp = str(int(software_instance.getModificationDate()))
key = "%s_bangstamp" % software_instance.getReference() key = "%s_bangstamp" % software_instance.getReference()
...@@ -896,9 +897,9 @@ class SlapTool(BaseTool): ...@@ -896,9 +897,9 @@ class SlapTool(BaseTool):
instance = self._getSoftwareInstanceForComputePartition( instance = self._getSoftwareInstanceForComputePartition(
compute_node_id, compute_node_id,
compute_partition_id) compute_partition_id)
status_changed = instance.setAccessStatus('#access Instance correctly started', "started")
if status_changed: instance.setAccessStatus(
instance.reindexObject() 'Instance correctly started', "started", reindex=1)
@convertToREST @convertToREST
def _stoppedComputePartition(self, compute_node_id, compute_partition_id): def _stoppedComputePartition(self, compute_node_id, compute_partition_id):
...@@ -908,9 +909,8 @@ class SlapTool(BaseTool): ...@@ -908,9 +909,8 @@ class SlapTool(BaseTool):
instance = self._getSoftwareInstanceForComputePartition( instance = self._getSoftwareInstanceForComputePartition(
compute_node_id, compute_node_id,
compute_partition_id) compute_partition_id)
status_changed = instance.setAccessStatus('#access Instance correctly stopped', "stopped") instance.setAccessStatus(
if status_changed: 'Instance correctly stopped', "stopped", reindex=1)
instance.reindexObject()
@convertToREST @convertToREST
def _destroyedComputePartition(self, compute_node_id, compute_partition_id): def _destroyedComputePartition(self, compute_node_id, compute_partition_id):
...@@ -1257,6 +1257,6 @@ class SlapTool(BaseTool): ...@@ -1257,6 +1257,6 @@ class SlapTool(BaseTool):
compute_node_document = self._getComputeNodeDocument(compute_node_id) compute_node_document = self._getComputeNodeDocument(compute_node_id)
software_installation = self._getSoftwareInstallationForComputeNode(url, software_installation = self._getSoftwareInstallationForComputeNode(url,
compute_node_document) compute_node_document)
software_installation.setAccessStatus('#error while installing %s' % url) software_installation.setErrorStatus('while installing %s' % url)
InitializeClass(SlapTool) InitializeClass(SlapTool)
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