Commit 9a8e2947 authored by Alain Takoudjou's avatar Alain Takoudjou

[slapos_pdm]: Prevent multiple activity nodes to create upgrade decision twice

parent 37589c69
...@@ -2,6 +2,12 @@ from DateTime import DateTime ...@@ -2,6 +2,12 @@ from DateTime import DateTime
portal = context.getPortalObject() portal = context.getPortalObject()
hosting_subscription = context hosting_subscription = context
tag = "%s_requestUpgradeDecisionCreation_inProgress" % hosting_subscription.getUid()
activate_kw = {'tag': tag}
if portal.portal_activities.countMessageWithTag(tag) > 0:
# nothing to do
return
root_instance = hosting_subscription.getPredecessorValue() root_instance = hosting_subscription.getPredecessorValue()
if root_instance is None or root_instance.getPortalType() == "Slave Instance": if root_instance is None or root_instance.getPortalType() == "Slave Instance":
return return
...@@ -29,23 +35,13 @@ if decision_in_progress and \ ...@@ -29,23 +35,13 @@ if decision_in_progress and \
newer_release.getUrlString()): newer_release.getUrlString()):
return return
requested_decision = context.REQUEST.get("upgrade_decision_request", None)
if requested_decision is not None and \
requested_decision.getTitle() == decision_title:
related_hosting = requested_decision.UpgradeDecision_getHostingSubscription()
related_release = requested_decision.UpgradeDecision_getSoftwareRelease()
if related_hosting is not None and \
related_hosting.getUid() == hosting_subscription.getUid() and \
related_release.getUid() == newer_release.getUid():
return
upgrade_decision = newer_release.SoftwareRelease_createUpgradeDecision( upgrade_decision = newer_release.SoftwareRelease_createUpgradeDecision(
source_url=hosting_subscription.getRelativeUrl(), source_url=hosting_subscription.getRelativeUrl(),
title=decision_title title=decision_title
) )
upgrade_decision.plan() with upgrade_decision.defaultActivateParameterDict(activate_kw):
upgrade_decision.setStartDate(DateTime()) upgrade_decision.plan()
context.REQUEST.set("upgrade_decision_request", upgrade_decision) upgrade_decision.setStartDate(DateTime())
# Prevent concurrent transaction to create 2 upgrade decision for the same hosting_subscription # Prevent concurrent transaction to create 2 upgrade decision for the same hosting_subscription
hosting_subscription.serialize() hosting_subscription.serialize()
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
# #
############################################################################## ##############################################################################
import transaction
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin, simulate from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin, simulate
from DateTime import DateTime from DateTime import DateTime
...@@ -1134,7 +1135,7 @@ class TestSlapOSPDMSkins(SlapOSTestCaseMixin): ...@@ -1134,7 +1135,7 @@ class TestSlapOSPDMSkins(SlapOSTestCaseMixin):
up_decision = hosting_subscription.HostingSubscription_createUpgradeDecision() up_decision = hosting_subscription.HostingSubscription_createUpgradeDecision()
self.assertEqual(up_decision, None) self.assertEqual(up_decision, None)
def testHostingSubscription_createUpgradeDecision_create_once(self): def testHostingSubscription_createUpgradeDecision_create_once_transaction(self):
person = self._makePerson() person = self._makePerson()
computer = self._makeComputer(allocation_scope="open/personal") computer = self._makeComputer(allocation_scope="open/personal")
computer.edit(source_administration_value=person) computer.edit(source_administration_value=person)
...@@ -1163,6 +1164,7 @@ class TestSlapOSPDMSkins(SlapOSTestCaseMixin): ...@@ -1163,6 +1164,7 @@ class TestSlapOSPDMSkins(SlapOSTestCaseMixin):
up_decision = hosting_subscription.HostingSubscription_createUpgradeDecision() up_decision = hosting_subscription.HostingSubscription_createUpgradeDecision()
self.assertNotEqual(up_decision, None) self.assertNotEqual(up_decision, None)
self.assertEqual(up_decision.getSimulationState(), 'planned') self.assertEqual(up_decision.getSimulationState(), 'planned')
transaction.commit()
# call a second time without tic # call a second time without tic
up_decision = hosting_subscription.HostingSubscription_createUpgradeDecision() up_decision = hosting_subscription.HostingSubscription_createUpgradeDecision()
# no new Upgrade decision created # no new Upgrade decision created
......
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