Commit 8310e4e4 authored by Jérome Perrin's avatar Jérome Perrin

testUpgradeInstanceWithOldDataFs: dump without a valid connection string

This dump was made with a connection string on 127.0.0.1, which must be
causing erros in logs:

    2020-04-09 09:35:02.699 CRITICAL ERP5Site Automatic migration of core tools failed
    Traceback (most recent call last):
      File "erp5/product/ERP5Type/dynamic/portal_type_class.py", line 456, in synchronizeDynamicModules
        portal.portal_activities.initialize()
      File "erp5/product/CMFActivity/ActivityTool.py", line 694, in initialize
        activity.initialize(self, clear=False)
      File "erp5/product/CMFActivity/Activity/SQLBase.py", line 173, in initialize
        db = activity_tool.getSQLConnection()
      File "erp5/product/CMFActivity/ActivityTool.py", line 674, in getSQLConnection
        return self.aq_inner.aq_parent.cmf_activity_sql_connection()
      File "eggs/Products.ZSQLMethods-2.13.5-py2.7.egg/Shared/DC/ZRDB/Connection.py", line 194, in __call__
        self.connect(s)
      File "erp5/product/ERP5Type/tests/ERP5TypeTestCase.py", line 926, in connect
        return original_ZMySQLDA_connect(self, *args, **kw)
      File "erp5/product/ZMySQLDA/DA.py", line 156, in connect
        connection = pool[self._p_jar] = DB(s)
      File "erp5/product/ZMySQLDA/db.py", line 229, in __init__
        self._forceReconnection()
      File "erp5/product/ZMySQLDA/db.py", line 316, in _forceReconnection
        self.db = MySQLdb.connect(**self._kw_args)
      File "develop-eggs/mysqlclient-1.3.12-py2.7-linux-x86_64.egg/MySQLdb/__init__.py", line 86, in Connect
        return Connection(*args, **kwargs)
      File "develop-eggs/mysqlclient-1.3.12-py2.7-linux-x86_64.egg/MySQLdb/connections.py", line 204, in __init__
        super(Connection, self).__init__(*args, **kwargs2)
    OperationalError: (2002, "Can't connect to MySQL server on '127.0.0.1' (115)")

We first thought about using a connection string that would work on test
node, something like:

    erp5_test_0@erp5-catalog-0:2099 testuser_0 testpassword0

but since testnodes share mysql connections, this would be wrong if for
exemple this testnode was affected with erp5_test_1 and another test
node was already running with erp5_test0.

Instead, we use another approach, the reference Data.fs uses a marker
string as connection string and before running test, the testnode
rewrite the Data.fs to replace the marker string by the actual
connection string. Because ZODB file storage is simple, we can just
replace string in the database file, as long as the replacement string
have the same length as the replaced string.

Dump was produced this way:

    runUnitTest --save --erp5_sql_connection_string 'erp5_test_0@erp5-catalog-0:2099               testuser_0 testpassword0' --portal_id=erp5 testUpgradeInstanceWithOldDataFs
    python3 rewrite_data_fs.py
parent b09e9975
# this dump was generated with --erp5_sql_connection_string 'erp5_test_0@erp5-catalog-0:2099 testuser_0 testpassword0'
actual_connection_string = b'erp5_test_0@erp5-catalog-0:2099 testuser_0 testpassword0'
marker_connection_string = b'CONNECTION_STRING_REPLACED_BY_TEST_INIT_______________________________'
with open('Data.fs', 'rb') as f:
data = f.read()
assert actual_connection_string in data
assert len(actual_connection_string) == len(marker_connection_string)
with open('Data.fs', 'wb') as f:
f.write(data.replace(actual_connection_string, marker_connection_string))
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