Commit 6c968390 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_subscription_request: Stop Subscription if Hosting Subscription is destroyed

   Include more verbose to the scripts to make debug easier.
parent f8e83af8
......@@ -4,6 +4,13 @@ if hosting_subscription is None:
# Probably we should raise here
return
# Instance is already destroyed so move into stopped state diretly.
if hosting_subscription.getValidationState() == "archived":
comment="Hosting Subscription is Destroyed and archived, Stop the Subscription Request"
context.start(comment=comment)
context.stop(comment=comment)
return comment
request_kw = dict(
software_release=hosting_subscription.getUrlString(),
software_title=hosting_subscription.getTitle(),
......@@ -18,17 +25,20 @@ if not context.SubscriptionRequest_testPaymentBalance():
if hosting_subscription.getSlapState() == "start_requested":
person = hosting_subscription.getDefaultDestinationSectionValue()
person.requestSoftwareInstance(state='stopped', **request_kw)
return
return "Skipped (Payment is pending)"
if hosting_subscription.getSlapState() == "stop_requested":
person = hosting_subscription.getDefaultDestinationSectionValue()
person.requestSoftwareInstance(state='started', **request_kw)
# Return to because it is useless continue right the way.
return
return "Skipped (Started instance)"
if not context.SubscriptionRequest_verifyInstanceIsAllocated():
# Only continue if instance is ready
return
return "Skipped (Instance is failing)"
if context.SubscriptionRequest_notifyInstanceIsReady():
context.start()
context.start(comment="Instance is ready")
return "Instance is ready"
return "Skipped (Instance isn't ready)"
......@@ -4,11 +4,11 @@ hosting_subscription = context.getAggregateValue()
if hosting_subscription is None:
context.SubscriptionRequest_processRequest()
# Don't perform everything on the same transaction
return
return "Skipped (Instance Requested)"
if hosting_subscription is not None:
if hosting_subscription.getCausalityState() == "diverged":
# Call it as soon as possible
# Call it as soon as possible
hosting_subscription.HostingSubscription_requestUpdateOpenSaleOrder()
instance = hosting_subscription.getPredecessorValue()
......@@ -21,17 +21,27 @@ if hosting_subscription is not None:
# create a Deduction for his fee
context.SubscriptionRequest_generateReservationRefoundSalePackingList()
# Instance is already destroyed so move into stopped state diretly.
if hosting_subscription.getValidationState() == "archived":
comment="Hosting Subscription is Destroyed and archived, Stop the Subscription Request"
context.confirm(comment=comment)
context.start(comment=comment)
context.stop(comment=comment)
first_period_payment = context.SubscriptionRequest_verifyPaymentBalanceIsReady()
if not first_period_payment:
# Payment isn't available for the user
return
return "Skipped (Payment isn't ready)"
if not context.SubscriptionRequest_verifyInstanceIsAllocated():
# Only continue if instance is ready
return
return "Skipped (Instance isn't ready)"
invoice = first_period_payment.getCausalityValue()
# Link to be sent is the invoice one
if context.SubscriptionRequest_notifyPaymentIsReady(payment=invoice):
context.confirm()
context.confirm(comment="Payment is ready for the user")
return "Payment is ready for the user"
return "Skipped (User isn't notified)"
......@@ -3,4 +3,4 @@ hosting_subscription = context.getAggregateValue()
if hosting_subscription is not None and \
hosting_subscription.getSlapState() == "destroy_requested":
context.stop()
context.stop(comment="Instance is Destroyed")
......@@ -1104,7 +1104,8 @@ class TestSubscriptionRequest_processOrdered(TestSubscriptionSkinsMixin):
self.tic()
self.assertEqual(
subscription_request.SubscriptionRequest_processOrdered(), None)
subscription_request.SubscriptionRequest_processOrdered(),
'Skipped (Instance Requested)')
self.tic()
hosting_subscription = subscription_request.getAggregateValue(portal_type="Hosting Subscription")
......@@ -1120,7 +1121,8 @@ class TestSubscriptionRequest_processOrdered(TestSubscriptionSkinsMixin):
self.assertEqual(
subscription_request.SubscriptionRequest_processOrdered(), None)
subscription_request.SubscriptionRequest_processOrdered(),
"Skipped (Payment isn't ready)")
self.tic()
self.assertEqual('solved', hosting_subscription.getCausalityState())
......@@ -1177,7 +1179,7 @@ class TestSubscriptionRequest_processOrdered(TestSubscriptionSkinsMixin):
self.tic()
self.assertEqual(
subscription_request.SubscriptionRequest_processOrdered(), None)
subscription_request.SubscriptionRequest_processOrdered(), 'Skipped (Instance Requested)')
self.tic()
hosting_subscription = subscription_request.getAggregateValue(portal_type="Hosting Subscription")
......@@ -1190,7 +1192,8 @@ class TestSubscriptionRequest_processOrdered(TestSubscriptionSkinsMixin):
self.assertEqual(
subscription_request.SubscriptionRequest_processOrdered(), None)
subscription_request.SubscriptionRequest_processOrdered(),
"Skipped (Payment isn't ready)")
self.tic()
self.assertEqual('solved', hosting_subscription.getCausalityState())
......@@ -1256,7 +1259,8 @@ class TestSubscriptionRequest_processOrdered(TestSubscriptionSkinsMixin):
self.tic()
self.assertEqual(
subscription_request.SubscriptionRequest_processOrdered(), None)
subscription_request.SubscriptionRequest_processOrdered(),
'Skipped (Instance Requested)')
self.tic()
hosting_subscription = subscription_request.getAggregateValue()
......@@ -1264,13 +1268,14 @@ class TestSubscriptionRequest_processOrdered(TestSubscriptionSkinsMixin):
self.assertEqual('diverged', hosting_subscription.getCausalityState())
self.assertEqual(
subscription_request.SubscriptionRequest_processOrdered(), None)
subscription_request.SubscriptionRequest_processOrdered(),
'Payment is ready for the user')
self.tic()
self.assertEqual('solved', hosting_subscription.getCausalityState())
self.assertEqual(
subscription_request.SubscriptionRequest_processOrdered(), None)
subscription_request.SubscriptionRequest_processOrdered(), "Skipped (User isn't notified)")
self.tic()
self.assertEqual(
subscription_request.getSimulationState(),
......@@ -1428,7 +1433,8 @@ class TestSubscriptionRequest_processConfirmed(TestSubscriptionSkinsMixin):
self.tic()
self.assertEqual(
subscription_request.SubscriptionRequest_processConfirmed(), None)
subscription_request.SubscriptionRequest_processConfirmed(),
'Skipped (Payment is pending)')
self.tic()
self.assertEqual(subscription_request.getSimulationState(), "confirmed")
......@@ -1466,7 +1472,8 @@ class TestSubscriptionRequest_processConfirmed(TestSubscriptionSkinsMixin):
self.tic()
self.assertEqual(
subscription_request.SubscriptionRequest_processConfirmed(), None)
subscription_request.SubscriptionRequest_processConfirmed(),
'Skipped (Started instance)')
self.tic()
self.assertEqual(subscription_request.getSimulationState(), "confirmed")
......
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