Commit d41637f6 authored by Romain Courteaud's avatar Romain Courteaud

slapos_pdm: test upgrade decision creation for not allocated instance tree

parent 02968f33
......@@ -6,6 +6,24 @@ instance_tree = context
if instance_tree.getSlapState() == "destroy_requested":
return
if portal.portal_catalog.getResultValue(
portal_type='Upgrade Decision',
aggregate__uid=instance_tree.getUid(),
simulation_state=['started', 'stopped', 'planned', 'confirmed']
) is not None:
# There is already a upgrade decision, do nothing
return
"""
if decision_in_progress is not None:
if 1:
raise NotImplementedError('reviewRegistration')
decision_in_progress.reviewRegistration(
software_release_url=newer_release.getUrlString())
if decision_in_progress.getSimulationState() != "cancelled":
return
"""
# Check if UpgradeDecision_approveRegistration is running
# XXX we should instead look at the current upgrade decision state
tag = "%s_requestUpgradeDecisionCreation_inProgress" % instance_tree.getUid()
......@@ -13,12 +31,7 @@ if portal.portal_activities.countMessageWithTag(tag) > 0:
# previous run not finished, skip
return
upgrade_scope = context.getUpgradeScope("ask_confirmation")
if upgrade_scope in ["never", "disabled"]:
return
software_product, software_release, software_type = instance_tree.InstanceTree_getSoftwareProduct()
if software_product is None:
# No way to upgrade, if we can find which Software Product to upgrade
return
......@@ -38,6 +51,9 @@ if len(root_instance_list) != 0:
compute_node = partition.getParentValue()
person = context.getDestinationSectionValue()
if person is None:
return
# Search if the product with the same type
# XXX search only for the main node
allocation_cell_list = software_product.getFollowUpValue().Project_getSoftwareProductPredicateList(
......@@ -55,20 +71,6 @@ if len(allocation_cell_list) == 1:
# XXX Upgrade
decision_title = 'A new upgrade is available for %s' % instance_tree.getTitle()
decision_in_progress = portal.portal_catalog.getResultValue(
portal_type='Upgrade Decision',
aggregate__uid=instance_tree.getUid()
)
if decision_in_progress is not None:
if 1:
raise NotImplementedError('reviewRegistration')
decision_in_progress.reviewRegistration(
software_release_url=newer_release.getUrlString())
if decision_in_progress.getSimulationState() != "cancelled":
return
upgrade_decision = portal.upgrade_decision_module.newContent(
portal_type='Upgrade Decision',
title=decision_title,
......@@ -80,7 +82,6 @@ if len(allocation_cell_list) == 1:
aggregate_value=instance_tree,
)
upgrade_decision.approveRegistration(
upgrade_scope=upgrade_scope)
upgrade_decision.approveRegistration()
return upgrade_decision
......@@ -24,8 +24,18 @@ import transaction
class TestSlapOSPDMCreateUpgradeDecisionSkins(TestSlapOSPDMMixinSkins):
def afterSetUp(self):
def _makeTreeForTestSlapOSPDMCreateUpgradeDecisionSkins(self, software_release_url, software_type, project):
self.instance_tree, self.instance = self._createInstance(software_release_url, software_type, project)
self.shared_instance_tree, self.shared_instance = self._createInstance(software_release_url, software_type, project, True)
self.instance.setAggregate(self.partition.getRelativeUrl())
self.shared_instance.setAggregate(self.partition.getRelativeUrl())
self.partition.markBusy()
self.tic()
def afterSetUpXXX(self):
TestSlapOSPDMMixinSkins.afterSetUp(self)
# XXX Stop modifying system preferences
# as it prevents using test on live system
preference = self.portal.portal_preferences.getActiveSystemPreference()
preference.setPreferredCloudContractEnabled(True)
self.tic()
......@@ -103,42 +113,133 @@ class TestSlapOSPDMCreateUpgradeDecisionSkins(TestSlapOSPDMMixinSkins):
self.tic()
return instance_tree, instance
def _makeTreeForTestSlapOSPDMCreateUpgradeDecisionSkins(self, software_release_url, software_type, project):
self.instance_tree, self.instance = self._createInstance(software_release_url, software_type, project)
self.shared_instance_tree, self.shared_instance = self._createInstance(software_release_url, software_type, project, True)
self.instance.setAggregate(self.partition.getRelativeUrl())
self.shared_instance.setAggregate(self.partition.getRelativeUrl())
self.partition.markBusy()
def test_createUpgradeDecision_destroyed_instance(self):
instance_tree = self.portal.instance_tree_module.newContent(
portal_type="Instance Tree"
)
self.portal.portal_workflow._jumpToStateFor(instance_tree,
'destroy_requested')
self.assertEqual(None, instance_tree.InstanceTree_createUpgradeDecision())
def test_createUpgradeDecision_without_softwareProduct(self):
instance_tree = self.portal.instance_tree_module.newContent(
portal_type="Instance Tree"
)
self.assertEqual(None, instance_tree.InstanceTree_createUpgradeDecision())
def bootstrapAllocableInstanceTree(self):
project = self.addProject()
person = self._makePerson(project)
software_product = self._makeSoftwareProduct(project)
release_variation = software_product.contentValues(portal_type='Software Product Release Variation')[0]
type_variation = software_product.contentValues(portal_type='Software Product Type Variation')[0]
self.tic()
person.requestComputeNode(compute_node_title='test compute node',
project_reference=project.getReference())
self.tic()
compute_node = self.portal.portal_catalog.getResultValue(
portal_type='Compute Node',
reference=self.portal.REQUEST.get('compute_node_reference')
)
assert compute_node is not None
instance_tree = self.portal.instance_tree_module.newContent(
portal_type="Instance Tree",
destination_section_value=person,
url_string=release_variation.getUrlString(),
source_reference=type_variation.getTitle(),
follow_up_value=project,
)
self.tic()
return software_product, release_variation, type_variation, compute_node, instance_tree
def test_tocheck_InstanceTree_createUpgradeDecision_upgradeScopeConfirmation(self):
# check upgrade decision on HS
self.instance_tree.setUpgradeScope('manual')
def test_createUpgradeDecision_notAllocated_newRelease(self):
software_product, _, type_variation, compute_node, instance_tree = self.bootstrapAllocableInstanceTree()
new_release_variation = self._makeSoftwareRelease(software_product)
self.addAllocationSupply("for compute node 2", compute_node, software_product,
new_release_variation, type_variation)
self.tic()
upgrade_decision = self.instance_tree.InstanceTree_createUpgradeDecision()
self.assertEqual('planned', upgrade_decision.getSimulationState())
shared_upgrade_decision = self.shared_instance_tree.InstanceTree_createUpgradeDecision()
self.assertEqual(None, shared_upgrade_decision)
# simulate upgrade of the instance tree
upgrade_decision.confirm()
upgrade_decision.start()
upgrade_decision.stop()
upgrade_decision.deliver()
self.instance_tree.edit(url_string=self.new_software_release.getUrlString())
self.instance.edit(url_string=self.new_software_release.getUrlString())
upgrade_decision = instance_tree.InstanceTree_createUpgradeDecision()
self.assertEqual('started', upgrade_decision.getSimulationState())
def test_createUpgradeDecision_notAllocated_sameRelease(self):
software_product, release_variation, type_variation, compute_node, instance_tree = self.bootstrapAllocableInstanceTree()
self.addAllocationSupply(
"for compute node", compute_node, software_product,
release_variation, type_variation)
self.assertEqual(None, instance_tree.InstanceTree_createUpgradeDecision())
def test_createUpgradeDecision_notAllocated_twoRelease(self):
software_product, release_variation, type_variation, compute_node, instance_tree = self.bootstrapAllocableInstanceTree()
self.addAllocationSupply(
"for compute node", compute_node, software_product,
release_variation, type_variation)
new_release_variation = self._makeSoftwareRelease(software_product)
self.addAllocationSupply("for compute node 2", compute_node, software_product,
new_release_variation, type_variation)
self.tic()
# check upgrade decision on shared HS related to upgraded HS
self.shared_instance_tree.setUpgradeScope('manual')
self.assertEqual(None, instance_tree.InstanceTree_createUpgradeDecision())
shared_upgrade_decision = self.shared_instance_tree.InstanceTree_createUpgradeDecision()
self.assertEqual('started', shared_upgrade_decision.getSimulationState())
def test_createUpgradeDecision_notAllocated_newRelease_ongoingDecision(self):
software_product, _, type_variation, compute_node, instance_tree = self.bootstrapAllocableInstanceTree()
def test_tocheck_InstanceTree_createUpgradeDecision_upgradeScopeAuto(self):
# check upgrade decision on HS
self.instance_tree.setUpgradeScope('auto')
new_release_variation = self._makeSoftwareRelease(software_product)
self.addAllocationSupply("for compute node 2", compute_node, software_product,
new_release_variation, type_variation)
self.tic()
upgrade_decision = instance_tree.InstanceTree_createUpgradeDecision()
self.assertEqual('started', upgrade_decision.getSimulationState())
self.tic()
self.assertEqual(None, instance_tree.InstanceTree_createUpgradeDecision())
def test_createUpgradeDecision_notAllocated_newRelease_ongoingDecisionActivity(self):
software_product, _, type_variation, compute_node, instance_tree = self.bootstrapAllocableInstanceTree()
new_release_variation = self._makeSoftwareRelease(software_product)
self.addAllocationSupply("for compute node 2", compute_node, software_product,
new_release_variation, type_variation)
self.tic()
upgrade_decision = instance_tree.InstanceTree_createUpgradeDecision()
self.assertEqual('started', upgrade_decision.getSimulationState())
self.commit()
self.assertEqual(None, instance_tree.InstanceTree_createUpgradeDecision())
def test_createUpgradeDecision_notAllocated_newRelease_cancelledDecision(self):
software_product, _, type_variation, compute_node, instance_tree = self.bootstrapAllocableInstanceTree()
new_release_variation = self._makeSoftwareRelease(software_product)
self.addAllocationSupply("for compute node 2", compute_node, software_product,
new_release_variation, type_variation)
self.tic()
upgrade_decision = instance_tree.InstanceTree_createUpgradeDecision()
self.assertEqual('started', upgrade_decision.getSimulationState())
upgrade_decision.reject()
self.tic()
upgrade_decision2 = instance_tree.InstanceTree_createUpgradeDecision()
self.assertEqual('started', upgrade_decision2.getSimulationState())
# not allocated 0 supply
# not allocated 1 same supply
# not allocated 1 different supply without existing decision
# not allocated 1 different supply with existing decision
# not allocated 1 different supply with existing rejected decision
# 2 supplies
def test_tocheck_InstanceTree_createUpgradeDecision(self):
upgrade_decision = self.instance_tree.InstanceTree_createUpgradeDecision()
self.assertEqual('started', upgrade_decision.getSimulationState())
shared_upgrade_decision = self.shared_instance_tree.InstanceTree_createUpgradeDecision()
......@@ -151,9 +252,6 @@ class TestSlapOSPDMCreateUpgradeDecisionSkins(TestSlapOSPDMMixinSkins):
self.instance.edit(url_string=self.new_software_release.getUrlString())
self.tic()
# check upgrade decision on shared HS related to upgraded HS
self.shared_instance_tree.setUpgradeScope('auto')
shared_upgrade_decision = self.shared_instance_tree.InstanceTree_createUpgradeDecision()
self.assertEqual('started', shared_upgrade_decision.getSimulationState())
......
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