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