Commit c78fce70 authored by Romain Courteaud's avatar Romain Courteaud

slapos_pdm: upgrade not allocated or allocated on remote slave instances

parent c864efa7
......@@ -42,14 +42,15 @@ root_instance_list = [
if q.getSlapState() != 'destroy_requested']
if len(root_instance_list) != 0:
root_instance = root_instance_list[0]
if root_instance.getPortalType() == 'Slave Instance':
# XXX do not upgrade Slave Instance for now
# should check Instance Node or allocation on same tree
return
partition = root_instance.getAggregateValue()
if partition is not None:
compute_node = partition.getParentValue()
if (root_instance.getPortalType() == 'Slave Instance') and \
(compute_node.getPortalType() != 'Remote Node'):
return
person = context.getDestinationSectionValue()
if person is None:
return
......@@ -65,6 +66,10 @@ allocation_cell_list = software_product.getFollowUpValue().Project_getSoftwarePr
predicate_portal_type='Allocation Supply Cell'
)
if (root_instance.getPortalType() == 'Slave Instance') and \
(compute_node is None):
allocation_cell_list = [x for x in allocation_cell_list if ("Remote Node" in [y.getPortalType() for y in x.getParentValue().getParentValue().getAggregateValueList()])]
# Only upgrade if there is no doubt (ie, only 1 url is allowed)
if len(allocation_cell_list) == 1:
if (allocation_cell_list[0].getSoftwareReleaseValue().getUrlString() != instance_tree.getUrlString()):
......
......@@ -37,7 +37,7 @@ class TestSlapOSPDMCreateUpgradeDecisionSkins(TestSlapOSPDMMixinSkins):
)
self.assertEqual(None, instance_tree.InstanceTree_createUpgradeDecision())
def bootstrapAllocableInstanceTree(self, is_allocated=False, shared=False):
def bootstrapAllocableInstanceTree(self, is_allocated=False, shared=False, node="compute"):
project = self.addProject()
person = self._makePerson(project)
software_product = self._makeSoftwareProduct(project)
......@@ -45,14 +45,22 @@ class TestSlapOSPDMCreateUpgradeDecisionSkins(TestSlapOSPDMMixinSkins):
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
if node == "compute":
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
elif node == "remote":
compute_node = self.portal.compute_node_module.newContent(
portal_type="Remote Node",
follow_up_value=project
)
else:
raise ValueError("Unsupported node value: %s" % node)
request_kw = dict(
software_release=release_variation.getUrlString(),
......@@ -78,7 +86,7 @@ class TestSlapOSPDMCreateUpgradeDecisionSkins(TestSlapOSPDMMixinSkins):
##########################################################################
# Not allocated
##########################################################################
def test_createUpgradeDecision_notAllocated_newRelease(self):
def test_createUpgradeDecision_notAllocated_newReleaseOnComputeNode(self):
software_product, _, type_variation, compute_node, instance_tree = self.bootstrapAllocableInstanceTree()
new_release_variation = self._makeSoftwareRelease(software_product)
......@@ -89,6 +97,17 @@ class TestSlapOSPDMCreateUpgradeDecisionSkins(TestSlapOSPDMMixinSkins):
upgrade_decision = instance_tree.InstanceTree_createUpgradeDecision()
self.assertEqual('started', upgrade_decision.getSimulationState())
def test_createUpgradeDecision_notAllocated_newReleaseOnRemoteNode(self):
software_product, _, type_variation, compute_node, instance_tree = self.bootstrapAllocableInstanceTree(node="remote")
new_release_variation = self._makeSoftwareRelease(software_product)
self.addAllocationSupply("for remote 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())
def test_createUpgradeDecision_notAllocated_sameRelease(self):
software_product, release_variation, type_variation, compute_node, instance_tree = self.bootstrapAllocableInstanceTree()
......@@ -155,6 +174,30 @@ class TestSlapOSPDMCreateUpgradeDecisionSkins(TestSlapOSPDMMixinSkins):
upgrade_decision2 = instance_tree.InstanceTree_createUpgradeDecision()
self.assertEqual('started', upgrade_decision2.getSimulationState())
##########################################################################
# Shared not allocated
##########################################################################
def test_createUpgradeDecision_sharedNotAllocated_newReleaseOnComputeNode(self):
software_product, _, type_variation, compute_node, instance_tree = self.bootstrapAllocableInstanceTree(shared=True)
new_release_variation = self._makeSoftwareRelease(software_product)
self.addAllocationSupply("for compute node", compute_node, software_product,
new_release_variation, type_variation)
self.tic()
self.assertEqual(None, instance_tree.InstanceTree_createUpgradeDecision())
def test_createUpgradeDecision_sharedNotAllocated_newReleaseOnRemoteNode(self):
software_product, _, type_variation, compute_node, instance_tree = self.bootstrapAllocableInstanceTree(shared=True, node="remote")
new_release_variation = self._makeSoftwareRelease(software_product)
self.addAllocationSupply("for remote node", compute_node, software_product,
new_release_variation, type_variation)
self.tic()
upgrade_decision = instance_tree.InstanceTree_createUpgradeDecision()
self.assertEqual('started', upgrade_decision.getSimulationState())
##########################################################################
# Allocated on Compute Node
##########################################################################
......@@ -205,7 +248,7 @@ class TestSlapOSPDMCreateUpgradeDecisionSkins(TestSlapOSPDMMixinSkins):
self.assertEqual(None, instance_tree.InstanceTree_createUpgradeDecision())
##########################################################################
# Slave allocated on Compute Node
# Shared allocated on Compute Node
##########################################################################
def test_createUpgradeDecision_slaveAllocatedOnComputeNodeSameTree_newReleaseOnComputeNodeButNotTree(self):
software_product, _, type_variation, compute_node, instance_tree = self.bootstrapAllocableInstanceTree(is_allocated=True, shared=True)
......@@ -229,3 +272,89 @@ class TestSlapOSPDMCreateUpgradeDecisionSkins(TestSlapOSPDMMixinSkins):
self.tic()
self.assertEqual(None, instance_tree.InstanceTree_createUpgradeDecision())
##########################################################################
# Allocated on Remote Node
##########################################################################
def test_createUpgradeDecision_allocatedOnRemoteNode_newReleaseOnRemoteNode(self):
software_product, _, type_variation, remote_node, instance_tree = self.bootstrapAllocableInstanceTree(is_allocated=True, node="remote")
new_release_variation = self._makeSoftwareRelease(software_product)
self.addAllocationSupply("for remote node", remote_node, software_product,
new_release_variation, type_variation)
self.tic()
upgrade_decision = instance_tree.InstanceTree_createUpgradeDecision()
self.assertEqual('started', upgrade_decision.getSimulationState())
def test_createUpgradeDecision_allocatedOnRemoteNode_twoRelease(self):
software_product, release_variation, type_variation, remote_node, instance_tree = self.bootstrapAllocableInstanceTree(is_allocated=True, node="remote")
self.addAllocationSupply(
"for remote node", remote_node, software_product,
release_variation, type_variation)
new_release_variation = self._makeSoftwareRelease(software_product)
self.addAllocationSupply("for compute node 2", remote_node, software_product,
new_release_variation, type_variation)
self.tic()
self.assertEqual(None, instance_tree.InstanceTree_createUpgradeDecision())
def test_createUpgradeDecision_allocatedOnRemoteNode_newReleaseOnAnoterRemoteNode(self):
software_product, _, type_variation, _, instance_tree = self.bootstrapAllocableInstanceTree(is_allocated=True, node="remote")
project = instance_tree.getFollowUpValue()
remote_node2 = self.portal.compute_node_module.newContent(
portal_type="Remote Node",
follow_up_value=project
)
new_release_variation = self._makeSoftwareRelease(software_product)
self.addAllocationSupply("for remote node 2", remote_node2, software_product,
new_release_variation, type_variation)
self.tic()
self.assertEqual(None, instance_tree.InstanceTree_createUpgradeDecision())
##########################################################################
# Shared allocated on Remote Node
##########################################################################
def test_createUpgradeDecision_slaveAllocatedOnRemoteNode_newReleaseOnComputeNode(self):
software_product, _, type_variation, remote_node, instance_tree = self.bootstrapAllocableInstanceTree(is_allocated=True, shared=True, node="remote")
new_release_variation = self._makeSoftwareRelease(software_product)
self.addAllocationSupply("for remote node", remote_node, software_product,
new_release_variation, type_variation)
self.tic()
upgrade_decision = instance_tree.InstanceTree_createUpgradeDecision()
self.assertEqual('started', upgrade_decision.getSimulationState())
def test_createUpgradeDecision_slaveAllocatedOnRemoteNode_twoRelease(self):
software_product, release_variation, type_variation, remote_node, instance_tree = self.bootstrapAllocableInstanceTree(is_allocated=True, shared=True, node="remote")
self.addAllocationSupply(
"for remote node", remote_node, software_product,
release_variation, type_variation)
new_release_variation = self._makeSoftwareRelease(software_product)
self.addAllocationSupply("for compute node 2", remote_node, software_product,
new_release_variation, type_variation)
self.tic()
self.assertEqual(None, instance_tree.InstanceTree_createUpgradeDecision())
def test_createUpgradeDecision_slaveAllocatedOnRemoteNode_newReleaseOnAnoterRemoteNode(self):
software_product, _, type_variation, _, instance_tree = self.bootstrapAllocableInstanceTree(is_allocated=True, shared=True, node="remote")
project = instance_tree.getFollowUpValue()
remote_node2 = self.portal.compute_node_module.newContent(
portal_type="Remote Node",
follow_up_value=project
)
new_release_variation = self._makeSoftwareRelease(software_product)
self.addAllocationSupply("for remote node 2", remote_node2, software_product,
new_release_variation, type_variation)
self.tic()
self.assertEqual(None, instance_tree.InstanceTree_createUpgradeDecision())
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