Commit 35b57e5a authored by Alain Takoudjou's avatar Alain Takoudjou Committed by Rafael Monnerat

Do not recreate upgrade decision for the same sr if it was rejected

parent 6d028a66
...@@ -61,14 +61,20 @@ decision_line_in_progress_list = portal.portal_catalog(\n ...@@ -61,14 +61,20 @@ decision_line_in_progress_list = portal.portal_catalog(\n
\n \n
for decision_line in decision_line_in_progress_list:\n for decision_line in decision_line_in_progress_list:\n
upgrade_decision = decision_line.getParentValue()\n upgrade_decision = decision_line.getParentValue()\n
if upgrade_decision.getSimulationState() not in [\'planned\',\n simulation_state = upgrade_decision.getSimulationState()\n
\'confirmed\', \'started\', \'stopped\']:\n if simulation_state not in [\'planned\', \'confirmed\',\n
\'started\', \'stopped\', \'rejected\']:\n
continue\n continue\n
release_list = decision_line.getAggregateValueList(portal_type="Software Release")\n release_list = decision_line.getAggregateValueList(portal_type="Software Release")\n
if len(release_list) > 1:\n if len(release_list) > 1:\n
continue\n continue\n
if not release_list[0]:\n if not release_list[0]:\n
continue\n continue\n
# If the current sr in rejected we must prevent creation of new upgrade decision for this sr\n
if simulation_state == \'rejected\' and \\\n
release_list[0].getUrlString() != context.getUrlString():\n
continue\n
\n
# If both software release belong to the same software product, there is an upgrade decision in progress \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 if product_reference == release_list[0].getAggregateReference():\n
return upgrade_decision\n return upgrade_decision\n
......
...@@ -51,9 +51,11 @@ ...@@ -51,9 +51,11 @@
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>upgrade_decision = context\n <value> <string>upgrade_decision = context\n
cancel_state_list = [\'confirmed\', \'planned\']\n cancellable_state_list = [\'confirmed\', \'planned\']\n
require_state_list = [\'rejected\', \'confirmed\', \'planned\']\n
simulation_state = upgrade_decision.getSimulationState()\n
\n \n
if upgrade_decision.getSimulationState() in cancel_state_list:\n if simulation_state in require_state_list:\n
current_release = upgrade_decision.UpgradeDecision_getSoftwareRelease()\n current_release = upgrade_decision.UpgradeDecision_getSoftwareRelease()\n
if not current_release:\n if not current_release:\n
# This upgrade decision is not valid\n # This upgrade decision is not valid\n
...@@ -61,6 +63,7 @@ if upgrade_decision.getSimulationState() in cancel_state_list:\n ...@@ -61,6 +63,7 @@ if upgrade_decision.getSimulationState() in cancel_state_list:\n
if current_release.getUrlString() == new_url_string:\n if current_release.getUrlString() == new_url_string:\n
# Cannot cancel because the software releases are the same\n # Cannot cancel because the software releases are the same\n
return False\n return False\n
if simulation_state in cancellable_state_list:\n
upgrade_decision.cancel()\n upgrade_decision.cancel()\n
return True\n return True\n
else:\n else:\n
......
...@@ -852,6 +852,42 @@ class TestSlapOSPDMSkins(testSlapOSMixin): ...@@ -852,6 +852,42 @@ class TestSlapOSPDMSkins(testSlapOSMixin):
computer.getUid()) computer.getUid())
self.assertEqual(in_progress.getReference(), upgrade_decision2.getReference()) self.assertEqual(in_progress.getReference(), upgrade_decision2.getReference())
def testSoftwareRelease_getUpgradeDecisionInProgress_rejected(self):
computer = self._makeComputer()
software_product = self._makeSoftwareProduct()
software_release = self._requestSoftwareRelease(
software_product.getRelativeUrl())
upgrade_decision = self._makeUpgradeDecision()
upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
upgrade_decision_line.setAggregateValueList([software_release, computer])
upgrade_decision.confirm()
upgrade_decision.reject()
self.tic()
in_progress = software_release.SoftwareRelease_getUpgradeDecisionInProgress(
computer.getUid())
# XXX - in_progress is the rejected upgrade decision
self.assertEqual(in_progress.getReference(), upgrade_decision.getReference())
new_release = self._requestSoftwareRelease(
software_product.getRelativeUrl())
self.tic()
in_progress = new_release.SoftwareRelease_getUpgradeDecisionInProgress(
computer.getUid())
self.assertEqual(in_progress, None)
upgrade_decision2 = self._makeUpgradeDecision()
upgrade_decision_line2 = self._makeUpgradeDecisionLine(upgrade_decision2)
upgrade_decision_line2.setAggregateValueList([new_release, computer])
upgrade_decision2.confirm()
upgrade_decision2.start()
self.tic()
in_progress = new_release.SoftwareRelease_getUpgradeDecisionInProgress(
computer.getUid())
self.assertEqual(in_progress.getReference(), upgrade_decision2.getReference())
def testSoftwareRelease_getUpgradeDecisionInProgress_hosting_subs(self): def testSoftwareRelease_getUpgradeDecisionInProgress_hosting_subs(self):
person = self._makePerson() person = self._makePerson()
hosting_subscription = self._makeHostingSubscription() hosting_subscription = self._makeHostingSubscription()
...@@ -971,6 +1007,25 @@ class TestSlapOSPDMSkins(testSlapOSMixin): ...@@ -971,6 +1007,25 @@ class TestSlapOSPDMSkins(testSlapOSMixin):
self.assertEqual(upgrade_decision2.UpgradeDecision_tryToCancel(url2), False) self.assertEqual(upgrade_decision2.UpgradeDecision_tryToCancel(url2), False)
self.assertEqual(upgrade_decision2.getSimulationState(), 'started') self.assertEqual(upgrade_decision2.getSimulationState(), 'started')
def testUpgradeDecision_tryToCancel_withRejected(self):
computer = self._makeComputer()
software_release = self._makeSoftwareRelease()
software_release2 = self._makeSoftwareRelease()
upgrade_decision = self._makeUpgradeDecision()
upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
upgrade_decision_line.setAggregateValueList([software_release, computer])
upgrade_decision.confirm()
upgrade_decision.reject()
url = software_release.getUrlString()
url2 = software_release2.getUrlString()
# Try to cancel rejected UD with the same sr will return False
self.assertEqual(upgrade_decision.UpgradeDecision_tryToCancel(url), False)
self.assertEqual(upgrade_decision.getSimulationState(), 'rejected')
# Try to cancel rejected UD will return True with url2
self.assertEqual(upgrade_decision.UpgradeDecision_tryToCancel(url2), True)
self.assertEqual(upgrade_decision.getSimulationState(), 'rejected')
def testComputer_checkAndCreateUpgradeDecision(self): def testComputer_checkAndCreateUpgradeDecision(self):
person = self._makePerson() person = self._makePerson()
...@@ -1173,6 +1228,91 @@ class TestSlapOSPDMSkins(testSlapOSMixin): ...@@ -1173,6 +1228,91 @@ class TestSlapOSPDMSkins(testSlapOSMixin):
self.assertEqual(release.getUrlString(), self.assertEqual(release.getUrlString(),
software_release3.getUrlString()) software_release3.getUrlString())
def testComputer_hostingSubscriptionCreateUpgradeDecision_rejected(self):
person = self._makePerson()
computer = self._makeComputer()
computer.edit(source_administration_value=person)
self._makeComputerPartitions(computer)
software_product = self._makeSoftwareProduct()
software_release = self._requestSoftwareRelease(
software_product.getRelativeUrl())
url_string = software_release.getUrlString()
self._makeSoftwareInstallation(computer, url_string)
# Create Hosting Subscription and Software Instance
hosting_subscription = self._makeFullHostingSubscription(
url_string, person)
self._makeFullSoftwareInstance(hosting_subscription, url_string)
self._markComputerPartitionBusy(computer,
hosting_subscription.getPredecessorValue())
# Install the Newest software release
software_release2 = self._requestSoftwareRelease(
software_product.getRelativeUrl())
self._makeSoftwareInstallation(computer, software_release2.getUrlString())
self.tic()
decision_list = computer.Computer_hostingSubscriptionCreateUpgradeDecision()
self.assertEqual(decision_list[0].getSimulationState(), 'planned')
# Reject upgrade decision
decision_list[0].reject()
self.tic()
in_progress = software_release2.SoftwareRelease_getUpgradeDecisionInProgress(
hosting_subscription.getUid())
decision_list = computer.Computer_hostingSubscriptionCreateUpgradeDecision()
# There is an upgrade decision in progress
self.assertNotEqual(in_progress, None)
# No new upgrade decision created with software_release2
self.assertEqual(decision_list, [])
def testComputer_hostingSubscriptionCreateUpgradeDecision_rejected_2(self):
person = self._makePerson()
computer = self._makeComputer()
computer.edit(source_administration_value=person)
self._makeComputerPartitions(computer)
software_product = self._makeSoftwareProduct()
software_release = self._requestSoftwareRelease(
software_product.getRelativeUrl())
url_string = software_release.getUrlString()
self._makeSoftwareInstallation(computer, url_string)
# Create Hosting Subscription and Software Instance
hosting_subscription = self._makeFullHostingSubscription(
url_string, person)
self._makeFullSoftwareInstance(hosting_subscription, url_string)
self._markComputerPartitionBusy(computer,
hosting_subscription.getPredecessorValue())
# Install the Newest software release
software_release2 = self._requestSoftwareRelease(
software_product.getRelativeUrl())
self._makeSoftwareInstallation(computer, software_release2.getUrlString())
self.tic()
decision_list = computer.Computer_hostingSubscriptionCreateUpgradeDecision()
self.assertEqual(decision_list[0].getSimulationState(), 'planned')
# Reject upgrade decision
up_decision = decision_list[0]
up_decision.reject()
self.tic()
# Install the another software release
software_release3 = self._requestSoftwareRelease(
software_product.getRelativeUrl())
self._makeSoftwareInstallation(computer, software_release3.getUrlString())
self.tic()
decision2 = computer.Computer_hostingSubscriptionCreateUpgradeDecision()[0]
self.assertEqual(decision2.getSimulationState(), 'planned')
self.assertEqual(up_decision.getSimulationState(), 'rejected')
release = decision2.UpgradeDecision_getSoftwareRelease()
self.assertEqual(release.getUrlString(),
software_release3.getUrlString())
def testBase_acceptUpgradeDecision_no_reference(self): def testBase_acceptUpgradeDecision_no_reference(self):
self._makeUpgradeDecision() self._makeUpgradeDecision()
......
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