Commit 1e9f8b4f authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud:

* ensure that alarm propagate parameters of orphaned Instance Tree
* drop usage of Subscription Request
* check the Subscription Request instead of the Cloud Contract
* drop checkCloudContract method
parent b9b92bde
......@@ -9,4 +9,15 @@ portal.portal_catalog.searchAndActivate(
method_id='InstanceTree_assertSuccessor',
activate_kw={'tag': tag})
# Instance tree without any Software Instance
select_dict= {'successor__uid': None}
portal.portal_catalog.searchAndActivate(
portal_type='Instance Tree',
validation_state='validated',
method_id='InstanceTree_assertSuccessor',
activate_kw={'tag': tag},
left_join_list=select_dict.keys(),
**select_dict
)
context.activate(after_tag=tag).getId()
......@@ -49,14 +49,6 @@ def assignComputePartition(software_instance, instance_tree):
if not person.Person_isAllowedToAllocate():
raise Unauthorized('Allocation disallowed')
subscription_reference = None
subscription_request = instance_tree.getAggregateRelatedValue(
portal_type="Subscription Request")
if subscription_request is not None:
subscription_reference = subscription_request.getReference()
if subscription_request.getSimulationState() not in ["ordered", "confirmed", "started"]:
raise Unauthorized("Related Subscription Requested isn't ordered, confirmed or started")
tag = None
try:
sla_dict = software_instance.getSlaXmlAsDict()
......@@ -111,22 +103,13 @@ def assignComputePartition(software_instance, instance_tree):
elif sla_dict.get('mode'):
computer_network_query = '-1'
"""
compute_partition_relative_url = person.Person_restrictMethodAsShadowUser(
shadow_document=person,
callable_object=person.Person_findPartition,
argument_list=[software_instance.getUrlString(), software_instance.getSourceReference(),
software_instance.getPortalType(), sla_dict, computer_network_query,
subscription_reference, instance_tree.isRootSlave()])
"""
compute_partition_relative_url = person.Person_findPartition(
instance_tree,
software_instance.getFollowUpUid(portal_type='Project'),
software_instance.getUrlString(),
software_instance.getSourceReference(),
software_instance.getPortalType(),
sla_dict, computer_network_query,
subscription_reference
sla_dict, computer_network_query
)
return compute_partition_relative_url, tag
......
......@@ -492,8 +492,13 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
shared_xml=shared_xml,
)
self.checkCloudContract(person_user_id, person_reference,
instance_title, software_release, software_type, server)
# XXX search only for this user
instance_tree = self.portal.portal_catalog.getResultValue(
portal_type="Instance Tree",
title=instance_title,
follow_up__reference=project_reference
)
self.checkServiceSubscriptionRequest(instance_tree)
self.stepCallSlaposAllocateInstanceAlarm()
self.tic()
......@@ -573,71 +578,22 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
if q.getTitle() == instance_title]
self.assertEqual(0, len(instance_tree_list))
def checkCloudContract(self, person_user_id, person_reference,
instance_title, software_release, software_type, server):
self.login()
self.assertTrue(self.portal.portal_preferences.getPreferredCloudContractEnabled())
self.stepCallSlaposContractRequestValidationPaymentAlarm()
self.tic()
# stabilise aggregated invoices and expand them
self.stepCallSlaposManageBuildingCalculatingDeliveryAlarm()
self.tic()
# update invoices with their tax & discount
self.stepCallSlaposTriggerBuildAlarm()
self.tic()
self.stepCallSlaposManageBuildingCalculatingDeliveryAlarm()
self.tic()
# update invoices with their tax & discount transaction lines
self.stepCallSlaposTriggerBuildAlarm()
self.tic()
self.stepCallSlaposManageBuildingCalculatingDeliveryAlarm()
self.tic()
# stop the invoices and solve them again
self.stepCallSlaposStopConfirmedAggregatedSaleInvoiceTransactionAlarm()
self.tic()
self.stepCallSlaposManageBuildingCalculatingDeliveryAlarm()
self.tic()
if 0:
# trigger the CRM interaction
self.stepCallSlaposCrmCreateRegularisationRequestAlarm()
self.tic()
# trigger the CRM interaction
self.stepCallSlaposCrmCreateRegularisationRequestAlarm()
self.tic()
def checkServiceSubscriptionRequest(self, service):
self.login()
person = self.portal.portal_catalog.getResultValue(
portal_type="Person",
user_id=person_user_id)
contract = self.portal.portal_catalog.getResultValue(
portal_type="Cloud Contract",
default_destination_section_uid=person.getUid(),
validation_state=['invalidated', 'validated'])
self.assertNotEqual(contract, None)
if contract.getValidationState() != 'validated':
self.assertEqual(contract.getValidationState(), "invalidated")
# HACK FOR NOW
contract.validate()
self.stepCallSlaposSubscriptionRequestCreateFromOrphanedItemAlarm()
self.tic()
self.login(person_user_id)
subscription_request = self.portal.portal_catalog.getResultValue(
portal_type="Subscription Request",
aggregate__uid=service.getUid(),
simulation_state='validated'
)
self.assertNotEqual(subscription_request, None)
self.stepCallSlaposContractRequestValidationPaymentAlarm()
self.stepCallSlaposAssertInstanceTreeSuccessorAlarm()
self.tic()
def checkInstanceAllocation(self, person_user_id, person_reference,
instance_title, software_release, software_type, server,
project_reference):
......@@ -651,12 +607,18 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
project_reference=project_reference
)
self.checkCloudContract(person_user_id, person_reference,
instance_title, software_release, software_type, server)
# XXX search only for this user
instance_tree = self.portal.portal_catalog.getResultValue(
portal_type="Instance Tree",
title=instance_title,
follow_up__reference=project_reference
)
self.checkServiceSubscriptionRequest(instance_tree)
self.stepCallSlaposAllocateInstanceAlarm()
self.tic()
self.login(person_user_id)
self.personRequestInstance(
software_release=software_release,
software_type=software_type,
......
......@@ -66,7 +66,19 @@ class TestSlapOSCoreSlapOSAssertInstanceTreeSuccessorAlarm(
self.assertFalse(self.instance_tree.getTitle() in
self.instance_tree.getSuccessorTitleList())
def test_alarm_renamed(self):
def test_InstanceTree_assertSuccessor_alarm_orphaned(self):
instance_tree = self.portal.instance_tree_module.newContent(
portal_type='Instance Tree'
)
instance_tree.validate()
self.tic()
self._test_alarm(
self.portal.portal_alarms.slapos_assert_instance_tree_successor,
instance_tree,
'InstanceTree_assertSuccessor'
)
def test_InstanceTree_assertSuccessor_alarm_renamed(self):
self.software_instance.edit(title=self.generateNewSoftwareTitle())
self._test_alarm(
self.portal.portal_alarms.slapos_assert_instance_tree_successor,
......@@ -74,7 +86,7 @@ class TestSlapOSCoreSlapOSAssertInstanceTreeSuccessorAlarm(
'InstanceTree_assertSuccessor'
)
def test_alarm_not_renamed(self):
def test_InstanceTree_assertSuccessor_alarm_not_renamed(self):
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_assert_instance_tree_successor,
self.instance_tree,
......
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