From 7c8096384507908a5e583f4554d0fc765ae5f2eb Mon Sep 17 00:00:00 2001 From: Kei Masumoto Date: Thu, 27 Jan 2011 20:39:33 +0900 Subject: adding testcode --- nova/scheduler/driver.py | 53 +++++++++++++++++++++-------------------------- nova/scheduler/manager.py | 28 ++++++++++++------------- 2 files changed, 37 insertions(+), 44 deletions(-) (limited to 'nova/scheduler') diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py index 65745093b..d4ad42388 100644 --- a/nova/scheduler/driver.py +++ b/nova/scheduler/driver.py @@ -69,11 +69,10 @@ class Scheduler(object): raise NotImplementedError(_("Must implement a fallback schedule")) def schedule_live_migration(self, context, instance_id, dest): - """ live migration method """ + """live migration method""" # Whether instance exists and running instance_ref = db.instance_get(context, instance_id) - ec2_id = instance_ref['hostname'] # Checking instance. self._live_migration_src_check(context, instance_ref) @@ -159,48 +158,45 @@ class Scheduler(object): def _live_migration_common_check(self, context, instance_ref, dest): """ - Live migration check routine. - Below pre-checkings are followed by - http://wiki.libvirt.org/page/TodoPreMigrationChecks + Live migration check routine. + Below pre-checkings are followed by + http://wiki.libvirt.org/page/TodoPreMigrationChecks """ # Checking dest exists. dservice_refs = db.service_get_all_by_host(context, dest) if len(dservice_refs) <= 0: - msg = _('%s does not exists.') - raise exception.Invalid(msg % dest) + raise exception.Invalid(_('%s does not exists.') % dest) dservice_ref = dservice_refs[0] # Checking original host( where instance was launched at) exists. - orighost = instance_ref['launched_on'] - oservice_refs = db.service_get_all_by_host(context, orighost) + oservice_refs = db.service_get_all_by_host(context, + instance_ref['launched_on']) if len(oservice_refs) <= 0: msg = _('%s(where instance was launched at) does not exists.') - raise exception.Invalid(msg % orighost) + raise exception.Invalid(msg % instance_ref['launched_on']) oservice_ref = oservice_refs[0] # Checking hypervisor is same. - otype = oservice_ref['hypervisor_type'] - dtype = dservice_ref['hypervisor_type'] - if otype != dtype: + if oservice_ref['hypervisor_type'] != dservice_ref['hypervisor_type']: msg = _('Different hypervisor type(%s->%s)') - raise exception.Invalid(msg % (otype, dtype)) + raise exception.Invalid(msg % (oservice_ref['hypervisor_type'], + dservice_ref['hypervisor_type'])) # Checkng hypervisor version. - oversion = oservice_ref['hypervisor_version'] - dversion = dservice_ref['hypervisor_version'] - if oversion > dversion: + if oservice_ref['hypervisor_version'] > \ + dservice_ref['hypervisor_version']: msg = _('Older hypervisor version(%s->%s)') - raise exception.Invalid(msg % (oversion, dversion)) + raise exception.Invalid(msg % (oservice_ref['hypervisor_version'], + dservice_ref['hypervisor_version'])) # Checking cpuinfo. - cpu_info = oservice_ref['cpu_info'] try: rpc.call(context, db.queue_get_for(context, FLAGS.compute_topic, dest), {"method": 'compare_cpu', - "args": {'cpu_info': cpu_info}}) + "args": {'cpu_info': oservice_ref['cpu_info']}}) except rpc.RemoteError, e: msg = _(("""%s doesnt have compatibility to %s""" @@ -211,7 +207,7 @@ class Scheduler(object): raise e def has_enough_resource(self, context, instance_ref, dest): - """ Check if destination host has enough resource for live migration""" + """Check if destination host has enough resource for live migration""" # Getting instance information ec2_id = instance_ref['hostname'] @@ -222,28 +218,27 @@ class Scheduler(object): # Gettin host information service_refs = db.service_get_all_by_host(context, dest) if len(service_refs) <= 0: - msg = _('%s does not exists.') - raise exception.Invalid(msg % dest) + raise exception.Invalid(_('%s does not exists.') % dest) service_ref = service_refs[0] total_cpu = int(service_ref['vcpus']) total_mem = int(service_ref['memory_mb']) total_hdd = int(service_ref['local_gb']) - instances_ref = db.instance_get_all_by_host(context, dest) - for i_ref in instances_ref: + instances_refs = db.instance_get_all_by_host(context, dest) + for i_ref in instances_refs: total_cpu -= int(i_ref['vcpus']) total_mem -= int(i_ref['memory_mb']) total_hdd -= int(i_ref['local_gb']) # Checking host has enough information - logging.debug('host(%s) remains vcpu:%s mem:%s hdd:%s,' % + logging.debug(_('host(%s) remains vcpu:%s mem:%s hdd:%s,') % (dest, total_cpu, total_mem, total_hdd)) - logging.debug('instance(%s) has vcpu:%s mem:%s hdd:%s,' % + logging.debug(_('instance(%s) has vcpu:%s mem:%s hdd:%s,') % (ec2_id, vcpus, mem, hdd)) if total_cpu <= vcpus or total_mem <= mem or total_hdd <= hdd: - msg = '%s doesnt have enough resource for %s' % (dest, ec2_id) - raise exception.NotEmpty(msg) + raise exception.NotEmpty(_('%s is not capable to migrate %s') % + (dest, ec2_id)) logging.debug(_('%s has_enough_resource() for %s') % (dest, ec2_id)) diff --git a/nova/scheduler/manager.py b/nova/scheduler/manager.py index 1cc767a03..a181225a6 100644 --- a/nova/scheduler/manager.py +++ b/nova/scheduler/manager.py @@ -73,17 +73,13 @@ class SchedulerManager(manager.Manager): # Based on bear design summit discussion, # just put this here for bexar release. def show_host_resource(self, context, host, *args): - """ show the physical/usage resource given by hosts.""" + """show the physical/usage resource given by hosts.""" - services = db.service_get_all_by_host(context, host) - if len(services) == 0: - return {'ret': False, 'msg': 'No such Host'} - - compute = [s for s in services if s['topic'] == 'compute'] - if 0 == len(compute): - service_ref = services[0] - else: - service_ref = compute[0] + computes = db.service_get_all_compute_sorted(context) + computes = [s for s,v in computes if s['host'] == host] + if 0 == len(computes): + return {'ret': False, 'msg': 'No such Host or not compute node.'} + service_ref = computes[0] # Getting physical resource information h_resource = {'vcpus': service_ref['vcpus'], @@ -92,13 +88,15 @@ class SchedulerManager(manager.Manager): # Getting usage resource information u_resource = {} - instances_ref = db.instance_get_all_by_host(context, - service_ref['host']) + instances_refs = db.instance_get_all_by_host(context, + service_ref['host']) - if 0 == len(instances_ref): - return {'ret': True, 'phy_resource': h_resource, 'usage': {}} + if 0 == len(instances_refs): + return {'ret': True, + 'phy_resource': h_resource, + 'usage': u_resource} - project_ids = [i['project_id'] for i in instances_ref] + project_ids = [i['project_id'] for i in instances_refs] project_ids = list(set(project_ids)) for p_id in project_ids: vcpus = db.instance_get_vcpu_sum_by_host_and_project(context, -- cgit From 09f2c4729456443c4874a8cadc53299817d6371a Mon Sep 17 00:00:00 2001 From: Kei Masumoto Date: Mon, 31 Jan 2011 18:41:10 +0900 Subject: 1. Discard nova-manage host list Reason: nova-manage service list can be replacement. Changes: nova-manage 2. Fix resource checking inappropriate design. Reason: nova.scheduler.driver.has_enough_resource has inappropriate design, so fix it. This method didnt check free memory but check total memory. We need to register free memory onto databases(periodically). But periodically updating may causes flooding request to db in case of many compute-node. Currently, since memory information is only used in this feature, we take the choice that administrators manually has to execute nova-manage to let compute node update their own memory information. Changes: nova.db.sqlalchemy.models - Adding memory_mb_used, local_gb_used, vcpu_used column to Service. (local_gb and vcpu is just for reference to admins for now) nova.compute.manager - Changing nova.compute.manager.update_service Service table column is changed, so updating method must be changed. - Adding nova.compute.manager.update_available_resource a responder to admin's request to let compute nodes update their memory infomation nova.virt.libvirt_conn nova.virt.xenapi_conn nova.virt.fake - Adding getter method for memory_mb_used/local_gb_used/vcpu_used. nova-manage - request method to let compute nodes update their own memory info. --- nova/scheduler/driver.py | 67 ++++++++++++++++++++++++++++++++--------------- nova/scheduler/manager.py | 11 +++++--- 2 files changed, 53 insertions(+), 25 deletions(-) (limited to 'nova/scheduler') diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py index d4ad42388..937f09c6f 100644 --- a/nova/scheduler/driver.py +++ b/nova/scheduler/driver.py @@ -33,6 +33,7 @@ from nova.compute import power_state FLAGS = flags.FLAGS flags.DEFINE_integer('service_down_time', 60, 'maximum time since last checkin for up service') +flags.DECLARE('instances_path', 'nova.compute.manager') class NoValidHost(exception.Error): @@ -163,6 +164,8 @@ class Scheduler(object): http://wiki.libvirt.org/page/TodoPreMigrationChecks """ + # Checking shared storage connectivity + self.mounted_on_same_shared_storage(context, instance_ref, dest) # Checking dest exists. dservice_refs = db.service_get_all_by_host(context, dest) @@ -207,38 +210,60 @@ class Scheduler(object): raise e def has_enough_resource(self, context, instance_ref, dest): - """Check if destination host has enough resource for live migration""" + """ + Check if destination host has enough resource for live migration. + Currently, only memory checking has been done. + If storage migration(block migration, meaning live-migration + without any shared storage) will be available, local storage + checking is also necessary. + """ # Getting instance information ec2_id = instance_ref['hostname'] - vcpus = instance_ref['vcpus'] mem = instance_ref['memory_mb'] - hdd = instance_ref['local_gb'] - # Gettin host information + # Getting host information service_refs = db.service_get_all_by_host(context, dest) if len(service_refs) <= 0: raise exception.Invalid(_('%s does not exists.') % dest) service_ref = service_refs[0] - total_cpu = int(service_ref['vcpus']) - total_mem = int(service_ref['memory_mb']) - total_hdd = int(service_ref['local_gb']) + mem_total = int(service_ref['memory_mb']) + mem_used = int(service_ref['memory_mb_used']) + mem_avail = mem_total - mem_used + mem_inst = instance_ref['memory_mb'] + if mem_avail <= mem_inst: + msg = _('%s is not capable to migrate %s(host:%s <= instance:%s)') + raise exception.NotEmpty(msg % (dest, ec2_id, mem_avail, mem_inst)) - instances_refs = db.instance_get_all_by_host(context, dest) - for i_ref in instances_refs: - total_cpu -= int(i_ref['vcpus']) - total_mem -= int(i_ref['memory_mb']) - total_hdd -= int(i_ref['local_gb']) + def mounted_on_same_shared_storage(self, context, instance_ref, dest): + """ + Check if /nova-inst-dir/insntances is mounted same storage at + live-migration src and dest host. + """ + src = instance_ref['host'] + dst_t = db.queue_get_for(context, FLAGS.compute_topic, dest) + src_t = db.queue_get_for(context, FLAGS.compute_topic, src) - # Checking host has enough information - logging.debug(_('host(%s) remains vcpu:%s mem:%s hdd:%s,') % - (dest, total_cpu, total_mem, total_hdd)) - logging.debug(_('instance(%s) has vcpu:%s mem:%s hdd:%s,') % - (ec2_id, vcpus, mem, hdd)) + # create tmpfile at dest host + try: + filename = rpc.call(context, dst_t, {"method": 'mktmpfile'}) + except rpc.RemoteError, e: + msg = _("Cannot create tmpfile at %s to confirm shared storage.") + logging.error(msg % FLAGS.instance_path) + raise e - if total_cpu <= vcpus or total_mem <= mem or total_hdd <= hdd: - raise exception.NotEmpty(_('%s is not capable to migrate %s') % - (dest, ec2_id)) + # make sure existence at src host. + try: + rpc.call(context, src_t, + {"method": 'exists', "args":{'path':filename}}) + + except (rpc.RemoteError, exception.NotFound), e: + msg = (_("""Cannot comfirm %s at %s to confirm shared storage.""" + """Check if %s is same shared storage""")) + logging.error(msg % FLAGS.instance_path) + raise e - logging.debug(_('%s has_enough_resource() for %s') % (dest, ec2_id)) + # then remove. + rpc.call(context, dst_t, + {"method": 'remove', "args":{'path':filename}}) diff --git a/nova/scheduler/manager.py b/nova/scheduler/manager.py index a181225a6..b40f46a85 100644 --- a/nova/scheduler/manager.py +++ b/nova/scheduler/manager.py @@ -84,7 +84,10 @@ class SchedulerManager(manager.Manager): # Getting physical resource information h_resource = {'vcpus': service_ref['vcpus'], 'memory_mb': service_ref['memory_mb'], - 'local_gb': service_ref['local_gb']} + 'local_gb': service_ref['local_gb'], + 'vcpus_used': service_ref['vcpus_used'], + 'memory_mb_used': service_ref['memory_mb_used'], + 'local_gb_used': service_ref['local_gb_used']} # Getting usage resource information u_resource = {} @@ -108,8 +111,8 @@ class SchedulerManager(manager.Manager): hdd = db.instance_get_disk_sum_by_host_and_project(context, host, p_id) - u_resource[p_id] = {'vcpus': vcpus, - 'memory_mb': mem, - 'local_gb': hdd} + u_resource[p_id] = {'vcpus': int(vcpus), + 'memory_mb': int(mem), + 'local_gb': int(hdd)} return {'ret': True, 'phy_resource': h_resource, 'usage': u_resource} -- cgit From d88d74c9a0a28e0ebd6cedf694753b9ee9decdac Mon Sep 17 00:00:00 2001 From: Kei Masumoto Date: Fri, 18 Feb 2011 14:15:04 +0900 Subject: fixed based on reviewer's comment. 1. erase wrapper function(remove/exists/mktempfile) from nova.utils. 2. nova-manage service describeresource(->describe_resource) 3. nova-manage service updateresource(->update_resource) 4. erase "my mistake print" statement Additional changes are made at: 1. nova.image.s3.show 2. nova.compute.api.create that's because instances cannot launched without this changes. --- nova/scheduler/manager.py | 1 - 1 file changed, 1 deletion(-) (limited to 'nova/scheduler') diff --git a/nova/scheduler/manager.py b/nova/scheduler/manager.py index af54c72be..ea7ae7bd2 100644 --- a/nova/scheduler/manager.py +++ b/nova/scheduler/manager.py @@ -60,7 +60,6 @@ class SchedulerManager(manager.Manager): host = getattr(self.driver, driver_method)(elevated, *args, **kwargs) except AttributeError, e: - print 'manager.attrerr', e host = self.driver.schedule(elevated, topic, *args, **kwargs) rpc.cast(context, -- cgit From c32e57999be09368b18f5a89315465e629ed4819 Mon Sep 17 00:00:00 2001 From: Kei Masumoto Date: Tue, 22 Feb 2011 23:55:03 +0900 Subject: Fixed based on reviewer's comment. 1. Change docstrings format 2. Fix comment grammer mistake, etc --- nova/scheduler/driver.py | 121 ++++++++++++++++++++++++++++++---------------- nova/scheduler/manager.py | 15 ++++-- 2 files changed, 91 insertions(+), 45 deletions(-) (limited to 'nova/scheduler') diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py index 41b87bbca..8c30702ba 100644 --- a/nova/scheduler/driver.py +++ b/nova/scheduler/driver.py @@ -70,9 +70,18 @@ class Scheduler(object): raise NotImplementedError(_("Must implement a fallback schedule")) def schedule_live_migration(self, context, instance_id, dest): - """live migration method""" + """Live migration scheduling method. - # Whether instance exists and running + :param context: + :param instance_id: + :param dest: destination host + :return: + The host where instance is running currently. + Then scheduler send request that host. + + """ + + # Whether instance exists and is running. instance_ref = db.instance_get(context, instance_id) # Checking instance. @@ -102,11 +111,16 @@ class Scheduler(object): return src def _live_migration_src_check(self, context, instance_ref): - """Live migration check routine (for src host)""" + """Live migration check routine (for src host). + + :param context: security context + :param instance_ref: nova.db.sqlalchemy.models.Instance object + + """ # Checking instance is running. - if power_state.RUNNING != instance_ref['state'] or \ - 'running' != instance_ref['state_description']: + if (power_state.RUNNING != instance_ref['state'] or \ + 'running' != instance_ref['state_description']): msg = _('Instance(%s) is not running') ec2_id = instance_ref['hostname'] raise exception.Invalid(msg % ec2_id) @@ -129,7 +143,13 @@ class Scheduler(object): raise exception.Invalid(msg % src) def _live_migration_dest_check(self, context, instance_ref, dest): - """Live migration check routine (for destination host)""" + """Live migration check routine (for destination host). + + :param context: security context + :param instance_ref: nova.db.sqlalchemy.models.Instance object + :param dest: destination host + + """ # Checking dest exists and compute node. dservice_refs = db.service_get_all_compute_by_host(context, dest) @@ -145,20 +165,25 @@ class Scheduler(object): src = instance_ref['host'] if dest == src: ec2_id = instance_ref['hostname'] - msg = _("""%(dest)s is where %(ec2_id)s is """ - """running now. choose other host.""") % locals() - raise exception.Invalid(msg) + raise exception.Invalid(_("%(dest)s is where %(ec2_id)s is " + "running now. choose other host.") + % locals()) # Checking dst host still has enough capacities. - self.has_enough_resource(context, instance_ref, dest) + self.has_enough_resources(context, instance_ref, dest) def _live_migration_common_check(self, context, instance_ref, dest): - """ - Live migration check routine. - Below pre-checkings are followed by + """Live migration common check routine. + + Below checkings are followed by http://wiki.libvirt.org/page/TodoPreMigrationChecks + :param context: security context + :param instance_ref: nova.db.sqlalchemy.models.Instance object + :param dest: destination host + """ + # Checking shared storage connectivity self.mounted_on_same_shared_storage(context, instance_ref, dest) @@ -168,27 +193,27 @@ class Scheduler(object): # Checking original host( where instance was launched at) exists. try: - oservice_refs = \ - db.service_get_all_compute_by_host(context, - instance_ref['launched_on']) + oservice_refs = db.service_get_all_compute_by_host(context, + instance_ref['launched_on']) except exception.NotFound: - msg = _('%s(where instance was launched at) does not exists.') - raise exception.Invalid(msg % instance_ref['launched_on']) + raise exception.Invalid(_("host %s where instance was launched " + "does not exist.") + % instance_ref['launched_on']) oservice_ref = oservice_refs[0]['compute_service'][0] # Checking hypervisor is same. o = oservice_ref['hypervisor_type'] d = dservice_ref['hypervisor_type'] if o != d: - msg = _('Different hypervisor type(%(o)s->%(d)s)') % locals() - raise exception.Invalid(msg) + raise exception.Invalid(_("Different hypervisor type" + "(%(o)s->%(d)s)')" % locals())) # Checkng hypervisor version. o = oservice_ref['hypervisor_version'] d = dservice_ref['hypervisor_version'] if o > d: - msg = _('Older hypervisor version(%(o)s->%(d)s)') % locals() - raise exception.Invalid(msg) + raise exception.Invalid(_('Older hypervisor version(%(o)s->%(d)s)') + % locals()) # Checking cpuinfo. try: @@ -200,19 +225,24 @@ class Scheduler(object): except rpc.RemoteError, e: ec2_id = instance_ref['hostname'] src = instance_ref['host'] - msg = _("""%(dest)s doesnt have compatibility to %(src)s""" - """(where %(ec2_id)s was launched at)""") - logging.exception(msg % locals()) - raise e + logging.exception(_("host %(dest)s is not compatible with " + "original host %(src)s.") % locals()) + raise + + def has_enough_resources(self, context, instance_ref, dest): + """Checks if destination host has enough resource for live migration. - def has_enough_resource(self, context, instance_ref, dest): - """ - Check if destination host has enough resource for live migration. Currently, only memory checking has been done. If storage migration(block migration, meaning live-migration without any shared storage) will be available, local storage checking is also necessary. + + :param context: security context + :param instance_ref: nova.db.sqlalchemy.models.Instance object + :param dest: destination host + """ + # Getting instance information ec2_id = instance_ref['hostname'] @@ -225,15 +255,23 @@ class Scheduler(object): mem_avail = mem_total - mem_used mem_inst = instance_ref['memory_mb'] if mem_avail <= mem_inst: - msg = _("""%(ec2_id)s is not capable to migrate %(dest)s""" - """(host:%(mem_avail)s <= instance:%(mem_inst)s)""") - raise exception.NotEmpty(msg % locals()) + raise exception.NotEmpty(_("%(ec2_id)s is not capable to " + "migrate %(dest)s (host:%(mem_avail)s " + " <= instance:%(mem_inst)s)") + % locals()) def mounted_on_same_shared_storage(self, context, instance_ref, dest): + """Check if the src and dest host mount same shared storage. + + At first, dest host creates temp file, and src host can see + it if they mounts same shared storage. Then src host erase it. + + :param context: security context + :param instance_ref: nova.db.sqlalchemy.models.Instance object + :param dest: destination host + """ - Check if /nova-inst-dir/insntances is mounted same storage at - live-migration src and dest host. - """ + src = instance_ref['host'] dst_t = db.queue_get_for(context, FLAGS.compute_topic, dest) src_t = db.queue_get_for(context, FLAGS.compute_topic, src) @@ -243,8 +281,8 @@ class Scheduler(object): filename = rpc.call(context, dst_t, {"method": 'mktmpfile'}) except rpc.RemoteError, e: msg = _("Cannot create tmpfile at %s to confirm shared storage.") - logging.error(msg % FLAGS.instance_path) - raise e + LOG.error(msg % FLAGS.instances_path) + raise # make sure existence at src host. try: @@ -252,8 +290,7 @@ class Scheduler(object): {"method": 'confirm_tmpfile', "args": {'path': filename}}) except (rpc.RemoteError, exception.NotFound), e: - ipath = FLAGS.instance_path - msg = _("""Cannot comfirm %(ipath)s at %(dest)s is located at""" - """ same shared storage.""") % locals() - logging.error(msg) - raise e + ipath = FLAGS.instances_path + logging.error(_("Cannot comfirm %(ipath)s at %(dest)s is " + "located at same shared storage.") % locals()) + raise diff --git a/nova/scheduler/manager.py b/nova/scheduler/manager.py index 584dc49d2..783594c6f 100644 --- a/nova/scheduler/manager.py +++ b/nova/scheduler/manager.py @@ -69,10 +69,19 @@ class SchedulerManager(manager.Manager): LOG.debug(_("Casting to %(topic)s %(host)s for %(method)s") % locals()) # NOTE (masumotok) : This method should be moved to nova.api.ec2.admin. - # Based on bear design summit discussion, + # Based on bexar design summit discussion, # just put this here for bexar release. - def show_host_resource(self, context, host, *args): - """show the physical/usage resource given by hosts.""" + def show_host_resources(self, context, host, *args): + """Shows the physical/usage resource given by hosts. + + :param context: security context + :param host: hostname + :returns: + example format is below. + {'resource':D, 'usage':{proj_id1:D, proj_id2:D}} + D: {'vcpus':3, 'memory_mb':2048, 'local_gb':2048} + + """ compute_ref = db.service_get_all_compute_by_host(context, host) compute_ref = compute_ref[0] -- cgit From 485a6c5a9502679bc5ecf02f8e758170ac0335dc Mon Sep 17 00:00:00 2001 From: Kei Masumoto Date: Wed, 23 Feb 2011 01:20:39 +0900 Subject: Fixed some docstring --- nova/scheduler/manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/scheduler') diff --git a/nova/scheduler/manager.py b/nova/scheduler/manager.py index 783594c6f..cd5012fd5 100644 --- a/nova/scheduler/manager.py +++ b/nova/scheduler/manager.py @@ -59,7 +59,7 @@ class SchedulerManager(manager.Manager): try: host = getattr(self.driver, driver_method)(elevated, *args, **kwargs) - except AttributeError, e: + except AttributeError: host = self.driver.schedule(elevated, topic, *args, **kwargs) rpc.cast(context, -- cgit From 693e4335dbef72317147abd70bdaa10e0d174020 Mon Sep 17 00:00:00 2001 From: Kei Masumoto Date: Thu, 3 Mar 2011 22:54:11 +0900 Subject: Fixed based on reviewer's comments. Main changes are below. 1. Rename nova.compute.manager.ComputeManager.mktmpfile for better naming. 2. Several tests code in tests/test_virt.py are removed. Because it only works in libvirt environment. Only db-related testcode remains. --- nova/scheduler/driver.py | 74 +++++++++++++++++++++++++---------------------- nova/scheduler/manager.py | 18 ++++++------ 2 files changed, 49 insertions(+), 43 deletions(-) (limited to 'nova/scheduler') diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py index 73ce651da..4485ba39f 100644 --- a/nova/scheduler/driver.py +++ b/nova/scheduler/driver.py @@ -100,9 +100,9 @@ class Scheduler(object): 'migrating') # Changing volume state - for v in instance_ref['volumes']: + for volume_ref in instance_ref['volumes']: db.volume_update(context, - v['id'], + volume_ref['id'], {'status': 'migrating'}) # Return value is necessary to send request to src @@ -121,17 +121,16 @@ class Scheduler(object): # Checking instance is running. if (power_state.RUNNING != instance_ref['state'] or \ 'running' != instance_ref['state_description']): - msg = _('Instance(%s) is not running') ec2_id = instance_ref['hostname'] - raise exception.Invalid(msg % ec2_id) + raise exception.Invalid(_('Instance(%s) is not running') % ec2_id) # Checing volume node is running when any volumes are mounted # to the instance. if len(instance_ref['volumes']) != 0: services = db.service_get_all_by_topic(context, 'volume') if len(services) < 1 or not self.service_is_up(services[0]): - msg = _('volume node is not alive(time synchronize problem?)') - raise exception.Invalid(msg) + raise exception.Invalid(_("volume node is not alive" + "(time synchronize problem?)")) # Checking src host exists and compute node src = instance_ref['host'] @@ -139,8 +138,8 @@ class Scheduler(object): # Checking src host is alive. if not self.service_is_up(services[0]): - msg = _('%s is not alive(time synchronize problem?)') - raise exception.Invalid(msg % src) + raise exception.Invalid(_("%s is not alive(time " + "synchronize problem?)") % src) def _live_migration_dest_check(self, context, instance_ref, dest): """Live migration check routine (for destination host). @@ -157,8 +156,8 @@ class Scheduler(object): # Checking dest host is alive. if not self.service_is_up(dservice_ref): - msg = _('%s is not alive(time synchronize problem?)') - raise exception.Invalid(msg % dest) + raise exception.Invalid(_("%s is not alive(time " + "synchronize problem?)") % dest) # Checking whether The host where instance is running # and dest is not same. @@ -170,7 +169,9 @@ class Scheduler(object): % locals()) # Checking dst host still has enough capacities. - self.has_enough_resources(context, instance_ref, dest) + self.assert_compute_node_has_enough_resources(context, + instance_ref, + dest) def _live_migration_common_check(self, context, instance_ref, dest): """Live migration common check routine. @@ -202,18 +203,20 @@ class Scheduler(object): oservice_ref = oservice_refs[0]['compute_service'][0] # Checking hypervisor is same. - o = oservice_ref['hypervisor_type'] - d = dservice_ref['hypervisor_type'] - if o != d: + orig_hypervisor = oservice_ref['hypervisor_type'] + dest_hypervisor = dservice_ref['hypervisor_type'] + if orig_hypervisor != dest_hypervisor: raise exception.Invalid(_("Different hypervisor type" - "(%(o)s->%(d)s)')" % locals())) + "(%(orig_hypervisor)s->" + "%(dest_hypervisor)s)')" % locals())) # Checkng hypervisor version. - o = oservice_ref['hypervisor_version'] - d = dservice_ref['hypervisor_version'] - if o > d: - raise exception.Invalid(_('Older hypervisor version(%(o)s->%(d)s)') - % locals()) + orig_hypervisor = oservice_ref['hypervisor_version'] + dest_hypervisor = dservice_ref['hypervisor_version'] + if orig_hypervisor > dest_hypervisor: + raise exception.Invalid(_("Older hypervisor version" + "(%(orig_hypervisor)s->" + "%(dest_hypervisor)s)") % locals()) # Checking cpuinfo. try: @@ -222,14 +225,15 @@ class Scheduler(object): {"method": 'compare_cpu', "args": {'cpu_info': oservice_ref['cpu_info']}}) - except rpc.RemoteError, e: + except rpc.RemoteError: ec2_id = instance_ref['hostname'] src = instance_ref['host'] logging.exception(_("host %(dest)s is not compatible with " "original host %(src)s.") % locals()) raise - def has_enough_resources(self, context, instance_ref, dest): + def assert_compute_node_has_enough_resources(self, context, + instance_ref, dest): """Checks if destination host has enough resource for live migration. Currently, only memory checking has been done. @@ -276,22 +280,24 @@ class Scheduler(object): dst_t = db.queue_get_for(context, FLAGS.compute_topic, dest) src_t = db.queue_get_for(context, FLAGS.compute_topic, src) - # create tmpfile at dest host try: - filename = rpc.call(context, dst_t, {"method": 'mktmpfile'}) - except rpc.RemoteError, e: - msg = _("Cannot create tmpfile at %s to confirm shared storage.") - LOG.error(msg % FLAGS.instances_path) - raise + # create tmpfile at dest host + filename = rpc.call(context, dst_t, + {"method": 'create_shared_storage_test_file'}) - # make sure existence at src host. - try: + # make sure existence at src host. rpc.call(context, src_t, - {"method": 'confirm_tmpfile', + {"method": 'check_shared_storage_test_file', "args": {'filename': filename}}) - except (rpc.RemoteError, exception.NotFound), e: + except rpc.RemoteError: ipath = FLAGS.instances_path - logging.error(_("Cannot comfirm %(ipath)s at %(dest)s is " - "located at same shared storage.") % locals()) + logging.error(_("Cannot comfirm tmpfile at %(ipath)s is on " + "same shared storage between %(src)s " + "and %(dest)s.") % locals()) raise + + finally: + rpc.call(context, dst_t, + {"method": 'cleanup_shared_storage_test_file', + "args": {'filename': filename}}) diff --git a/nova/scheduler/manager.py b/nova/scheduler/manager.py index cd5012fd5..a50d3ab20 100644 --- a/nova/scheduler/manager.py +++ b/nova/scheduler/manager.py @@ -98,24 +98,24 @@ class SchedulerManager(manager.Manager): # Getting usage resource information usage = {} instance_refs = db.instance_get_all_by_host(context, - compute_ref['host']) - if 0 == len(instance_refs): + compute_ref['host']) + if not instance_refs: return {'resource': resource, 'usage': usage} project_ids = [i['project_id'] for i in instance_refs] project_ids = list(set(project_ids)) - for i in project_ids: + for project_id in project_ids: vcpus = db.instance_get_vcpu_sum_by_host_and_project(context, host, - i) + project_id) mem = db.instance_get_memory_sum_by_host_and_project(context, host, - i) + project_id) hdd = db.instance_get_disk_sum_by_host_and_project(context, host, - i) - usage[i] = {'vcpus': int(vcpus), - 'memory_mb': int(mem), - 'local_gb': int(hdd)} + project_id) + usage[project_id] = {'vcpus': int(vcpus), + 'memory_mb': int(mem), + 'local_gb': int(hdd)} return {'resource': resource, 'usage': usage} -- cgit From 137a4946785b9460aadb9fe40f2b0e18bd7f6063 Mon Sep 17 00:00:00 2001 From: Kei Masumoto Date: Fri, 4 Mar 2011 01:09:21 +0900 Subject: Merged to trunk rev 757. Main changes are below. 1. Rename db table ComputeService -> ComputeNode 2. nova-manage option instance_type is reserved and we cannot use option instance, so change instance -> vm. --- nova/scheduler/driver.py | 10 +++++----- nova/scheduler/manager.py | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'nova/scheduler') diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py index 4485ba39f..791f9000d 100644 --- a/nova/scheduler/driver.py +++ b/nova/scheduler/driver.py @@ -190,7 +190,7 @@ class Scheduler(object): # Checking dest exists. dservice_refs = db.service_get_all_compute_by_host(context, dest) - dservice_ref = dservice_refs[0]['compute_service'][0] + dservice_ref = dservice_refs[0]['compute_node'][0] # Checking original host( where instance was launched at) exists. try: @@ -200,7 +200,7 @@ class Scheduler(object): raise exception.Invalid(_("host %s where instance was launched " "does not exist.") % instance_ref['launched_on']) - oservice_ref = oservice_refs[0]['compute_service'][0] + oservice_ref = oservice_refs[0]['compute_node'][0] # Checking hypervisor is same. orig_hypervisor = oservice_ref['hypervisor_type'] @@ -252,10 +252,10 @@ class Scheduler(object): # Getting host information service_refs = db.service_get_all_compute_by_host(context, dest) - compute_service_ref = service_refs[0]['compute_service'][0] + compute_node_ref = service_refs[0]['compute_node'][0] - mem_total = int(compute_service_ref['memory_mb']) - mem_used = int(compute_service_ref['memory_mb_used']) + mem_total = int(compute_node_ref['memory_mb']) + mem_used = int(compute_node_ref['memory_mb_used']) mem_avail = mem_total - mem_used mem_inst = instance_ref['memory_mb'] if mem_avail <= mem_inst: diff --git a/nova/scheduler/manager.py b/nova/scheduler/manager.py index a50d3ab20..090d8b89d 100644 --- a/nova/scheduler/manager.py +++ b/nova/scheduler/manager.py @@ -87,13 +87,13 @@ class SchedulerManager(manager.Manager): compute_ref = compute_ref[0] # Getting physical resource information - compute_service_ref = compute_ref['compute_service'][0] - resource = {'vcpus': compute_service_ref['vcpus'], - 'memory_mb': compute_service_ref['memory_mb'], - 'local_gb': compute_service_ref['local_gb'], - 'vcpus_used': compute_service_ref['vcpus_used'], - 'memory_mb_used': compute_service_ref['memory_mb_used'], - 'local_gb_used': compute_service_ref['local_gb_used']} + compute_node_ref = compute_ref['compute_node'][0] + resource = {'vcpus': compute_node_ref['vcpus'], + 'memory_mb': compute_node_ref['memory_mb'], + 'local_gb': compute_node_ref['local_gb'], + 'vcpus_used': compute_node_ref['vcpus_used'], + 'memory_mb_used': compute_node_ref['memory_mb_used'], + 'local_gb_used': compute_node_ref['local_gb_used']} # Getting usage resource information usage = {} -- cgit From f0bb6d9fc47b92d335c7d7fa238dfd43f0dbdf69 Mon Sep 17 00:00:00 2001 From: Kei Masumoto Date: Thu, 10 Mar 2011 13:30:52 +0900 Subject: fixed based on reviewer's comment. --- nova/scheduler/driver.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'nova/scheduler') diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py index 791f9000d..ed3dfe1c0 100644 --- a/nova/scheduler/driver.py +++ b/nova/scheduler/driver.py @@ -226,7 +226,6 @@ class Scheduler(object): "args": {'cpu_info': oservice_ref['cpu_info']}}) except rpc.RemoteError: - ec2_id = instance_ref['hostname'] src = instance_ref['host'] logging.exception(_("host %(dest)s is not compatible with " "original host %(src)s.") % locals()) @@ -259,9 +258,10 @@ class Scheduler(object): mem_avail = mem_total - mem_used mem_inst = instance_ref['memory_mb'] if mem_avail <= mem_inst: - raise exception.NotEmpty(_("%(ec2_id)s is not capable to " - "migrate %(dest)s (host:%(mem_avail)s " - " <= instance:%(mem_inst)s)") + raise exception.NotEmpty(_("Unable to migrate %(ec2_id)s " + "to destination: %(dest)s " + "(host:%(mem_avail)s " + "<= instance:%(mem_inst)s)") % locals()) def mounted_on_same_shared_storage(self, context, instance_ref, dest): @@ -292,7 +292,7 @@ class Scheduler(object): except rpc.RemoteError: ipath = FLAGS.instances_path - logging.error(_("Cannot comfirm tmpfile at %(ipath)s is on " + logging.error(_("Cannot confirm tmpfile at %(ipath)s is on " "same shared storage between %(src)s " "and %(dest)s.") % locals()) raise -- cgit