Commit ec040fbf authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: propagate remote node destruction

parent 4387416d
......@@ -5,6 +5,7 @@ portal.portal_catalog.searchAndActivate(
free_for_request=0,
parent_portal_type='Remote Node',
method_id='ComputePartition_propagateRemoteNode',
method_kw={"activate_kw": {'tag': tag}},
activate_kw={'tag': tag}
)
......
......@@ -15,16 +15,43 @@ if compute_partition.getId() == 'SHARED_REMOTE':
# Hardcoded ID behaviour
local_instance_list = portal.portal_catalog(
portal_type='Slave Instance',
aggregate__uid=compute_partition.getUid()
aggregate__uid=compute_partition.getUid(),
validation_state='validated'
)
else:
local_instance_list = [portal.portal_catalog.getResultValue(
portal_type='Software Instance',
aggregate__uid=compute_partition.getUid()
aggregate__uid=compute_partition.getUid(),
validation_state='validated'
)]
for local_instance in local_instance_list:
# If local instance destruction has been propagated, do nothing
if local_instance.getValidationState() != 'validated':
continue
# if local instance is destroyed, propagate blindly
if local_instance.getSlapState() == 'destroy_requested':
remote_person.requestSoftwareInstance(
project_reference=remote_project.getReference(),
software_release=local_instance.getUrlString(),
software_title='_remote_%s_%s' % (remote_node.getFollowUpReference(), local_instance.getReference()),
software_type=local_instance.getSourceReference(),
instance_xml=local_instance.getTextContent(),
sla_xml=None,
shared=(local_instance.getPortalType() == 'Slave Instance'),
state='destroyed'
)
local_instance.invalidate(comment='Remote destruction has been propagated')
# Try to no trigger the script again on this object
local_instance.reindexObject(activate_kw=activate_kw)
requested_instance_tree = context.REQUEST.get('request_instance_tree')
if requested_instance_tree is not None:
requested_instance_tree.reindexObject(activate_kw=activate_kw)
return
# do not increase the workflow history
# Use the 'cached' API instead
# manually search the instance and compare all parameters
......@@ -72,7 +99,16 @@ for local_instance in local_instance_list:
state={'start_requested': 'started', 'stop_requested': 'stopped'}[local_instance.getSlapState()]
)
requested_software_instance = context.REQUEST.get('request_instance')
requested_instance_tree = context.REQUEST.get('request_instance_tree')
# Try to no trigger the script again on this object
requested_instance_tree.reindexObject(activate_kw=activate_kw)
if requested_software_instance is not None:
requested_software_instance.reindexObject(activate_kw=activate_kw)
if (requested_software_instance is not None) and \
(requested_software_instance.getConnectionXml() != local_instance.getConnectionXml()):
local_instance.edit(connection_xml=requested_software_instance.getConnectionXml())
# Try to no trigger the script again on this object
local_instance.edit(
connection_xml=requested_software_instance.getConnectionXml(),
activate_kw=activate_kw
)
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value>
<value> <string>activate_kw=None, REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -1655,3 +1655,89 @@ class TestSlapOSPropagateRemoteNodeInstance(SlapOSTestCaseMixin):
self.assertEqual(software_instance.getConnectionXml(),
remote_instance.getConnectionXml())
def test_propagateRemoteNode_script_propagateDestructionIfValidated(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()
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_modification_date = remote_instance_tree.getModificationDate()
self.portal.portal_workflow._jumpToStateFor(software_instance, 'destroy_requested')
self.tic()
self.assertEqual(software_instance.getValidationState(), 'validated')
partition.ComputePartition_propagateRemoteNode()
self.assertNotEqual(remote_instance_tree.getModificationDate(),
remote_modification_date)
self.assertEqual(remote_instance_tree.getValidationState(), "archived")
self.assertEqual(remote_instance_tree.getSlapState(), "destroy_requested")
self.assertEqual(remote_instance_tree.getUrlString(),
software_instance.getUrlString())
self.assertEqual(remote_instance_tree.getSourceReference(),
software_instance.getSourceReference())
self.assertEqual(remote_instance_tree.getTextContent(),
software_instance.getTextContent())
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.assertEqual(software_instance.getValidationState(), 'invalidated')
def test_propagateRemoteNode_script_doNotPropagateDestructionIfInvalidated(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()
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_modification_date = remote_instance_tree.getModificationDate()
self.portal.portal_workflow._jumpToStateFor(software_instance, 'destroy_requested')
self.portal.portal_workflow._jumpToStateFor(software_instance, 'invalidated')
self.tic()
partition.ComputePartition_propagateRemoteNode()
self.assertEqual(remote_instance_tree.getModificationDate(),
remote_modification_date)
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