Commit 28351604 authored by Sebastien Robin's avatar Sebastien Robin

upgrader: simplify dependencies between steps, add a mode to force upgrade

- do dependency between steps only based on tags. This avoid having hardcoded
list of method ids that are not friendly with further extension
- add a mode to force doing the upgrade. Doing fully upgrade based on previous
sense() is not acceptable. For example we might be in a case of broken catalog
that does not support any new insertion until upgrade is finished
parent 62285282
...@@ -50,52 +50,45 @@ ...@@ -50,52 +50,45 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[ <value> <string>"""\n
"""\n
Run upgrader\n Run upgrader\n
"""\n """\n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
portal_alarms = portal.portal_alarms\n portal_alarms = portal.portal_alarms\n
\n \n
def launchUpgraderAlarm(alarm_id, after_method_id=[]):\n def launchUpgraderAlarm(alarm_id, after_tag=None):\n
""" Get the alarm and use sense and solve """\n """ Get the alarm and use sense and solve """\n
if after_tag is None:\n
after_tag = []\n
upgrader_alarm = getattr(portal_alarms, alarm_id, None)\n upgrader_alarm = getattr(portal_alarms, alarm_id, None)\n
if upgrader_alarm is not None and upgrader_alarm.sense():\n if upgrader_alarm is not None and (force or upgrader_alarm.sense()):\n
# call solve method\n # call solve method\n
kw = dict(tag=alarm_id)\n tag = alarm_id\n
if len(after_method_id) > 0:\n activate_kw = dict(tag=tag)\n
kw["after_method_id"] = after_method_id\n activate_kw["after_tag"] = after_tag\n
method_id = upgrader_alarm.getSolveMethodId()\n method_id = upgrader_alarm.getSolveMethodId()\n
if method_id not in (None, \'\'):\n if method_id not in (None, \'\'):\n
method = getattr(upgrader_alarm.activate(**kw), method_id)\n method = getattr(upgrader_alarm.activate(**activate_kw), method_id)\n
method()\n method(force=force, activate_kw=activate_kw)\n
return [method_id] + after_method_id\n return [tag] + after_tag\n
return after_method_id\n return after_tag\n
\n
previous_method_id = launchUpgraderAlarm(\'upgrader_check_pre_upgrade\')\n
\n \n
previous_method_id.extend([\'recursiveImmediateReindexObject\',\n previous_tag = launchUpgraderAlarm(\'upgrader_check_pre_upgrade\')\n
\'immediateReindexObject\',\n
\'Base_postCheckConsistencyResult\'])\n
\n \n
previous_method_id = launchUpgraderAlarm(\'upgrader_check_upgrader\',\n previous_tag = launchUpgraderAlarm(\'upgrader_check_upgrader\',\n
after_method_id=previous_method_id)\n after_tag=previous_tag)\n
\n \n
previous_method_id.append(\'updateBusinessTemplateFromUrl\')\n previous_tag = launchUpgraderAlarm(\'upgrader_check_post_upgrade\',\n
previous_method_id = launchUpgraderAlarm(\'upgrader_check_post_upgrade\',\n after_tag=previous_tag)\n
after_method_id=previous_method_id)\n
\n \n
# Nothing else to do, so we can disable.\n # Nothing else to do, so we can disable.\n
context.setEnabled(False)\n context.setEnabled(False)\n
return\n return\n
</string> </value>
]]></string> </value>
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>**kw</string> </value> <value> <string>force=0, **kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -58,7 +58,7 @@ active_process = context.newActiveProcess()\n ...@@ -58,7 +58,7 @@ active_process = context.newActiveProcess()\n
\n \n
# We should not run post upgrade if upgrader was not solved or never executed\n # We should not run post upgrade if upgrader was not solved or never executed\n
alarm = getattr(portal_alarms, \'upgrader_check_upgrader\')\n alarm = getattr(portal_alarms, \'upgrader_check_upgrader\')\n
if alarm.sense() in (None, True):\n if not(force) and alarm.sense() in (None, True):\n
active_process.postActiveResult(summary=context.getTitle(),\n active_process.postActiveResult(summary=context.getTitle(),\n
severity=1,\n severity=1,\n
detail="Is required run upgrade before solve it. " +\\\n detail="Is required run upgrade before solve it. " +\\\n
...@@ -66,6 +66,7 @@ if alarm.sense() in (None, True):\n ...@@ -66,6 +66,7 @@ if alarm.sense() in (None, True):\n
return\n return\n
\n \n
context.ERP5Site_checkUpgraderConsistency(fixit=True,\n context.ERP5Site_checkUpgraderConsistency(fixit=True,\n
activate_kw=activate_kw,\n
active_process=active_process,\n active_process=active_process,\n
filter_dict={"constraint_type": "post_upgrade"})\n filter_dict={"constraint_type": "post_upgrade"})\n
\n \n
...@@ -75,7 +76,7 @@ return\n ...@@ -75,7 +76,7 @@ return\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>**kw</string> </value> <value> <string>force=0, activate_kw={}, **kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
Run Pre upgrade\n Run Pre upgrade\n
"""\n """\n
context.ERP5Site_checkUpgraderConsistency(fixit=True,\n context.ERP5Site_checkUpgraderConsistency(fixit=True,\n
activate_kw=activate_kw,\n
active_process=context.newActiveProcess(),\n active_process=context.newActiveProcess(),\n
filter_dict={"constraint_type": "pre_upgrade"})\n filter_dict={"constraint_type": "pre_upgrade"})\n
\n \n
...@@ -63,7 +64,7 @@ return\n ...@@ -63,7 +64,7 @@ return\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>**kw</string> </value> <value> <string>force=0, activate_kw={}, **kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -67,7 +67,7 @@ active_process = context.newActiveProcess()\n ...@@ -67,7 +67,7 @@ active_process = context.newActiveProcess()\n
\n \n
# We should not run upgrader if pre upgrade was not solved or never executed \n # We should not run upgrader if pre upgrade was not solved or never executed \n
alarm = getattr(portal_alarms, \'upgrader_check_pre_upgrade\')\n alarm = getattr(portal_alarms, \'upgrader_check_pre_upgrade\')\n
if alarm.sense() in (None, True):\n if not(force) and alarm.sense() in (None, True):\n
active_process.postActiveResult(summary=context.getTitle(),\n active_process.postActiveResult(summary=context.getTitle(),\n
severity=1,\n severity=1,\n
detail="Is required solve Pre Upgrade first. " +\\\n detail="Is required solve Pre Upgrade first. " +\\\n
...@@ -90,6 +90,7 @@ for portal_type in portal_type_list:\n ...@@ -90,6 +90,7 @@ for portal_type in portal_type_list:\n
if portal.portal_catalog.countResults(\n if portal.portal_catalog.countResults(\n
portal_type=portal_type_list)[0][0] > REINDEX_SPLIT_COUNT:\n portal_type=portal_type_list)[0][0] > REINDEX_SPLIT_COUNT:\n
portal.portal_catalog.searchAndActivate(\'Base_postCheckConsistencyResult\',\n portal.portal_catalog.searchAndActivate(\'Base_postCheckConsistencyResult\',\n
activate_kw=activate_kw,\n
portal_type=portal_type,\n portal_type=portal_type,\n
method_kw=method_kw)\n method_kw=method_kw)\n
else:\n else:\n
...@@ -104,7 +105,7 @@ return\n ...@@ -104,7 +105,7 @@ return\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>**kw</string> </value> <value> <string>force=0, activate_kw={}, **kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -64,6 +64,7 @@ for portal_type, constraint_type_list in constraint_type_per_type.iteritems():\n ...@@ -64,6 +64,7 @@ for portal_type, constraint_type_list in constraint_type_per_type.iteritems():\n
if portal_type_list:\n if portal_type_list:\n
context.getPortalObject().portal_catalog.searchAndActivate(\n context.getPortalObject().portal_catalog.searchAndActivate(\n
\'Base_postCheckConsistencyResult\',\n \'Base_postCheckConsistencyResult\',\n
activate_kw=activate_kw,\n
portal_type=portal_type_list,\n portal_type=portal_type_list,\n
method_kw={\n method_kw={\n
\'fixit\': fixit,\n \'fixit\': fixit,\n
...@@ -75,7 +76,7 @@ if portal_type_list:\n ...@@ -75,7 +76,7 @@ if portal_type_list:\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>active_process, fixit=False, filter_dict={}</string> </value> <value> <string>active_process, activate_kw={}, fixit=False, filter_dict={}</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
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