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 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
"""\n
<value> <string>"""\n
Run upgrader\n
"""\n
portal = context.getPortalObject()\n
portal_alarms = portal.portal_alarms\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
if after_tag is None:\n
after_tag = []\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
kw = dict(tag=alarm_id)\n
if len(after_method_id) > 0:\n
kw["after_method_id"] = after_method_id\n
tag = alarm_id\n
activate_kw = dict(tag=tag)\n
activate_kw["after_tag"] = after_tag\n
method_id = upgrader_alarm.getSolveMethodId()\n
if method_id not in (None, \'\'):\n
method = getattr(upgrader_alarm.activate(**kw), method_id)\n
method()\n
return [method_id] + after_method_id\n
return after_method_id\n
\n
previous_method_id = launchUpgraderAlarm(\'upgrader_check_pre_upgrade\')\n
method = getattr(upgrader_alarm.activate(**activate_kw), method_id)\n
method(force=force, activate_kw=activate_kw)\n
return [tag] + after_tag\n
return after_tag\n
\n
previous_method_id.extend([\'recursiveImmediateReindexObject\',\n
\'immediateReindexObject\',\n
\'Base_postCheckConsistencyResult\'])\n
previous_tag = launchUpgraderAlarm(\'upgrader_check_pre_upgrade\')\n
\n
previous_method_id = launchUpgraderAlarm(\'upgrader_check_upgrader\',\n
after_method_id=previous_method_id)\n
previous_tag = launchUpgraderAlarm(\'upgrader_check_upgrader\',\n
after_tag=previous_tag)\n
\n
previous_method_id.append(\'updateBusinessTemplateFromUrl\')\n
previous_method_id = launchUpgraderAlarm(\'upgrader_check_post_upgrade\',\n
after_method_id=previous_method_id)\n
previous_tag = launchUpgraderAlarm(\'upgrader_check_post_upgrade\',\n
after_tag=previous_tag)\n
\n
# Nothing else to do, so we can disable.\n
context.setEnabled(False)\n
return\n
]]></string> </value>
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>**kw</string> </value>
<value> <string>force=0, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -58,7 +58,7 @@ active_process = context.newActiveProcess()\n
\n
# We should not run post upgrade if upgrader was not solved or never executed\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
severity=1,\n
detail="Is required run upgrade before solve it. " +\\\n
......@@ -66,6 +66,7 @@ if alarm.sense() in (None, True):\n
return\n
\n
context.ERP5Site_checkUpgraderConsistency(fixit=True,\n
activate_kw=activate_kw,\n
active_process=active_process,\n
filter_dict={"constraint_type": "post_upgrade"})\n
\n
......@@ -75,7 +76,7 @@ return\n
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>**kw</string> </value>
<value> <string>force=0, activate_kw={}, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -54,6 +54,7 @@
Run Pre upgrade\n
"""\n
context.ERP5Site_checkUpgraderConsistency(fixit=True,\n
activate_kw=activate_kw,\n
active_process=context.newActiveProcess(),\n
filter_dict={"constraint_type": "pre_upgrade"})\n
\n
......@@ -63,7 +64,7 @@ return\n
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>**kw</string> </value>
<value> <string>force=0, activate_kw={}, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -67,7 +67,7 @@ active_process = context.newActiveProcess()\n
\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
if alarm.sense() in (None, True):\n
if not(force) and alarm.sense() in (None, True):\n
active_process.postActiveResult(summary=context.getTitle(),\n
severity=1,\n
detail="Is required solve Pre Upgrade first. " +\\\n
......@@ -90,6 +90,7 @@ for portal_type in portal_type_list:\n
if portal.portal_catalog.countResults(\n
portal_type=portal_type_list)[0][0] > REINDEX_SPLIT_COUNT:\n
portal.portal_catalog.searchAndActivate(\'Base_postCheckConsistencyResult\',\n
activate_kw=activate_kw,\n
portal_type=portal_type,\n
method_kw=method_kw)\n
else:\n
......@@ -104,7 +105,7 @@ return\n
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>**kw</string> </value>
<value> <string>force=0, activate_kw={}, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -64,6 +64,7 @@ for portal_type, constraint_type_list in constraint_type_per_type.iteritems():\n
if portal_type_list:\n
context.getPortalObject().portal_catalog.searchAndActivate(\n
\'Base_postCheckConsistencyResult\',\n
activate_kw=activate_kw,\n
portal_type=portal_type_list,\n
method_kw={\n
\'fixit\': fixit,\n
......@@ -75,7 +76,7 @@ if portal_type_list:\n
</item>
<item>
<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>
<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