]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix comparison of Variant and other type in test_model_sync
authorAKamyshnikova <akamyshnikova@mirantis.com>
Wed, 16 Dec 2015 12:32:45 +0000 (15:32 +0300)
committerHenry Gessau <gessau@gmail.com>
Wed, 16 Dec 2015 23:52:12 +0000 (18:52 -0500)
Tests TestModelsMigrations failed on comparation Variant type and
BigInteger after alembic 0.8.4 release.
Current change corrected compare_type for such case.

Closes-bug: #1526675

Co-Authored-By: Ihar Hrachyshka <ihrachys@redhat.com>
Change-Id: I7ae7aaf053a81f487d9ec14859700806fa4f9017

neutron/tests/functional/db/test_migrations.py

index 80a011737a938bdc292ee1acafc7908db1077342..76489b71f9329d37a06be26df37a5104fbdcc82c 100644 (file)
@@ -23,6 +23,7 @@ from oslo_db.sqlalchemy import test_base
 from oslo_db.sqlalchemy import test_migrations
 import sqlalchemy
 from sqlalchemy import event
+import sqlalchemy.types as types
 
 from neutron.api.v2 import attributes as attr
 import neutron.db.migration as migration_help
@@ -134,6 +135,24 @@ class _TestModelsMigrations(test_migrations.ModelsMigrationsSync):
     def filter_metadata_diff(self, diff):
         return list(filter(self.remove_unrelated_errors, diff))
 
+    # TODO(akamyshikova): remove this method as soon as comparison with Variant
+    # will be implemented in oslo.db or alembic
+    def compare_type(self, ctxt, insp_col, meta_col, insp_type, meta_type):
+        if isinstance(meta_type, types.Variant):
+            orig_type = meta_col.type
+            meta_col.type = meta_type.impl
+            try:
+                return self.compare_type(ctxt, insp_col, meta_col, insp_type,
+                                         meta_type.impl)
+            finally:
+                meta_col.type = orig_type
+        else:
+            ret = super(_TestModelsMigrations, self).compare_type(
+                ctxt, insp_col, meta_col, insp_type, meta_type)
+            if ret is not None:
+                return ret
+            return ctxt.impl.compare_type(insp_col, meta_col)
+
     # Remove some difference that are not mistakes just specific of
     # dialects, etc
     def remove_unrelated_errors(self, element):