Commit 500d46b7 authored by Rafael Monnerat's avatar Rafael Monnerat

Improve upgrade decision creation

parent 2d16a9e0
......@@ -53,12 +53,12 @@
<value> <string>computer = context\n
portal = context.getPortalObject()\n
\n
full_software_release_list = [si.getUrlString() for si in \n
portal.portal_catalog(\n
portal_type=\'Software Installation\',\n
default_aggregate_uid=computer.getUid(),\n
validation_state=\'validated\'\n
) if si.getSlapState() == \'start_requested\']\n
full_software_release_list = [si.getUrlString() for si in\n
portal.portal_catalog(\n
portal_type=\'Software Installation\',\n
default_aggregate_uid=computer.getUid(),\n
validation_state=\'validated\'\n
) if si.getSlapState() == \'start_requested\']\n
\n
if len(full_software_release_list) == 0:\n
return\n
......@@ -68,7 +68,7 @@ software_release_list = portal.portal_catalog(\n
url_string=full_software_release_list,\n
group_by=\'default_aggregate_uid\'\n
)\n
\n
upgrade_decision_list = []\n
for software_release in software_release_list:\n
software_product_reference = software_release.getAggregateReference()\n
sorted_list = portal.SoftwareProduct_getSortedSoftwareReleaseList(\n
......@@ -79,17 +79,28 @@ for software_release in software_release_list:\n
sorted_list[0].getUrlString() not in full_software_release_list:\n
\n
newer_release = sorted_list[0]\n
title = \'A new software release is available for %s\' % \\\n
software_product_reference\n
# Search if exist upgrade decision for this software product (by title)\n
is_decision_in_progress = newer_release.\\\n
SoftwareRelease_isUpgradeDecisionInProgress(title=title)\n
if is_decision_in_progress:\n
title = \'A new version of %s is available for %s\' % \\\n
(software_product_reference, context.getTitle()) \n
# If exist upgrade decision in progress try to cancel it\n
decision_in_progress = newer_release.\\\n
SoftwareRelease_getUpgradeDecisionInProgress(computer.getUid())\n
if decision_in_progress and \\\n
not decision_in_progress.UpgradeDecision_tryToCancel(\n
newer_release.getUrlString()):\n
continue\n
\n
return newer_release.SoftwareRelease_createUpgradeDecision(\n
source_url=computer.getRelativeUrl(), title=title\n
)\n
upgrade_decision = newer_release.SoftwareRelease_createUpgradeDecision(\n
source_url=computer.getRelativeUrl(),\n
title=title)\n
\n
if context.getAllocationScope() in ["open/public", "open/friend"]:\n
upgrade_decision.start()\n
elif context.getAllocationScope() in ["open/personal"]:\n
upgrade_decision.plan()\n
\n
upgrade_decision_list.append(upgrade_decision)\n
\n
return upgrade_decision_list\n
</string> </value>
</item>
<item>
......
......@@ -50,56 +50,51 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>computer = context\n
portal = context.getPortalObject()\n
<value> <string>portal = context.getPortalObject()\n
\n
partition_list = portal.portal_catalog(portal_type=\'Computer Partition\',\n
free_for_request=0,\n
parent_uid=computer.getUid())\n
parent_uid=context.getUid())\n
valid_slap_state = [\'start_requested\', \'stop_requested\']\n
\n
# Get Hosting Subscription for all allocated partition\n
hosting_subscription_list = []\n
upgrade_decision_list = []\n
for partition in partition_list:\n
software_instance = partition.getAggregateRelatedValue(\n
portal_type=\'Software Instance\')\n
if software_instance:\n
hs = software_instance.getSpecialiseValue(\n
portal_type=\'Hosting Subscription\')\n
if hs and hs.getSlapState() in \\\n
[\'start_requested\', \'stop_requested\'] and \\\n
not hs in hosting_subscription_list:\n
hosting_subscription_list.append(hs)\n
\n
if len(hosting_subscription_list) == 0:\n
return\n
if not software_instance:\n
continue\n
\n
for hosting_subscription in hosting_subscription_list:\n
is_upgradable = hosting_subscription.HostingSubscription_isUpgradable()\n
if not is_upgradable:\n
hosting_subscription = software_instance.getSpecialiseValue(\n
portal_type=\'Hosting Subscription\')\n
if hosting_subscription and hosting_subscription.getSlapState() \\\n
in valid_slap_state and not \\\n
hosting_subscription in hosting_subscription_list:\n
hosting_subscription_list.append(hosting_subscription)\n
else:\n
continue\n
\n
newer_release_string = hosting_subscription.\\\n
HostingSubscription_getNewerSofwareRelease()\n
if not newer_release_string:\n
newer_release = hosting_subscription.\\\n
HostingSubscription_getUpgradableSoftwareRelease()\n
if newer_release is None:\n
continue\n
\n
software_release = portal.portal_catalog.getResultValue(\n
portal_type=\'Software Release\',\n
url_string=newer_release_string)\n
if not software_release:\n
continue\n
decision_in_progress = newer_release.\\\n
SoftwareRelease_getUpgradeDecisionInProgress(hosting_subscription.getUid())\n
\n
title = \'A new software release is available for %s\' % \\\n
hosting_subscription.getReference()\n
# Search if exist upgrade decision for this Hosting Subscription (by title)\n
is_decision_in_progress = software_release.\\\n
SoftwareRelease_isUpgradeDecisionInProgress(title=title)\n
if is_decision_in_progress:\n
if decision_in_progress and \\\n
not decision_in_progress.UpgradeDecision_tryToCancel(\n
newer_release.getUrlString()):\n
continue\n
\n
upgrade_decision = newer_release.SoftwareRelease_createUpgradeDecision(\n
source_url=hosting_subscription.getRelativeUrl(),\n
title=\'A new upgrade is available for %s\' % hosting_subscription.getTitle()\n
)\n
upgrade_decision.plan()\n
upgrade_decision_list.append(upgrade_decision)\n
\n
return software_release.SoftwareRelease_createUpgradeDecision(\n
source_url=hosting_subscription.getRelativeUrl(), title=title\n
)\n
return upgrade_decision_list\n
</string> </value>
</item>
<item>
......
......@@ -55,8 +55,8 @@
from DateTime import DateTime\n
\n
portal = context.getPortalObject()\n
\n
software_release = context\n
\n
source_product = portal.restrictedTraverse(source_url, None)\n
if not source_product:\n
return\n
......@@ -73,14 +73,12 @@ if not person_url:\n
return\n
\n
upgrade_decision = portal.upgrade_decision_module.\\\n
template_upgrade_decision.Base_createCloneDocument(batch_mode=1) \n
template_upgrade_decision.Base_createCloneDocument(batch_mode=1)\n
upgrade_decision.edit(\n
title=title,\n
destination_section=person_url,\n
destination_decision=person_url,\n
start_date=DateTime()\n
destination_decision=person_url\n
)\n
upgrade_decision.confirm()\n
decision_line_list = upgrade_decision.contentValues(\n
portal_type=\'Upgrade Decision Line\')\n
if len(decision_line_list) > 0:\n
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
portal = context.getPortalObject()\n
product_reference = context.getAggregateReference()\n
\n
decision_line_in_progress_list = portal.portal_catalog(\n
portal_type=\'Upgrade Decision Line\',\n
aggregate_uid=aggregate_uid)\n
\n
for decision_line in decision_line_in_progress_list:\n
upgrade_decision = decision_line.getParentValue()\n
if upgrade_decision.getSimulationState() not in [\'planned\',\n
\'confirmed\', \'started\', \'stopped\']:\n
continue\n
release_list = decision_line.getAggregateValueList(portal_type="Software Release")\n
if len(release_list) > 1:\n
continue\n
if not release_list[0]:\n
continue\n
# If both software release belong to the same software product, there is an upgrade decision in progress \n
if product_reference == release_list[0].getAggregateReference():\n
return upgrade_decision\n
]]></string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>aggregate_uid</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SoftwareRelease_getUpgradeDecisionInProgress</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -50,39 +50,30 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>url_string = context.getUrlString()\n
portal = context.getPortalObject()\n
<value> <string>upgrade_decision = context\n
cancel_state_list = [\'confirmed\', \'planned\']\n
\n
# Check if there is an upgrade decision in progress\n
kw[\'portal_type\'] = \'Upgrade Decision\'\n
upgrade_decision_in_progress = portal.portal_catalog(**kw)\n
\n
if len(upgrade_decision_in_progress) == 0:\n
if upgrade_decision.getSimulationState() in cancel_state_list:\n
current_release = upgrade_decision.UpgradeDecision_getSoftwareRelease()\n
if not current_release:\n
# This upgrade decision is not valid\n
return False\n
if current_release.getUrlString() == new_url_string:\n
# Cannot cancel because the software releases are the same\n
return False\n
upgrade_decision.cancel()\n
return True\n
else:\n
return False\n
\n
in_progress = False\n
for decision_in_progress in upgrade_decision_in_progress:\n
try:\n
software_release = decision_in_progress.\\\n
UpgradeDecision_getSoftwareRelease()\n
except ValueError:\n
continue\n
if not software_release:\n
continue\n
if url_string == software_release.getUrlString():\n
in_progress = True\n
break\n
\n
return in_progress\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>**kw</string> </value>
<value> <string>new_url_string</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SoftwareRelease_isUpgradeDecisionInProgress</string> </value>
<value> <string>UpgradeDecision_tryToCancel</string> </value>
</item>
</dictionary>
</pickle>
......
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