Commit 64f7fab7 authored by Romain Courteaud's avatar Romain Courteaud

slapos_subscription_request: create Subscription Request for Compute Node

parent d9d4f419
portal = context.getPortalObject()
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, NegatedQuery
# XXX TODO this is really not efficient
# this does not scale with millions of uid
# how to use a left join instead? or a single query with the embedded subquery?
subscribed_uid_list = [x.uid for x in portal.portal_catalog(
portal_type=["Compute Node", "Instance Tree"],
aggregate__related__portal_type="Subscription Request"
)]
sql_kw = {}
if subscribed_uid_list:
sql_kw['subscribed_uid_list'] = NegatedQuery(SimpleQuery(uid=subscribed_uid_list))
return portal.portal_catalog.searchAndActivate(
method_id='Item_createSubscriptionRequest',
portal_type=["Compute Node", "Instance Tree"],
activate_kw={'tag': tag},
**sql_kw
)
"""
# XXX if there is a non Subscription Request with such aggregate link
# it will lead to not creating the Subscription Request
# TODO find a way to check the portal type
......@@ -12,9 +31,9 @@ kw.update(select_dict)
portal.portal_catalog.searchAndActivate(
method_id='Item_createSubscriptionRequest',
# Project are created only from UI for now
portal_type=["Instance Tree"],
portal_type=["Instance Tree", "Compute Node"],
activate_kw={'tag': tag},
**kw
)
"""
context.activate(after_tag=tag).getId()
......@@ -40,6 +40,12 @@ if item.getPortalType() == 'Instance Tree':
'software_type/%s' % software_type.getRelativeUrl()
]
resource_vcl.sort()
elif item.getPortalType() == 'Compute Node':
service = portal.restrictedTraverse('service_module/slapos_compute_node_subscription')
resource_vcl = None
project_value = item.getFollowUpValue(portal_type="Project")
if project_value is not None:
source_decision_value = project_value.getDestinationValue(portal_type="Person")
else:
raise ValueError('Unsupported portal type: %s (%s)' % (item.getPortalType(), item.getRelativeUrl()))
# service = self.portal.restrictedTraverse('service_module/slapos_virtual_master_subscription')
......
......@@ -8,7 +8,9 @@ project_value = None
if resource.getPortalType() == "Software Product":
project_value = resource.getFollowUpValue(portal_type="Project")
elif resource.getPortalType() == "Service":
if resource.getRelativeUrl() != "service_module/slapos_virtual_master_subscription":
if resource.getRelativeUrl() not in (
"service_module/slapos_virtual_master_subscription",
"service_module/slapos_compute_node_subscription"):
raise NotImplementedError('Unsupported resource: %s' % resource.getRelativeUrl())
else:
raise NotImplementedError('Unsupported resource: %s' % resource.getRelativeUrl())
......
......@@ -11,6 +11,7 @@ if item is None:
# create the project
item = portal.project_module.newContent(
portal_type='Project',
destination_value=customer
)
item.validate()
......
......@@ -50,7 +50,6 @@ class TestSlapOSSubscriptionRequestProcessAlarm(SlapOSTestCaseMixin):
#####################################################
# Instance Tree aggregated to another portal type
# TODO how to ensure Instance Tree is visited?
instance_tree = self.portal.instance_tree_module.newContent(
portal_type='Instance Tree',
title="Test Instance Tree another portal type %s" % self.new_id
......@@ -62,4 +61,4 @@ class TestSlapOSSubscriptionRequestProcessAlarm(SlapOSTestCaseMixin):
portal_type="Sale Packing List Line",
aggregate_value=instance_tree
)
self._test_alarm_not_visited(alarm, instance_tree, script_name)
self._test_alarm(alarm, instance_tree, script_name)
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