Commit f55a00e8 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_cloud: Propagate activate_kw when edit

    and don't exclude/add successor if nothing changed
parent 06c91260
...@@ -74,6 +74,7 @@ if (request_software_instance is None): ...@@ -74,6 +74,7 @@ if (request_software_instance is None):
else: else:
instance_found = True instance_found = True
# First time that the software instance is requested # First time that the software instance is requested
successor = None
# Create a new one # Create a new one
reference = "SOFTINST-%s" % portal.portal_ids.generateNewId( reference = "SOFTINST-%s" % portal.portal_ids.generateNewId(
...@@ -105,8 +106,8 @@ else: ...@@ -105,8 +106,8 @@ else:
successor = request_software_instance.getSuccessorRelatedValue(portal_type="Software Instance") successor = request_software_instance.getSuccessorRelatedValue(portal_type="Software Instance")
if (successor is None): if (successor is None):
# Check if the precessor is a Instance Tree # Check if the precessor is a Instance Tree
instance_tree_precessesor = request_software_instance.getSuccessorRelatedValue(portal_type="Instance Tree") instance_tree_successor = request_software_instance.getSuccessorRelatedValue(portal_type="Instance Tree")
if (requester_instance.getPortalType() != "Instance Tree" and instance_tree_precessesor is not None): if (requester_instance.getPortalType() != "Instance Tree" and instance_tree_successor is not None):
raise ValueError('It is disallowed to request root software instance %s' % request_software_instance.getRelativeUrl()) raise ValueError('It is disallowed to request root software instance %s' % request_software_instance.getRelativeUrl())
else: else:
successor = requester_instance successor = requester_instance
...@@ -114,10 +115,14 @@ else: ...@@ -114,10 +115,14 @@ else:
if request_software_instance.getUid() not in graph: if request_software_instance.getUid() not in graph:
graph[request_software_instance.getUid()] = request_software_instance.getSuccessorUidList() graph[request_software_instance.getUid()] = request_software_instance.getSuccessorUidList()
successor_uid_list = successor.getSuccessorUidList() successor_uid_list = successor.getSuccessorUidList()
if request_software_instance.getUid() in successor_uid_list: if successor != requester_instance:
successor_uid_list.remove(request_software_instance.getUid()) if request_software_instance.getUid() in successor_uid_list:
successor.edit(successor_uid_list=successor_uid_list) successor_uid_list.remove(request_software_instance.getUid())
successor.edit(
successor_uid_list=successor_uid_list,
activate_kw={'tag': tag}
)
graph[successor.getUid()] = successor_uid_list graph[successor.getUid()] = successor_uid_list
if instance_found: if instance_found:
...@@ -142,7 +147,11 @@ if instance_found: ...@@ -142,7 +147,11 @@ if instance_found:
else: else:
raise ValueError, "state should be started, stopped or destroyed" raise ValueError, "state should be started, stopped or destroyed"
successor_list = requester_instance.getSuccessorList() + [request_software_instance_url] successor_list = requester_instance.getSuccessorList()
successor_uid_list = requester_instance.getSuccessorUidList()
if successor != requester_instance:
successor_list.append(request_software_instance_url)
successor_uid_list.append(request_software_instance.getUid())
uniq_successor_list = list(set(successor_list)) uniq_successor_list = list(set(successor_list))
successor_list.sort() successor_list.sort()
uniq_successor_list.sort() uniq_successor_list.sort()
...@@ -150,13 +159,16 @@ if instance_found: ...@@ -150,13 +159,16 @@ if instance_found:
assert successor_list == uniq_successor_list, "%s != %s" % (successor_list, uniq_successor_list) assert successor_list == uniq_successor_list, "%s != %s" % (successor_list, uniq_successor_list)
# update graph to reflect requested operation # update graph to reflect requested operation
graph[requester_instance.getUid()] = requester_instance.getSuccessorUidList() + [request_software_instance.getUid()] graph[requester_instance.getUid()] = successor_uid_list
# check if all elements are still connected and if there is no cycle # check if all elements are still connected and if there is no cycle
request_software_instance.checkConnected(graph, instance_tree.getUid()) request_software_instance.checkConnected(graph, instance_tree.getUid())
request_software_instance.checkNotCyclic(graph) request_software_instance.checkNotCyclic(graph)
requester_instance.edit(successor_list=successor_list) if successor != requester_instance:
requester_instance.edit(
successor_list=successor_list,
activate_kw={'tag': tag}
)
else: else:
context.REQUEST.set('request_instance', None) context.REQUEST.set('request_instance', None)
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