Commit c4e940f6 authored by Romain Courteaud's avatar Romain Courteaud 🐸

slapos_cloud: fixup allocation supply cell upgrade/consistency check

- Support Slave Instance allocated in the same tree
- allow creating allocation consistency ticket on Instance Node
- handle allocation consistency for Slave Instance without Instance Node
parent c27057c5
......@@ -2,6 +2,10 @@ from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
# If there is no software product, skip directly
if software_product is None:
return (None, [])
allocation_cell_list = []
instance_tree = context
compute_node = None
......@@ -20,16 +24,18 @@ if len(root_instance_list) == 1:
# Search the instance node linked to this partition
soft_instance = partition.getAggregateRelatedValue(portal_type='Software Instance')
if soft_instance is None:
return (None, allocation_cell_list)
# No way to guess how the Slave Instance was allocated if the Software Instance is not there anymore
return (None, [])
instance_node = soft_instance.getSpecialiseRelatedValue(portal_type='Instance Node')
if instance_node is None:
return (None, allocation_cell_list)
if instance_node is not None:
compute_node = instance_node
# Else, the Slave Instance was allocated with 'slave_on_same_instance_tree_allocable '
elif (compute_node.getPortalType() != 'Remote Node'):
return (None, allocation_cell_list)
if software_product is None:
return (compute_node, allocation_cell_list)
raise NotImplementedError('Unhandled node portal type: %s for %s' % (
compute_node.getPortalType(),
compute_node.getRelativeUrl()
))
person = context.getDestinationSectionValue(checked_permission='Access contents information')
......@@ -52,6 +58,10 @@ if (compute_node is None) and (root_instance is not None):
elif (root_instance.getPortalType() == 'Software Instance'):
allocation_cell_list = [x for x, y in allocation_cell_node_list if ("Remote Node" in y) or ("Compute Node" in y)]
if (compute_node is not None) and (root_instance is not None) and (root_instance.getPortalType() == 'Slave Instance') and (compute_node.getPortalType() == 'Compute Node'):
# If a Slave Instance uses a Compute Node to allocate, it requires slave_on_same_instance_tree_allocable
allocation_cell_list = [x for x in allocation_cell_list if x.isSlaveOnSameInstanceTreeAllocable()]
# Remove duplicated allocation cells
# ie, multiple allocation cells matching the same release/type/node
software_release_uid_dict = {}
......
......@@ -11,83 +11,65 @@ project = context.getFollowUpValue()
if project.Project_isSupportRequestCreationClosed():
return
# 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
reference = context.getReference()
compute_node_title = context.getTitle()
all_node_error_dict = {}
# Since we would like a single ticket per node,
# we aggregate all detected errors
for compute_partition in context.contentValues(portal_type='Compute Partition'):
if compute_partition.getSlapState() == 'busy':
compute_partition_error_dict = compute_partition.ComputePartition_checkAllocationConsistencyState()
for node_relative_url, node_release_dict in compute_partition_error_dict.items():
if node_relative_url not in all_node_error_dict:
all_node_error_dict[node_relative_url] = {}
for node_release_url, node_type_dict in node_release_dict.items():
if node_release_url not in all_node_error_dict[node_relative_url]:
all_node_error_dict[node_relative_url][node_release_url] = {}
for node_type, failing_instance in node_type_dict.items():
all_node_error_dict[node_relative_url][node_release_url][node_type] = failing_instance
# Use same dict from monitoring so we are consistent while writting
# Notification messages
error_dict = {
'should_notify': None,
'ticket_title': "%s has missing allocation supplies." % compute_node_title,
ticket_list = []
# Generate a single ticket per non consistent node
ticket_portal_type = 'Support Request'
for non_consistent_node_relative_url in all_node_error_dict:
non_consistent_node = portal.restrictedTraverse(non_consistent_node_relative_url)
non_consistent_node_title = non_consistent_node.getTitle()
non_consistent_node_reference = non_consistent_node.getReference()
# Use same dict from monitoring so we are consistent while writting
# Notification messages
compute_node_error_dict = all_node_error_dict[non_consistent_node_relative_url]
error_dict = {
'should_notify': True,
'ticket_title': "%s has missing allocation supplies." % non_consistent_node_title,
'ticket_description': None,
'notification_message_reference': 'slapos-crm-compute_node_check_allocation_supply_state.notification',
'compute_node_title': compute_node_title,
'compute_node_id': reference,
'compute_node_title': non_consistent_node_title,
'compute_node_id': non_consistent_node_reference,
'last_contact': None,
'issue_document_reference': None,
'message': None,
'compute_node_error_dict': {}
'compute_node_error_dict': compute_node_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()
if 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:
""" % context.getPortalType()
message = """The following contains instances that has Software Releases/Types that are missing on this %s's Allocation Supply configuration:
# It includes instance nodes lacking supplies
error_dict_len = len(error_dict['compute_node_error_dict'])
for compute_node in error_dict['compute_node_error_dict']:
compute_node_error_dict = error_dict['compute_node_error_dict'][compute_node]
compute_node_value = portal.restrictedTraverse(compute_node)
if error_dict_len > 1 or compute_node_value.getPortalType() == 'Instance Node':
# Highlight better where it comes from, it may include instance nodes
# lacking supplies.
message += """
%s %s (%s)
""" % (compute_node_value.getTitle(),
compute_node_value.getReference(),
compute_node_value.getPortalType())
""" % non_consistent_node.getPortalType()
for sofware_release_url in compute_node_error_dict:
message += """ * Software Release: %s
""" % sofware_release_url
for sofware_type, value_list in six.iteritems(compute_node_error_dict[sofware_release_url]):
for sofware_type, instance in six.iteritems(compute_node_error_dict[sofware_release_url]):
message += """ * Software Type: %s (ie: %s)
""" % (sofware_type, value_list[0].getTitle())
""" % (sofware_type, instance.getTitle())
error_dict['message'] = message
support_request = project.Project_createTicketWithCausality(
error_dict['message'] = message
support_request = project.Project_createTicketWithCausality(
ticket_portal_type,
error_dict['ticket_title'],
error_dict['ticket_description'],
causality=context.getRelativeUrl(),
causality=non_consistent_node.getRelativeUrl(),
destination_decision=project.getDestination()
)
)
if support_request is not None:
if support_request is not None:
support_request.Ticket_createProjectEvent(
error_dict['ticket_title'], 'outgoing', 'Web Message',
portal.service_module.slapos_crm_information.getRelativeUrl(),
......@@ -97,4 +79,10 @@ if support_request is not None:
#language=XXX,
substitution_method_parameter_dict=error_dict
)
return support_request
ticket_list.append(support_request)
if not ticket_list:
return
if len(ticket_list) == 1:
return ticket_list[0]
return ticket_list
......@@ -42,30 +42,34 @@ for instance in instance_list:
software_product, software_release, software_type = instance_tree_context.InstanceTree_getSoftwareProduct()
if software_product is None:
allocable_compute_node, allocation_cell_list = compute_node, []
else:
allocable_compute_node, allocation_cell_list = instance_tree_context.InstanceTree_getNodeAndAllocationSupplyCellList(
software_product=software_product,
software_release=software_release,
software_type=software_type)
if allocable_compute_node is None:
# Such case is not expected
raise ValueError('No allocable_compute_node found for %s' % instance_tree_context.getRelativeUrl())
if not allocation_cell_list:
# Sampling of the structure
# error_dict = {
# compute_node or instance_node or remote_node : {
# software_release_url: {
# software_type: (sample_instance, compute_node)
# software_type: sample_instance
# }
# }
# }
if allocable_compute_node is None:
value = (instance, compute_node)
else:
value = (instance, allocable_compute_node)
compute_node_url = value[1].getRelativeUrl()
if compute_node_url not in error_dict:
error_dict[compute_node_url] = {}
if instance_software_release_url not in error_dict:
error_dict[compute_node_url][instance_software_release_url] = {}
if instance_software_type not in error_dict[compute_node_url][instance_software_release_url]:
error_dict[compute_node_url][instance.getUrlString()][instance_software_type] = value
# value = (instance, allocable_compute_node)
allocable_compute_node_url = allocable_compute_node.getRelativeUrl()
if allocable_compute_node_url not in error_dict:
error_dict[allocable_compute_node_url] = {}
if instance_software_release_url not in error_dict[allocable_compute_node_url]:
error_dict[allocable_compute_node_url][instance_software_release_url] = {}
if instance_software_type not in error_dict[allocable_compute_node_url][instance_software_release_url]:
error_dict[allocable_compute_node_url][instance_software_release_url][instance_software_type] = instance
return error_dict
......@@ -149,28 +149,23 @@ class TestSlapOSCrmCheckProjectAllocationConsistencyState(TestSlapOSCrmMonitorin
class TestSlapOSCrmMonitoringCheckAllocationConsistencyState(TestSlapOSCrmMonitoringMixin):
def assertAllocationErrorDict(self, error_dict, compute_node, partition,
def assertAllocationErrorDict(self, error_dict, allocation_node,
release_variation, type_variation):
self.assertNotEqual({}, error_dict)
self.assertEqual(1, len(error_dict), error_dict)
self.assertTrue(allocation_node.getRelativeUrl() in error_dict, error_dict.keys())
type_reference = type_variation.getReference()
release_url = release_variation.getUrlString()
_error_dict = error_dict[compute_node.getRelativeUrl()]
self.assertEqual([release_url], _error_dict.keys())
self.assertEqual([type_reference], _error_dict[release_url].keys())
self.assertEqual(partition.getAggregateRelatedValue().getUid(),
_error_dict[release_url][type_reference][0].getUid())
self.assertEqual(compute_node.getUid(),
_error_dict[release_url][type_reference][1].getUid())
_error_dict = error_dict[allocation_node.getRelativeUrl()]
self.assertTrue(release_url in _error_dict, _error_dict.keys())
self.assertTrue(type_reference in _error_dict[release_url], _error_dict[release_url].keys())
#############################################################################
# ComputeNode_checkProjectAllocationConsistencyState > ComputeNode_checkAllocationConsistencyState
#############################################################################
@simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
def test_ComputeNode_checkAllocationConsistencyState_script_noAllocationCell(self):
def test_ComputeNode_checkAllocationConsistencyState_script_ComputeNodeInstanceNoAllocationCell(self):
with PinnedDateTime(self, DateTime() - 1.1):
_, \
release_variation, \
......@@ -185,7 +180,7 @@ class TestSlapOSCrmMonitoringCheckAllocationConsistencyState(TestSlapOSCrmMonito
# Double check error dict
error_dict = partition.ComputePartition_checkAllocationConsistencyState()
self.assertAllocationErrorDict(error_dict, compute_node, partition,
self.assertAllocationErrorDict(error_dict, compute_node,
release_variation, type_variation)
ticket_title = "%s has missing allocation supplies." % compute_node.getTitle()
self.assertNotEqual(ticket, None)
......@@ -204,98 +199,103 @@ class TestSlapOSCrmMonitoringCheckAllocationConsistencyState(TestSlapOSCrmMonito
self.assertEventTicket(event, ticket, compute_node)
@simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
def test_ComputeNode_checkAllocationConsistencyState_script_hasTicketAlready(self):
def test_ComputeNode_checkAllocationConsistencyState_script_ComputeNodeInstanceWithAllocationCell(self):
with PinnedDateTime(self, DateTime() - 1.1):
_, \
release_variation, \
type_variation, \
_, \
_, \
compute_node, \
partition, \
_ = self.bootstrapAllocableInstanceTree(allocation_state='allocated')
_ = self.bootstrapAllocableInstanceTree(allocation_state='allocated',
has_allocation_supply=True)
project = compute_node.getFollowUpValue()
title = "checkAllocationConsistencyState %s" % self.generateNewId()
support_request = project.Project_createTicketWithCausality(
"Support Request", title, title,
causality=compute_node.getRelativeUrl(),
destination_decision=project.getDestination()
)
self.assertNotEqual(support_request, None)
self.tic()
ticket = compute_node.ComputeNode_checkAllocationConsistencyState()
self.assertEqual(ticket, None)
# Double check error dict exists despite ticket isnt created.
# Double check error dict
error_dict = partition.ComputePartition_checkAllocationConsistencyState()
self.assertAllocationErrorDict(error_dict, compute_node, partition,
release_variation, type_variation)
self.assertEqual({}, error_dict)
@simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
def test_ComputeNode_checkAllocationConsistencyState_script_ongoingUpgrade(self):
def test_ComputeNode_checkAllocationConsistencyState_script_ComputeNodeSlaveNoAllocationCell(self):
with PinnedDateTime(self, DateTime() - 1.1):
_, _, _, \
_, \
release_variation, \
type_variation, \
compute_node, \
partition, \
instance_tree = self.bootstrapAllocableInstanceTree(allocation_state='allocated')
ud = self.portal.upgrade_decision_module.newContent(
portal_type="Upgrade Decision",
aggregate_value=instance_tree)
ud.plan()
_ = self.bootstrapAllocableInstanceTree(allocation_state='allocated',
shared=True)
self.tic()
ticket = compute_node.ComputeNode_checkAllocationConsistencyState()
self.tic()
# Double check error dict
error_dict = partition.ComputePartition_checkAllocationConsistencyState()
self.assertEqual({}, error_dict)
self.assertEqual(None, ticket)
@simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 1')
def test_ComputeNode_checkAllocationConsistencyState_script_creationClosed(self):
with PinnedDateTime(self, DateTime() - 1.1):
_, _, _, compute_node, \
_, _ = self.bootstrapAllocableInstanceTree(allocation_state='allocated')
self.assertAllocationErrorDict(error_dict, compute_node,
release_variation, type_variation)
ticket_title = "%s has missing allocation supplies." % compute_node.getTitle()
self.assertNotEqual(ticket, None)
self.assertEqual(ticket.getTitle(), ticket_title)
self.tic()
event_list = ticket.getFollowUpRelatedValueList()
self.assertEqual(len(event_list), 1)
event = event_list[0]
ticket = compute_node.ComputeNode_checkAllocationConsistencyState()
self.assertEqual(None, ticket)
self.assertIn("The following contains instances that has Software Releases/Types",
event.getTextContent())
self.assertIn(release_variation.getUrlString(), event.getTextContent())
self.assertIn(type_variation.getReference(), event.getTextContent())
self.assertEventTicket(event, ticket, compute_node)
@simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
def test_ComputeNode_checkAllocationConsistencyState_script_monitorDisabled(self):
def test_ComputeNode_checkAllocationConsistencyState_script_ComputeNodeSlaveWithAllocationCell(self):
with PinnedDateTime(self, DateTime() - 1.1):
_, _, _, compute_node, \
_, _ = self.bootstrapAllocableInstanceTree(allocation_state='allocated')
_, \
_, \
_, \
compute_node, \
partition, \
_ = self.bootstrapAllocableInstanceTree(allocation_state='allocated',
shared=True,
has_allocation_supply=True)
compute_node.setMonitorScope('disabled')
self.tic()
ticket = compute_node.ComputeNode_checkAllocationConsistencyState()
self.assertEqual(None, ticket)
self.tic()
self.assertEqual(ticket, None)
# Double check error dict
error_dict = partition.ComputePartition_checkAllocationConsistencyState()
self.assertEqual({}, error_dict)
@simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
def test_ComputeNode_checkAllocationConsistencyState_script_RemotenoAllocationCell(self):
def test_ComputeNode_checkAllocationConsistencyState_script_RemoteNodeInstanceNoAllocationCell(self):
with PinnedDateTime(self, DateTime() - 1.1):
_, release_variation, \
_, \
release_variation, \
type_variation, \
compute_node, \
remote_node, \
partition, \
_ = self.bootstrapAllocableInstanceTree(
allocation_state='allocated', node='remote', shared=True)
_ = self.bootstrapAllocableInstanceTree(allocation_state='allocated',
node="remote")
self.tic()
ticket = compute_node.ComputeNode_checkAllocationConsistencyState()
ticket = remote_node.ComputeNode_checkAllocationConsistencyState()
self.tic()
# Double check error dict
error_dict = partition.ComputePartition_checkAllocationConsistencyState()
self.assertAllocationErrorDict(error_dict, compute_node, partition,
self.assertAllocationErrorDict(error_dict, remote_node,
release_variation, type_variation)
ticket_title = "%s has missing allocation supplies." % compute_node.getTitle()
ticket_title = "%s has missing allocation supplies." % remote_node.getTitle()
self.assertNotEqual(ticket, None)
self.assertEqual(ticket.getTitle(), ticket_title)
......@@ -309,69 +309,113 @@ class TestSlapOSCrmMonitoringCheckAllocationConsistencyState(TestSlapOSCrmMonito
self.assertIn(release_variation.getUrlString(), event.getTextContent())
self.assertIn(type_variation.getReference(), event.getTextContent())
self.assertEventTicket(event, ticket, compute_node)
self.assertEventTicket(event, ticket, remote_node)
@simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
def test_ComputeNode_checkAllocationConsistencyState_script_InstanceNodenoAllocationCell(self):
def test_ComputeNode_checkAllocationConsistencyState_script_RemoteNodeInstanceWithAllocationCell(self):
with PinnedDateTime(self, DateTime() - 1.1):
_, release_variation, \
type_variation, \
instance_node, \
_, \
_, \
_, \
remote_node, \
partition, \
_ = self.bootstrapAllocableInstanceTree(
allocation_state='allocated', node='instance', shared=True)
_ = self.bootstrapAllocableInstanceTree(allocation_state='allocated',
node="remote",
has_allocation_supply=True)
self.tic()
compute_node = partition.getParentValue()
self.assertEqual(compute_node.getPortalType(), 'Compute Node')
ticket = remote_node.ComputeNode_checkAllocationConsistencyState()
self.assertEqual(ticket, None)
ticket = compute_node.ComputeNode_checkAllocationConsistencyState()
# Double check error dict
error_dict = partition.ComputePartition_checkAllocationConsistencyState()
self.assertEqual({}, error_dict)
@simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
def test_ComputeNode_checkAllocationConsistencyState_script_RemoteNodeSlaveNoAllocationCell(self):
with PinnedDateTime(self, DateTime() - 1.1):
_, \
release_variation, \
type_variation, \
remote_node, \
partition, \
_ = self.bootstrapAllocableInstanceTree(allocation_state='allocated',
node="remote",
shared=True)
self.tic()
ticket = remote_node.ComputeNode_checkAllocationConsistencyState()
# Double check error dict
error_dict = partition.ComputePartition_checkAllocationConsistencyState()
self.assertAllocationErrorDict(error_dict, remote_node,
release_variation, type_variation)
ticket_title = "%s has missing allocation supplies." % remote_node.getTitle()
self.assertNotEqual(ticket, None)
self.assertEqual(ticket.getTitle(), ticket_title)
self.assertNotEqual({}, error_dict)
self.assertEqual(2, len(error_dict), error_dict)
self.tic()
event_list = ticket.getFollowUpRelatedValueList()
self.assertEqual(len(event_list), 1)
event = event_list[0]
# Type refers to slave instance type
type_reference = type_variation.getReference()
release_url = release_variation.getUrlString()
self.assertIn("The following contains instances that has Software Releases/Types",
event.getTextContent())
# Check first missing allocation supply for the instance on the computer
_error_dict = error_dict[compute_node.getRelativeUrl()]
self.assertIn(release_variation.getUrlString(), event.getTextContent())
self.assertIn(type_variation.getReference(), event.getTextContent())
self.assertEventTicket(event, ticket, remote_node)
@simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
def test_ComputeNode_checkAllocationConsistencyState_script_RemoteNodeSlaveWithAllocationCell(self):
with PinnedDateTime(self, DateTime() - 1.1):
_, \
_, \
_, \
remote_node, \
partition, \
_ = self.bootstrapAllocableInstanceTree(allocation_state='allocated',
shared=True,
node="remote",
has_allocation_supply=True)
software_instance = partition.getAggregateRelatedValue(
portal_type="Software Instance")
self.assertEqual([release_url], _error_dict.keys())
instance_software_type = software_instance.getSourceReference()
self.assertEqual([instance_software_type],
_error_dict[release_url].keys())
self.tic()
self.assertEqual(software_instance.getRelativeUrl(),
_error_dict[release_url][instance_software_type][0].getRelativeUrl())
self.assertEqual(compute_node.getRelativeUrl(),
_error_dict[release_url][instance_software_type][1].getRelativeUrl())
ticket = remote_node.ComputeNode_checkAllocationConsistencyState()
self.tic()
self.assertEqual(ticket, None)
for _index in error_dict:
if _index != compute_node.getRelativeUrl():
instance_error_dict = error_dict[_index]
# Double check error dict
error_dict = partition.ComputePartition_checkAllocationConsistencyState()
self.assertEqual({}, error_dict)
slave_instance = partition.getAggregateRelatedValue(portal_type='Slave Instance')
self.assertEqual([release_url], instance_error_dict.keys())
self.assertEqual([type_reference], instance_error_dict[release_url].keys())
@simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
def test_ComputeNode_checkAllocationConsistencyState_script_InstanceNodeSlaveNoAllocationCell(self):
with PinnedDateTime(self, DateTime() - 1.1):
_, \
release_variation, \
type_variation, \
instance_node, \
partition, \
_ = self.bootstrapAllocableInstanceTree(allocation_state='allocated',
node="instance",
shared=True)
self.assertEqual(slave_instance.getSourceReference(), type_reference)
self.assertEqual(slave_instance.getRelativeUrl(),
instance_error_dict[release_url][type_reference][0].getRelativeUrl())
self.assertNotEqual(compute_node.getRelativeUrl(),
instance_error_dict[release_url][type_reference][1].getRelativeUrl())
self.tic()
instance_node = instance_error_dict[release_url][type_reference][1]
self.assertEqual(instance_node.getPortalType(), 'Instance Node')
compute_node = partition.getParentValue()
ticket_list = compute_node.ComputeNode_checkAllocationConsistencyState()
ticket_title = "%s has missing allocation supplies." % compute_node.getTitle()
# Double check error dict
error_dict = partition.ComputePartition_checkAllocationConsistencyState()
self.assertEqual(2, len(error_dict), error_dict)
self.assertAllocationErrorDict(error_dict, instance_node,
release_variation, type_variation)
ticket_title = "%s has missing allocation supplies." % instance_node.getTitle()
self.assertEqual(len(ticket_list), 2)
ticket = ([x for x in ticket_list if x.getTitle() == ticket_title] or [None])[0]
self.assertNotEqual(ticket, None)
self.assertEqual(ticket.getTitle(), ticket_title)
......@@ -385,8 +429,104 @@ class TestSlapOSCrmMonitoringCheckAllocationConsistencyState(TestSlapOSCrmMonito
self.assertIn(release_variation.getUrlString(), event.getTextContent())
self.assertIn(type_variation.getReference(), event.getTextContent())
self.assertEventTicket(event, ticket, compute_node)
self.assertEventTicket(event, ticket, instance_node)
@simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
def test_ComputeNode_checkAllocationConsistencyState_script_InstanceNodeSlaveWithAllocationCell(self):
with PinnedDateTime(self, DateTime() - 1.1):
_, \
_, \
_, \
_, \
partition, \
_ = self.bootstrapAllocableInstanceTree(allocation_state='allocated',
shared=True,
node="instance",
has_allocation_supply=True)
self.tic()
compute_node = partition.getParentValue()
ticket = compute_node.ComputeNode_checkAllocationConsistencyState()
self.tic()
self.assertEqual(ticket, None)
# Double check error dict
error_dict = partition.ComputePartition_checkAllocationConsistencyState()
self.assertEqual({}, error_dict)
@simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
def test_ComputeNode_checkAllocationConsistencyState_script_hasTicketAlready(self):
with PinnedDateTime(self, DateTime() - 1.1):
_, \
release_variation, \
type_variation, \
compute_node, \
partition, \
_ = self.bootstrapAllocableInstanceTree(allocation_state='allocated')
project = compute_node.getFollowUpValue()
title = "checkAllocationConsistencyState %s" % self.generateNewId()
support_request = project.Project_createTicketWithCausality(
"Support Request", title, title,
causality=compute_node.getRelativeUrl(),
destination_decision=project.getDestination()
)
self.assertNotEqual(support_request, None)
self.tic()
ticket = compute_node.ComputeNode_checkAllocationConsistencyState()
self.assertEqual(ticket, None)
# Double check error dict exists despite ticket isnt created.
error_dict = partition.ComputePartition_checkAllocationConsistencyState()
self.assertAllocationErrorDict(error_dict, compute_node,
release_variation, type_variation)
@simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
def test_ComputeNode_checkAllocationConsistencyState_script_ongoingUpgrade(self):
with PinnedDateTime(self, DateTime() - 1.1):
_, _, _, \
compute_node, \
partition, \
instance_tree = self.bootstrapAllocableInstanceTree(allocation_state='allocated')
ud = self.portal.upgrade_decision_module.newContent(
portal_type="Upgrade Decision",
aggregate_value=instance_tree)
ud.plan()
self.tic()
ticket = compute_node.ComputeNode_checkAllocationConsistencyState()
# Double check error dict
error_dict = partition.ComputePartition_checkAllocationConsistencyState()
self.assertEqual({}, error_dict)
self.assertEqual(None, ticket)
@simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 1')
def test_ComputeNode_checkAllocationConsistencyState_script_creationClosed(self):
with PinnedDateTime(self, DateTime() - 1.1):
_, _, _, compute_node, \
_, _ = self.bootstrapAllocableInstanceTree(allocation_state='allocated')
self.tic()
ticket = compute_node.ComputeNode_checkAllocationConsistencyState()
self.assertEqual(None, ticket)
@simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
def test_ComputeNode_checkAllocationConsistencyState_script_monitorDisabled(self):
with PinnedDateTime(self, DateTime() - 1.1):
_, _, _, compute_node, \
_, _ = self.bootstrapAllocableInstanceTree(allocation_state='allocated')
compute_node.setMonitorScope('disabled')
self.tic()
ticket = compute_node.ComputeNode_checkAllocationConsistencyState()
self.assertEqual(None, ticket)
class TestSlapOSCrmMonitoringCheckComputeNodeProjectState(TestSlapOSCrmMonitoringMixin):
......@@ -1239,15 +1379,25 @@ class TestSlapOSCrmSoftwareInstance_checkInstanceTreeMonitoringState(TestSlapOSC
# the software instance.
_, _, _, _, _, instance_tree = self.bootstrapAllocableInstanceTree(
allocation_state='allocated', shared=True)
software_instance = instance_tree.getSuccessorValue()
slave_instance = instance_tree.getSuccessorValue(portal_type="Slave Instance")
software_instance = instance_tree.getSpecialiseRelatedValue(portal_type="Software Instance")
instance_tree.requestInstance(
software_title=software_instance.getTitle(),
state='destroyed',
software_release=software_instance.getUrlString(),
software_type=software_instance.getSourceReference(),
instance_xml=software_instance.getTextContent(),
sla_xml=software_instance.getSlaXml(),
shared=False,
)
software_instance.unallocatePartition()
self.tic()
error_dict = software_instance.SoftwareInstance_getReportedErrorDict()
software_instance.SoftwareInstance_checkInstanceTreeMonitoringState()
error_dict = slave_instance.SoftwareInstance_getReportedErrorDict()
slave_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)
......
......@@ -481,7 +481,10 @@ class TestSlapOSPDMCreateUpgradeDecisionSkins(SlapOSTestCaseMixin):
is_slave_on_same_instance_tree_allocable=True, disable_alarm=True)
self.tic()
self.assertEqual(None, instance_tree.InstanceTree_createUpgradeDecision())
self.checkCreatedUpgradeDecision(
instance_tree.InstanceTree_createUpgradeDecision(),
instance_tree, software_product, new_release_variation, type_variation
)
##########################################################################
# Allocated on Remote Node
......
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