Commit 7a16ccdf authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_pdm: Fix up cancellation of Upgrade Decision when monitor is disabled

parent b7c3ae84
Pipeline #12511 failed with stage
in 0 seconds
......@@ -4,6 +4,9 @@ software_release = context.getAggregateValue(portal_type="Software Release")
upgrade_decision = context.getParentValue()
if upgrade_decision.getSimulationState() == "cancelled":
return
if software_release.getValidationState() == "archived":
upgrade_decision.cancel(comment="Software Release is archived.")
return
......@@ -12,7 +15,7 @@ if hosting_subscription is not None:
if hosting_subscription.getUpgradeScope() in ['never', 'disabled']:
upgrade_decision.cancel("Upgrade scope was disabled on the related Hosting Subscription")
if hosting_subscription.getSlapState() == "destroy_requested":
elif hosting_subscription.getSlapState() == "destroy_requested":
upgrade_decision.cancel(comment="Hosting Subscription is destroyed.")
elif hosting_subscription.getUrlString() == software_release.getUrlString():
......@@ -24,8 +27,9 @@ computer = context.getAggregateValue(portal_type="Computer")
if computer is not None:
if computer.getUpgradeScope() in ['never', 'disabled']:
upgrade_decision.cancel("Upgrade scope was disabled on the related Hosting Subscription")
return
if computer.getAllocationScope() in ["closed/forever", "closed/termination"]:
elif computer.getAllocationScope() in ["closed/forever", "closed/termination"]:
upgrade_decision.cancel(comment="Computer is closed.")
return
......
......@@ -1559,6 +1559,19 @@ ${new_software_release_url}""",
self.assertEqual(event.getSimulationState(), "delivered")
def testUpgradeDecisionLine_cancel_already_cancelled(self):
software_release = self._makeSoftwareRelease()
upgrade_decision = self._makeUpgradeDecision()
upgrade_decision.cancel(comment="Cancelled by the test")
upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
upgrade_decision_line.setAggregateValueList([software_release])
self.tic()
upgrade_decision_line.UpgradeDecisionLine_cancel()
self.assertEqual('cancelled', upgrade_decision.getSimulationState())
workflow_history_list = upgrade_decision.Base_getWorkflowHistoryItemList('upgrade_decision_workflow', display=0)
self.assertEqual("Cancelled by the test", workflow_history_list[-1].comment)
def testUpgradeDecisionLine_cancel_archived_software_release(self):
software_release = self._makeSoftwareRelease()
upgrade_decision = self._makeUpgradeDecision()
......@@ -1617,6 +1630,52 @@ ${new_software_release_url}""",
workflow_history_list = upgrade_decision.Base_getWorkflowHistoryItemList('upgrade_decision_workflow', display=0)
self.assertEqual("Hosting Subscription is destroyed.", workflow_history_list[-1].comment)
@simulate('NotificationTool_getDocumentValue',
'reference=None',
'assert reference == "slapos-upgrade-delivered-computer.notification"\n' \
'return context.restrictedTraverse(' \
'context.REQUEST["testUpgradeDecisionLine_cancel_destroyed_hosting_subscription"])')
def testUpgradeDecisionLine_cancel_destroyed_hosting_subscription_and_disabled_monitor(self):
software_release = self._makeSoftwareRelease()
hosting_subscription = self._makeFullHostingSubscription(software_release.getUrlString())
upgrade_decision = self._makeUpgradeDecision()
upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
upgrade_decision_line.setAggregateValueList([software_release, hosting_subscription])
notification_message = self.portal.notification_message_module.newContent(
portal_type="Notification Message",
title='Test NM title %s' % self.new_id,
text_content_substitution_mapping_method_id=
"NotificationMessage_getSubstitutionMappingDictFromArgument",
text_content="""${software_product_title}
${computer_title}
${computer_reference}
${software_release_name}
${software_release_reference}
${new_software_release_url}""",
content_type='text/html',
)
self.portal.REQUEST\
['testUpgradeDecisionLine_cancel_destroyed_hosting_subscription'] = \
notification_message.getRelativeUrl()
self.tic()
kw = dict(
software_release = hosting_subscription.getUrlString(),
software_type = hosting_subscription.getSourceReference(),
instance_xml = hosting_subscription.getTextContent(),
sla_xml = self.generateSafeXml(),
shared = False
)
hosting_subscription.requestDestroy(**kw)
hosting_subscription.setMonitorScope("disabled")
self.tic()
upgrade_decision_line.UpgradeDecisionLine_cancel()
self.assertEqual('cancelled', upgrade_decision.getSimulationState())
workflow_history_list = upgrade_decision.Base_getWorkflowHistoryItemList('upgrade_decision_workflow', display=0)
self.assertEqual("Hosting Subscription is destroyed.", workflow_history_list[-1].comment)
@simulate('NotificationTool_getDocumentValue',
'reference=None',
'assert reference == "slapos-upgrade-delivered-computer.notification"\n' \
......
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