Commit 035e7b8b authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_crm: Report missing Software Release/Type rather them instance.

  Optimise to skip recalculation if the Release+Type was already detected missing.
parent d882b8ab
Pipeline #38387 failed with stage
in 0 seconds
from DateTime import DateTime
import six
portal = context.getPortalObject()
# Remote Node has no monitor scope.
......@@ -29,7 +30,7 @@ compute_node_title = context.getTitle()
# Notification messages
error_dict = {
'should_notify': None,
'ticket_title': "%s has inconsistent allocated instances" % compute_node_title,
'ticket_title': "%s has missing allocation supplies." % compute_node_title,
'ticket_description': None,
'notification_message_reference': 'slapos-crm-compute_node_check_allocation_supply_state.notification',
'compute_node_title': compute_node_title,
......@@ -43,35 +44,28 @@ error_dict = {
# Since we would like a single ticket per compute node do all at once:
for compute_partition in context.contentValues(portal_type='Compute Partition'):
if compute_partition.getSlapState() == 'busy':
compute_partition_error_dict = compute_partition.ComputePartition_checkAllocationConsistencyState()
compute_partition_error_dict = compute_partition.ComputePartition_checkAllocationConsistencyState(
known_error_dict=error_dict['compute_node_error_dict'])
if compute_partition_error_dict:
error_dict['compute_node_error_dict'][compute_partition.getId()] = compute_partition_error_dict
error_dict['should_notify'] = True
error_dict['compute_node_error_dict'].update(compute_partition_error_dict)
if not error_dict['should_notify']:
return
message = """The following contains instances that has Software Releases/Types that are missing on this %s's Allocation Supply configuration:
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
""" % context.getPortalType()
# 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
# Sample compute_node_error_dict[software_release_url][software_type] = (instance, compute_partition)
for sofware_release_url in error_dict['compute_node_error_dict']:
message += """ * Software Release: %s
""" % sofware_release_url
for sofware_type, value_list in six.iteritems(error_dict['compute_node_error_dict'][sofware_release_url]):
message += """ * Software Type: %s (ie: %s on %s)
""" % (sofware_type, value_list[0].getTitle(), value_list[1].getReference())
error_dict['message'] = """%s:
%s
""" % (error_dict['ticket_title'], error_msg)
error_dict['message'] = message
support_request = project.Project_createTicketWithCausality(
ticket_portal_type,
......
portal = context.getPortalObject()
compute_partition = context
error_dict = {}
if known_error_dict is None:
known_error_dict = {}
compute_node = compute_partition.getParentValue()
assert compute_node.getPortalType() in ['Compute Node', 'Remote Node']
......@@ -15,6 +17,15 @@ for instance in instance_list:
# we skip for now.
continue
instance_software_release_url = instance.getUrlString()
instance_software_type = instance.getSourceReference()
for _e_dict in [error_dict, known_error_dict]:
if instance_software_release_url in _e_dict:
if instance_software_type in _e_dict[instance_software_release_url]:
# Skip calculate same thing again?
continue
# Now check allocation supply consistency
instance_tree = instance.getSpecialiseValue(portal_type="Instance Tree")
......@@ -27,33 +38,32 @@ for instance in instance_list:
continue
instance_tree_context = instance_tree.asContext(
default_source_reference=instance.getSourceReference(),
url_string=instance.getUrlString())
software_product, software_release, software_type = instance_tree_context.InstanceTree_getSoftwareProduct()
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()
error_dict[instance.getRelativeUrl()]['allocation_supply_error'] = message
continue
default_source_reference=instance_software_type,
url_string=instance_software_release_url)
project = instance.getFollowUpValue()
assert project is not None, 'Project is None'
person = instance_tree.getDestinationSectionValue()
allocation_cell_list = project.Project_getSoftwareProductPredicateList(
software_product=software_product,
software_product_type=software_type,
software_product_release=software_release,
destination_value=person,
node_value=compute_node,
predicate_portal_type='Allocation Supply Cell'
)
allocation_cell_list = []
software_product, software_release, software_type = instance_tree_context.InstanceTree_getSoftwareProduct()
if software_product is not None:
allocation_cell_list = project.Project_getSoftwareProductPredicateList(
software_product=software_product,
software_product_type=software_type,
software_product_release=software_release,
destination_value=instance_tree.getDestinationSectionValue(),
node_value=compute_node,
predicate_portal_type='Allocation Supply Cell'
)
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()
error_dict[instance.getRelativeUrl()]['allocation_supply_error'] = message
# Sampling of the structure.
# error_dict[software_release_url][software_type] = (instance, compute_partition)
value = (instance, compute_partition)
if instance_software_release_url not in error_dict:
error_dict[instance_software_release_url] = {}
if instance_software_type not in error_dict[instance_software_release_url]:
error_dict[instance.getUrlString()][instance_software_type] = value
return error_dict
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
<value> <string>known_error_dict=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
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