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