Commit fc74fe8b authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: test: check remote node parameters propagation

parent df876a5e
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
compute_partition = context
......@@ -21,18 +25,37 @@ else:
)]
for local_instance in local_instance_list:
# XXX TODO this will increase the workflow history
# do not increase the workflow history
# Use the 'cached' API instead
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={'start_requested': 'started', 'stop_requested': 'stopped'}[local_instance.getSlapState()]
# manually search the instance and compare all parameters
remote_instance_tree = portal.portal_catalog.getResultValue(
portal_type='Instance Tree',
validation_state='validated',
destination_section__uid=remote_person.getUid(),
follow_up__uid=remote_project.getUid(),
title='_remote_%s_%s' % (local_instance.getFollowUpReference(),
local_instance.getReference())
)
requested_software_instance = context.REQUEST.get('request_instance')
if requested_software_instance is not None:
local_instance.setConnectionXml(requested_software_instance.getConnectionXml())
if remote_instance_tree is not None:
requested_software_instance = remote_instance_tree.getSuccessorValue(title=remote_instance_tree.getTitle())
if (remote_instance_tree is None) or \
(local_instance.getTextContent() != remote_instance_tree.getTextContent()) or \
(local_instance.getSlapState() != remote_instance_tree.getSlapState()):
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={'start_requested': 'started', 'stop_requested': 'stopped'}[local_instance.getSlapState()]
)
requested_software_instance = context.REQUEST.get('request_instance')
if (requested_software_instance is not None) and \
(requested_software_instance.getConnectionXml() != local_instance.getConnectionXml()):
local_instance.edit(connection_xml=requested_software_instance.getConnectionXml())
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
<value> <string>REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -345,19 +345,29 @@ class SlapOSTestCaseMixin(testSlapOSMixin):
self.requested_software_instance.validate()
self.tic()
def addComputeNodeAndPartition(self, project=None):
def addComputeNodeAndPartition(self, project=None,
portal_type='Compute Node'):
# XXX replace _makeComputeNode
if project is None:
project = self.addProject()
self.tic()
edit_kw = {}
if portal_type == 'Remote Node':
# Be nice, and create remote user/project
remote_project = self.addProject()
remote_user = self.makePerson(remote_project)
edit_kw['destination_project_value'] = remote_project
edit_kw['destination_section_value'] = remote_user
reference = 'TESTCOMP-%s' % self.generateNewId()
compute_node = self.portal.compute_node_module.newContent(
portal_type="Compute Node",
portal_type=portal_type,
#allocation_scope=allocation_scope,
reference=reference,
title=reference,
follow_up_value=project
follow_up_value=project,
**edit_kw
)
# The edit above will update capacity scope due the interaction workflow
# The line above force capacity scope to be open, keeping the previous
......
......@@ -1070,7 +1070,6 @@ class TestSlapOSGarbageCollectUnlinkedInstanceAlarm(SlapOSTestCaseMixin):
self.assertEqual(instance_instance0.getSlapState(), 'start_requested')
class TestSlapOSInvalidateDestroyedInstance(SlapOSTestCaseMixin):
#################################################################
# slapos_cloud_invalidate_destroyed_instance
......@@ -1179,3 +1178,290 @@ class TestSlapOSInvalidateDestroyedInstance(SlapOSTestCaseMixin):
self.assertEqual(software_instance.getValidationState(), "validated")
self.assertEqual(software_instance.getSlapState(), "destroy_requested")
class TestSlapOSPropagateRemoteNodeInstance(SlapOSTestCaseMixin):
#################################################################
# slapos_cloud_propagate_remote_node_instance
#################################################################
def test_propagateRemoteNode_alarm_busyPartitionInRemoteNode(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
_, 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()
self._test_alarm(
self.portal.portal_alarms.slapos_cloud_propagate_remote_node_instance,
partition,
'ComputePartition_propagateRemoteNode'
)
def test_propagateRemoteNode_alarm_busyPartitionInComputeNode(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
_, partition = self.addComputeNodeAndPartition(
project=instance_tree.getFollowUpValue()
)
software_instance.setAggregateValue(partition)
partition.markBusy()
with TemporaryAlarmScript(self.portal, 'ComputePartition_propagateRemoteNode', ""):
self.tic()
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_cloud_propagate_remote_node_instance,
partition,
'ComputePartition_propagateRemoteNode'
)
def test_propagateRemoteNode_alarm_freePartitionInRemoteNode(self):
instance_tree = self.addInstanceTree()
_, partition = self.addComputeNodeAndPartition(
project=instance_tree.getFollowUpValue(),
portal_type='Remote Node'
)
with TemporaryAlarmScript(self.portal, 'ComputePartition_propagateRemoteNode', ""):
self.tic()
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_cloud_propagate_remote_node_instance,
partition,
'ComputePartition_propagateRemoteNode'
)
#################################################################
# ComputePartition_propagateRemoteNode
#################################################################
def test_propagateRemoteNode_REQUEST_disallowed(self):
instance_tree = self.addInstanceTree()
_, partition = self.addComputeNodeAndPartition(
project=instance_tree.getFollowUpValue(),
portal_type='Remote Node'
)
self.assertRaises(
Unauthorized,
partition.ComputePartition_propagateRemoteNode,
REQUEST={})
def test_propagateRemoteNode_script_unexpectedContext(self):
instance_tree = self.addInstanceTree()
_, partition = self.addComputeNodeAndPartition(
project=instance_tree.getFollowUpValue()
)
self.assertRaises(
AssertionError,
partition.ComputePartition_propagateRemoteNode,
)
def test_propagateRemoteNode_script_createRemoteInstanceTree(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())
)
self.assertEqual(remote_instance_tree.getValidationState(), "validated")
self.assertEqual(remote_instance_tree.getSlapState(), "start_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)
def test_propagateRemoteNode_script_doNotRequestIfNotNeeded(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()
partition.ComputePartition_propagateRemoteNode()
self.assertEqual(remote_instance_tree.getModificationDate(),
remote_modification_date)
def test_propagateRemoteNode_script_propageParameterChangesToRemoteInstanceTree(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, 'stop_requested')
software_instance.edit(
#url_string=self.generateNewSoftwareReleaseUrl(),
#source_reference=self.generateNewSoftwareType(),
text_content=self.generateSafeXml(),
sla_xml=self.generateSafeXml()
)
partition.ComputePartition_propagateRemoteNode()
self.assertNotEqual(remote_instance_tree.getModificationDate(),
remote_modification_date)
self.assertEqual(remote_instance_tree.getValidationState(), "validated")
self.assertEqual(remote_instance_tree.getSlapState(), "stop_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)
def test_propagateRemoteNode_script_doNotPropageConnectionXmlIfNotChanged(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
_, 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()
modification_date = software_instance.getModificationDate()
with TemporaryAlarmScript(self.portal, 'Item_getSubscriptionStatus', "'subscribed'"):
partition.ComputePartition_propagateRemoteNode()
self.assertEqual(software_instance.getModificationDate(), modification_date)
def test_propagateRemoteNode_script_propageConnectionXmlFromRemoteInstanceTree(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())
)
modification_date = software_instance.getModificationDate()
remote_instance = remote_instance_tree.getSuccessorValue()
remote_instance.edit(
connection_xml=self.generateSafeXml()
)
with TemporaryAlarmScript(self.portal, 'Item_getSubscriptionStatus', "'subscribed'"):
partition.ComputePartition_propagateRemoteNode()
self.assertNotEqual(software_instance.getModificationDate(), modification_date)
self.assertEqual(remote_instance_tree.getValidationState(), "validated")
self.assertEqual(remote_instance_tree.getSlapState(), "start_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(),
remote_instance.getConnectionXml())
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