From b44c36e5ba43aa8c07d0aa68b90a2cf9e130ecc7 Mon Sep 17 00:00:00 2001 From: silvacarloss Date: Wed, 20 Sep 2023 18:50:18 -0300 Subject: [PATCH] Fix py311 unit test issues - Dell EMC driver had an issue with mocking an object and sending it forward. - Some of the create table statements in the database migrations didn't have the charset specified. That seemed to trick the DB engine while defining foreign keys and adding a name to them, as the default charset was defined in the schema, but not in the tables. This behavior was also noted in different places, like [1]. Fix this issue by adding the charset to all create table statements, so they match the engine default charset. [1] https://github.com/apache/superset/issues/8808 Change-Id: I7cd6fa0cc8e054af112493746e753fef2024000f --- doc/source/contributor/database.rst | 5 +++++ .../38e632621e5a_change_volume_type_to_share_type.py | 2 +- .../versions/a77e2ad5012d_add_share_snapshot_access.py | 9 ++++++--- .../b516de97bfee_add_quota_per_share_type_model.py | 1 + .../dda6de06349_add_export_locations_metadata.py | 1 + .../versions/e1949a93157a_add_share_group_types_table.py | 3 +++ .../versions/ef0c02b4366_add_share_type_projects.py | 1 + manila/tests/share/drivers/dell_emc/test_driver.py | 2 +- 8 files changed, 19 insertions(+), 5 deletions(-) diff --git a/doc/source/contributor/database.rst b/doc/source/contributor/database.rst index 1f2421e27f..1a2302c196 100644 --- a/doc/source/contributor/database.rst +++ b/doc/source/contributor/database.rst @@ -64,3 +64,8 @@ possible to use ``manila-manage db revision`` or the corresponding tox command:: In addition every migration script must be tested. See examples in ``manila/tests/db/migrations/alembic/migrations_data_checks.py``. + +.. note:: + When writing database migrations that create tables with unique constraints + or foreign keys, please ensure that the ``mysql_charset`` matches the + referenced table. diff --git a/manila/db/migrations/alembic/versions/38e632621e5a_change_volume_type_to_share_type.py b/manila/db/migrations/alembic/versions/38e632621e5a_change_volume_type_to_share_type.py index f7788a1786..223b40c1ef 100644 --- a/manila/db/migrations/alembic/versions/38e632621e5a_change_volume_type_to_share_type.py +++ b/manila/db/migrations/alembic/versions/38e632621e5a_change_volume_type_to_share_type.py @@ -60,7 +60,7 @@ def upgrade(): nullable=False), sa.Column('spec_key', sa.String(length=255)), sa.Column('spec_value', sa.String(length=255)), - mysql_engine='InnoDB') + mysql_engine='InnoDB', mysql_charset='utf8') LOG.info("Migrating volume_type_extra_specs to " "share_type_extra_specs") diff --git a/manila/db/migrations/alembic/versions/a77e2ad5012d_add_share_snapshot_access.py b/manila/db/migrations/alembic/versions/a77e2ad5012d_add_share_snapshot_access.py index 88c385558f..43d5c28db2 100644 --- a/manila/db/migrations/alembic/versions/a77e2ad5012d_add_share_snapshot_access.py +++ b/manila/db/migrations/alembic/versions/a77e2ad5012d_add_share_snapshot_access.py @@ -45,7 +45,8 @@ def upgrade(): sa.ForeignKey('share_snapshots.id', name='ssam_snapshot_fk')), sa.Column('access_type', sa.String(255)), - sa.Column('access_to', sa.String(255)) + sa.Column('access_to', sa.String(255)), + mysql_charset='utf8' ) op.create_table( @@ -62,7 +63,8 @@ def upgrade(): sa.ForeignKey('share_snapshot_access_map.id', name='ssam_access_fk')), sa.Column('state', sa.String(255), - default=constants.ACCESS_STATE_QUEUED_TO_APPLY) + default=constants.ACCESS_STATE_QUEUED_TO_APPLY), + mysql_charset='utf8' ) op.create_table( @@ -76,7 +78,8 @@ def upgrade(): sa.ForeignKey('share_snapshot_instances.id', name='ssiel_snapshot_instance_fk')), sa.Column('path', sa.String(2000)), - sa.Column('is_admin_only', sa.Boolean, default=False, nullable=False) + sa.Column('is_admin_only', sa.Boolean, default=False, nullable=False), + mysql_charset='utf8' ) op.add_column('shares', diff --git a/manila/db/migrations/alembic/versions/b516de97bfee_add_quota_per_share_type_model.py b/manila/db/migrations/alembic/versions/b516de97bfee_add_quota_per_share_type_model.py index 52a246c9dd..f4558b5089 100644 --- a/manila/db/migrations/alembic/versions/b516de97bfee_add_quota_per_share_type_model.py +++ b/manila/db/migrations/alembic/versions/b516de97bfee_add_quota_per_share_type_model.py @@ -49,6 +49,7 @@ def upgrade(): 'share_type_id', 'resource', 'deleted', name="uc_quotas_per_share_types"), mysql_engine='InnoDB', + mysql_charset='utf8', ) for table_name in ('quota_usages', 'reservations'): op.add_column( diff --git a/manila/db/migrations/alembic/versions/dda6de06349_add_export_locations_metadata.py b/manila/db/migrations/alembic/versions/dda6de06349_add_export_locations_metadata.py index aede75c2f0..010356caef 100644 --- a/manila/db/migrations/alembic/versions/dda6de06349_add_export_locations_metadata.py +++ b/manila/db/migrations/alembic/versions/dda6de06349_add_export_locations_metadata.py @@ -99,6 +99,7 @@ def upgrade(): sa.UniqueConstraint('export_location_id', 'key', 'deleted', name="elm_el_id_uc"), mysql_engine='InnoDB', + mysql_charset='utf8', ) except Exception: LOG.error("Failed to create '%s' table!", ELM_TABLE_NAME) diff --git a/manila/db/migrations/alembic/versions/e1949a93157a_add_share_group_types_table.py b/manila/db/migrations/alembic/versions/e1949a93157a_add_share_group_types_table.py index e1228e8a97..250af7b42e 100644 --- a/manila/db/migrations/alembic/versions/e1949a93157a_add_share_group_types_table.py +++ b/manila/db/migrations/alembic/versions/e1949a93157a_add_share_group_types_table.py @@ -49,6 +49,7 @@ def upgrade(): sql.UniqueConstraint( 'name', 'deleted', name="uniq_share_group_type_name"), mysql_engine='InnoDB', + mysql_charset='utf8', ) except Exception: LOG.error("Table |%s| not created!", 'share_group_types') @@ -70,6 +71,7 @@ def upgrade(): sql.ForeignKey( 'share_group_types.id', name="sgtp_id_extra_specs_fk")), mysql_engine='InnoDB', + mysql_charset='utf8', ) except Exception: LOG.error("Table |%s| not created!", 'share_group_type_specs') @@ -92,6 +94,7 @@ def upgrade(): 'share_group_type_id', 'project_id', 'deleted', name="sgtp_project_id_uc"), mysql_engine='InnoDB', + mysql_charset='utf8', ) except Exception: LOG.error("Table |%s| not created!", 'share_group_type_projects') diff --git a/manila/db/migrations/alembic/versions/ef0c02b4366_add_share_type_projects.py b/manila/db/migrations/alembic/versions/ef0c02b4366_add_share_type_projects.py index 15701d95d9..320ce89e18 100644 --- a/manila/db/migrations/alembic/versions/ef0c02b4366_add_share_type_projects.py +++ b/manila/db/migrations/alembic/versions/ef0c02b4366_add_share_type_projects.py @@ -59,6 +59,7 @@ def upgrade(): sql.UniqueConstraint('share_type_id', 'project_id', 'deleted', name="stp_project_id_uc"), mysql_engine='InnoDB', + mysql_charset='utf8' ) except Exception: LOG.error("Table |%s| not created!", 'share_type_projects') diff --git a/manila/tests/share/drivers/dell_emc/test_driver.py b/manila/tests/share/drivers/dell_emc/test_driver.py index a5ee348f4d..915a2e423d 100644 --- a/manila/tests/share/drivers/dell_emc/test_driver.py +++ b/manila/tests/share/drivers/dell_emc/test_driver.py @@ -278,7 +278,7 @@ class EMCShareFrameworkTestCase(test.TestCase): snapshot_access_rules, share_server) def test_unmanage_manage(self): - share = mock.Mock() + share = {} server_details = {} share_server = mock.Mock() snapshot = mock.Mock()