summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorRick Harris <rconradharris@gmail.com>2013-05-25 01:01:13 +0000
committerRick Harris <rconradharris@gmail.com>2013-06-07 02:07:41 +0000
commitf261afdfbed05cef9d534e418ddd8bcb26970cc6 (patch)
tree274b4f73c7c6ef95192eb71e457bfa1ac9c6cf89 /nova/tests
parent7d423d3c919cd8b3526010981b0037e7579132d1 (diff)
downloadnova-f261afdfbed05cef9d534e418ddd8bcb26970cc6.tar.gz
nova-f261afdfbed05cef9d534e418ddd8bcb26970cc6.tar.xz
nova-f261afdfbed05cef9d534e418ddd8bcb26970cc6.zip
Speeding up scheduler tests
Database access is costly in tests and many tests don't actually need it. This patch provides a simple way we can speed up the Nova tests by providing a new base class, `NoDBTestCase` which allows us to white-list tests not needing database access. The following speedups were observed: With TestCase: Ran 265 tests in 17.080s With NoDBTestCase: Ran 265 tests in 9.478s Further optimizaton could be done by fixing `test_host_filters` to not hit the database. This will require some effort though in order to maintain the quality of test coverage since part of what's doing is testing the code in the DB layer. Change-Id: Ic34c4c39d7f680ac501efb459fdeaa51331ffe1c
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/scheduler/fakes.py10
-rw-r--r--nova/tests/scheduler/test_filter_scheduler.py33
-rw-r--r--nova/tests/scheduler/test_host_filters.py7
-rw-r--r--nova/tests/scheduler/test_host_manager.py6
-rw-r--r--nova/tests/scheduler/test_rpcapi.py2
-rw-r--r--nova/tests/scheduler/test_scheduler.py16
-rw-r--r--nova/tests/scheduler/test_scheduler_options.py2
-rw-r--r--nova/tests/scheduler/test_weights.py4
8 files changed, 56 insertions, 24 deletions
diff --git a/nova/tests/scheduler/fakes.py b/nova/tests/scheduler/fakes.py
index c9157d11c..3dfc7c452 100644
--- a/nova/tests/scheduler/fakes.py
+++ b/nova/tests/scheduler/fakes.py
@@ -18,7 +18,6 @@ Fakes For Scheduler tests.
import mox
-from nova.compute import flavors
from nova.compute import vm_states
from nova import db
from nova.scheduler import filter_scheduler
@@ -107,14 +106,14 @@ class FakeHostState(host_manager.HostState):
class FakeInstance(object):
- def __init__(self, context=None, params=None, type_name='m1.tiny'):
+ def __init__(self, context=None, params=None):
"""Create a test instance. Returns uuid."""
self.context = context
- i = self._create_fake_instance(params, type_name=type_name)
+ i = self._create_fake_instance(params=params)
self.uuid = i['uuid']
- def _create_fake_instance(self, params=None, type_name='m1.tiny'):
+ def _create_fake_instance(self, params=None):
"""Create a test instance."""
if not params:
params = {}
@@ -125,8 +124,7 @@ class FakeInstance(object):
inst['reservation_id'] = 'r-fakeres'
inst['user_id'] = 'fake'
inst['project_id'] = 'fake'
- type_id = flavors.get_instance_type_by_name(type_name)['id']
- inst['instance_type_id'] = type_id
+ inst['instance_type_id'] = 2
inst['ami_launch_index'] = 0
inst.update(params)
return db.instance_create(self.context, inst)
diff --git a/nova/tests/scheduler/test_filter_scheduler.py b/nova/tests/scheduler/test_filter_scheduler.py
index 80680dda8..919187fd8 100644
--- a/nova/tests/scheduler/test_filter_scheduler.py
+++ b/nova/tests/scheduler/test_filter_scheduler.py
@@ -18,7 +18,6 @@ Tests For Filter Scheduler.
import mox
-from nova.compute import flavors
from nova.compute import rpcapi as compute_rpcapi
from nova.compute import utils as compute_utils
from nova.compute import vm_states
@@ -78,6 +77,10 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase):
compute_utils.add_instance_fault_from_exc(fake_context,
mox.IsA(conductor_api.LocalAPI), new_ref,
mox.IsA(exception.NoValidHost), mox.IgnoreArg())
+
+ self.mox.StubOutWithMock(db, 'compute_node_get_all')
+ db.compute_node_get_all(mox.IgnoreArg()).AndReturn([])
+
self.mox.ReplayAll()
sched.schedule_run_instance(
fake_context, request_spec, None, None, None, None, {})
@@ -240,6 +243,10 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase):
request_spec = dict(instance_properties=instance_properties)
filter_properties = {}
+ self.mox.StubOutWithMock(db, 'compute_node_get_all')
+ db.compute_node_get_all(mox.IgnoreArg()).AndReturn([])
+ self.mox.ReplayAll()
+
sched._schedule(self.context, request_spec,
filter_properties=filter_properties)
@@ -255,6 +262,10 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase):
request_spec = dict(instance_properties=instance_properties)
filter_properties = {}
+ self.mox.StubOutWithMock(db, 'compute_node_get_all')
+ db.compute_node_get_all(mox.IgnoreArg()).AndReturn([])
+ self.mox.ReplayAll()
+
sched._schedule(self.context, request_spec,
filter_properties=filter_properties)
@@ -272,6 +283,10 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase):
retry = dict(num_attempts=1)
filter_properties = dict(retry=retry)
+ self.mox.StubOutWithMock(db, 'compute_node_get_all')
+ db.compute_node_get_all(mox.IgnoreArg()).AndReturn([])
+ self.mox.ReplayAll()
+
sched._schedule(self.context, request_spec,
filter_properties=filter_properties)
@@ -335,10 +350,22 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase):
sched = fakes.FakeFilterScheduler()
image = 'image'
- instance = db.instance_create(self.context, {})
+ instance = {'disable_terminate': False,
+ 'uuid': 'fakeuuid',
+ 'deleted': 0, 'info_cache': {},
+ 'created_at': None,
+ 'system_metadata': [], 'shutdown_terminate': False,
+ 'id': 1, 'security_groups': [], 'metadata': []}
instance_properties = {'project_id': 'fake', 'os_type': 'Linux'}
- instance_type = flavors.get_instance_type_by_name("m1.tiny")
+ instance_type = {
+ 'memory_mb': 1024, 'root_gb': 40, 'deleted_at': None,
+ 'name': u'm1.medium', 'deleted': 0, 'created_at': None,
+ 'ephemeral_gb': 0, 'updated_at': None, 'disabled': False,
+ 'vcpus': 2, 'extra_specs': {}, 'swap': 0,
+ 'rxtx_factor': 1.0, 'is_public': True, 'flavorid': u'3',
+ 'vcpu_weight': None, 'id': 1}
+
request_spec = {'instance_properties': instance_properties,
'instance_type': instance_type}
retry = {'hosts': [], 'num_attempts': 1}
diff --git a/nova/tests/scheduler/test_host_filters.py b/nova/tests/scheduler/test_host_filters.py
index 7d7c12339..b09e23f1d 100644
--- a/nova/tests/scheduler/test_host_filters.py
+++ b/nova/tests/scheduler/test_host_filters.py
@@ -44,7 +44,7 @@ class TestBogusFilter(object):
pass
-class ExtraSpecsOpsTestCase(test.TestCase):
+class ExtraSpecsOpsTestCase(test.NoDBTestCase):
def _do_extra_specs_ops_test(self, value, req, matches):
assertion = self.assertTrue if matches else self.assertFalse
assertion(extra_specs_ops.match(value, req))
@@ -230,8 +230,11 @@ class ExtraSpecsOpsTestCase(test.TestCase):
matches=False)
-class HostFiltersTestCase(test.TestCase):
+class HostFiltersTestCase(test.NoDBTestCase):
"""Test case for host filters."""
+ # FIXME(sirp): These tests still require DB access until we can separate
+ # the testing of the DB API code from the host-filter code.
+ USES_DB = True
def fake_oat_request(self, *args, **kwargs):
"""Stubs out the response from OAT service."""
diff --git a/nova/tests/scheduler/test_host_manager.py b/nova/tests/scheduler/test_host_manager.py
index c03c66c4e..8db62bfea 100644
--- a/nova/tests/scheduler/test_host_manager.py
+++ b/nova/tests/scheduler/test_host_manager.py
@@ -37,7 +37,7 @@ class FakeFilterClass2(filters.BaseHostFilter):
pass
-class HostManagerTestCase(test.TestCase):
+class HostManagerTestCase(test.NoDBTestCase):
"""Test case for HostManager class."""
def setUp(self):
@@ -358,7 +358,7 @@ class HostManagerTestCase(test.TestCase):
8388608)
-class HostManagerChangedNodesTestCase(test.TestCase):
+class HostManagerChangedNodesTestCase(test.NoDBTestCase):
"""Test case for HostManager class."""
def setUp(self):
@@ -416,7 +416,7 @@ class HostManagerChangedNodesTestCase(test.TestCase):
self.assertEqual(len(host_states_map), 0)
-class HostStateTestCase(test.TestCase):
+class HostStateTestCase(test.NoDBTestCase):
"""Test case for HostState class."""
# update_from_compute_node() and consume_from_instance() are tested
diff --git a/nova/tests/scheduler/test_rpcapi.py b/nova/tests/scheduler/test_rpcapi.py
index 44e6a91b8..cecc55f20 100644
--- a/nova/tests/scheduler/test_rpcapi.py
+++ b/nova/tests/scheduler/test_rpcapi.py
@@ -28,7 +28,7 @@ from nova import test
CONF = cfg.CONF
-class SchedulerRpcAPITestCase(test.TestCase):
+class SchedulerRpcAPITestCase(test.NoDBTestCase):
def _test_scheduler_api(self, method, rpc_method, **kwargs):
ctxt = context.RequestContext('fake_user', 'fake_project')
rpcapi = scheduler_rpcapi.SchedulerAPI()
diff --git a/nova/tests/scheduler/test_scheduler.py b/nova/tests/scheduler/test_scheduler.py
index f4f607647..7742962bd 100644
--- a/nova/tests/scheduler/test_scheduler.py
+++ b/nova/tests/scheduler/test_scheduler.py
@@ -48,7 +48,7 @@ from nova.tests.scheduler import fakes
from nova import utils
-class SchedulerManagerTestCase(test.TestCase):
+class SchedulerManagerTestCase(test.NoDBTestCase):
"""Test case for scheduler manager."""
manager_cls = manager.SchedulerManager
@@ -373,7 +373,7 @@ class SchedulerManagerTestCase(test.TestCase):
self.context, None, request)
-class SchedulerTestCase(test.TestCase):
+class SchedulerTestCase(test.NoDBTestCase):
"""Test case for base scheduler driver class."""
# So we can subclass this test and re-use tests if we need.
@@ -435,9 +435,13 @@ class SchedulerTestCase(test.TestCase):
self.assertEqual(result, ['host2'])
def _live_migration_instance(self):
- inst_type = flavors.get_instance_type(1)
- # NOTE(danms): we have _got_ to stop doing this!
- inst_type['memory_mb'] = 1024
+ inst_type = {'memory_mb': 1024, 'root_gb': 40, 'deleted_at': None,
+ 'name': u'm1.medium', 'deleted': 0, 'created_at': None,
+ 'ephemeral_gb': 0, 'updated_at': None, 'disabled': False,
+ 'vcpus': 2, 'extra_specs': {}, 'swap': 0,
+ 'rxtx_factor': 1.0, 'is_public': True, 'flavorid': u'3',
+ 'vcpu_weight': None, 'id': 1}
+
sys_meta = utils.dict_to_metadata(
flavors.save_instance_type_info({}, inst_type))
return {'id': 31337,
@@ -952,7 +956,7 @@ class SchedulerDriverBaseTestCase(SchedulerTestCase):
fake_request_spec, {}, {}, {}, None)
-class SchedulerDriverModuleTestCase(test.TestCase):
+class SchedulerDriverModuleTestCase(test.NoDBTestCase):
"""Test case for scheduler driver module methods."""
def setUp(self):
diff --git a/nova/tests/scheduler/test_scheduler_options.py b/nova/tests/scheduler/test_scheduler_options.py
index df54cde5f..6ab245ef9 100644
--- a/nova/tests/scheduler/test_scheduler_options.py
+++ b/nova/tests/scheduler/test_scheduler_options.py
@@ -50,7 +50,7 @@ class FakeSchedulerOptions(scheduler_options.SchedulerOptions):
return self._time_now
-class SchedulerOptionsTestCase(test.TestCase):
+class SchedulerOptionsTestCase(test.NoDBTestCase):
def test_get_configuration_first_time_no_flag(self):
last_checked = None
now = datetime.datetime(2012, 1, 1, 1, 1, 1)
diff --git a/nova/tests/scheduler/test_weights.py b/nova/tests/scheduler/test_weights.py
index aa0f0c15f..7495edacc 100644
--- a/nova/tests/scheduler/test_weights.py
+++ b/nova/tests/scheduler/test_weights.py
@@ -23,7 +23,7 @@ from nova.tests import matchers
from nova.tests.scheduler import fakes
-class TestWeighedHost(test.TestCase):
+class TestWeighedHost(test.NoDBTestCase):
def test_dict_conversion(self):
host_state = fakes.FakeHostState('somehost', None, {})
host = weights.WeighedHost(host_state, 'someweight')
@@ -38,7 +38,7 @@ class TestWeighedHost(test.TestCase):
self.assertIn('RAMWeigher', class_names)
-class RamWeigherTestCase(test.TestCase):
+class RamWeigherTestCase(test.NoDBTestCase):
def setUp(self):
super(RamWeigherTestCase, self).setUp()
self.host_manager = fakes.FakeHostManager()