Replace TestCase with NoDBTestCase

It was suggested that we replace TestCase with NoDBTestCase [1]. This
does two things. First it prevents the test case setup from running the
database schema migrations unnecessarily which should improve
performance. Second it will cause the test to fail if the code does
touch the DB when the developer is claiming that it shouldn't.

[1] https://review.openstack.org/#/c/409404/46/nova/tests/unit/virt/powervm/test_media.py

Change-Id: I8bcc9cbdcadd9fe89a4450ca405387899baa9fc3
This commit is contained in:
esberglu 2017-11-07 11:44:07 -06:00
parent 3929e58001
commit c1a17ca319
22 changed files with 35 additions and 35 deletions

View File

@ -22,7 +22,7 @@ from nova_powervm import conf as cfg
CONF = cfg.CONF
class TestConf(test.TestCase):
class TestConf(test.NoDBTestCase):
def setUp(self):
super(TestConf, self).setUp()
@ -42,7 +42,7 @@ class TestConf(test.TestCase):
self.assertEqual(1, CONF.powervm.ports_per_fabric)
class TestConfBounds(test.TestCase):
class TestConfBounds(test.NoDBTestCase):
def setUp(self):
super(TestConfBounds, self).setUp()
@ -89,7 +89,7 @@ class TestConfBounds(test.TestCase):
ports_per_fabric=2)
class TestConfChoices(test.TestCase):
class TestConfChoices(test.NoDBTestCase):
def setUp(self):
super(TestConfChoices, self).setUp()
@ -141,7 +141,7 @@ class TestConfChoices(test.TestCase):
cfg.powervm.vol_adapter_opts, 'fc_attach_strategy')
class TestConfDynamic(test.TestCase):
class TestConfDynamic(test.NoDBTestCase):
def setUp(self):
super(TestConfDynamic, self).setUp()
self.conf_fx = self.useFixture(

View File

@ -23,7 +23,7 @@ from nova_powervm.tests.virt.powervm import fixtures as fx
from nova_powervm.virt.powervm.disk import driver as disk_dvr
class TestDiskAdapter(test.TestCase):
class TestDiskAdapter(test.NoDBTestCase):
"""Unit Tests for the generic storage driver."""
def setUp(self):

View File

@ -23,7 +23,7 @@ from pypowervm.wrappers import virtual_io_server as pvm_vios
from nova_powervm.virt.powervm.disk import imagecache as imagecache
class TestImageCache(test.TestCase):
class TestImageCache(test.NoDBTestCase):
"""Unit Tests for the LocalDisk storage driver."""
def setUp(self):

View File

@ -33,7 +33,7 @@ from nova_powervm.virt.powervm import exception as npvmex
from nova_powervm.virt.powervm import vm
class TestLocalDisk(test.TestCase):
class TestLocalDisk(test.NoDBTestCase):
"""Unit Tests for the LocalDisk storage driver."""
def setUp(self):

View File

@ -56,7 +56,7 @@ class SSPFixture(fixtures.Fixture):
'pypowervm.tasks.storage.default_tier_for_ssp')
class TestSSPDiskAdapter(test.TestCase):
class TestSSPDiskAdapter(test.NoDBTestCase):
"""Unit Tests for the LocalDisk storage driver."""
def setUp(self):

View File

@ -27,7 +27,7 @@ from nova_powervm.virt.powervm.nvram import manager
from nova_powervm.virt.powervm import vm
class TestNvramManager(test.TestCase):
class TestNvramManager(test.NoDBTestCase):
def setUp(self):
super(TestNvramManager, self).setUp()
self.fake_store = fake_api.NoopNvramStore()

View File

@ -25,7 +25,7 @@ from nova_powervm.virt.powervm.nvram import api
from nova_powervm.virt.powervm.nvram import swift
class TestSwiftStore(test.TestCase):
class TestSwiftStore(test.NoDBTestCase):
def setUp(self):
super(TestSwiftStore, self).setUp()

View File

