Commit 53542666 authored by Romain Courteaud's avatar Romain Courteaud

slapos_crm: create monitoring Support Request for Slave Instances in error,...

slapos_crm: create monitoring Support Request for Slave Instances in error, and instances on a Remote Node
parent 2a8f91d5
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, ComplexQuery
portal = context.getPortalObject() portal = context.getPortalObject()
monitor_enabled_category = portal.restrictedTraverse( monitor_enabled_category = portal.restrictedTraverse(
"portal_categories/monitor_scope/enabled", None) "portal_categories/monitor_scope/enabled", None)
portal = context.getPortalObject() portal = context.getPortalObject()
portal.portal_catalog.searchAndActivate( portal.portal_catalog.searchAndActivate(
portal_type='Compute Node',
validation_state='validated', validation_state='validated',
method_id='ComputeNode_checkProjectMontoringState', method_id='ComputeNode_checkProjectMontoringState',
monitor_scope__uid=monitor_enabled_category.getUid(), node=ComplexQuery(
SimpleQuery(portal_type='Remote Node'),
ComplexQuery(
SimpleQuery(portal_type='Compute Node'),
SimpleQuery(monitor_scope__uid=monitor_enabled_category.getUid()),
logical_operator='and'
),
logical_operator='or'
),
group_by=['follow_up_uid'], group_by=['follow_up_uid'],
method_kw={'tag': tag}, method_kw={'tag': tag},
activate_kw={'tag': tag, 'priority': 2} activate_kw={'tag': tag, 'priority': 2}
......
...@@ -38,19 +38,9 @@ if compute_node.getPortalType() == "Compute Node" and \ ...@@ -38,19 +38,9 @@ if compute_node.getPortalType() == "Compute Node" and \
error_dict['ticket_description'] = error_dict['message'] error_dict['ticket_description'] = error_dict['message']
return error_dict return error_dict
if context.getPortalType() == 'Slave Instance':
# We skip if the the slave is already allocated.
return error_dict
# Skip to check if monitor disabled on the compute node. # Skip to check if monitor disabled on the compute node.
# Remote node has no state. # Remote node has no state.
if compute_node.getPortalType() != "Compute Node": if (compute_node.getPortalType() == "Compute Node") and (compute_node.getMonitorScope() != "enabled"):
portal_type = compute_partition.getParentValue().getPortalType()
error_dict['ticket_title'] = "Instance is allocated on a %s" % portal_type
error_dict['ticket_description'] = error_dict['ticket_title']
return error_dict
if compute_partition.getParentValue().getMonitorScope() != "enabled":
error_dict['ticket_title'] = "Monitor is disabled on the Compute Node" error_dict['ticket_title'] = "Monitor is disabled on the Compute Node"
error_dict['ticket_description'] = error_dict['ticket_title'] error_dict['ticket_description'] = error_dict['ticket_title']
return error_dict return error_dict
......
...@@ -54,6 +54,13 @@ class TestSlapOSCrmMonitoringCheckComputeNodeProjectState(TestSlapOSCrmMonitorin ...@@ -54,6 +54,13 @@ class TestSlapOSCrmMonitoringCheckComputeNodeProjectState(TestSlapOSCrmMonitorin
########################################################################## ##########################################################################
# slapos_crm_monitoring_project > ComputeNode_checkMonitoringState # slapos_crm_monitoring_project > ComputeNode_checkMonitoringState
########################################################################## ##########################################################################
def test_ComputeNode_checkProjectMontoringState_alarm_remoteNode(self):
compute_node, _ = self.addComputeNodeAndPartition(self.addProject(), portal_type='Remote Node')
self.tic()
alarm = self.portal.portal_alarms.\
slapos_crm_monitoring_project
self._test_alarm(alarm, compute_node, "ComputeNode_checkProjectMontoringState")
def test_ComputeNode_checkProjectMontoringState_alarm_monitoredComputeNodeState(self): def test_ComputeNode_checkProjectMontoringState_alarm_monitoredComputeNodeState(self):
self._makeComputeNode(self.addProject()) self._makeComputeNode(self.addProject())
self.tic() self.tic()
...@@ -902,6 +909,76 @@ class TestSlapOSCrmSoftwareInstance_checkInstanceTreeMonitoringState(TestSlapOSC ...@@ -902,6 +909,76 @@ class TestSlapOSCrmSoftwareInstance_checkInstanceTreeMonitoringState(TestSlapOSC
self.assertEqual(ticket, None) self.assertEqual(ticket, None)
self.assertEqual(error_dict['should_notify'], True) self.assertEqual(error_dict['should_notify'], True)
@simulate('Project_isSupportRequestCreationClosed', '', 'return 0')
def test_SoftwareInstance_checkInstanceTreeMonitoringState_script_slaveInstance(self):
with PinnedDateTime(self, DateTime() - 1.1):
_, _, _, _, _, instance_tree = self.bootstrapAllocableInstanceTree(allocation_state='allocated', shared=True)
software_instance = instance_tree.getSuccessorValue()
software_instance.setErrorStatus("foo")
self.tic()
error_dict = software_instance.SoftwareInstance_getReportedErrorDict()
software_instance.SoftwareInstance_checkInstanceTreeMonitoringState()
self.tic()
ticket = self._getGeneratedSupportRequest(instance_tree.getUid())
self.assertEqual(error_dict['should_notify'], True)
ticket_title = "Instance Tree %s is failing." % (instance_tree.getTitle())
self.assertEqual(error_dict['ticket_title'], ticket_title)
ticket = self._getGeneratedSupportRequest(instance_tree.getUid())
self.assertNotEqual(ticket, None)
self.assertEqual(ticket.getTitle(), error_dict['ticket_title'])
event_list = ticket.getFollowUpRelatedValueList()
self.assertEqual(len(event_list), 1)
event = event_list[0]
self.assertIn('#error foo', event.getTextContent())
self.assertEqual(event.getFollowUp(), ticket.getRelativeUrl())
self.assertEqual(event.getSourceProject(), instance_tree.getFollowUp())
self.assertEqual(ticket.getSourceProject(), instance_tree.getFollowUp())
self.assertEqual(ticket.getCausality(), instance_tree.getRelativeUrl())
self.assertEqual(ticket.getSimulationState(), "submitted")
self.assertEqual(event.getSimulationState(), "delivered")
self.assertEqual(event.getPortalType(), "Web Message")
@simulate('Project_isSupportRequestCreationClosed', '', 'return 0')
def test_SoftwareInstance_checkInstanceTreeMonitoringState_script_instanceOnRemoteNode(self):
with PinnedDateTime(self, DateTime() - 1.1):
_, _, _, _, _, instance_tree = self.bootstrapAllocableInstanceTree(allocation_state='allocated', node='remote')
software_instance = instance_tree.getSuccessorValue()
software_instance.setErrorStatus("foo2")
self.tic()
error_dict = software_instance.SoftwareInstance_getReportedErrorDict()
software_instance.SoftwareInstance_checkInstanceTreeMonitoringState()
self.tic()
ticket = self._getGeneratedSupportRequest(instance_tree.getUid())
self.assertEqual(error_dict['should_notify'], True)
ticket_title = "Instance Tree %s is failing." % (instance_tree.getTitle())
self.assertEqual(error_dict['ticket_title'], ticket_title)
ticket = self._getGeneratedSupportRequest(instance_tree.getUid())
self.assertNotEqual(ticket, None)
self.assertEqual(ticket.getTitle(), error_dict['ticket_title'])
event_list = ticket.getFollowUpRelatedValueList()
self.assertEqual(len(event_list), 1)
event = event_list[0]
self.assertIn('#error foo2', event.getTextContent())
self.assertEqual(event.getFollowUp(), ticket.getRelativeUrl())
self.assertEqual(event.getSourceProject(), instance_tree.getFollowUp())
self.assertEqual(ticket.getSourceProject(), instance_tree.getFollowUp())
self.assertEqual(ticket.getCausality(), instance_tree.getRelativeUrl())
self.assertEqual(ticket.getSimulationState(), "submitted")
self.assertEqual(event.getSimulationState(), "delivered")
self.assertEqual(event.getPortalType(), "Web Message")
class TestSlaposCrmUpdateSupportRequestState(SlapOSTestCaseMixinWithAbort): class TestSlaposCrmUpdateSupportRequestState(SlapOSTestCaseMixinWithAbort):
......
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