Commit 4b61347e authored by Łukasz Nowak's avatar Łukasz Nowak Committed by Rafael Monnerat

slapos_pdm: Test HostingSubscription_createUpgradeDecision

parent 58ab7ea3
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2019 Nexedi SA and Contributors. All Rights Reserved.
#
##############################################################################
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin
from DateTime import DateTime
class TestSlapOSPDMUpgradeDecisionSkins(SlapOSTestCaseMixin):
def _makeSoftwareProductCatalog(self):
self.software_product = self._makeSoftwareProduct(self.generateNewId())
self.previous_software_release = self._makeSoftwareRelease(self.generateNewId())
self.new_software_release = self._makeSoftwareRelease(self.generateNewId())
self.previous_software_release.publish()
self.new_software_release.publish()
self.previous_software_release.edit(
aggregate=self.software_product.getRelativeUrl(),
url_string=self.generateNewSoftwareReleaseUrl(),
version='1',
effective_date=DateTime()-1,
)
self.new_software_release.edit(
aggregate=self.software_product.getRelativeUrl(),
url_string=self.generateNewSoftwareReleaseUrl(),
version='2',
effective_date=DateTime(),
)
self.tic()
def _installSoftwareOnTheComputer(self, software_release_url_list):
for software_release in software_release_url_list:
software_installation = self.portal.software_installation_module\
.newContent(portal_type='Software Installation',
url_string=software_release,
aggregate=self.computer.getRelativeUrl())
software_installation.validate()
software_installation.requestStart()
self.tic()
def _createInstance(self, url_string, shared=False):
hosting_subscription = self.portal.hosting_subscription_module\
.template_hosting_subscription.Base_createCloneDocument(batch_mode=1)
hosting_subscription.edit(
)
hosting_subscription.validate()
hosting_subscription.edit(
title=self.generateNewSoftwareTitle(),
reference="TESTHS-%s" % self.generateNewId(),
destination_section_value=self.person
)
request_kw = dict(
software_release=url_string,
software_type=self.generateNewSoftwareType(),
instance_xml=self.generateSafeXml(),
sla_xml=self.generateSafeXml(),
shared=shared,
software_title=hosting_subscription.getTitle(),
state='started'
)
hosting_subscription.requestStart(**request_kw)
hosting_subscription.requestInstance(**request_kw)
instance = hosting_subscription.getPredecessorValue()
self.tic()
return hosting_subscription, instance
def _makeTree(self, software_release_url):
self.hosting_subscription, self.instance = self._createInstance(software_release_url)
self.shared_hosting_subscription, self.shared_instance = self._createInstance(software_release_url, True)
self.instance.setAggregate(self.partition.getRelativeUrl())
self.shared_instance.setAggregate(self.partition.getRelativeUrl())
self.partition.markBusy()
self.tic()
def afterSetUp(self):
SlapOSTestCaseMixin.afterSetUp(self)
preference = self.portal.portal_preferences.getActiveSystemPreference()
preference.setPreferredCloudContractEnabled(True)
self.tic()
self._makeComputer()
self._makeSoftwareProductCatalog()
self._installSoftwareOnTheComputer([
self.previous_software_release.getUrlString(),
self.new_software_release.getUrlString()
])
self.person = self.makePerson()
self.tic()
self._makeTree(self.previous_software_release.getUrlString())
def test_HostingSubscription_createUpgradeDecision_upgradeScopeConfirmation(self):
# check upgrade decision on HS
self.hosting_subscription.setUpgradeScope('manual')
self.tic()
upgrade_decision = self.hosting_subscription.HostingSubscription_createUpgradeDecision()
self.assertEqual('planned', upgrade_decision.getSimulationState())
shared_upgrade_decision = self.shared_hosting_subscription.HostingSubscription_createUpgradeDecision()
self.assertEqual(None, shared_upgrade_decision)
# simulate upgrade of the hosting subscription
upgrade_decision.confirm()
upgrade_decision.start()
upgrade_decision.stop()
upgrade_decision.deliver()
self.hosting_subscription.edit(url_string=self.new_software_release.getUrlString())
self.instance.edit(url_string=self.new_software_release.getUrlString())
self.tic()
# check upgrade decision on shared HS related to upgraded HS
self.shared_hosting_subscription.setUpgradeScope('manual')
shared_upgrade_decision = self.shared_hosting_subscription.HostingSubscription_createUpgradeDecision()
self.assertEqual('started', shared_upgrade_decision.getSimulationState())
def test_HostingSubscription_createUpgradeDecision_upgradeScopeAuto(self):
# check upgrade decision on HS
self.hosting_subscription.setUpgradeScope('auto')
self.tic()
upgrade_decision = self.hosting_subscription.HostingSubscription_createUpgradeDecision()
self.assertEqual('started', upgrade_decision.getSimulationState())
shared_upgrade_decision = self.shared_hosting_subscription.HostingSubscription_createUpgradeDecision()
self.assertEqual(None, shared_upgrade_decision)
# simulate upgrade of the hosting subscription
upgrade_decision.stop()
upgrade_decision.deliver()
self.hosting_subscription.edit(url_string=self.new_software_release.getUrlString())
self.instance.edit(url_string=self.new_software_release.getUrlString())
self.tic()
# check upgrade decision on shared HS related to upgraded HS
self.shared_hosting_subscription.setUpgradeScope('auto')
shared_upgrade_decision = self.shared_hosting_subscription.HostingSubscription_createUpgradeDecision()
self.assertEqual('started', shared_upgrade_decision.getSimulationState())
def test_HostingSubscription_createUpgradeDecision_upgradeScopeDisabled(self):
# check upgrade decision on HS
self.hosting_subscription.setUpgradeScope('disabled')
self.tic()
upgrade_decision = self.hosting_subscription.HostingSubscription_createUpgradeDecision()
self.assertEqual(None, upgrade_decision)
shared_upgrade_decision = self.shared_hosting_subscription.HostingSubscription_createUpgradeDecision()
self.assertEqual(None, shared_upgrade_decision)
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testSlapOSPDMUpgradeDecisionSkins</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testSlapOSPDMUpgradeDecisionSkins</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
test.erp5.testSlapOSPDMAlarm
test.erp5.testSlapOSPDMSkins
test.erp5.testSlapOSPDMDestroySoftwareInstallationWithArchivedSoftwareReleaseAlarm
\ No newline at end of file
test.erp5.testSlapOSPDMDestroySoftwareInstallationWithArchivedSoftwareReleaseAlarm
test.erp5.testSlapOSPDMUpgradeDecisionSkins
\ No newline at end of file
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