Commit abec45b4 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_pdm: Improve criterias to cancel an Upgrade Decision

Upgrade Decision should be Cancelled if it is not applicable anymore.
parent 968d5cbc
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>active_sense_method_id</string> </key> <key> <string>active_sense_method_id</string> </key>
<value> <string>Alarm_cancelUpgradeDestroyedHostingSubscription</string> </value> <value> <string>Alarm_cancelUpgradeDecision</string> </value>
</item> </item>
<item> <item>
<key> <string>automatic_solve</string> </key> <key> <string>automatic_solve</string> </key>
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
</item> </item>
<item> <item>
<key> <string>description</string> </key> <key> <string>description</string> </key>
<value> <string>Cancel Upgrade Decisions which are related to destroyed instances</string> </value> <value> <string>Cancel Upgrade Decision which arent applicable anymore (Destroyed Hosting Subscriptions, Closed computers, already deployed softwares)</string> </value>
</item> </item>
<item> <item>
<key> <string>enabled</string> </key> <key> <string>enabled</string> </key>
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>slapos_pdm_hosting_subscription_auto_cancel_upgrade_decision</string> </value> <value> <string>slapos_pdm_auto_cancel_upgrade_decision</string> </value>
</item> </item>
<item> <item>
<key> <string>periodicity_day_frequency</string> </key> <key> <string>periodicity_day_frequency</string> </key>
...@@ -107,7 +107,7 @@ ...@@ -107,7 +107,7 @@
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>Auto Cancel Upgrade Decision for Destroyed Hosting Subscriptions</string> </value> <value> <string>Auto Cancel Upgrade Decision when not applicable</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -4,7 +4,7 @@ portal = context.getPortalObject() ...@@ -4,7 +4,7 @@ portal = context.getPortalObject()
portal.portal_catalog.searchAndActivate( portal.portal_catalog.searchAndActivate(
portal_type="Upgrade Decision Line", portal_type="Upgrade Decision Line",
simulation_state="confirmed", simulation_state="confirmed",
method_id = 'UpgradeDecisionLine_cancelDestroyed', method_id = 'UpgradeDecisionLine_cancel',
activate_kw = {'tag':tag} activate_kw = {'tag':tag}
) )
......
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>Alarm_cancelUpgradeDestroyedHostingSubscription</string> </value> <value> <string>Alarm_cancelUpgradeDecision</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
hosting_subscription = context.getAggregateValue(portal_type="Hosting Subscription")
software_release = context.getAggregateValue(portal_type="Software Release")
upgrade_decision = context.getParentValue()
if software_release.getValidationState() == "archived":
upgrade_decision.cancel(comment="Software Release is archived")
if hosting_subscription is not None:
if hosting_subscription.getSlapState() == "destroy_requested":
upgrade_decision.cancel(comment="Hosting Subscription is destroyed.")
elif hosting_subscription.getUrlString() == software_release.getUrlString():
upgrade_decision.cancel(comment="Hosting subscription is already upgraded.")
return
computer = context.getAggregateValue(portal_type="Computer")
if computer is not None:
if computer.getAllocationScope() in ["closed/forever", "closed/termination"]:
upgrade_decision.cancel(comment="Computer is closed.")
return
already_deployed = len(context.portal_catalog(limit=1,
portal_type="Computer Partition",
parent_reference=computer.getReference(),
software_release_url=software_release.getUrlString()))
if already_deployed:
context.getParentValue().cancel(comment="Computer already has the software release")
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>UpgradeDecisionLine_cancelDestroyed</string> </value> <value> <string>UpgradeDecisionLine_cancel</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
software_instance = context.getAggregateValue(portal_type="Hosting Subscription")
if software_instance is not None and software_instance.getSlapState() == "destroy_requested":
context.getParentValue().cancel()
...@@ -3,8 +3,8 @@ notification_message_module/slapos_upgrade_delivered_computer_notification ...@@ -3,8 +3,8 @@ notification_message_module/slapos_upgrade_delivered_computer_notification
notification_message_module/slapos_upgrade_delivered_hosting_subscription_notification notification_message_module/slapos_upgrade_delivered_hosting_subscription_notification
notification_message_module/slapos_upgrade_hosting_subscription_notification notification_message_module/slapos_upgrade_hosting_subscription_notification
portal_alarms/slapos_manage_software_catalog portal_alarms/slapos_manage_software_catalog
portal_alarms/slapos_pdm_auto_cancel_upgrade_decision
portal_alarms/slapos_pdm_computer_create_upgrade_decision portal_alarms/slapos_pdm_computer_create_upgrade_decision
portal_alarms/slapos_pdm_hosting_subscription_auto_cancel_upgrade_decision
portal_alarms/slapos_pdm_hosting_subscription_create_upgrade_decision portal_alarms/slapos_pdm_hosting_subscription_create_upgrade_decision
portal_alarms/slapos_pdm_upgrade_decision_process_planned portal_alarms/slapos_pdm_upgrade_decision_process_planned
portal_alarms/slapos_pdm_upgrade_decision_process_started portal_alarms/slapos_pdm_upgrade_decision_process_started
......
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