Commit fd07f858 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: requesting an instance tree requires a project

parent 644fbd35
......@@ -13,8 +13,9 @@ try:
sla_xml = kwargs["sla_xml"]
is_slave = kwargs["shared"]
root_state = kwargs["state"]
project_reference = kwargs['project_reference']
except KeyError:
raise TypeError, "Person_requestSoftwareInstance takes exactly 7 arguments"
raise TypeError, "Person_requestSoftwareInstance takes exactly 8 arguments"
if is_slave not in [True, False]:
raise ValueError, "shared should be a boolean"
......@@ -29,6 +30,12 @@ if (portal.portal_activities.countMessageWithTag(tag) > 0):
# As it is not possible to fetch informations, it is better to raise an error
raise NotImplementedError(tag)
# Ensure project is correctly set
project_list = portal.portal_catalog.portal_catalog(portal_type='Project', reference=project_reference,
validation_state='validated', limit=2)
if len(project_list) != 1:
raise NotImplementedError("%i projects '%s'" % (len(project_list), project_reference))
# Check if it already exists
request_instance_tree_list = portal.portal_catalog(
portal_type=instance_tree_portal_type,
......@@ -41,6 +48,7 @@ if len(request_instance_tree_list) > 1:
raise NotImplementedError, "Too many instance tree %s found %s" % (software_title, [x.path for x in request_instance_tree_list])
elif len(request_instance_tree_list) == 1:
request_instance_tree = request_instance_tree_list[0].getObject()
assert request_instance_tree.getFollowUp() == project_list[0].getRelativeUrl()
if (request_instance_tree.getSlapState() == "destroy_requested") or \
(request_instance_tree.getTitle() != software_title) or \
(request_instance_tree.getValidationState() != "validated") or \
......@@ -59,6 +67,7 @@ else:
title=software_title,
destination_section=person.getRelativeUrl(),
upgrade_scope="auto",
follow_up_value=project_list[0],
activate_kw={'tag': tag},
)
......
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