@ -21,7 +21,7 @@ from nova import test
from nova_powervm.virt.powervm.tasks import image as tsk_img
class TestImage(test.TestCase):
class TestImage(test.NoDBTestCase):
def test_update_task_state(self):
def func(task_state, expected_state='delirious'):
self.assertEqual('task_state', task_state)

View File

@ -37,7 +37,7 @@ def cna(mac):
return nic
class TestNetwork(test.TestCase):
class TestNetwork(test.NoDBTestCase):
def setUp(self):
super(TestNetwork, self).setUp()
self.flags(host='host1')

View File

@ -21,7 +21,7 @@ from nova import test
from nova_powervm.virt.powervm.tasks import slot
class TestSaveSlotStore(test.TestCase):
class TestSaveSlotStore(test.NoDBTestCase):
def setUp(self):
super(TestSaveSlotStore, self).setUp()
@ -33,7 +33,7 @@ class TestSaveSlotStore(test.TestCase):
slot_mgr.save.assert_called_once_with()
class TestDeleteSlotStore(test.TestCase):
class TestDeleteSlotStore(test.NoDBTestCase):
def setUp(self):
super(TestDeleteSlotStore, self).setUp()

View File

@ -23,7 +23,7 @@ from nova_powervm.virt.powervm import exception as npvmex
from nova_powervm.virt.powervm.tasks import storage as tf_stg
class TestStorage(test.TestCase):
class TestStorage(test.NoDBTestCase):
def setUp(self):
super(TestStorage, self).setUp()

View File

@ -28,7 +28,7 @@ from taskflow.patterns import linear_flow as tf_lf
from taskflow import task as tf_tsk
class TestVMTasks(test.TestCase):
class TestVMTasks(test.NoDBTestCase):
def setUp(self):
super(TestVMTasks, self).setUp()
self.apt = mock.Mock()

View File

