summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/test_compute.py24
-rw-r--r--nova/tests/test_scheduler.py5
-rw-r--r--nova/tests/test_service.py77
-rw-r--r--nova/tests/test_virt.py6
-rw-r--r--nova/tests/test_volume.py7
5 files changed, 52 insertions, 67 deletions
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index 85c2c948b..71899ba9e 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -89,14 +89,14 @@ class ComputeTestCase(test.TestCase):
Use this when any testcase executed later than test_run_terminate
"""
vol1 = models.Volume()
- vol1.__setitem__('id', 1)
+ vol1['id'] = 1
vol2 = models.Volume()
- vol2.__setitem__('id', 2)
+ vol2['id'] = 2
instance_ref = models.Instance()
- instance_ref.__setitem__('id', 1)
- instance_ref.__setitem__('volumes', [vol1, vol2])
- instance_ref.__setitem__('hostname', 'i-00000001')
- instance_ref.__setitem__('host', 'dummy')
+ instance_ref['id'] = 1
+ instance_ref['volumes'] = [vol1, vol2]
+ instance_ref['hostname'] = 'i-00000001'
+ instance_ref['host'] = 'dummy'
return instance_ref
def test_create_instance_defaults_display_name(self):
@@ -114,9 +114,9 @@ class ComputeTestCase(test.TestCase):
"""Make sure create associates security groups"""
group = self._create_group()
instance_ref = models.Instance()
- instance_ref.__setitem__('id', 1)
- instance_ref.__setitem__('volumes', [{'id': 1}, {'id': 2}])
- instance_ref.__setitem__('hostname', 'i-00000001')
+ instance_ref['id'] = 1
+ instance_ref['volumes'] = [{'id': 1}, {'id': 2}]
+ instance_ref['hostname'] = 'i-00000001'
return instance_ref
def test_create_instance_defaults_display_name(self):
@@ -390,7 +390,7 @@ class ComputeTestCase(test.TestCase):
def test_pre_live_migration_instance_has_no_volume(self):
"""Confirm log meg when instance doesn't mount any volumes."""
i_ref = self._get_dummy_instance()
- i_ref.__setitem__('volumes', [])
+ i_ref['volumes'] = []
c = context.get_admin_context()
self._setup_other_managers()
@@ -501,7 +501,7 @@ class ComputeTestCase(test.TestCase):
def test_live_migration_dest_raises_exception_no_volume(self):
"""Same as above test(input pattern is different) """
i_ref = self._get_dummy_instance()
- i_ref.__setitem__('volumes', [])
+ i_ref['volumes'] = []
c = context.get_admin_context()
topic = db.queue_get_for(c, FLAGS.compute_topic, i_ref['host'])
@@ -526,7 +526,7 @@ class ComputeTestCase(test.TestCase):
def test_live_migration_works_correctly_no_volume(self):
"""Confirm live_migration() works as expected correctly."""
i_ref = self._get_dummy_instance()
- i_ref.__setitem__('volumes', [])
+ i_ref['volumes'] = []
c = context.get_admin_context()
topic = db.queue_get_for(c, FLAGS.compute_topic, i_ref['host'])
diff --git a/nova/tests/test_scheduler.py b/nova/tests/test_scheduler.py
index 711b66af7..8ac02c5a4 100644
--- a/nova/tests/test_scheduler.py
+++ b/nova/tests/test_scheduler.py
@@ -119,7 +119,8 @@ class SchedulerTestCase(test.TestCase):
try:
scheduler.show_host_resources(ctxt, dest)
except exception.NotFound, e:
- c1 = (0 <= e.message.find('does not exist or not compute node'))
+ c1 = (e.message.find(_("does not exist or is not a "
+ "compute node.")) >= 0)
self.assertTrue(c1)
def _dic_is_equal(self, dic1, dic2, keys=None):
@@ -786,7 +787,7 @@ class SimpleDriverTestCase(test.TestCase):
i_ref,
'somewhere')
except exception.NotEmpty, e:
- c = (e.message.find('is not capable to migrate') >= 0)
+ c = (e.message.find('Unable to migrate') >= 0)
self.assertTrue(c)
db.instance_destroy(self.context, instance_id)
diff --git a/nova/tests/test_service.py b/nova/tests/test_service.py
index d17f6a22a..666c4a11d 100644
--- a/nova/tests/test_service.py
+++ b/nova/tests/test_service.py
@@ -42,24 +42,6 @@ class FakeManager(manager.Manager):
def test_method(self):
return 'manager'
-# temporary variable to store host/binary/self.mox
-# from each method to fake class.
-global_host = None
-global_binary = None
-global_mox = None
-
-
-class FakeComputeManager(compute_manager.ComputeManager):
- """Fake computemanager manager for tests"""
-
- def __init__(self, compute_driver=None, *args, **kwargs):
- global ghost, gbinary, gmox
- self.update_available_resource(mox.IgnoreArg())
- gmox.ReplayAll()
- super(FakeComputeManager, self).__init__(compute_driver,
- *args,
- **kwargs)
-
class ExtendedService(service.Service):
def test_method(self):
@@ -275,37 +257,38 @@ class ServiceTestCase(test.TestCase):
"""Confirm compute updates their record of compute-service table."""
host = 'foo'
binary = 'nova-compute'
- topic = 'compute1'
- service_create = {'host': host,
- 'binary': binary,
- 'topic': topic,
- 'report_count': 0,
- 'availability_zone': 'nova'}
- service_ref = {'host': host,
- 'binary': binary,
- 'topic': topic,
- 'report_count': 0,
- 'availability_zone': 'nova',
- 'id': 1}
-
- service.db.service_get_by_args(mox.IgnoreArg(),
- host,
- binary).AndRaise(exception.NotFound())
- service.db.service_create(mox.IgnoreArg(),
- service_create).AndReturn(service_ref)
- self.mox.StubOutWithMock(compute_manager.ComputeManager,
- 'update_available_resource')
-
- global ghost, gbinary, gmox
- ghost = host
- gbinary = binary
- gmox = self.mox
-
+ topic = 'compute'
+
+ # Any mocks are not working without UnsetStubs() here.
+ self.mox.UnsetStubs()
+ ctxt = context.get_admin_context()
+ service_ref = db.service_create(ctxt, {'host': host,
+ 'binary': binary,
+ 'topic': topic})
serv = service.Service(host,
binary,
topic,
- 'nova.tests.test_service.FakeComputeManager')
- # ReplayAll has been executed FakeComputeManager.__init__()
- #self.mox.ReplayAll()
+ 'nova.compute.manager.ComputeManager')
+
+ # This testcase want to test calling update_available_resource.
+ # No need to call periodic call, then below variable must be set 0.
+ serv.report_interval = 0
+ serv.periodic_interval = 0
+
+ # Creating mocks
+ self.mox.StubOutWithMock(service.rpc.Connection, 'instance')
+ service.rpc.Connection.instance(new=mox.IgnoreArg())
+ service.rpc.Connection.instance(new=mox.IgnoreArg())
+ self.mox.StubOutWithMock(serv.manager.driver,
+ 'update_available_resource')
+ serv.manager.driver.update_available_resource(mox.IgnoreArg(), host)
+
+ # Just doing start()-stop(), not confirm new db record is created,
+ # because update_available_resource() works only in libvirt environment.
+ # This testcase confirms update_available_resource() is called.
+ # Otherwise, mox complains.
+ self.mox.ReplayAll()
serv.start()
serv.stop()
+
+ db.service_destroy(ctxt, service_ref['id'])
diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py
index 7ea8c0fb5..ee41ae732 100644
--- a/nova/tests/test_virt.py
+++ b/nova/tests/test_virt.py
@@ -283,7 +283,7 @@ class LibvirtConnTestCase(test.TestCase):
self.assertEquals(uri, testuri)
db.instance_destroy(user_context, instance_ref['id'])
- def tes1t_update_available_resource_works_correctly(self):
+ def test_update_available_resource_works_correctly(self):
"""Confirm compute_node table is updated successfully."""
org_path = FLAGS.instances_path = ''
FLAGS.instances_path = '.'
@@ -314,7 +314,7 @@ class LibvirtConnTestCase(test.TestCase):
compute_node = service_ref['compute_node'][0]
if sys.platform.upper() == 'LINUX2':
- self.assertTrue(compute_node['vcpus'] > 0)
+ self.assertTrue(compute_node['vcpus'] >= 0)
self.assertTrue(compute_node['memory_mb'] > 0)
self.assertTrue(compute_node['local_gb'] > 0)
self.assertTrue(compute_node['vcpus_used'] == 0)
@@ -323,7 +323,7 @@ class LibvirtConnTestCase(test.TestCase):
self.assertTrue(len(compute_node['hypervisor_type']) > 0)
self.assertTrue(compute_node['hypervisor_version'] > 0)
else:
- self.assertTrue(compute_node['vcpus'] > 0)
+ self.assertTrue(compute_node['vcpus'] >= 0)
self.assertTrue(compute_node['memory_mb'] == 0)
self.assertTrue(compute_node['local_gb'] > 0)
self.assertTrue(compute_node['vcpus_used'] == 0)
diff --git a/nova/tests/test_volume.py b/nova/tests/test_volume.py
index e8b4ceee8..d88e363da 100644
--- a/nova/tests/test_volume.py
+++ b/nova/tests/test_volume.py
@@ -284,9 +284,10 @@ class AOETestCase(DriverTestCase):
self.volume.check_for_export(self.context, self.instance_id)
except exception.ProcessExecutionError, e:
volume_id = volume_id_list[0]
- msg = _("""Cannot confirm exported volume id:%(volume_id)s."""
- """vblade process for e%(shelf_id)s.%(blade_id)s """
- """isn't running.""") % locals()
+ msg = _("Cannot confirm exported volume id:%(volume_id)s. "
+ "vblade process for e%(shelf_id)s.%(blade_id)s "
+ "isn't running.") % locals()
+
msg_is_match = (0 <= e.message.find(msg))
self.assertTrue(msg_is_match)