Commit 4faf1cfa authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_pdm: Create and launch upgrade based on upgrade scope

parent 26f32724
......@@ -2,10 +2,10 @@ portal = context.getPortalObject()
portal.portal_catalog.searchAndActivate(
portal_type='Hosting Subscription',
validation_state = 'validated',
slap_state=['start_requested', 'stop_requested'],
method_id = 'HostingSubscription_createUpgradeDecision',
packet_size=1,
activate_kw = {'tag':tag}
activate_kw = {'tag':tag},
**{"slapos_item.slap_state": ['start_requested', 'stop_requested']}
)
context.activate(after_tag=tag).getId()
......@@ -2,8 +2,12 @@ from DateTime import DateTime
computer = context
portal = context.getPortalObject()
full_software_release_list = [si.getUrlString() for si in
if context.getUpgradeScope() == "never":
return
full_software_release_list = [si.url_string for si in
portal.portal_catalog(
select_dict = {"url_string": None},
portal_type='Software Installation',
default_aggregate_uid=computer.getUid(),
validation_state='validated'
......@@ -45,9 +49,9 @@ for software_release in software_release_list:
source_url=computer.getRelativeUrl(),
title=title)
if context.getAllocationScope() in ["open/public", "open/friend", "open/subscription"]:
if context.getUpgradeScope() == "auto":
upgrade_decision.start()
elif context.getAllocationScope() in ["open/personal"] and upgrade_decision.getSimulationState() != "planned":
elif context.getUpgradeScope() == "ask_confirmation" and upgrade_decision.getSimulationState() != "planned":
upgrade_decision.plan()
upgrade_decision.setStartDate(DateTime())
......
......@@ -2,22 +2,27 @@ from DateTime import DateTime
portal = context.getPortalObject()
hosting_subscription = context
if context.getUpgradeScope() == "never":
return
root_instance = hosting_subscription.getPredecessorValue(portal_type="Software Instance")
if root_instance is None:
return
if hosting_subscription.getSlapState() == "destroy_requested":
return
tag = "%s_requestUpgradeDecisionCreation_inProgress" % hosting_subscription.getUid()
activate_kw = {'tag': tag}
if portal.portal_activities.countMessageWithTag(tag) > 0:
# nothing to do
return
root_instance = hosting_subscription.getPredecessorValue()
if root_instance is None or root_instance.getPortalType() == "Slave Instance":
return
if hosting_subscription.getSlapState() == "destroy_requested":
return
partition = root_instance.getAggregateValue(portal_type="Computer Partition")
if partition is None:
return
if not partition.getParent().getAllocationScopeUid() in [category.getUid() \
if not partition.getParentValue().getAllocationScopeUid() in [category.getUid() \
for category in portal.portal_categories.allocation_scope.open.objectValues()]:
return
......@@ -42,6 +47,8 @@ upgrade_decision = newer_release.SoftwareRelease_createUpgradeDecision(
with upgrade_decision.defaultActivateParameterDict(activate_kw):
upgrade_decision.plan()
upgrade_decision.setStartDate(DateTime())
if hosting_subscription.getUpgradeScope() == "auto":
upgrade_decision.start()
# Prevent concurrent transaction to create 2 upgrade decision for the same hosting_subscription
hosting_subscription.serialize()
......
......@@ -1026,9 +1026,8 @@ class TestSlapOSPDMSkins(SlapOSTestCaseMixin):
def testComputer_checkAndCreateUpgradeDecision_personal_with_exist(self):
person = self._makePerson()
computer = self._makeComputer()
computer.edit(source_administration_value=person,
allocation_scope="open/personal")
computer = self._makeComputer(allocation_scope="open/personal")
computer.edit(source_administration_value=person)
software_product = self._makeSoftwareProduct()
software_release = self._requestSoftwareRelease(
software_product.getRelativeUrl())
......@@ -1037,6 +1036,7 @@ class TestSlapOSPDMSkins(SlapOSTestCaseMixin):
self._requestSoftwareRelease(software_product.getRelativeUrl())
self.tic()
self.assertEqual(computer.getUpgradeScope(), "ask_confirmation")
upgrade_decision = computer.Computer_checkAndCreateUpgradeDecision()[0]
self.assertEqual(upgrade_decision.getSimulationState(), 'planned')
......
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