Commit 9cbd8ad8 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_pdm: Include tests and general fixes for Upgrade Decision

Conflicts:
	master/bt5/slapos_pdm/bt/revision

Conflicts:
	master/bt5/slapos_pdm/bt/revision
parent 1af3e850
...@@ -22,6 +22,12 @@ ...@@ -22,6 +22,12 @@
<key> <string>factory</string> </key> <key> <string>factory</string> </key>
<value> <string>addXMLObject</string> </value> <value> <string>addXMLObject</string> </value>
</item> </item>
<item>
<key> <string>group_list</string> </key>
<value>
<tuple/>
</value>
</item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>Upgrade Decision</string> </value> <value> <string>Upgrade Decision</string> </value>
......
...@@ -61,7 +61,7 @@ upgrade_decision_list = portal.portal_catalog(\n ...@@ -61,7 +61,7 @@ upgrade_decision_list = portal.portal_catalog(\n
portal_type="Upgrade Decision", \n portal_type="Upgrade Decision", \n
reference=reference, limit=2)\n reference=reference, limit=2)\n
\n \n
if upgrade_decision_list is None:\n if not len(upgrade_decision_list):\n
return context.Base_redirect("", \n return context.Base_redirect("", \n
keep_items={"portal_status_message": \n keep_items={"portal_status_message": \n
context.Base_translateString("Unable to find the Upgrade Decision.")})\n context.Base_translateString("Unable to find the Upgrade Decision.")})\n
...@@ -74,7 +74,7 @@ upgrade_decision = upgrade_decision_list[0]\n ...@@ -74,7 +74,7 @@ upgrade_decision = upgrade_decision_list[0]\n
if upgrade_decision.getSimulationState() in [\'draft\', \'planned\']:\n if upgrade_decision.getSimulationState() in [\'draft\', \'planned\']:\n
message = "Sorry, the upgrade is not possible yet!"\n message = "Sorry, the upgrade is not possible yet!"\n
\n \n
elif upgrade_decision.getSimulationState() in [\'cancel\', \'rejected\']:\n elif upgrade_decision.getSimulationState() in [\'cancelled\', \'rejected\']:\n
message = "Sorry, the upgrade is not possble, Upgrade Decision was Canceled or Rejected!"\n message = "Sorry, the upgrade is not possble, Upgrade Decision was Canceled or Rejected!"\n
\n \n
elif upgrade_decision.getSimulationState() == \'started\':\n elif upgrade_decision.getSimulationState() == \'started\':\n
......
...@@ -61,7 +61,7 @@ upgrade_decision_list = portal.portal_catalog(\n ...@@ -61,7 +61,7 @@ upgrade_decision_list = portal.portal_catalog(\n
portal_type="Upgrade Decision", \n portal_type="Upgrade Decision", \n
reference=reference, limit=2)\n reference=reference, limit=2)\n
\n \n
if upgrade_decision_list is None:\n if len(upgrade_decision_list) == 0:\n
return context.Base_redirect("", \n return context.Base_redirect("", \n
keep_items={"portal_status_message": \n keep_items={"portal_status_message": \n
context.Base_translateString("Unable to find the Upgrade Decision.")})\n context.Base_translateString("Unable to find the Upgrade Decision.")})\n
...@@ -72,7 +72,7 @@ if len(upgrade_decision_list) > 1:\n ...@@ -72,7 +72,7 @@ if len(upgrade_decision_list) > 1:\n
upgrade_decision = upgrade_decision_list[0]\n upgrade_decision = upgrade_decision_list[0]\n
\n \n
\n \n
if upgrade_decision.getSimulationState() in [\'cancel\', \'rejected\']:\n if upgrade_decision.getSimulationState() in [\'cancelled\', \'rejected\']:\n
message = "Upgrade Decision is already Rejected!"\n message = "Upgrade Decision is already Rejected!"\n
\n \n
elif upgrade_decision.getSimulationState() == \'started\':\n elif upgrade_decision.getSimulationState() == \'started\':\n
......
...@@ -52,6 +52,10 @@ ...@@ -52,6 +52,10 @@
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>from DateTime import DateTime\n <value> <string>from DateTime import DateTime\n
\n \n
if context.getSimulationState() != \'planned\':\n
# XXX Don\'t notify the ones which are not planned.\n
return \n
\n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
\n \n
person = context.getDestinationDecisionValue(portal_type="Person")\n person = context.getDestinationDecisionValue(portal_type="Person")\n
...@@ -65,50 +69,41 @@ software_product_title = software_release.getAggregateTitle(\n ...@@ -65,50 +69,41 @@ software_product_title = software_release.getAggregateTitle(\n
portal_type="Software Product")\n portal_type="Software Product")\n
reference = context.getReference()\n reference = context.getReference()\n
\n \n
if hosting_subscription is not None:\n mapping_dict = {\n
\n \'software_product_title\': software_product_title,\n
notification_message = portal.portal_notifications.getDocumentValue(\n \'upgrade_accept_link\': \'Base_acceptUpgradeDecision?reference=%s\' % reference,\n
reference=\'slapos-upgrade-hosting-subscription.notification\')\n \'upgrade_reject_link\': \'Base_rejectUpgradeDecision?reference=%s\' % reference,\n
\'software_release_name\': software_release.getTitle(),\n
\'software_release_reference\': software_release.getReference(),\n
\'new_software_release_url\': software_release.getUrlString(),\n
\n \n
}\n
if hosting_subscription is not None:\n
notification_message_reference = \'slapos-upgrade-hosting-subscription.notification\'\n
title = "New Upgrade available for %s" % hosting_subscription.getTitle()\n title = "New Upgrade available for %s" % hosting_subscription.getTitle()\n
mapping_dict = {\'software_product_title\': software_product_title,\n mapping_dict.update(**{\n
\'hosting_subscription_title\': hosting_subscription.getTitle(),\n \'hosting_subscription_title\': hosting_subscription.getTitle(),\n
\'software_release_name\': software_release.getTitle(),\n \'old_software_release_url\': hosting_subscription.getUrlString()})\n
\'software_release_reference\': software_release.getReference(),\n
\'upgrade_accept_link\': \n
\'Base_acceptUpgradeDecision?reference=%s\' % reference,\n
\'upgrade_reject_link\':\n
\'Base_rejectUpgradeDecision?reference=%s\' % reference,\n
\'old_software_release_url\': hosting_subscription.getUrlString(),\n
\'new_software_release_url\': software_release.getUrlString(),\n
}\n
\n \n
\n \n
elif computer is not None:\n elif computer is not None:\n
\n \n
notification_message = portal.portal_notifications.getDocumentValue(\n notification_message_reference = \'slapos-upgrade-computer.notification\' \n
reference=\'slapos-upgrade-computer.notification\')\n \n
\n title = "New Software available for Installation at %s" % computer.getTitle()\n
computer = "New Software available for Installation at %s" % computer.getTitle()\n mapping_dict.update(**{\'computer_title\': computer.getTitle(),\n
mapping_dict = {\'software_product_title\': software_product_title,\n \'computer_reference\': computer.getReference()})\n
\'computer_title\': computer.getTitle(),\n \n
\'computer_reference\': computer.getReference(),\n \n
\'software_release_name\': software_release.getTitle(),\n if notification_message_reference is None:\n
\'software_release_reference\': software_release.getReference(),\n
\'upgrade_accept_link\': \n
\'Base_acceptUpgradeDecision?reference=%s\' % reference,\n
\'upgrade_reject_link\':\n
\'Base_rejectUpgradeDecision?reference=%s\' % reference,\n
\'new_software_release_url\': software_release.getUrlString(),\n
}\n
\n
\n
if notification_message is not None:\n
message = notification_message.asEntireHTML(\n
substitution_method_parameter_dict={\'mapping_dict\': mapping_dict})\n
else:\n
raise ValueError("No Notification Message")\n raise ValueError("No Notification Message")\n
\n \n
notification_message = portal.portal_notifications.getDocumentValue(\n
reference=notification_message_reference)\n
\n
message = notification_message.asEntireHTML(\n
substitution_method_parameter_dict={\'mapping_dict\': mapping_dict})\n
\n
event = context.SupportRequest_trySendNotificationMessage(title,\n event = context.SupportRequest_trySendNotificationMessage(title,\n
message, person.getRelativeUrl())\n message, person.getRelativeUrl())\n
\n \n
......
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
<string>delete_action</string> <string>delete_action</string>
<string>plan</string> <string>plan</string>
<string>plan_action</string> <string>plan_action</string>
<string>reject</string>
<string>reject_action</string>
<string>start</string> <string>start</string>
<string>start_action</string> <string>start_action</string>
</tuple> </tuple>
......
27 28
\ No newline at end of file \ No newline at end of file
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