From e009eed87504f709934accefc725620fef14ffe7 Mon Sep 17 00:00:00 2001 From: Abhishek Raut Date: Sun, 11 Sep 2016 18:34:42 -0700 Subject: [PATCH] Fix test_migration import Model migration tests were not run because of incorrect import. Run them in unit test mode instead of functional jobs. Also fix existing migrations and models which are not in sync. Change-Id: I4f7362972929308201776214fe01c007f14a6580 --- test-requirements.txt | 2 + tox.ini | 3 + vmware_nsx/db/extended_security_group.py | 4 +- .../d49ac91b560e_nsxv_lbaasv2_shared_pools.py | 2 +- vmware_nsx/db/migration/models/head.py | 2 + vmware_nsx/tests/unit/__init__.py | 2 - .../tests/{functional => unit}/db/__init__.py | 0 .../db/test_migrations.py | 74 +++++++++++++++++-- 8 files changed, 80 insertions(+), 9 deletions(-) rename vmware_nsx/tests/{functional => unit}/db/__init__.py (100%) rename vmware_nsx/tests/{functional => unit}/db/test_migrations.py (53%) diff --git a/test-requirements.txt b/test-requirements.txt index 0676e3726e..eeec94ddff 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -9,6 +9,8 @@ fixtures>=3.0.0 # Apache-2.0/BSD mock>=2.0 # BSD python-subunit>=0.0.18 # Apache-2.0/BSD sphinx!=1.3b1,<1.4,>=1.2.1 # BSD +psycopg2>=2.5 # LGPL/ZPL +PyMySQL!=0.7.7,>=0.6.2 # MIT License oslosphinx>=4.7.0 # Apache-2.0 oslotest>=1.10.0 # Apache-2.0 testrepository>=0.0.18 # Apache-2.0/BSD diff --git a/tox.ini b/tox.ini index ce72bbfd72..1b587be2d2 100644 --- a/tox.ini +++ b/tox.ini @@ -58,6 +58,9 @@ sitepackages = True [testenv:releasenotes] commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html +[testenv:py27] +setenv = OS_FAIL_ON_MISSING_DEPS=1 + [testenv:pep8] basepython = python2.7 deps = diff --git a/vmware_nsx/db/extended_security_group.py b/vmware_nsx/db/extended_security_group.py index 94011ca34a..d2765f5872 100644 --- a/vmware_nsx/db/extended_security_group.py +++ b/vmware_nsx/db/extended_security_group.py @@ -18,6 +18,7 @@ from oslo_utils import uuidutils import sqlalchemy as sa from sqlalchemy import orm from sqlalchemy.orm import exc +from sqlalchemy import sql from neutron.api.v2 import attributes from neutron.common import utils as n_utils @@ -41,7 +42,8 @@ class NsxExtendedSecurityGroupProperties(model_base.BASEV2): ondelete="CASCADE"), primary_key=True) logging = sa.Column(sa.Boolean, default=False, nullable=False) - provider = sa.Column(sa.Boolean, default=False, nullable=False) + provider = sa.Column(sa.Boolean, default=False, server_default=sql.false(), + nullable=False) security_group = orm.relationship( securitygroups_db.SecurityGroup, backref=orm.backref('ext_properties', lazy='joined', diff --git a/vmware_nsx/db/migration/alembic_migrations/versions/newton/contract/d49ac91b560e_nsxv_lbaasv2_shared_pools.py b/vmware_nsx/db/migration/alembic_migrations/versions/newton/contract/d49ac91b560e_nsxv_lbaasv2_shared_pools.py index 47ac1e2ed8..0951873bbe 100644 --- a/vmware_nsx/db/migration/alembic_migrations/versions/newton/contract/d49ac91b560e_nsxv_lbaasv2_shared_pools.py +++ b/vmware_nsx/db/migration/alembic_migrations/versions/newton/contract/d49ac91b560e_nsxv_lbaasv2_shared_pools.py @@ -46,6 +46,6 @@ def upgrade(): def change_pk_constraint(table_name, columns): inspector = reflection.Inspector.from_engine(op.get_bind()) pk_constraint = inspector.get_pk_constraint(table_name) - op.drop_constraint(pk_constraint, table_name, type_='primary') + op.drop_constraint(pk_constraint.get('name'), table_name, type_='primary') op.drop_column(table_name, 'listener_id') op.create_primary_key(None, table_name, columns) diff --git a/vmware_nsx/db/migration/models/head.py b/vmware_nsx/db/migration/models/head.py index 822d71655c..5b2d618119 100644 --- a/vmware_nsx/db/migration/models/head.py +++ b/vmware_nsx/db/migration/models/head.py @@ -14,6 +14,8 @@ from neutron.db.migration.models import head +from vmware_nsx.db import extended_security_group # noqa +from vmware_nsx.db import extended_security_group_rule # noqa from vmware_nsx.db import nsx_models # noqa from vmware_nsx.db import nsxv_models # noqa from vmware_nsx.db import vcns_models # noqa diff --git a/vmware_nsx/tests/unit/__init__.py b/vmware_nsx/tests/unit/__init__.py index cd4e83d217..b1aba0a50d 100644 --- a/vmware_nsx/tests/unit/__init__.py +++ b/vmware_nsx/tests/unit/__init__.py @@ -16,8 +16,6 @@ import os -from networking_l2gw.db.l2gateway import l2gateway_models # noqa - from vmware_nsx.api_client import client as nsx_client from vmware_nsx.api_client import eventlet_client from vmware_nsx import extensions diff --git a/vmware_nsx/tests/functional/db/__init__.py b/vmware_nsx/tests/unit/db/__init__.py similarity index 100% rename from vmware_nsx/tests/functional/db/__init__.py rename to vmware_nsx/tests/unit/db/__init__.py diff --git a/vmware_nsx/tests/functional/db/test_migrations.py b/vmware_nsx/tests/unit/db/test_migrations.py similarity index 53% rename from vmware_nsx/tests/functional/db/test_migrations.py rename to vmware_nsx/tests/unit/db/test_migrations.py index 0749cc79bb..639a2a43cf 100644 --- a/vmware_nsx/tests/functional/db/test_migrations.py +++ b/vmware_nsx/tests/unit/db/test_migrations.py @@ -22,11 +22,74 @@ from neutron.tests.functional.db import test_migrations from neutron.tests.unit import testlib_api from vmware_nsx.db.migration import alembic_migrations -from vmware_nsx.db.models import head +from vmware_nsx.db.migration.models import head + +#TODO(abhiraut): Remove this list from here once *aaS repos forms its +# own list. +# Add *aaS tables to EXTERNAL_TABLES since they should not be +# tested. +LBAAS_TABLES = { + 'nsxv_edge_monitor_mappings', + 'nsxv_edge_pool_mappings', + 'nsxv_edge_vip_mappings', + + # LBaaS v2 tables + 'lbaas_healthmonitors', + 'lbaas_l7policies', + 'lbaas_l7rules', + 'lbaas_listeners', + 'lbaas_loadbalancer_statistics', + 'lbaas_loadbalanceragentbindings', + 'lbaas_loadbalancers', + 'lbaas_members', + 'lbaas_pools', + 'lbaas_sessionpersistences', + 'lbaas_sni', +} + +L2GW_TABLES = { + 'l2gw_alembic_version', + 'physical_locators', + 'physical_switches', + 'physical_ports', + 'logical_switches', + 'ucast_macs_locals', + 'ucast_macs_remotes', + 'vlan_bindings', + 'l2gatewayconnections', + 'l2gatewayinterfaces', + 'l2gatewaydevices', + 'l2gateways', + 'pending_ucast_macs_remotes' +} + +SFC_TABLES = { + 'sfc_flow_classifier_l7_parameters', + 'sfc_flow_classifiers', + 'sfc_port_chain_parameters', + 'sfc_service_function_params', + 'sfc_port_pair_group_params', + 'sfc_chain_classifier_associations', + 'sfc_port_pairs', + 'sfc_chain_group_associations', + 'sfc_port_pair_groups', + 'sfc_port_chains', + 'sfc_uuid_intid_associations', + 'sfc_path_port_associations', + 'sfc_portpair_details', + 'sfc_path_nodes', +} + +TAAS_TABLES = { + 'tap_services', + 'tap_flows', + 'tap_id_associations', +} # EXTERNAL_TABLES should contain all names of tables that are not related to # current repo. -EXTERNAL_TABLES = set(external.TABLES) - set(external.REPO_VMWARE_TABLES) +EXTERNAL_TABLES = (set(external.TABLES) | LBAAS_TABLES | + L2GW_TABLES | SFC_TABLES | TAAS_TABLES) class _TestModelsMigrationsFoo(test_migrations._TestModelsMigrations): @@ -42,12 +105,13 @@ class _TestModelsMigrationsFoo(test_migrations._TestModelsMigrations): return head.get_metadata() def include_object(self, object_, name, type_, reflected, compare_to): - if type_ == 'table' and (name == 'alembic' or + if type_ == 'table' and (name.startswith('alembic') or name == alembic_migrations.VERSION_TABLE or name in EXTERNAL_TABLES): return False - else: - return True + if type_ == 'index' and reflected and name.startswith("idx_autoinc_"): + return False + return True class TestModelsMigrationsMysql(testlib_api.MySQLTestCaseMixin,