@ -53,7 +53,7 @@ LOG = logging.getLogger(__name__)
logging.basicConfig()
class TestPowerVMDriverInit(test.TestCase):
class TestPowerVMDriverInit(test.NoDBTestCase):
"""A test class specifically for the driver setup.
Handles testing the configuration of the agent with the backing REST API.
@ -86,7 +86,7 @@ class TestPowerVMDriverInit(test.TestCase):
mock_evt_listener.subscribe.assert_called_once_with('evt_hdlr')
class TestPowerVMDriver(test.TestCase):
class TestPowerVMDriver(test.NoDBTestCase):
def setUp(self):
super(TestPowerVMDriver, self).setUp()

View File

@ -24,7 +24,7 @@ from pypowervm.wrappers import event as pvm_evt
from nova_powervm.virt.powervm import event
class TestGetInstance(test.TestCase):
class TestGetInstance(test.NoDBTestCase):
@mock.patch('nova.context.get_admin_context')
@mock.patch('nova_powervm.virt.powervm.vm.get_instance')
def test_get_instance(self, mock_get_inst, mock_get_context):
@ -48,7 +48,7 @@ class TestGetInstance(test.TestCase):
# Don't reset mock_get_context
class TestPowerVMNovaEventHandler(test.TestCase):
class TestPowerVMNovaEventHandler(test.NoDBTestCase):
def setUp(self):
super(TestPowerVMNovaEventHandler, self).setUp()
lceh_process_p = mock.patch(
@ -282,7 +282,7 @@ class TestPowerVMNovaEventHandler(test.TestCase):
mock_get_instance.assert_not_called()
class TestPowerVMLifecycleEventHandler(test.TestCase):
class TestPowerVMLifecycleEventHandler(test.NoDBTestCase):
def setUp(self):
super(TestPowerVMLifecycleEventHandler, self).setUp()
self.mock_driver = mock.MagicMock()

View File

@ -27,7 +27,7 @@ else:
_BUILTIN = 'builtins'
class TestImage(test.TestCase):
class TestImage(test.NoDBTestCase):
@mock.patch('nova.utils.temporary_chown')
@mock.patch(_BUILTIN + '.open')

View File

@ -31,7 +31,7 @@ from nova_powervm.tests.virt.powervm import fixtures as fx
from nova_powervm.virt.powervm import live_migration as lpm
class TestLPM(test.TestCase):
class TestLPM(test.NoDBTestCase):
def setUp(self):
super(TestLPM, self).setUp()

View File

@ -27,7 +27,7 @@ from pypowervm.wrappers import virtual_io_server as pvm_vios
from nova_powervm.virt.powervm import media as m
class TestConfigDrivePowerVM(test.TestCase):
class TestConfigDrivePowerVM(test.NoDBTestCase):
"""Unit Tests for the ConfigDrivePowerVM class."""
def setUp(self):

View File

@ -28,7 +28,7 @@ from nova_powervm.virt.powervm import mgmt
LPAR_HTTPRESP_FILE = "lpar.txt"
class TestMgmt(test.TestCase):
class TestMgmt(test.NoDBTestCase):
def setUp(self):
super(TestMgmt, self).setUp()
self.apt = self.useFixture(pvm_fx.AdapterFx()).adpt

View File

@ -24,7 +24,7 @@ from nova_powervm.virt.powervm import slot
from pypowervm import exceptions as pvm_exc
class TestNovaSlotManager(test.TestCase):
class TestNovaSlotManager(test.NoDBTestCase):
def setUp(self):
super(TestNovaSlotManager, self).setUp()
@ -53,7 +53,7 @@ class TestNovaSlotManager(test.TestCase):
self.assertTrue(slot_mgr.is_rebuild)
class TestSwiftSlotManager(test.TestCase):
class TestSwiftSlotManager(test.NoDBTestCase):
def setUp(self):
super(TestSwiftSlotManager, self).setUp()

View File

@ -50,7 +50,7 @@ class FakeNetworkAPI(object):
return physnet
class TestVifFunctions(test.TestCase):
class TestVifFunctions(test.NoDBTestCase):
def setUp(self):
super(TestVifFunctions, self).setUp()
@ -358,7 +358,7 @@ class TestVifFunctions(test.TestCase):
vif._get_trunk_dev_name(mock_vif))
class TestVifSriovDriver(test.TestCase):
class TestVifSriovDriver(test.NoDBTestCase):
def setUp(self):
super(TestVifSriovDriver, self).setUp()
@ -571,7 +571,7 @@ class FakeDirectVif(dict):
return self._physnet
class TestVifSeaDriver(test.TestCase):
class TestVifSeaDriver(test.NoDBTestCase):
def setUp(self):
super(TestVifSeaDriver, self).setUp()
@ -672,7 +672,7 @@ class TestVifSeaDriver(test.TestCase):
self.assertEqual(1, cnas[2].delete.call_count)
class TestVifOvsDriver(test.TestCase):
class TestVifOvsDriver(test.NoDBTestCase):
def setUp(self):
super(TestVifOvsDriver, self).setUp()

View File

@ -55,7 +55,7 @@ class FakeAdapterResponse(object):
self.status = status
class TestVMBuilder(test.TestCase):
class TestVMBuilder(test.NoDBTestCase):
def setUp(self):
super(TestVMBuilder, self).setUp()
@ -263,7 +263,7 @@ class TestVMBuilder(test.TestCase):
self.lpar_b._flavor_bool, r, 'key')
class TestVM(test.TestCase):
class TestVM(test.NoDBTestCase):
def setUp(self):
super(TestVM, self).setUp()
self.apt = self.useFixture(pvm_fx.AdapterFx(

View File

@ -29,7 +29,7 @@ from nova_powervm.virt.powervm.volume import npiv
from nova_powervm.virt.powervm.volume import vscsi
class TestVolumeAdapter(test.TestCase):
class TestVolumeAdapter(test.NoDBTestCase):
def setUp(self):
super(TestVolumeAdapter, self).setUp()
@ -44,7 +44,7 @@ class TestVolumeAdapter(test.TestCase):
self.mock_get_inst_wrap.return_value = self.mock_inst_wrap
class TestInitMethods(test.TestCase):
class TestInitMethods(test.NoDBTestCase):
# Volume driver types to classes
volume_drivers = {