Fixed based on reviewer's comment.
1. Change docstrings format 2. Fix comment grammer mistake, etc
This commit is contained in:
@@ -38,13 +38,11 @@ from nova import flags
|
|||||||
from nova import log as logging
|
from nova import log as logging
|
||||||
from nova import version
|
from nova import version
|
||||||
from nova import wsgi
|
from nova import wsgi
|
||||||
from nova import utils
|
|
||||||
|
|
||||||
logging.basicConfig()
|
logging.basicConfig()
|
||||||
LOG = logging.getLogger('nova.api')
|
LOG = logging.getLogger('nova.api')
|
||||||
LOG.setLevel(logging.DEBUG)
|
LOG.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
utils.default_flagfile()
|
|
||||||
FLAGS = flags.FLAGS
|
FLAGS = flags.FLAGS
|
||||||
|
|
||||||
API_ENDPOINTS = ['ec2', 'osapi']
|
API_ENDPOINTS = ['ec2', 'osapi']
|
||||||
|
|||||||
@@ -125,7 +125,6 @@ def main():
|
|||||||
LOG.debug(msg)
|
LOG.debug(msg)
|
||||||
globals()[action + '_lease'](mac, ip, hostname, interface)
|
globals()[action + '_lease'](mac, ip, hostname, interface)
|
||||||
else:
|
else:
|
||||||
open('/tmp/aaa', 'w+').write('-- %s' % interface)
|
|
||||||
print init_leases(interface)
|
print init_leases(interface)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -548,7 +548,12 @@ class InstanceCommands(object):
|
|||||||
"""Class for mangaging VM instances."""
|
"""Class for mangaging VM instances."""
|
||||||
|
|
||||||
def live_migration(self, ec2_id, dest):
|
def live_migration(self, ec2_id, dest):
|
||||||
"""Migrates a running instance to a new machine."""
|
"""Migrates a running instance to a new machine.
|
||||||
|
|
||||||
|
:param ec2_id: instance id which comes from euca-describe-instance.
|
||||||
|
:param dest: destination host name.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
ctxt = context.get_admin_context()
|
ctxt = context.get_admin_context()
|
||||||
instance_id = ec2_id_to_id(ec2_id)
|
instance_id = ec2_id_to_id(ec2_id)
|
||||||
@@ -569,9 +574,8 @@ class InstanceCommands(object):
|
|||||||
"dest": dest,
|
"dest": dest,
|
||||||
"topic": FLAGS.compute_topic}})
|
"topic": FLAGS.compute_topic}})
|
||||||
|
|
||||||
msg = 'Migration of %s initiated. ' % ec2_id
|
print _('Migration of %s initiated.'
|
||||||
msg += 'Check its progress using euca-describe-instances.'
|
'Check its progress using euca-describe-instances.') % ec2_id
|
||||||
print msg
|
|
||||||
|
|
||||||
|
|
||||||
class ServiceCommands(object):
|
class ServiceCommands(object):
|
||||||
@@ -619,15 +623,17 @@ class ServiceCommands(object):
|
|||||||
db.service_update(ctxt, svc['id'], {'disabled': True})
|
db.service_update(ctxt, svc['id'], {'disabled': True})
|
||||||
|
|
||||||
def describe_resource(self, host):
|
def describe_resource(self, host):
|
||||||
"""describe cpu/memory/hdd info for host."""
|
"""Describes cpu/memory/hdd info for host.
|
||||||
|
|
||||||
|
:param host: hostname.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
result = rpc.call(context.get_admin_context(),
|
result = rpc.call(context.get_admin_context(),
|
||||||
FLAGS.scheduler_topic,
|
FLAGS.scheduler_topic,
|
||||||
{"method": "show_host_resource",
|
{"method": "show_host_resources",
|
||||||
"args": {"host": host}})
|
"args": {"host": host}})
|
||||||
|
|
||||||
# Checking result msg format is necessary, that will have done
|
|
||||||
# when this feture is included in API.
|
|
||||||
if type(result) != dict:
|
if type(result) != dict:
|
||||||
print 'Unexpected error occurs'
|
print 'Unexpected error occurs'
|
||||||
print '[Result]', result
|
print '[Result]', result
|
||||||
@@ -650,7 +656,11 @@ class ServiceCommands(object):
|
|||||||
val['local_gb'])
|
val['local_gb'])
|
||||||
|
|
||||||
def update_resource(self, host):
|
def update_resource(self, host):
|
||||||
"""update available vcpu/memory/disk info for host."""
|
"""Updates available vcpu/memory/disk info for host.
|
||||||
|
|
||||||
|
:param host: hostname.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
ctxt = context.get_admin_context()
|
ctxt = context.get_admin_context()
|
||||||
service_refs = db.service_get_all_by_host(ctxt, host)
|
service_refs = db.service_get_all_by_host(ctxt, host)
|
||||||
|
|||||||
@@ -314,10 +314,7 @@ class ComputeTestCase(test.TestCase):
|
|||||||
self.compute_driver = utils.import_object(FLAGS.compute_driver)
|
self.compute_driver = utils.import_object(FLAGS.compute_driver)
|
||||||
|
|
||||||
def test_pre_live_migration_instance_has_no_fixed_ip(self):
|
def test_pre_live_migration_instance_has_no_fixed_ip(self):
|
||||||
"""
|
"""Confirm raising exception if instance doesn't have fixed_ip."""
|
||||||
if instances that are intended to be migrated doesnt have fixed_ip
|
|
||||||
(not happens usually), pre_live_migration has to raise Exception.
|
|
||||||
"""
|
|
||||||
instance_ref = self._get_dummy_instance()
|
instance_ref = self._get_dummy_instance()
|
||||||
c = context.get_admin_context()
|
c = context.get_admin_context()
|
||||||
i_id = instance_ref['id']
|
i_id = instance_ref['id']
|
||||||
@@ -331,14 +328,9 @@ class ComputeTestCase(test.TestCase):
|
|||||||
self.assertRaises(exception.NotFound,
|
self.assertRaises(exception.NotFound,
|
||||||
self.compute.pre_live_migration,
|
self.compute.pre_live_migration,
|
||||||
c, instance_ref['id'])
|
c, instance_ref['id'])
|
||||||
self.mox.ResetAll()
|
|
||||||
|
|
||||||
def test_pre_live_migration_instance_has_volume(self):
|
def test_pre_live_migration_instance_has_volume(self):
|
||||||
"""if any volumes are attached to the instances that are
|
"""Confirm setup_compute_volume is called when volume is mounted."""
|
||||||
intended to be migrated, setup_compute_volume must be
|
|
||||||
called because aoe module should be inserted at destination
|
|
||||||
host. This testcase checks on it.
|
|
||||||
"""
|
|
||||||
i_ref = self._get_dummy_instance()
|
i_ref = self._get_dummy_instance()
|
||||||
c = context.get_admin_context()
|
c = context.get_admin_context()
|
||||||
|
|
||||||
@@ -364,14 +356,9 @@ class ComputeTestCase(test.TestCase):
|
|||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
ret = self.compute.pre_live_migration(c, i_ref['id'])
|
ret = self.compute.pre_live_migration(c, i_ref['id'])
|
||||||
self.assertEqual(ret, None)
|
self.assertEqual(ret, None)
|
||||||
self.mox.ResetAll()
|
|
||||||
|
|
||||||
def test_pre_live_migration_instance_has_no_volume(self):
|
def test_pre_live_migration_instance_has_no_volume(self):
|
||||||
"""if any volumes are not attached to the instances that are
|
"""Confirm log meg when instance doesn't mount any volumes."""
|
||||||
intended to be migrated, log message should be appears
|
|
||||||
because administrator can proove instance conditions before
|
|
||||||
live_migration if any trouble occurs.
|
|
||||||
"""
|
|
||||||
i_ref = self._get_dummy_instance()
|
i_ref = self._get_dummy_instance()
|
||||||
i_ref.__setitem__('volumes', [])
|
i_ref.__setitem__('volumes', [])
|
||||||
c = context.get_admin_context()
|
c = context.get_admin_context()
|
||||||
@@ -395,14 +382,14 @@ class ComputeTestCase(test.TestCase):
|
|||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
ret = self.compute.pre_live_migration(c, i_ref['id'])
|
ret = self.compute.pre_live_migration(c, i_ref['id'])
|
||||||
self.assertEqual(ret, None)
|
self.assertEqual(ret, None)
|
||||||
self.mox.ResetAll()
|
|
||||||
|
|
||||||
def test_pre_live_migration_setup_compute_node_fail(self):
|
def test_pre_live_migration_setup_compute_node_fail(self):
|
||||||
"""setup_compute_node sometimes fail since concurrent request
|
"""Confirm operation setup_compute_network() fails.
|
||||||
comes to iptables and iptables complains. Then this method
|
|
||||||
tries to retry, but raise exception in case of over
|
It retries and raise exception when timeout exceeded.
|
||||||
max_retry_count. this method confirms raising exception.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
i_ref = self._get_dummy_instance()
|
i_ref = self._get_dummy_instance()
|
||||||
c = context.get_admin_context()
|
c = context.get_admin_context()
|
||||||
|
|
||||||
@@ -427,14 +414,9 @@ class ComputeTestCase(test.TestCase):
|
|||||||
self.assertRaises(exception.ProcessExecutionError,
|
self.assertRaises(exception.ProcessExecutionError,
|
||||||
self.compute.pre_live_migration,
|
self.compute.pre_live_migration,
|
||||||
c, i_ref['id'])
|
c, i_ref['id'])
|
||||||
self.mox.ResetAll()
|
|
||||||
|
|
||||||
def test_live_migration_instance_has_volume(self):
|
def test_live_migration_works_correctly_with_volume(self):
|
||||||
"""Any volumes are mounted by instances to be migrated are found,
|
"""Confirm check_for_export to confirm volume health check."""
|
||||||
vblade health must be checked before starting live-migration.
|
|
||||||
And that is checked by check_for_export().
|
|
||||||
This testcase confirms check_for_export() is called.
|
|
||||||
"""
|
|
||||||
i_ref = self._get_dummy_instance()
|
i_ref = self._get_dummy_instance()
|
||||||
c = context.get_admin_context()
|
c = context.get_admin_context()
|
||||||
topic = db.queue_get_for(c, FLAGS.compute_topic, i_ref['host'])
|
topic = db.queue_get_for(c, FLAGS.compute_topic, i_ref['host'])
|
||||||
@@ -457,15 +439,9 @@ class ComputeTestCase(test.TestCase):
|
|||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
ret = self.compute.live_migration(c, i_ref['id'], i_ref['host'])
|
ret = self.compute.live_migration(c, i_ref['id'], i_ref['host'])
|
||||||
self.assertEqual(ret, None)
|
self.assertEqual(ret, None)
|
||||||
self.mox.ResetAll()
|
|
||||||
|
|
||||||
def test_live_migration_instance_has_volume_and_exception(self):
|
def test_live_migration_dest_raises_exception(self):
|
||||||
"""In addition to test_live_migration_instance_has_volume testcase,
|
"""Confirm exception when pre_live_migration fails."""
|
||||||
this testcase confirms if any exception raises from
|
|
||||||
check_for_export(). Then, valid seaquence of this method should
|
|
||||||
recovering instance/volumes status(ex. instance['state_description']
|
|
||||||
is changed from 'migrating' -> 'running', was changed by scheduler)
|
|
||||||
"""
|
|
||||||
i_ref = self._get_dummy_instance()
|
i_ref = self._get_dummy_instance()
|
||||||
c = context.get_admin_context()
|
c = context.get_admin_context()
|
||||||
topic = db.queue_get_for(c, FLAGS.compute_topic, i_ref['host'])
|
topic = db.queue_get_for(c, FLAGS.compute_topic, i_ref['host'])
|
||||||
@@ -484,20 +460,16 @@ class ComputeTestCase(test.TestCase):
|
|||||||
'state': power_state.RUNNING,
|
'state': power_state.RUNNING,
|
||||||
'host': i_ref['host']})
|
'host': i_ref['host']})
|
||||||
for v in i_ref['volumes']:
|
for v in i_ref['volumes']:
|
||||||
dbmock.volume_update(c, v['id'], {'status': 'in-use',
|
dbmock.volume_update(c, v['id'], {'status': 'in-use'})
|
||||||
'host': i_ref['host']})
|
|
||||||
|
|
||||||
self.compute.db = dbmock
|
self.compute.db = dbmock
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
self.assertRaises(rpc.RemoteError,
|
self.assertRaises(rpc.RemoteError,
|
||||||
self.compute.live_migration,
|
self.compute.live_migration,
|
||||||
c, i_ref['id'], i_ref['host'])
|
c, i_ref['id'], i_ref['host'])
|
||||||
self.mox.ResetAll()
|
|
||||||
|
|
||||||
def test_live_migration_instance_has_no_volume_and_exception(self):
|
def test_live_migration_dest_raises_exception_no_volume(self):
|
||||||
"""Simpler than
|
"""Same as above test(input pattern is different) """
|
||||||
test_live_migration_instance_has_volume_and_exception
|
|
||||||
"""
|
|
||||||
i_ref = self._get_dummy_instance()
|
i_ref = self._get_dummy_instance()
|
||||||
i_ref.__setitem__('volumes', [])
|
i_ref.__setitem__('volumes', [])
|
||||||
c = context.get_admin_context()
|
c = context.get_admin_context()
|
||||||
@@ -520,10 +492,9 @@ class ComputeTestCase(test.TestCase):
|
|||||||
self.assertRaises(rpc.RemoteError,
|
self.assertRaises(rpc.RemoteError,
|
||||||
self.compute.live_migration,
|
self.compute.live_migration,
|
||||||
c, i_ref['id'], i_ref['host'])
|
c, i_ref['id'], i_ref['host'])
|
||||||
self.mox.ResetAll()
|
|
||||||
|
|
||||||
def test_live_migration_instance_has_no_volume(self):
|
def test_live_migration_works_correctly_no_volume(self):
|
||||||
"""Simpler than test_live_migration_instance_has_volume."""
|
"""Confirm live_migration() works as expected correctly."""
|
||||||
i_ref = self._get_dummy_instance()
|
i_ref = self._get_dummy_instance()
|
||||||
i_ref.__setitem__('volumes', [])
|
i_ref.__setitem__('volumes', [])
|
||||||
c = context.get_admin_context()
|
c = context.get_admin_context()
|
||||||
@@ -545,11 +516,9 @@ class ComputeTestCase(test.TestCase):
|
|||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
ret = self.compute.live_migration(c, i_ref['id'], i_ref['host'])
|
ret = self.compute.live_migration(c, i_ref['id'], i_ref['host'])
|
||||||
self.assertEqual(ret, None)
|
self.assertEqual(ret, None)
|
||||||
self.mox.ResetAll()
|
|
||||||
|
|
||||||
def test_post_live_migration_working_correctly(self):
|
def test_post_live_migration_working_correctly(self):
|
||||||
"""post_live_migration works as expected correctly """
|
"""Confirm post_live_migration() works as expected correctly."""
|
||||||
|
|
||||||
dest = 'desthost'
|
dest = 'desthost'
|
||||||
flo_addr = '1.2.1.2'
|
flo_addr = '1.2.1.2'
|
||||||
|
|
||||||
@@ -579,19 +548,15 @@ class ComputeTestCase(test.TestCase):
|
|||||||
# executing
|
# executing
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
ret = self.compute.post_live_migration(c, i_ref, dest)
|
ret = self.compute.post_live_migration(c, i_ref, dest)
|
||||||
self.mox.UnsetStubs()
|
|
||||||
|
|
||||||
# make sure every data is rewritten to dest
|
# make sure every data is rewritten to dest
|
||||||
i_ref = db.instance_get(c, i_ref['id'])
|
i_ref = db.instance_get(c, i_ref['id'])
|
||||||
c1 = (i_ref['host'] == dest)
|
c1 = (i_ref['host'] == dest)
|
||||||
v_ref = db.volume_get(c, v_ref['id'])
|
|
||||||
c2 = (v_ref['host'] == dest)
|
|
||||||
c3 = False
|
|
||||||
flo_refs = db.floating_ip_get_all_by_host(c, dest)
|
flo_refs = db.floating_ip_get_all_by_host(c, dest)
|
||||||
c3 = (len(flo_refs) != 0 and flo_refs[0]['address'] == flo_addr)
|
c2 = (len(flo_refs) != 0 and flo_refs[0]['address'] == flo_addr)
|
||||||
|
|
||||||
# post operaton
|
# post operaton
|
||||||
self.assertTrue(c1 and c2 and c3)
|
self.assertTrue(c1 and c2)
|
||||||
db.instance_destroy(c, instance_id)
|
db.instance_destroy(c, instance_id)
|
||||||
db.volume_destroy(c, v_ref['id'])
|
db.volume_destroy(c, v_ref['id'])
|
||||||
db.floating_ip_destroy(c, flo_addr)
|
db.floating_ip_destroy(c, flo_addr)
|
||||||
|
|||||||
@@ -108,22 +108,21 @@ class SchedulerTestCase(test.TestCase):
|
|||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
scheduler.named_method(ctxt, 'topic', num=7)
|
scheduler.named_method(ctxt, 'topic', num=7)
|
||||||
|
|
||||||
def test_show_host_resource_host_not_exit(self):
|
def test_show_host_resources_host_not_exit(self):
|
||||||
"""
|
"""A host given as an argument does not exists."""
|
||||||
A testcase of driver.has_enough_resource
|
|
||||||
given host does not exists.
|
|
||||||
"""
|
|
||||||
scheduler = manager.SchedulerManager()
|
scheduler = manager.SchedulerManager()
|
||||||
dest = 'dummydest'
|
dest = 'dummydest'
|
||||||
ctxt = context.get_admin_context()
|
ctxt = context.get_admin_context()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
scheduler.show_host_resource(ctxt, dest)
|
scheduler.show_host_resources(ctxt, dest)
|
||||||
except exception.NotFound, e:
|
except exception.NotFound, e:
|
||||||
c1 = (0 <= e.message.find('does not exist or not compute node'))
|
c1 = (0 <= e.message.find('does not exist or not compute node'))
|
||||||
self.assertTrue(c1)
|
self.assertTrue(c1)
|
||||||
|
|
||||||
def _dic_is_equal(self, dic1, dic2, keys=None):
|
def _dic_is_equal(self, dic1, dic2, keys=None):
|
||||||
|
"""Compares 2 dictionary contents(Helper method)"""
|
||||||
if not keys:
|
if not keys:
|
||||||
keys = ['vcpus', 'memory_mb', 'local_gb',
|
keys = ['vcpus', 'memory_mb', 'local_gb',
|
||||||
'vcpus_used', 'memory_mb_used', 'local_gb_used']
|
'vcpus_used', 'memory_mb_used', 'local_gb_used']
|
||||||
@@ -133,16 +132,14 @@ class SchedulerTestCase(test.TestCase):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def test_show_host_resource_no_project(self):
|
def test_show_host_resources_no_project(self):
|
||||||
"""
|
"""No instance are running on the given host."""
|
||||||
A testcase of driver.show_host_resource
|
|
||||||
no instance stays on the given host
|
|
||||||
"""
|
|
||||||
scheduler = manager.SchedulerManager()
|
scheduler = manager.SchedulerManager()
|
||||||
ctxt = context.get_admin_context()
|
ctxt = context.get_admin_context()
|
||||||
s_ref = self._create_compute_service()
|
s_ref = self._create_compute_service()
|
||||||
|
|
||||||
result = scheduler.show_host_resource(ctxt, s_ref['host'])
|
result = scheduler.show_host_resources(ctxt, s_ref['host'])
|
||||||
|
|
||||||
# result checking
|
# result checking
|
||||||
c1 = ('resource' in result and 'usage' in result)
|
c1 = ('resource' in result and 'usage' in result)
|
||||||
@@ -152,11 +149,9 @@ class SchedulerTestCase(test.TestCase):
|
|||||||
self.assertTrue(c1 and c2 and c3)
|
self.assertTrue(c1 and c2 and c3)
|
||||||
db.service_destroy(ctxt, s_ref['id'])
|
db.service_destroy(ctxt, s_ref['id'])
|
||||||
|
|
||||||
def test_show_host_resource_works_correctly(self):
|
def test_show_host_resources_works_correctly(self):
|
||||||
"""
|
"""show_host_resources() works correctly as expected."""
|
||||||
A testcase of driver.show_host_resource
|
|
||||||
to make sure everything finished with no error.
|
|
||||||
"""
|
|
||||||
scheduler = manager.SchedulerManager()
|
scheduler = manager.SchedulerManager()
|
||||||
ctxt = context.get_admin_context()
|
ctxt = context.get_admin_context()
|
||||||
s_ref = self._create_compute_service()
|
s_ref = self._create_compute_service()
|
||||||
@@ -164,7 +159,7 @@ class SchedulerTestCase(test.TestCase):
|
|||||||
i_ref2 = self._create_instance(project_id='p-02', vcpus=3,
|
i_ref2 = self._create_instance(project_id='p-02', vcpus=3,
|
||||||
host=s_ref['host'])
|
host=s_ref['host'])
|
||||||
|
|
||||||
result = scheduler.show_host_resource(ctxt, s_ref['host'])
|
result = scheduler.show_host_resources(ctxt, s_ref['host'])
|
||||||
|
|
||||||
c1 = ('resource' in result and 'usage' in result)
|
c1 = ('resource' in result and 'usage' in result)
|
||||||
compute_service = s_ref['compute_service'][0]
|
compute_service = s_ref['compute_service'][0]
|
||||||
@@ -284,6 +279,7 @@ class SimpleDriverTestCase(test.TestCase):
|
|||||||
return db.volume_create(self.context, vol)['id']
|
return db.volume_create(self.context, vol)['id']
|
||||||
|
|
||||||
def _create_compute_service(self, **kwargs):
|
def _create_compute_service(self, **kwargs):
|
||||||
|
"""Create a compute service."""
|
||||||
|
|
||||||
dic = {'binary': 'nova-compute', 'topic': 'compute',
|
dic = {'binary': 'nova-compute', 'topic': 'compute',
|
||||||
'report_count': 0, 'availability_zone': 'dummyzone'}
|
'report_count': 0, 'availability_zone': 'dummyzone'}
|
||||||
@@ -698,13 +694,13 @@ class SimpleDriverTestCase(test.TestCase):
|
|||||||
volume1.kill()
|
volume1.kill()
|
||||||
volume2.kill()
|
volume2.kill()
|
||||||
|
|
||||||
def test_scheduler_live_migraiton_with_volume(self):
|
def test_scheduler_live_migration_with_volume(self):
|
||||||
"""
|
"""scheduler_live_migration() works correctly as expected.
|
||||||
driver.scheduler_live_migration finishes successfully
|
|
||||||
(volumes are attached to instances)
|
Also, checks instance state is changed from 'running' -> 'migrating'.
|
||||||
This testcase make sure schedule_live_migration
|
|
||||||
changes instance state from 'running' -> 'migrating'
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
instance_id = self._create_instance()
|
instance_id = self._create_instance()
|
||||||
i_ref = db.instance_get(self.context, instance_id)
|
i_ref = db.instance_get(self.context, instance_id)
|
||||||
dic = {'instance_id': instance_id, 'size': 1}
|
dic = {'instance_id': instance_id, 'size': 1}
|
||||||
@@ -737,11 +733,9 @@ class SimpleDriverTestCase(test.TestCase):
|
|||||||
db.instance_destroy(self.context, instance_id)
|
db.instance_destroy(self.context, instance_id)
|
||||||
db.volume_destroy(self.context, v_ref['id'])
|
db.volume_destroy(self.context, v_ref['id'])
|
||||||
|
|
||||||
def test_live_migraiton_src_check_instance_not_running(self):
|
def test_live_migration_src_check_instance_not_running(self):
|
||||||
"""
|
"""The instance given by instance_id is not running."""
|
||||||
A testcase of driver._live_migration_src_check.
|
|
||||||
The instance given by instance_id is not running.
|
|
||||||
"""
|
|
||||||
instance_id = self._create_instance(state_description='migrating')
|
instance_id = self._create_instance(state_description='migrating')
|
||||||
i_ref = db.instance_get(self.context, instance_id)
|
i_ref = db.instance_get(self.context, instance_id)
|
||||||
|
|
||||||
@@ -754,12 +748,9 @@ class SimpleDriverTestCase(test.TestCase):
|
|||||||
self.assertTrue(c)
|
self.assertTrue(c)
|
||||||
db.instance_destroy(self.context, instance_id)
|
db.instance_destroy(self.context, instance_id)
|
||||||
|
|
||||||
def test_live_migraiton_src_check_volume_node_not_alive(self):
|
def test_live_migration_src_check_volume_node_not_alive(self):
|
||||||
"""
|
"""Raise exception when volume node is not alive."""
|
||||||
A testcase of driver._live_migration_src_check.
|
|
||||||
Volume node is not alive if any volumes are attached to
|
|
||||||
the given instance.
|
|
||||||
"""
|
|
||||||
instance_id = self._create_instance()
|
instance_id = self._create_instance()
|
||||||
i_ref = db.instance_get(self.context, instance_id)
|
i_ref = db.instance_get(self.context, instance_id)
|
||||||
dic = {'instance_id': instance_id, 'size': 1}
|
dic = {'instance_id': instance_id, 'size': 1}
|
||||||
@@ -782,11 +773,8 @@ class SimpleDriverTestCase(test.TestCase):
|
|||||||
db.service_destroy(self.context, s_ref['id'])
|
db.service_destroy(self.context, s_ref['id'])
|
||||||
db.volume_destroy(self.context, v_ref['id'])
|
db.volume_destroy(self.context, v_ref['id'])
|
||||||
|
|
||||||
def test_live_migraiton_src_check_compute_node_not_alive(self):
|
def test_live_migration_src_check_compute_node_not_alive(self):
|
||||||
"""
|
"""Confirms src-compute node is alive."""
|
||||||
A testcase of driver._live_migration_src_check.
|
|
||||||
The testcase make sure src-compute node is alive.
|
|
||||||
"""
|
|
||||||
instance_id = self._create_instance()
|
instance_id = self._create_instance()
|
||||||
i_ref = db.instance_get(self.context, instance_id)
|
i_ref = db.instance_get(self.context, instance_id)
|
||||||
t = datetime.datetime.utcnow() - datetime.timedelta(10)
|
t = datetime.datetime.utcnow() - datetime.timedelta(10)
|
||||||
@@ -803,11 +791,8 @@ class SimpleDriverTestCase(test.TestCase):
|
|||||||
db.instance_destroy(self.context, instance_id)
|
db.instance_destroy(self.context, instance_id)
|
||||||
db.service_destroy(self.context, s_ref['id'])
|
db.service_destroy(self.context, s_ref['id'])
|
||||||
|
|
||||||
def test_live_migraiton_src_check_works_correctly(self):
|
def test_live_migration_src_check_works_correctly(self):
|
||||||
"""
|
"""Confirms this method finishes with no error."""
|
||||||
A testcase of driver._live_migration_src_check.
|
|
||||||
The testcase make sure everything finished with no error.
|
|
||||||
"""
|
|
||||||
instance_id = self._create_instance()
|
instance_id = self._create_instance()
|
||||||
i_ref = db.instance_get(self.context, instance_id)
|
i_ref = db.instance_get(self.context, instance_id)
|
||||||
s_ref = self._create_compute_service(host=i_ref['host'])
|
s_ref = self._create_compute_service(host=i_ref['host'])
|
||||||
@@ -819,11 +804,8 @@ class SimpleDriverTestCase(test.TestCase):
|
|||||||
db.instance_destroy(self.context, instance_id)
|
db.instance_destroy(self.context, instance_id)
|
||||||
db.service_destroy(self.context, s_ref['id'])
|
db.service_destroy(self.context, s_ref['id'])
|
||||||
|
|
||||||
def test_live_migraiton_dest_check_not_alive(self):
|
def test_live_migration_dest_check_not_alive(self):
|
||||||
"""
|
"""Confirms exception raises in case dest host does not exist."""
|
||||||
A testcase of driver._live_migration_dst_check.
|
|
||||||
Destination host does not exist.
|
|
||||||
"""
|
|
||||||
instance_id = self._create_instance()
|
instance_id = self._create_instance()
|
||||||
i_ref = db.instance_get(self.context, instance_id)
|
i_ref = db.instance_get(self.context, instance_id)
|
||||||
t = datetime.datetime.utcnow() - datetime.timedelta(10)
|
t = datetime.datetime.utcnow() - datetime.timedelta(10)
|
||||||
@@ -841,11 +823,8 @@ class SimpleDriverTestCase(test.TestCase):
|
|||||||
db.instance_destroy(self.context, instance_id)
|
db.instance_destroy(self.context, instance_id)
|
||||||
db.service_destroy(self.context, s_ref['id'])
|
db.service_destroy(self.context, s_ref['id'])
|
||||||
|
|
||||||
def test_live_migraiton_dest_check_service_same_host(self):
|
def test_live_migration_dest_check_service_same_host(self):
|
||||||
"""
|
"""Confirms exceptioin raises in case dest and src is same host."""
|
||||||
A testcase of driver._live_migration_dst_check.
|
|
||||||
Destination host is same as src host.
|
|
||||||
"""
|
|
||||||
instance_id = self._create_instance()
|
instance_id = self._create_instance()
|
||||||
i_ref = db.instance_get(self.context, instance_id)
|
i_ref = db.instance_get(self.context, instance_id)
|
||||||
s_ref = self._create_compute_service(host=i_ref['host'])
|
s_ref = self._create_compute_service(host=i_ref['host'])
|
||||||
@@ -861,11 +840,8 @@ class SimpleDriverTestCase(test.TestCase):
|
|||||||
db.instance_destroy(self.context, instance_id)
|
db.instance_destroy(self.context, instance_id)
|
||||||
db.service_destroy(self.context, s_ref['id'])
|
db.service_destroy(self.context, s_ref['id'])
|
||||||
|
|
||||||
def test_live_migraiton_dest_check_service_lack_memory(self):
|
def test_live_migration_dest_check_service_lack_memory(self):
|
||||||
"""
|
"""Confirms exception raises when dest doesn't have enough memory."""
|
||||||
A testcase of driver._live_migration_dst_check.
|
|
||||||
destination host doesnt have enough memory.
|
|
||||||
"""
|
|
||||||
instance_id = self._create_instance()
|
instance_id = self._create_instance()
|
||||||
i_ref = db.instance_get(self.context, instance_id)
|
i_ref = db.instance_get(self.context, instance_id)
|
||||||
s_ref = self._create_compute_service(host='somewhere',
|
s_ref = self._create_compute_service(host='somewhere',
|
||||||
@@ -882,11 +858,8 @@ class SimpleDriverTestCase(test.TestCase):
|
|||||||
db.instance_destroy(self.context, instance_id)
|
db.instance_destroy(self.context, instance_id)
|
||||||
db.service_destroy(self.context, s_ref['id'])
|
db.service_destroy(self.context, s_ref['id'])
|
||||||
|
|
||||||
def test_live_migraiton_dest_check_service_works_correctly(self):
|
def test_live_migration_dest_check_service_works_correctly(self):
|
||||||
"""
|
"""Confirms method finishes with no error."""
|
||||||
A testcase of driver._live_migration_dst_check.
|
|
||||||
The testcase make sure everything finished with no error.
|
|
||||||
"""
|
|
||||||
instance_id = self._create_instance()
|
instance_id = self._create_instance()
|
||||||
i_ref = db.instance_get(self.context, instance_id)
|
i_ref = db.instance_get(self.context, instance_id)
|
||||||
s_ref = self._create_compute_service(host='somewhere',
|
s_ref = self._create_compute_service(host='somewhere',
|
||||||
@@ -899,13 +872,11 @@ class SimpleDriverTestCase(test.TestCase):
|
|||||||
db.instance_destroy(self.context, instance_id)
|
db.instance_destroy(self.context, instance_id)
|
||||||
db.service_destroy(self.context, s_ref['id'])
|
db.service_destroy(self.context, s_ref['id'])
|
||||||
|
|
||||||
def test_live_migraiton_common_check_service_orig_not_exists(self):
|
def test_live_migration_common_check_service_orig_not_exists(self):
|
||||||
"""
|
"""Destination host does not exist."""
|
||||||
A testcase of driver._live_migration_common_check.
|
|
||||||
Destination host does not exist.
|
|
||||||
"""
|
|
||||||
dest = 'dummydest'
|
dest = 'dummydest'
|
||||||
# mocks for live_migraiton_common_check()
|
# mocks for live_migration_common_check()
|
||||||
instance_id = self._create_instance()
|
instance_id = self._create_instance()
|
||||||
i_ref = db.instance_get(self.context, instance_id)
|
i_ref = db.instance_get(self.context, instance_id)
|
||||||
t1 = datetime.datetime.utcnow() - datetime.timedelta(10)
|
t1 = datetime.datetime.utcnow() - datetime.timedelta(10)
|
||||||
@@ -929,18 +900,15 @@ class SimpleDriverTestCase(test.TestCase):
|
|||||||
i_ref,
|
i_ref,
|
||||||
dest)
|
dest)
|
||||||
except exception.Invalid, e:
|
except exception.Invalid, e:
|
||||||
c = (e.message.find('does not exists') >= 0)
|
c = (e.message.find('does not exist') >= 0)
|
||||||
|
|
||||||
self.assertTrue(c)
|
self.assertTrue(c)
|
||||||
self.mox.UnsetStubs()
|
self.mox.UnsetStubs()
|
||||||
db.instance_destroy(self.context, instance_id)
|
db.instance_destroy(self.context, instance_id)
|
||||||
db.service_destroy(self.context, s_ref['id'])
|
db.service_destroy(self.context, s_ref['id'])
|
||||||
|
|
||||||
def test_live_migraiton_common_check_service_different_hypervisor(self):
|
def test_live_migration_common_check_service_different_hypervisor(self):
|
||||||
"""
|
"""Original host and dest host has different hypervisor type."""
|
||||||
A testcase of driver._live_migration_common_check.
|
|
||||||
Original host and dest host has different hypervisor type.
|
|
||||||
"""
|
|
||||||
dest = 'dummydest'
|
dest = 'dummydest'
|
||||||
instance_id = self._create_instance()
|
instance_id = self._create_instance()
|
||||||
i_ref = db.instance_get(self.context, instance_id)
|
i_ref = db.instance_get(self.context, instance_id)
|
||||||
@@ -969,11 +937,8 @@ class SimpleDriverTestCase(test.TestCase):
|
|||||||
db.service_destroy(self.context, s_ref['id'])
|
db.service_destroy(self.context, s_ref['id'])
|
||||||
db.service_destroy(self.context, s_ref2['id'])
|
db.service_destroy(self.context, s_ref2['id'])
|
||||||
|
|
||||||
def test_live_migraiton_common_check_service_different_version(self):
|
def test_live_migration_common_check_service_different_version(self):
|
||||||
"""
|
"""Original host and dest host has different hypervisor version."""
|
||||||
A testcase of driver._live_migration_common_check.
|
|
||||||
Original host and dest host has different hypervisor version.
|
|
||||||
"""
|
|
||||||
dest = 'dummydest'
|
dest = 'dummydest'
|
||||||
instance_id = self._create_instance()
|
instance_id = self._create_instance()
|
||||||
i_ref = db.instance_get(self.context, instance_id)
|
i_ref = db.instance_get(self.context, instance_id)
|
||||||
@@ -1003,11 +968,9 @@ class SimpleDriverTestCase(test.TestCase):
|
|||||||
db.service_destroy(self.context, s_ref['id'])
|
db.service_destroy(self.context, s_ref['id'])
|
||||||
db.service_destroy(self.context, s_ref2['id'])
|
db.service_destroy(self.context, s_ref2['id'])
|
||||||
|
|
||||||
def test_live_migraiton_common_check_service_checking_cpuinfo_fail(self):
|
def test_live_migration_common_check_checking_cpuinfo_fail(self):
|
||||||
"""
|
"""Raise excetion when original host doen't have compatible cpu."""
|
||||||
A testcase of driver._live_migration_common_check.
|
|
||||||
Original host and dest host has different hypervisor version.
|
|
||||||
"""
|
|
||||||
dest = 'dummydest'
|
dest = 'dummydest'
|
||||||
instance_id = self._create_instance()
|
instance_id = self._create_instance()
|
||||||
i_ref = db.instance_get(self.context, instance_id)
|
i_ref = db.instance_get(self.context, instance_id)
|
||||||
@@ -1025,7 +988,7 @@ class SimpleDriverTestCase(test.TestCase):
|
|||||||
rpc.call(mox.IgnoreArg(), mox.IgnoreArg(),
|
rpc.call(mox.IgnoreArg(), mox.IgnoreArg(),
|
||||||
{"method": 'compare_cpu',
|
{"method": 'compare_cpu',
|
||||||
"args": {'cpu_info': s_ref2['compute_service'][0]['cpu_info']}}).\
|
"args": {'cpu_info': s_ref2['compute_service'][0]['cpu_info']}}).\
|
||||||
AndRaise(rpc.RemoteError('doesnt have compatibility to', '', ''))
|
AndRaise(rpc.RemoteError("doesn't have compatibility to", "", ""))
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
try:
|
try:
|
||||||
@@ -1033,7 +996,7 @@ class SimpleDriverTestCase(test.TestCase):
|
|||||||
i_ref,
|
i_ref,
|
||||||
dest)
|
dest)
|
||||||
except rpc.RemoteError, e:
|
except rpc.RemoteError, e:
|
||||||
c = (e.message.find(_('doesnt have compatibility to')) >= 0)
|
c = (e.message.find(_("doesn't have compatibility to")) >= 0)
|
||||||
|
|
||||||
self.assertTrue(c)
|
self.assertTrue(c)
|
||||||
self.mox.UnsetStubs()
|
self.mox.UnsetStubs()
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ from nova import context
|
|||||||
from nova import db
|
from nova import db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import test
|
|
||||||
from nova import logging
|
from nova import logging
|
||||||
|
from nova import test
|
||||||
from nova import utils
|
from nova import utils
|
||||||
from nova.api.ec2 import cloud
|
from nova.api.ec2 import cloud
|
||||||
from nova.auth import manager
|
from nova.auth import manager
|
||||||
@@ -76,12 +76,12 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
'bridge': 'br101',
|
'bridge': 'br101',
|
||||||
'instance_type': 'm1.small'}
|
'instance_type': 'm1.small'}
|
||||||
|
|
||||||
def _driver_dependent_test_setup(self):
|
def _driver_dependant_test_setup(self):
|
||||||
"""
|
"""Call this method at the top of each testcase method.
|
||||||
Setup method.
|
|
||||||
Call this method at the top of each testcase method,
|
Checks if libvirt and cheetah, etc is installed.
|
||||||
if the testcase is necessary libvirt and cheetah.
|
Otherwise, skip testing."""
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
global libvirt
|
global libvirt
|
||||||
global libxml2
|
global libxml2
|
||||||
@@ -92,10 +92,9 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
except ImportError, e:
|
except ImportError, e:
|
||||||
logging.warn("""This test has not been done since """
|
logging.warn("""This test has not been done since """
|
||||||
"""using driver-dependent library Cheetah/libvirt/libxml2.""")
|
"""using driver-dependent library Cheetah/libvirt/libxml2.""")
|
||||||
raise e
|
raise
|
||||||
|
|
||||||
# inebitable mocks for calling
|
# inebitable mocks for calling
|
||||||
#nova.virt.libvirt_conn.LibvirtConnection.__init__
|
|
||||||
obj = utils.import_object(FLAGS.firewall_driver)
|
obj = utils.import_object(FLAGS.firewall_driver)
|
||||||
fwmock = self.mox.CreateMock(obj)
|
fwmock = self.mox.CreateMock(obj)
|
||||||
self.mox.StubOutWithMock(libvirt_conn, 'utils',
|
self.mox.StubOutWithMock(libvirt_conn, 'utils',
|
||||||
@@ -258,51 +257,31 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
self.assertEquals(uri, testuri)
|
self.assertEquals(uri, testuri)
|
||||||
|
|
||||||
def test_get_vcpu_total(self):
|
def test_get_vcpu_total(self):
|
||||||
"""
|
"""Check if get_vcpu_total returns appropriate cpu value."""
|
||||||
Check if get_vcpu_total returns appropriate cpu value
|
|
||||||
Connection/OS/driver differenct does not matter for this method,
|
|
||||||
everyone can execute for checking.
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
self._driver_dependent_test_setup()
|
self._driver_dependant_test_setup()
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
conn = libvirt_conn.LibvirtConnection(False)
|
conn = libvirt_conn.LibvirtConnection(False)
|
||||||
self.assertTrue(0 < conn.get_vcpu_total())
|
self.assertTrue(0 < conn.get_vcpu_total())
|
||||||
self.mox.UnsetStubs()
|
|
||||||
|
|
||||||
def test_get_memory_mb_total(self):
|
def test_get_memory_mb_total(self):
|
||||||
"""Check if get_memory_mb returns appropriate memory value"""
|
"""Check if get_memory_mb returns appropriate memory value."""
|
||||||
try:
|
try:
|
||||||
self._driver_dependent_test_setup()
|
self._driver_dependant_test_setup()
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
conn = libvirt_conn.LibvirtConnection(False)
|
conn = libvirt_conn.LibvirtConnection(False)
|
||||||
self.assertTrue(0 < conn.get_memory_mb_total())
|
self.assertTrue(0 < conn.get_memory_mb_total())
|
||||||
self.mox.UnsetStubs()
|
|
||||||
|
|
||||||
def test_get_local_gb_total(self):
|
|
||||||
"""Check if get_local_gb_total returns appropriate disk value"""
|
|
||||||
# Note(masumotok): leave this b/c FLAGS.instances_path is inevitable..
|
|
||||||
#try:
|
|
||||||
# self._driver_dependent_test_setup()
|
|
||||||
#except:
|
|
||||||
# return
|
|
||||||
#
|
|
||||||
#self.mox.ReplayAll()
|
|
||||||
#conn = libvirt_conn.LibvirtConnection(False)
|
|
||||||
#self.assertTrue(0 < conn.get_local_gb_total())
|
|
||||||
#self.mox.UnsetStubs()
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_get_vcpu_used(self):
|
def test_get_vcpu_used(self):
|
||||||
"""Check if get_local_gb_total returns appropriate disk value"""
|
"""Check if get_local_gb_total returns appropriate disk value."""
|
||||||
try:
|
try:
|
||||||
self._driver_dependent_test_setup()
|
self._driver_dependant_test_setup()
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -321,52 +300,45 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
conn = libvirt_conn.LibvirtConnection(False)
|
conn = libvirt_conn.LibvirtConnection(False)
|
||||||
self.assertTrue(conn.get_vcpu_used() == 4)
|
self.assertTrue(conn.get_vcpu_used() == 4)
|
||||||
self.mox.UnsetStubs()
|
|
||||||
|
|
||||||
def test_get_memory_mb_used(self):
|
def test_get_memory_mb_used(self):
|
||||||
"""Check if get_memory_mb returns appropriate memory value"""
|
"""Check if get_memory_mb returns appropriate memory value."""
|
||||||
try:
|
try:
|
||||||
self._driver_dependent_test_setup()
|
self._driver_dependant_test_setup()
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
conn = libvirt_conn.LibvirtConnection(False)
|
conn = libvirt_conn.LibvirtConnection(False)
|
||||||
self.assertTrue(0 < conn.get_memory_mb_used())
|
self.assertTrue(0 < conn.get_memory_mb_used())
|
||||||
self.mox.UnsetStubs()
|
|
||||||
|
|
||||||
def test_get_local_gb_used(self):
|
|
||||||
"""Check if get_local_gb_total returns appropriate disk value"""
|
|
||||||
# Note(masumotok): leave this b/c FLAGS.instances_path is inevitable
|
|
||||||
#try:
|
|
||||||
# self._driver_dependent_test_setup()
|
|
||||||
#except:
|
|
||||||
# return
|
|
||||||
|
|
||||||
#self.mox.ReplayAll()
|
|
||||||
#conn = libvirt_conn.LibvirtConnection(False)
|
|
||||||
#self.assertTrue(0 < conn.get_local_gb_used())
|
|
||||||
#self.mox.UnsetStubs()
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_get_cpu_info_works_correctly(self):
|
def test_get_cpu_info_works_correctly(self):
|
||||||
|
"""Check if get_cpu_info works correctly as expected."""
|
||||||
|
xml = """<cpu>
|
||||||
|
<arch>x86_64</arch>
|
||||||
|
<model>Nehalem</model>
|
||||||
|
<vendor>Intel</vendor>
|
||||||
|
<topology sockets='2' cores='4' threads='2'/>
|
||||||
|
<feature name='rdtscp'/>
|
||||||
|
<feature name='dca'/>
|
||||||
|
<feature name='xtpr'/>
|
||||||
|
<feature name='tm2'/>
|
||||||
|
<feature name='est'/>
|
||||||
|
<feature name='vmx'/>
|
||||||
|
<feature name='ds_cpl'/>
|
||||||
|
<feature name='monitor'/>
|
||||||
|
<feature name='pbe'/>
|
||||||
|
<feature name='tm'/>
|
||||||
|
<feature name='ht'/>
|
||||||
|
<feature name='ss'/>
|
||||||
|
<feature name='acpi'/>
|
||||||
|
<feature name='ds'/>
|
||||||
|
<feature name='vme'/>
|
||||||
|
</cpu>
|
||||||
"""
|
"""
|
||||||
Check if get_cpu_info works correctly.
|
|
||||||
(in case libvirt.getCapabilities() works correctly)
|
|
||||||
"""
|
|
||||||
xml = ("""<cpu><arch>x86_64</arch><model>Nehalem</model>"""
|
|
||||||
"""<vendor>Intel</vendor><topology sockets='2' """
|
|
||||||
"""cores='4' threads='2'/><feature name='rdtscp'/>"""
|
|
||||||
"""<feature name='dca'/><feature name='xtpr'/>"""
|
|
||||||
"""<feature name='tm2'/><feature name='est'/>"""
|
|
||||||
"""<feature name='vmx'/><feature name='ds_cpl'/>"""
|
|
||||||
"""<feature name='monitor'/><feature name='pbe'/>"""
|
|
||||||
"""<feature name='tm'/><feature name='ht'/>"""
|
|
||||||
"""<feature name='ss'/><feature name='acpi'/>"""
|
|
||||||
"""<feature name='ds'/><feature name='vme'/></cpu>""")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._driver_dependent_test_setup()
|
self._driver_dependant_test_setup()
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
self.mox.StubOutWithMock(libvirt_conn.LibvirtConnection,
|
self.mox.StubOutWithMock(libvirt_conn.LibvirtConnection,
|
||||||
@@ -376,27 +348,34 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
conn = libvirt_conn.LibvirtConnection(False)
|
conn = libvirt_conn.LibvirtConnection(False)
|
||||||
self.assertTrue(0 < len(conn.get_cpu_info()))
|
self.assertTrue(0 < len(conn.get_cpu_info()))
|
||||||
self.mox.UnsetStubs()
|
|
||||||
|
|
||||||
def test_get_cpu_info_inappropreate_xml(self):
|
def test_get_cpu_info_inappropreate_xml(self):
|
||||||
|
"""Raise exception if given xml is inappropriate."""
|
||||||
|
xml = """<cccccpu>
|
||||||
|
<arch>x86_64</arch>
|
||||||
|
<model>Nehalem</model>
|
||||||
|
<vendor>Intel</vendor>
|
||||||
|
<topology sockets='2' cores='4' threads='2'/>
|
||||||
|
<feature name='rdtscp'/>
|
||||||
|
<feature name='dca'/>
|
||||||
|
<feature name='xtpr'/>
|
||||||
|
<feature name='tm2'/>
|
||||||
|
<feature name='est'/>
|
||||||
|
<feature name='vmx'/>
|
||||||
|
<feature name='ds_cpl'/>
|
||||||
|
<feature name='monitor'/>
|
||||||
|
<feature name='pbe'/>
|
||||||
|
<feature name='tm'/>
|
||||||
|
<feature name='ht'/>
|
||||||
|
<feature name='ss'/>
|
||||||
|
<feature name='acpi'/>
|
||||||
|
<feature name='ds'/>
|
||||||
|
<feature name='vme'/>
|
||||||
|
</cccccpu>
|
||||||
"""
|
"""
|
||||||
Check if get_cpu_info raises exception
|
|
||||||
in case libvirt.getCapabilities() returns wrong xml
|
|
||||||
(in case of xml doesnt have <cpu> tag)
|
|
||||||
"""
|
|
||||||
xml = ("""<cccccpu><arch>x86_64</arch><model>Nehalem</model>"""
|
|
||||||
"""<vendor>Intel</vendor><topology sockets='2' """
|
|
||||||
"""cores='4' threads='2'/><feature name='rdtscp'/>"""
|
|
||||||
"""<feature name='dca'/><feature name='xtpr'/>"""
|
|
||||||
"""<feature name='tm2'/><feature name='est'/>"""
|
|
||||||
"""<feature name='vmx'/><feature name='ds_cpl'/>"""
|
|
||||||
"""<feature name='monitor'/><feature name='pbe'/>"""
|
|
||||||
"""<feature name='tm'/><feature name='ht'/>"""
|
|
||||||
"""<feature name='ss'/><feature name='acpi'/>"""
|
|
||||||
"""<feature name='ds'/><feature name='vme'/></cccccpu>""")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._driver_dependent_test_setup()
|
self._driver_dependant_test_setup()
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
self.mox.StubOutWithMock(libvirt_conn.LibvirtConnection,
|
self.mox.StubOutWithMock(libvirt_conn.LibvirtConnection,
|
||||||
@@ -410,28 +389,33 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
except exception.Invalid, e:
|
except exception.Invalid, e:
|
||||||
c1 = (0 <= e.message.find('Invalid xml'))
|
c1 = (0 <= e.message.find('Invalid xml'))
|
||||||
self.assertTrue(c1)
|
self.assertTrue(c1)
|
||||||
self.mox.UnsetStubs()
|
|
||||||
|
|
||||||
def test_get_cpu_info_inappropreate_xml2(self):
|
def test_get_cpu_info_inappropreate_xml2(self):
|
||||||
"""
|
"""Raise exception if given xml is inappropriate(topology tag)."""
|
||||||
Check if get_cpu_info raises exception
|
|
||||||
in case libvirt.getCapabilities() returns wrong xml
|
|
||||||
(in case of xml doesnt have inproper <topology> tag
|
|
||||||
meaning missing "socket" attribute)
|
|
||||||
"""
|
|
||||||
xml = ("""<cpu><arch>x86_64</arch><model>Nehalem</model>"""
|
|
||||||
"""<vendor>Intel</vendor><topology """
|
|
||||||
"""cores='4' threads='2'/><feature name='rdtscp'/>"""
|
|
||||||
"""<feature name='dca'/><feature name='xtpr'/>"""
|
|
||||||
"""<feature name='tm2'/><feature name='est'/>"""
|
|
||||||
"""<feature name='vmx'/><feature name='ds_cpl'/>"""
|
|
||||||
"""<feature name='monitor'/><feature name='pbe'/>"""
|
|
||||||
"""<feature name='tm'/><feature name='ht'/>"""
|
|
||||||
"""<feature name='ss'/><feature name='acpi'/>"""
|
|
||||||
"""<feature name='ds'/><feature name='vme'/></cpu>""")
|
|
||||||
|
|
||||||
|
xml = """<cpu>
|
||||||
|
<arch>x86_64</arch>
|
||||||
|
<model>Nehalem</model>
|
||||||
|
<vendor>Intel</vendor><topology cores='4' threads='2'/>
|
||||||
|
<feature name='rdtscp'/>
|
||||||
|
<feature name='dca'/>
|
||||||
|
<feature name='xtpr'/>
|
||||||
|
<feature name='tm2'/>
|
||||||
|
<feature name='est'/>
|
||||||
|
<feature name='vmx'/>
|
||||||
|
<feature name='ds_cpl'/>
|
||||||
|
<feature name='monitor'/>
|
||||||
|
<feature name='pbe'/>
|
||||||
|
<feature name='tm'/>
|
||||||
|
<feature name='ht'/>
|
||||||
|
<feature name='ss'/>
|
||||||
|
<feature name='acpi'/>
|
||||||
|
<feature name='ds'/>
|
||||||
|
<feature name='vme'/>
|
||||||
|
</cpu>
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
self._driver_dependent_test_setup()
|
self._driver_dependant_test_setup()
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
self.mox.StubOutWithMock(libvirt_conn.LibvirtConnection,
|
self.mox.StubOutWithMock(libvirt_conn.LibvirtConnection,
|
||||||
@@ -445,28 +429,11 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
except exception.Invalid, e:
|
except exception.Invalid, e:
|
||||||
c1 = (0 <= e.message.find('Invalid xml: topology'))
|
c1 = (0 <= e.message.find('Invalid xml: topology'))
|
||||||
self.assertTrue(c1)
|
self.assertTrue(c1)
|
||||||
self.mox.UnsetStubs()
|
|
||||||
|
|
||||||
def test_update_available_resource_works_correctly(self):
|
def test_update_available_resource_works_correctly(self):
|
||||||
"""
|
"""Confirm compute_service table is updated successfully."""
|
||||||
In this method, vcpus/memory_mb/local_gb/vcpu_used/
|
|
||||||
memory_mb_used/local_gb_used/hypervisor_type/
|
|
||||||
hypervisor_version/cpu_info should be changed.
|
|
||||||
Based on this specification, this testcase confirms
|
|
||||||
if this method finishes successfully,
|
|
||||||
meaning self.db.service_update must be called with dictinary
|
|
||||||
|
|
||||||
{'vcpu':aaa, 'memory_mb':bbb, 'local_gb':ccc,
|
|
||||||
'vcpu_used':aaa, 'memory_mb_used':bbb, 'local_gb_sed':ccc,
|
|
||||||
'hypervisor_type':ddd, 'hypervisor_version':eee,
|
|
||||||
'cpu_info':fff}
|
|
||||||
|
|
||||||
Since each value of above dict can be obtained through
|
|
||||||
driver(different depends on environment),
|
|
||||||
only dictionary keys are checked.
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
self._driver_dependent_test_setup()
|
self._driver_dependant_test_setup()
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -478,7 +445,9 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
|
|
||||||
host = 'foo'
|
host = 'foo'
|
||||||
binary = 'nova-compute'
|
binary = 'nova-compute'
|
||||||
service_ref = {'id': 1, 'host': host, 'binary': binary,
|
service_ref = {'id': 1,
|
||||||
|
'host': host,
|
||||||
|
'binary': binary,
|
||||||
'topic': 'compute'}
|
'topic': 'compute'}
|
||||||
|
|
||||||
self.mox.StubOutWithMock(db, 'service_get_all_by_topic')
|
self.mox.StubOutWithMock(db, 'service_get_all_by_topic')
|
||||||
@@ -491,15 +460,11 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
conn = libvirt_conn.LibvirtConnection(False)
|
conn = libvirt_conn.LibvirtConnection(False)
|
||||||
conn.update_available_resource(host)
|
conn.update_available_resource(host)
|
||||||
self.mox.UnsetStubs()
|
|
||||||
|
|
||||||
def test_update_resource_info_raise_exception(self):
|
def test_update_resource_info_raise_exception(self):
|
||||||
"""
|
"""Raise exception if no recorde found on services table."""
|
||||||
This testcase confirms if no record found on Service
|
|
||||||
table, exception can be raised.
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
self._driver_dependent_test_setup()
|
self._driver_dependant_test_setup()
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -518,18 +483,19 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
msg = 'Cannot insert compute manager specific info'
|
msg = 'Cannot insert compute manager specific info'
|
||||||
c1 = (0 <= e.message.find(msg))
|
c1 = (0 <= e.message.find(msg))
|
||||||
self.assertTrue(c1)
|
self.assertTrue(c1)
|
||||||
self.mox.ResetAll()
|
|
||||||
|
|
||||||
def test_compare_cpu_works_correctly(self):
|
def test_compare_cpu_works_correctly(self):
|
||||||
"""Calling libvirt.compute_cpu() and works correctly """
|
"""Calling libvirt.compute_cpu() and works correctly."""
|
||||||
|
t = {}
|
||||||
t = ("""{"arch":"%s", "model":"%s", "vendor":"%s", """
|
t['arch'] = 'x86'
|
||||||
""""topology":{"cores":"%s", "threads":"%s", """
|
t['model'] = 'model'
|
||||||
""""sockets":"%s"}, "features":[%s]}""")
|
t['vendor'] = 'Intel'
|
||||||
cpu_info = t % ('x86', 'model', 'vendor', '2', '1', '4', '"tm"')
|
t['topology'] = {'cores': "2", "threads": "1", "sockets": "4"}
|
||||||
|
t['features'] = ["tm"]
|
||||||
|
cpu_info = utils.dumps(t)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._driver_dependent_test_setup()
|
self._driver_dependant_test_setup()
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -542,20 +508,19 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
conn = libvirt_conn.LibvirtConnection(False)
|
conn = libvirt_conn.LibvirtConnection(False)
|
||||||
self.assertTrue(None == conn.compare_cpu(cpu_info))
|
self.assertTrue(None == conn.compare_cpu(cpu_info))
|
||||||
self.mox.UnsetStubs()
|
|
||||||
|
|
||||||
def test_compare_cpu_raises_exception(self):
|
def test_compare_cpu_raises_exception(self):
|
||||||
"""
|
"""Libvirt-related exception occurs when calling compare_cpu()."""
|
||||||
Libvirt-related exception occurs when calling
|
t = {}
|
||||||
libvirt.compare_cpu().
|
t['arch'] = 'x86'
|
||||||
"""
|
t['model'] = 'model'
|
||||||
t = ("""{"arch":"%s", "model":"%s", "vendor":"%s", """
|
t['vendor'] = 'Intel'
|
||||||
""""topology":{"cores":"%s", "threads":"%s", """
|
t['topology'] = {'cores': "2", "threads": "1", "sockets": "4"}
|
||||||
""""sockets":"%s"}, "features":[%s]}""")
|
t['features'] = ["tm"]
|
||||||
cpu_info = t % ('x86', 'model', 'vendor', '2', '1', '4', '"tm"')
|
cpu_info = utils.dumps(t)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._driver_dependent_test_setup()
|
self._driver_dependant_test_setup()
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -567,18 +532,19 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
conn = libvirt_conn.LibvirtConnection(False)
|
conn = libvirt_conn.LibvirtConnection(False)
|
||||||
self.assertRaises(libvirt.libvirtError, conn.compare_cpu, cpu_info)
|
self.assertRaises(libvirt.libvirtError, conn.compare_cpu, cpu_info)
|
||||||
self.mox.UnsetStubs()
|
|
||||||
|
|
||||||
def test_compare_cpu_no_compatibility(self):
|
def test_compare_cpu_no_compatibility(self):
|
||||||
"""libvirt.compare_cpu() return less than 0.(no compatibility)"""
|
"""Libvirt.compare_cpu() return less than 0.(no compatibility)."""
|
||||||
|
t = {}
|
||||||
t = ("""{"arch":"%s", "model":"%s", "vendor":"%s", """
|
t['arch'] = 'x86'
|
||||||
""""topology":{"cores":"%s", "threads":"%s", """
|
t['model'] = 'model'
|
||||||
""""sockets":"%s"}, "features":[%s]}""")
|
t['vendor'] = 'Intel'
|
||||||
cpu_info = t % ('x86', 'model', 'vendor', '2', '1', '4', '"tm"')
|
t['topology'] = {'cores': "2", "threads": "1", "sockets": "4"}
|
||||||
|
t['features'] = ["tm"]
|
||||||
|
cpu_info = utils.dumps(t)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._driver_dependent_test_setup()
|
self._driver_dependant_test_setup()
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -590,16 +556,14 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
conn = libvirt_conn.LibvirtConnection(False)
|
conn = libvirt_conn.LibvirtConnection(False)
|
||||||
self.assertRaises(exception.Invalid, conn.compare_cpu, cpu_info)
|
self.assertRaises(exception.Invalid, conn.compare_cpu, cpu_info)
|
||||||
self.mox.UnsetStubs()
|
|
||||||
|
|
||||||
def test_ensure_filtering_rules_for_instance_works_correctly(self):
|
def test_ensure_filtering_rules_for_instance_works_correctly(self):
|
||||||
"""ensure_filtering_rules_for_instance works as expected correctly"""
|
"""ensure_filtering_rules_for_instance() works successfully."""
|
||||||
|
|
||||||
instance_ref = models.Instance()
|
instance_ref = models.Instance()
|
||||||
instance_ref.__setitem__('id', 1)
|
instance_ref.__setitem__('id', 1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
nwmock, fwmock = self._driver_dependent_test_setup()
|
nwmock, fwmock = self._driver_dependant_test_setup()
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -613,16 +577,14 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
conn = libvirt_conn.LibvirtConnection(False)
|
conn = libvirt_conn.LibvirtConnection(False)
|
||||||
conn.ensure_filtering_rules_for_instance(instance_ref)
|
conn.ensure_filtering_rules_for_instance(instance_ref)
|
||||||
self.mox.UnsetStubs()
|
|
||||||
|
|
||||||
def test_ensure_filtering_rules_for_instance_timeout(self):
|
def test_ensure_filtering_rules_for_instance_timeout(self):
|
||||||
"""ensure_filtering_fules_for_instance finishes with timeout"""
|
"""ensure_filtering_fules_for_instance() finishes with timeout."""
|
||||||
|
|
||||||
instance_ref = models.Instance()
|
instance_ref = models.Instance()
|
||||||
instance_ref.__setitem__('id', 1)
|
instance_ref.__setitem__('id', 1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
nwmock, fwmock = self._driver_dependent_test_setup()
|
nwmock, fwmock = self._driver_dependant_test_setup()
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -642,11 +604,9 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
except exception.Error, e:
|
except exception.Error, e:
|
||||||
c1 = (0 <= e.message.find('Timeout migrating for'))
|
c1 = (0 <= e.message.find('Timeout migrating for'))
|
||||||
self.assertTrue(c1)
|
self.assertTrue(c1)
|
||||||
self.mox.UnsetStubs()
|
|
||||||
|
|
||||||
def test_live_migration_works_correctly(self):
|
def test_live_migration_works_correctly(self):
|
||||||
"""_live_migration works as expected correctly """
|
"""_live_migration() works as expected correctly."""
|
||||||
|
|
||||||
class dummyCall(object):
|
class dummyCall(object):
|
||||||
f = None
|
f = None
|
||||||
|
|
||||||
@@ -659,7 +619,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
ctxt = context.get_admin_context()
|
ctxt = context.get_admin_context()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._driver_dependent_test_setup()
|
self._driver_dependant_test_setup()
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -681,13 +641,9 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
# Not setting post_method/recover_method in this testcase.
|
# Not setting post_method/recover_method in this testcase.
|
||||||
ret = conn._live_migration(ctxt, i_ref, i_ref['host'], '', '')
|
ret = conn._live_migration(ctxt, i_ref, i_ref['host'], '', '')
|
||||||
self.assertTrue(ret == None)
|
self.assertTrue(ret == None)
|
||||||
self.mox.UnsetStubs()
|
|
||||||
|
|
||||||
def test_live_migration_raises_exception(self):
|
def test_live_migration_raises_exception(self):
|
||||||
"""
|
"""Confirms recover method is called when exceptions are raised."""
|
||||||
_live_migration raises exception, then this testcase confirms
|
|
||||||
recovered method is called.
|
|
||||||
"""
|
|
||||||
i_ref = models.Instance()
|
i_ref = models.Instance()
|
||||||
i_ref.__setitem__('id', 1)
|
i_ref.__setitem__('id', 1)
|
||||||
i_ref.__setitem__('host', 'dummy')
|
i_ref.__setitem__('host', 'dummy')
|
||||||
@@ -697,7 +653,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
nwmock, fwmock = self._driver_dependent_test_setup()
|
nwmock, fwmock = self._driver_dependant_test_setup()
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -724,7 +680,6 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
conn._mlive_migration,
|
conn._mlive_migration,
|
||||||
ctxt, instance_ref, dest,
|
ctxt, instance_ref, dest,
|
||||||
'', dummy_recover_method)
|
'', dummy_recover_method)
|
||||||
self.mox.UnsetStubs()
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(LibvirtConnTestCase, self).tearDown()
|
super(LibvirtConnTestCase, self).tearDown()
|
||||||
|
|||||||
Reference in New Issue
Block a user