Commit 4a746445 authored by Ayush Tiwari's avatar Ayush Tiwari

multiple_catalog: Python Scripts to create and delete multiple catalogs at a time

parent 5eaa62f4
portal = context.getPortalObject()
portal_catalog = portal.portal_catalog
for i in range(101, 164):
catalog_id = 'erp5_mysql_innodb%s'%i
catalog = getattr(portal_catalog, catalog_id)
if catalog.getValidationState() != 'validated':
catalog.validate()
<?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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>CatalogTool_validateCatalog</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
original_connection_id = 'test_connection'
original_deferred_connection_id = 'erp5_sql_deferred_connection'
for i in range(164, 165):
new_connection_id = 'erp5_sql_connection%s'%str(i)
new_deferred_connection_id = 'erp5_sql_deferred_connection%s'%i
new_connection_string = 'erp5_test_%(i)s@10.0.159.93:2099 testuser_%(i)s testpassword%(i)s'%{'i': i}
# Skip this test if default connection string is not "test test".
original_connection = getattr(portal, original_connection_id)
connection_string = original_connection.connection_string
if (connection_string == new_connection_string):
message = 'SKIPPED: default connection string is the same as the default catalog'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
addSQLConnection = portal.manage_addProduct['ZMySQLDA'] \
.manage_addZMySQLConnection
# Create new connectors
try:
addSQLConnection(new_connection_id,'', new_connection_string)
new_connection = portal[new_connection_id]
new_connection.manage_open_connection()
addSQLConnection(new_deferred_connection_id,'', new_connection_string)
new_connection = portal[new_deferred_connection_id]
new_connection.manage_open_connection()
except:
pass
# the transactionless connector must not be changed because this one
# creates the portal_ids otherwise it will create conflicts with uid
# objects
# Create new catalog
portal_catalog = portal.portal_catalog
erp5_catalog = portal_catalog.getSQLCatalog()
original_catalog_id = 'erp5_mysql_innodb'
new_catalog_id = original_catalog_id + str(i)
new_catalog = portal_catalog.cloneCatalog(new_catalog_id)
#new_catalog = portal_catalog.manage_clone(erp5_catalog, new_catalog_id)
#self.tic()
# Parse all methods in the new catalog in order to change the connector
source_sql_connection_id_list=list((original_connection_id,
original_deferred_connection_id))
destination_sql_connection_id_list=list((new_connection_id,
new_deferred_connection_id))
# Construct a mapping for connection ids.
sql_connection_id_dict = None
if source_sql_connection_id_list is not None and \
destination_sql_connection_id_list is not None:
sql_connection_id_dict = {}
for source_sql_connection_id, destination_sql_connection_id in \
zip(source_sql_connection_id_list,
destination_sql_connection_id_list):
if source_sql_connection_id != destination_sql_connection_id:
sql_connection_id_dict[source_sql_connection_id] = \
destination_sql_connection_id
# Call the method to update the connection ids for the new catalog
portal_catalog.changeSQLConnectionIds(new_catalog,
sql_connection_id_dict)
# Clear the new catalog incase it uses some old connection string
new_catalog.manage_catalogClear()
# Now validate the newly created catalog
#new_catalog.validate()
<?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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5_createMultipleCatalog</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
portal_catalog = portal.portal_catalog
catalog_id_list = []
connection_id_list = []
deferred_connection_id_list = []
for i in range(164, 200):
catalog_id = 'erp5_mysql_innodb%s'%i
catalog_id_list.append(catalog_id)
connection_id = 'erp5_sql_connection%s'%i
connection_id_list.append(connection_id)
deferred_connection_id = 'erp5_sql_deferred_connection%s'%i
deferred_connection_id_list.append(deferred_connection_id)
portal.manage_delObjects(connection_id_list)
portal.manage_delObjects(deferred_connection_id_list)
portal_catalog.manage_delObjects(catalog_id_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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5_deleteMultipleCatalog</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
for i in range(101, 164):
connection_id = 'erp5_sql_connection%s'%i
deferred_connection_id = 'erp5_sql_deferred_connection%s'%i
connection_string = connection_string = 'erp5_test_%(i)s@10.0.159.93:2099 testuser_%(i)s testpassword%(i)s'%{'i': i}
getattr(portal, connection_id).connect(connection_string)
getattr(portal, deferred_connection_id).connect(connection_string)
<?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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5_restartDBConnection</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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