Refactor test_ipam functional testing module

Use existing testing ifrastructure to better integrate with the rest of
Neutron tests. This change allows test_ipam module to work with future
db engine facade changes.

Change-Id: I6c95cce56f36dd0c97f727c337ef6af04bc13a40
Related-Bug: 1520719
This commit is contained in:
Ann Kamyshnikova 2016-04-14 20:27:54 +03:00
parent 81c61a9939
commit 71ccd79103
1 changed files with 19 additions and 46 deletions

View File

@ -14,7 +14,6 @@
# under the License.
from oslo_config import cfg
from oslo_db.sqlalchemy import session
import testtools
from neutron.api.v2 import attributes
@ -22,42 +21,32 @@ from neutron.common import constants
from neutron.common import exceptions as n_exc
from neutron import context
from neutron.db import db_base_plugin_v2 as base_plugin
from neutron.db import model_base
from neutron.db import models_v2
from neutron.ipam.drivers.neutrondb_ipam import db_models as ipam_models
from neutron.tests import base
from neutron.tests.common import base as common_base
from neutron.tests.unit import testlib_api
def get_admin_test_context(db_url):
"""
get_admin_test_context is used to provide a test context. A new session is
created using the db url specified
"""
ctx = context.Context(user_id=None,
tenant_id=None,
is_admin=True,
overwrite=False)
facade = session.EngineFacade(db_url, mysql_sql_mode='STRICT_ALL_TABLES')
ctx._session = facade.get_session(autocommit=False, expire_on_commit=True)
return ctx
class IpamTestCase(object):
class IpamTestCase(base.BaseTestCase):
"""
Base class for tests that aim to test ip allocation.
"""
use_pluggable_ipam = False
def configure_test(self, use_pluggable_ipam=False):
model_base.BASEV2.metadata.create_all(self.engine)
def setUp(self):
super(IpamTestCase, self).setUp()
cfg.CONF.set_override('notify_nova_on_port_status_changes', False)
if use_pluggable_ipam:
self.useFixture(testlib_api.SqlFixture())
if self.use_pluggable_ipam:
self._turn_on_pluggable_ipam()
else:
self._turn_off_pluggable_ipam()
self.plugin = base_plugin.NeutronDbPluginV2()
self.cxt = get_admin_test_context(self.engine.url)
self.addCleanup(self.cxt._session.close)
self.cxt = context.Context(user_id=None,
tenant_id=None,
is_admin=True,
overwrite=False)
self.tenant_id = 'test_tenant'
self.network_id = 'test_net_id'
self.subnet_id = 'test_sub_id'
@ -219,33 +208,17 @@ class IpamTestCase(object):
ip_avail_ranges_expected)
class TestIpamMySql(common_base.MySQLTestCase, base.BaseTestCase,
IpamTestCase):
def setUp(self):
super(TestIpamMySql, self).setUp()
self.configure_test()
class TestIpamMySql(common_base.MySQLTestCase, IpamTestCase):
pass
class TestIpamPsql(common_base.PostgreSQLTestCase,
base.BaseTestCase, IpamTestCase):
def setUp(self):
super(TestIpamPsql, self).setUp()
self.configure_test()
class TestIpamPsql(common_base.PostgreSQLTestCase, IpamTestCase):
pass
class TestPluggableIpamMySql(common_base.MySQLTestCase,
base.BaseTestCase, IpamTestCase):
def setUp(self):
super(TestPluggableIpamMySql, self).setUp()
self.configure_test(use_pluggable_ipam=True)
class TestPluggableIpamMySql(common_base.MySQLTestCase, IpamTestCase):
use_pluggable_ipam = True
class TestPluggableIpamPsql(common_base.PostgreSQLTestCase,
base.BaseTestCase, IpamTestCase):
def setUp(self):
super(TestPluggableIpamPsql, self).setUp()
self.configure_test(use_pluggable_ipam=True)
class TestPluggableIpamPsql(common_base.PostgreSQLTestCase, IpamTestCase):
use_pluggable_ipam = True