Commit a7edd506 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: migrate predecessor category to successor

parent 5c595568
<property_sheet_list>
<portal_type id="Alarm Tool">
<item>SlapOSMasterUpgradeConstraint</item>
</portal_type>
<portal_type id="Assignment">
<item>SlaposAssignmentConstraint</item>
</portal_type>
......@@ -23,6 +26,7 @@
<item>HostingSubscription</item>
<item>SlaposHostingSubscriptionConstraint</item>
<item>SoftwareInstance</item>
<item>SoftwareInstanceUpgradeConstraint</item>
<item>TextDocument</item>
<item>Url</item>
<item>VariationRange</item>
......@@ -49,6 +53,7 @@
<item>Reference</item>
<item>SoftwareInstance</item>
<item>SoftwareInstanceConstraint</item>
<item>SoftwareInstanceUpgradeConstraint</item>
<item>TextDocument</item>
<item>Url</item>
<item>VariationRange</item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Property Sheet" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_count</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>_mt_index</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>_tree</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SlapOSMasterUpgradeConstraint</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Property Sheet</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Length" module="BTrees.Length"/>
</pickle>
<pickle> <int>0</int> </pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Script Constraint" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_identity_criterion</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>_range_criterion</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>constraint_type/post_upgrade</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>predecessor_to_successor_migration_constraint</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Script Constraint</string> </value>
</item>
<item>
<key> <string>script_id</string> </key>
<value> <string>AlarmTool_checkPredecessorToSuccessorMigrationConsistency</string> </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/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Category Property" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>predecessor_category</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Category Property</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Property Sheet" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_count</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>_mt_index</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>_tree</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SoftwareInstanceUpgradeConstraint</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Property Sheet</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Length" module="BTrees.Length"/>
</pickle>
<pickle> <int>0</int> </pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Script Constraint" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_identity_criterion</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>_range_criterion</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>constraint_type/default</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>predecessor_to_successor_migration_constraint</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Script Constraint</string> </value>
</item>
<item>
<key> <string>script_id</string> </key>
<value> <string>SoftwareInstance_checkPredecessorToSuccessorMigrationConsistency</string> </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/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
result_list = []
migration_kw = {
'portal_type': ['Software Instance', 'Hosting Subscription'],
'predecessor__uid': '%'
}
non_migrated_instance = portal.portal_catalog(limit=1, **migration_kw)
if len(non_migrated_instance) == 1:
result_list.append("all X needs updates %s" % non_migrated_instance[0].getRelativeUrl())
if fixit:
portal.portal_catalog.searchAndActivate(
activate_kw=dict(priority=5,
tag=script.getId(),
after_method_id=('immediateReindexObject',
'recursiveImmediateReindexObject')),
method_id='fixConsistency',
**migration_kw)
return result_list
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>fixit=False</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>AlarmTool_checkPredecessorToSuccessorMigrationConsistency</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
predecessor_list = context.getPredecessorList()
successor_list = context.getSuccessorList()
error_list = []
if predecessor_list:
if successor_list:
return ['Error: Instance has both predecessor and successor categories']
error_list.append('Instance has predecessor categories not yet migrated to successor categories')
if fixit:
context.edit(successor_list=predecessor_list, predecessor_list=[])
assert not context.getPredecessorList()
assert len(context.getSuccessorList()) == len(predecessor_list)
return error_list
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>fixit=False</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SoftwareInstance_checkPredecessorToSuccessorMigrationConsistency</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2021 Nexedi SA and Contributors. All Rights Reserved.
#
##############################################################################
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin
def getMessageList(instance):
return [str(m.getMessage()) for m in instance.checkConsistency()]
class TestSlapOSCloudUpgrader(SlapOSTestCaseMixin):
def check_upgrade_instance_predecessor(self, portal_type):
error_message = 'Error: Instance has both predecessor and successor categories'
migration_message = 'Instance has predecessor categories not yet migrated to successor categories'
module = self.portal.getDefaultModule(portal_type)
instance_nothing_to_migrate = module.newContent(
portal_type=portal_type
)
instance_to_migrate = module.newContent(
portal_type=portal_type,
predecessor_value=instance_nothing_to_migrate
)
instance_badly_migrated = module.newContent(
portal_type=portal_type,
predecessor_value=instance_nothing_to_migrate,
successor_value=instance_nothing_to_migrate
)
# Nothing to migrate
self.assertFalse(migration_message in getMessageList(instance_nothing_to_migrate))
self.assertFalse(error_message in getMessageList(instance_nothing_to_migrate))
# Migrate
self.assertTrue(migration_message in getMessageList(instance_to_migrate))
self.assertFalse(error_message in getMessageList(instance_to_migrate))
instance_to_migrate.fixConsistency()
self.assertEqual(None, instance_to_migrate.getPredecessor())
self.assertEqual(instance_nothing_to_migrate.getRelativeUrl(),
instance_to_migrate.getSuccessor())
self.assertFalse(migration_message in getMessageList(instance_to_migrate))
self.assertFalse(error_message in getMessageList(instance_to_migrate))
# Error
self.assertFalse(migration_message in getMessageList(instance_badly_migrated))
self.assertTrue(error_message in getMessageList(instance_badly_migrated))
instance_badly_migrated.fixConsistency()
self.assertEqual(instance_nothing_to_migrate.getRelativeUrl(),
instance_badly_migrated.getPredecessor())
self.assertEqual(instance_nothing_to_migrate.getRelativeUrl(),
instance_badly_migrated.getSuccessor())
self.assertFalse(migration_message in getMessageList(instance_badly_migrated))
self.assertTrue(error_message in getMessageList(instance_badly_migrated))
def test_upgrade_software_instance_predecessor(self):
return self.check_upgrade_instance_predecessor('Software Instance')
def test_upgrade_hosting_subscription_predecessor(self):
return self.check_upgrade_instance_predecessor('Hosting Subscription')
<?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>testSlapOSCloudUpgrader</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testSlapOSCloudUpgrader</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.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<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>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Alarm Tool | SlapOSMasterUpgradeConstraint
Assignment | SlaposAssignmentConstraint
Computer Model | SlaposCapacity
Computer Partition | ComputerPartition
......@@ -11,6 +12,7 @@ Email | SlaposEmailConstraint
Hosting Subscription | HostingSubscription
Hosting Subscription | SlaposHostingSubscriptionConstraint
Hosting Subscription | SoftwareInstance
Hosting Subscription | SoftwareInstanceUpgradeConstraint
Hosting Subscription | TextDocument
Hosting Subscription | Url
Hosting Subscription | VariationRange
......@@ -29,6 +31,7 @@ Software Instance | HostingSubscription
Software Instance | Reference
Software Instance | SoftwareInstance
Software Instance | SoftwareInstanceConstraint
Software Instance | SoftwareInstanceUpgradeConstraint
Software Instance | TextDocument
Software Instance | Url
Software Instance | VariationRange
......
SoftwareInstanceConstraint
SlapOSMasterUpgradeConstraint
SlaposComputerPartitionConstraint
SlaposHostingSubscriptionConstraint
SlaveInstanceConstraint
InternetProtocolAddress
ComputerPartition
SoftwareInstance
SoftwareInstanceUpgradeConstraint
HostingSubscription
SlaposCapacity
SlaposPersonConstraint
......
......@@ -3,6 +3,7 @@ test.erp5.testSlapOSCloudAllocationAlarm
test.erp5.testSlapOSCloudWorkflow
test.erp5.testSlapOSCloudSecurityGroup
test.erp5.testSlapOSCloudConstraint
test.erp5.testSlapOSCloudUpgrader
test.erp5.testSlapOSCloudShadow
test.erp5.SlapOSTestCaseMixin
test.erp5.SlapOSTestCaseDefaultScenarioMixin
......
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