Commit 03fcd5ca authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_crm: Improve message when create the ticket

parent aaf06d29
......@@ -8,10 +8,18 @@ project = context.getFollowUpValue()
if project.Project_isSupportRequestCreationClosed():
return
# Check if there is another consistency ticket already issued
# ....
# Exceptionally, we pre-check if the computer has a ticket already
# Since calculation is a bit expensive to "just try".
monitor_service_uid = portal.service_module.slapos_crm_monitoring.getUid()
ticket_portal_type = "Support Request"
if portal.portal_catalog.getResultValue(
portal_type=ticket_portal_type,
resource__uid=monitor_service_uid,
simulation_state=["validated", "submitted", "suspended"],
causality__uid=context.getUid(),
) is not None:
return
compute_node_error_dict = {}
reference = context.getReference()
compute_node_title = context.getTitle()
......@@ -41,11 +49,30 @@ for compute_partition in context.contentValues(portal_type='Compute Partition'):
if not error_dict['should_notify']:
return
## Write minimal message here, and replace the dict
error_dict['message'] = error_dict['compute_node_error_dict']
error_msg = ""
for _compute_node_error_dict in error_dict['compute_node_error_dict'].values():
for instance_error_dict in _compute_node_error_dict.values():
# Add Allocation Supply Error
allocation_supply_error = instance_error_dict.get('allocation_supply_error', None)
if allocation_supply_error:
error_msg += """ * %s
""" % allocation_supply_error
# Append sla errors
sla_error_list = instance_error_dict.get('sla_error_list', None)
if sla_error_list:
for entry in sla_error_list:
error_msg += """ * %s
""" % entry
error_dict['message'] = """%s:
%s
""" % (error_dict['ticket_title'], error_msg)
support_request = project.Project_createTicketWithCausality(
'Support Request',
ticket_portal_type,
error_dict['ticket_title'],
error_dict['ticket_description'],
causality=context.getRelativeUrl(),
......
......@@ -3,7 +3,7 @@ compute_partition = context
error_dict = {}
compute_node = compute_partition.getParentValue()
assert compute_node.getPortalType() == 'Compute Node'
assert compute_node.getPortalType() in ['Compute Node', 'Remote Node']
instance_list = compute_partition.getAggregateRelatedValueList(portal_type=[
'Software Instance', 'Slave Instance'])
......@@ -23,40 +23,40 @@ for instance in instance_list:
if "computer_guid" in sla_dict:
computer_guid = sla_dict.pop("computer_guid")
if compute_node.getReference() != computer_guid:
instance_sla_error_list.append('computer_guid do not match (%s != %s)' % (
computer_guid, compute_node.getReference()))
instance_sla_error_list.append('computer_guid do not match on: %s (%s != %s)' % (
instance.getTitle(), computer_guid, compute_node.getReference()))
if "instance_guid" in sla_dict:
if instance.getPortalType() != 'Slave Instance':
instance_sla_error_list.append('instance_guid is provided to a Software Instance')
instance_sla_error_list.append('instance_guid is provided to a Software Instance: %s' % instance.getTitle())
else:
instance_guid = sla_dict.pop("instance_guid")
software_instance = compute_partition.getAggregateRelatedValue(portal_type='Software Instance')
if software_instance is None:
instance_sla_error_list.append('instance_guid provided but no Software Instance was found')
instance_sla_error_list.append('instance_guid provided on %s but no Software Instance was found' % instance.getTitle())
if software_instance.getReference() != instance_guid:
instance_sla_error_list.append('instance_guid do not match (%s != %s)' % (
instance_guid != software_instance.getReference()))
instance_sla_error_list.append('instance_guid do not match on: %s (%s != %s)' % (
instance.getTitle(), instance_guid, software_instance.getReference()))
if 'network_guid' in sla_dict:
network_guid = sla_dict.pop('network_guid')
network_reference = compute_node.getSubordinationReference()
if network_reference != network_guid:
instance_sla_error_list.append('network_guid do not match (%s != %s)' % (
network_guid, network_reference))
instance_sla_error_list.append('network_guid do not match on: %s (%s != %s)' % (
instance.getTitle(), network_guid, network_reference))
project_reference = compute_node.getFollowUpReference()
if 'project_guid' in sla_dict:
project_guid = sla_dict.pop("project_guid")
if project_reference != project_guid:
instance_sla_error_list.append('project_guid do not match (%s != %s)' % (
project_guid, project_reference))
instance_sla_error_list.append('project_guid do not match on: %s (%s != %s)' % (
instance.getTitle(), project_guid, project_reference))
instance_project_reference = instance.getFollowUpReference()
if project_reference != instance_project_reference:
instance_sla_error_list.append("Instance and Compute node project don't match (%s != %s)" % (
project_reference, instance_project_reference))
instance_sla_error_list.append("Instance and Compute node project don't match on: %s (%s != %s)" % (
instance.getTitle(), project_reference, instance_project_reference))
if instance_sla_error_list:
error_dict[instance.getRelativeUrl()] = {
......@@ -83,7 +83,7 @@ for instance in instance_list:
if software_product is None:
if instance.getRelativeUrl() not in error_dict:
error_dict[instance.getRelativeUrl()] = {'instance': instance}
message = 'No Software Product matching for %s' % instance.getTitle()
message = 'No Software Product matching for: %s' % instance.getTitle()
error_dict[instance.getRelativeUrl()]['allocation_supply_error'] = message
continue
......@@ -102,7 +102,7 @@ for instance in instance_list:
if not allocation_cell_list:
if instance.getRelativeUrl() not in error_dict:
error_dict[instance.getRelativeUrl()] = {'instance': instance}
message = 'No Allocation Supply for %s' % instance.getTitle()
message = 'No Allocation Supply for: %s' % instance.getTitle()
error_dict[instance.getRelativeUrl()]['allocation_supply_error'] = message
return error_dict
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