Commit 57e27fdc authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud:

* cleanup request when instance is not subscribed yet
* stop instance tree propagation on instance_slap_interface_workflow
  Some alarm call request directly on the Instance Tree (this is expected)
* rename Service_getSubscriptionStatus to Item_getSubscriptionStatus
parent 99d26d99
......@@ -8,6 +8,7 @@ open_sale_order_movement_list = portal.portal_catalog(
validation_state='validated',
limit=1
)
context.log("%s %s" % (service.getRelativeUrl(), len(open_sale_order_movement_list)))
if len(open_sale_order_movement_list) == 0:
return "not_subscribed"
......
......@@ -54,7 +54,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Service_getSubscriptionStatus</string> </value>
<value> <string>Item_getSubscriptionStatus</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -199,8 +199,7 @@ for compute_partition_candidate in portal.portal_catalog(
compute_node = compute_partition_candidate.getParentValue()
if compute_node.getPortalType() == 'Compute Node':
subscription_state = compute_node.Service_getSubscriptionStatus()
compute_node.log('subscription_state for Compute Node %s: %s' % (compute_node.getRelativeUrl(), subscription_state))
subscription_state = compute_node.Item_getSubscriptionStatus()
if subscription_state in ('not_subscribed', 'nopaid'):
continue
elif subscription_state in ('subscribed', 'todestroy'):
......
......@@ -600,7 +600,7 @@ class SlapOSTestCaseMixin(testSlapOSMixin):
url_string='type%s' % self.generateNewId(),
)
@simulate('Service_getSubscriptionStatus', '*args, **kwargs', 'return "subscribed"')
@simulate('Item_getSubscriptionStatus', '*args, **kwargs', 'return "subscribed"')
def bootstrapAllocableInstanceTree(self, allocation_state='possible', shared=False, node="compute",
is_accountable=False, base_price=None, has_organisation=False):
if allocation_state not in ('impossible', 'possible', 'allocated'):
......
......@@ -3,6 +3,8 @@ portal = requester_instance.getPortalObject()
# Get required arguments
kwargs = state_change.kwargs
context.REQUEST.set('request_instance', None)
# Required args
# Raise TypeError if all parameters are not provided
try:
......@@ -23,6 +25,18 @@ if is_slave not in [True, False]:
# Instance tree is used as the root of the instance tree
if requester_instance.getPortalType() == "Instance Tree":
instance_tree = requester_instance
# Do not propagate instante tree changes if current user
# subscription status is not OK
subscription_state = instance_tree.Item_getSubscriptionStatus()
if subscription_state in ('not_subscribed', 'nopaid'):
context.REQUEST.set('request_instance', None)
return
elif subscription_state in ('subscribed', 'todestroy'):
pass
else:
raise NotImplementedError('Unhandled subscription state: %s' % subscription_state)
else:
instance_tree = requester_instance.getSpecialiseValue(portal_type="Instance Tree")
......
......@@ -91,22 +91,15 @@ elif (root_state == "destroyed"):
else:
raise ValueError, "state should be started, stopped or destroyed"
subscription_state = request_instance_tree.Service_getSubscriptionStatus()
request_instance_tree.log('subscription_state %s' % subscription_state)
if subscription_state in ('not_subscribed', 'nopaid'):
pass
elif subscription_state in ('subscribed', 'todestroy'):
request_instance_tree.requestInstance(
software_release=software_release_url_string,
software_title=software_title,
software_type=software_type,
instance_xml=instance_xml,
sla_xml=sla_xml,
shared=is_slave,
state=root_state,
)
else:
raise NotImplementedError('Unhandled subscription state: %s' % subscription_state)
request_instance_tree.requestInstance(
software_release=software_release_url_string,
software_title=software_title,
software_type=software_type,
instance_xml=instance_xml,
sla_xml=sla_xml,
shared=is_slave,
state=root_state,
)
# Change the state at the end to allow to execute updateLocalRoles only once in the transaction
validation_state = request_instance_tree.getValidationState()
......
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