Commit c89a51ba authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: try to create an upgrade decision for a remote instance

parent ab54c13a
......@@ -40,6 +40,22 @@ for local_instance in local_instance_list:
if remote_instance_tree is not None:
requested_software_instance = remote_instance_tree.getSuccessorValue(title=remote_instance_tree.getTitle())
if (remote_instance_tree is not None) and \
((local_instance.getUrlString() != remote_instance_tree.getUrlString()) or \
(local_instance.getSourceReference() != remote_instance_tree.getSourceReference())):
# Try to create an Upgrade Decision for the new release
_, new_release_variation, new_type_variation = remote_instance_tree.asContext(
url_string=local_instance.getUrlString(),
source_reference=local_instance.getSourceReference()
).InstanceTree_getSoftwareProduct()
if new_release_variation is None:
return
else:
return remote_instance_tree.InstanceTree_createUpgradeDecision(
target_software_release=new_release_variation,
target_software_type=new_type_variation
)
if (remote_instance_tree is None) or \
(local_instance.getTextContent() != remote_instance_tree.getTextContent()) or \
(local_instance.getSlapState() != remote_instance_tree.getSlapState()):
......
......@@ -1389,6 +1389,105 @@ class TestSlapOSPropagateRemoteNodeInstance(SlapOSTestCaseMixin):
self.assertEqual(software_instance.getConnectionXml(), None)
def test_propagateRemoteNode_script_propageReleaseChangesToUpgradeDecision(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
remote_node, partition = self.addComputeNodeAndPartition(
project=instance_tree.getFollowUpValue(),
portal_type='Remote Node'
)
software_instance.setAggregateValue(partition)
partition.markBusy()
with TemporaryAlarmScript(self.portal, 'ComputePartition_propagateRemoteNode', ""):
self.tic()
with TemporaryAlarmScript(self.portal, 'Item_getSubscriptionStatus', "'subscribed'"):
partition.ComputePartition_propagateRemoteNode()
self.tic()
remote_user = remote_node.getDestinationSectionValue()
remote_project = remote_node.getDestinationProjectValue()
remote_instance_tree = self.portal.portal_catalog.getResultValue(
portal_type='Instance Tree',
destination_section__uid=remote_user.getUid(),
follow_up__uid=remote_project.getUid(),
title='_remote_%s_%s' % (software_instance.getFollowUpReference(),
software_instance.getReference())
)
remote_software_instance = remote_instance_tree.getSuccessorValue()
# Create allocated partition to allow Upgrade Decision
remote_compute_node, remote_partition = self.addComputeNodeAndPartition(
project=remote_instance_tree.getFollowUpValue(),
)
remote_software_instance.setAggregateValue(remote_partition)
remote_partition.markBusy()
# Create remote Software Product, to allow generating the Upgrade Decision
new_id = self.generateNewId()
software_product = self.portal.software_product_module.newContent(
reference='TESTSOFTPROD-%s' % new_id,
title='Test software product %s' % new_id,
follow_up_value=remote_project
)
old_release_variation = software_product.newContent(
portal_type='Software Product Release Variation',
url_string=remote_instance_tree.getUrlString()
)
type_variation = software_product.newContent(
portal_type='Software Product Type Variation',
reference=remote_instance_tree.getSourceReference()
)
software_product.publish()
new_release_variation = self._makeSoftwareRelease(software_product)
self.addAllocationSupply("old release compute node", remote_compute_node, software_product,
old_release_variation, type_variation, disable_alarm=True)
self.addAllocationSupply("new release compute node", remote_compute_node, software_product,
new_release_variation, type_variation, disable_alarm=True)
self.tic()
self.portal.portal_workflow._jumpToStateFor(software_instance, 'stop_requested')
old_release_url = software_instance.getUrlString()
old_text_content = software_instance.getTextContent()
software_instance.edit(
url_string=new_release_variation.getUrlString(),
text_content=self.generateSafeXml()
)
with TemporaryAlarmScript(self.portal, 'Item_getSubscriptionStatus', "'subscribed'"):
partition.ComputePartition_propagateRemoteNode()
# Instance tree is not modified
self.assertEqual(remote_instance_tree.getValidationState(), "validated")
self.assertEqual(remote_instance_tree.getSlapState(), "start_requested")
self.assertEqual(remote_instance_tree.getUrlString(),
old_release_url)
self.assertEqual(remote_instance_tree.getSourceReference(),
software_instance.getSourceReference())
self.assertEqual(remote_instance_tree.getTextContent(),
old_text_content)
self.assertEqual(remote_instance_tree.getSlaXml(), None)
self.assertEqual(remote_instance_tree.isRootSlave(False),
software_instance.getPortalType() == 'Slave Instance')
self.assertEqual(software_instance.getConnectionXml(), None)
self.tic()
# An upgrade decision is proposed
upgrade_decision = self.portal.portal_catalog.getResultValue(
portal_type='Upgrade Decision',
destination_section__uid=remote_user.getUid(),
destination_project__uid=remote_project.getUid(),
aggregate__uid=remote_instance_tree.getUid(),
resource__uid=software_product.getUid(),
software_release__uid=new_release_variation.getUid(),
software_type__uid=type_variation.getUid(),
simulation_state='confirmed'
)
self.assertNotEqual(upgrade_decision, None)
def test_propagateRemoteNode_script_doNotPropageConnectionXmlIfNotChanged(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
......
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