def test_get_by_topic(self): self.mox.StubOutWithMock(db, "service_get_all_by_topic") db.service_get_all_by_topic(self.context, "fake-topic").AndReturn([fake_service]) self.mox.ReplayAll() services = service.ServiceList.get_by_topic(self.context, "fake-topic") self.assertEqual(1, len(services)) self.compare_obj(services[0], fake_service, allow_missing=OPTIONAL)
def test_with_two_zones(self): scheduler = manager.SchedulerManager() ctxt = context.get_admin_context() service_list = [self._create_service_model(id=1, host='host1', zone='zone1'), self._create_service_model(id=2, host='host2', zone='zone2'), self._create_service_model(id=3, host='host3', zone='zone2'), self._create_service_model(id=4, host='host4', zone='zone2'), self._create_service_model(id=5, host='host5', zone='zone2')] self.mox.StubOutWithMock(db, 'service_get_all_by_topic') arg = IgnoreArg() db.service_get_all_by_topic(arg, arg).AndReturn(service_list) self.mox.StubOutWithMock(rpc, 'cast', use_mock_anything=True) rpc.cast(ctxt, 'compute.host1', {'method': 'run_instance', 'args': {'instance_id': 'i-ffffffff', 'availability_zone': 'zone1'}}) self.mox.ReplayAll() scheduler.run_instance(ctxt, 'compute', instance_id='i-ffffffff', availability_zone='zone1')
def test_live_migration_compute_src_not_alive(self): """Raise exception when src compute node is not alive.""" self.mox.StubOutWithMock(db, 'instance_get') self.mox.StubOutWithMock(db, 'service_get_all_by_topic') self.mox.StubOutWithMock(utils, 'service_is_up') self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host') dest = 'fake_host2' block_migration = False instance = self._live_migration_instance() db.instance_get(self.context, instance['id']).AndReturn(instance) # Volume up db.service_get_all_by_topic(self.context, 'volume').AndReturn( ['fake_service']) utils.service_is_up('fake_service').AndReturn(True) # Compute down db.service_get_all_compute_by_host(self.context, instance['host']).AndReturn(['fake_service2']) utils.service_is_up('fake_service2').AndReturn(False) self.mox.ReplayAll() self.assertRaises(exception.ComputeServiceUnavailable, self.driver.schedule_live_migration, self.context, instance_id=instance['id'], dest=dest, block_migration=block_migration)
def test_get_by_topic(self): self.mox.StubOutWithMock(db, 'service_get_all_by_topic') db.service_get_all_by_topic(self.context, 'fake-topic').AndReturn( [fake_service]) self.mox.ReplayAll() services = service.ServiceList.get_by_topic(self.context, 'fake-topic') self.assertEqual(1, len(services)) compare(services[0], fake_service)
def test_hosts_up(self): service1 = {"host": "host1"} service2 = {"host": "host2"} services = [service1, service2] self.mox.StubOutWithMock(db, "service_get_all_by_topic") self.mox.StubOutWithMock(servicegroup.API, "service_is_up") db.service_get_all_by_topic(self.context, self.topic).AndReturn(services) self.servicegroup_api.service_is_up(service1).AndReturn(False) self.servicegroup_api.service_is_up(service2).AndReturn(True) self.mox.ReplayAll() result = self.driver.hosts_up(self.context, self.topic) self.assertEqual(result, ["host2"])
def hosts_up(self, context, topic): """Return the list of hosts that have a running service for topic.""" services = db.service_get_all_by_topic(context, topic) return [service['host'] for service in services if utils.service_is_up(service)]
def _live_migration_src_check(self, context, instance_ref): """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 instance_ref["power_state"] != power_state.RUNNING: instance_id = ec2utils.id_to_ec2_id(instance_ref["id"]) raise exception.InstanceNotRunning(instance_id=instance_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 utils.service_is_up(services[0]): raise exception.VolumeServiceUnavailable() # Checking src host exists and compute node src = instance_ref["host"] services = db.service_get_all_compute_by_host(context, src) # Checking src host is alive. if not utils.service_is_up(services[0]): raise exception.ComputeServiceUnavailable(host=src)
def test_hosts_up(self): service1 = {'host': 'host1'} service2 = {'host': 'host2'} services = [service1, service2] self.mox.StubOutWithMock(db, 'service_get_all_by_topic') self.mox.StubOutWithMock(servicegroup.API, 'service_is_up') db.service_get_all_by_topic(self.context, self.topic).AndReturn(services) self.servicegroup_api.service_is_up(service1).AndReturn(False) self.servicegroup_api.service_is_up(service2).AndReturn(True) self.mox.ReplayAll() result = self.driver.hosts_up(self.context, self.topic) self.assertEqual(result, ['host2'])
def _live_migration_src_check(self, context, instance_ref): """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 instance_ref['power_state'] != power_state.RUNNING and not ( FLAGS.libvirt_type == 'xen' and instance_ref['power_state'] == power_state.BLOCKED): raise exception.InstanceNotRunning( instance_id=instance_ref['uuid']) # 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 utils.service_is_up(services[0]): raise exception.VolumeServiceUnavailable() # Checking src host exists and compute node src = instance_ref['host'] services = db.service_get_all_compute_by_host(context, src) # Checking src host is alive. if not utils.service_is_up(services[0]): raise exception.ComputeServiceUnavailable(host=src)
def _get_abnormal_service_by_topic(self, ctxt, topic): """ get service info from db, judging service's status by the latest updated time. :param service_name: service name :returns: None if service is normal, True if can not get service info from db, service info if service is judged abnormal """ try: abnormal_services = [] services = db.service_get_all_by_topic(ctxt, topic) now = timeutils.utcnow() for service_ref in services: service_updated_time = service_ref['updated_at'] service_failure_time = self.service_failure_time host = service_ref['host'] if not self.is_time_valid(service_updated_time, now, service_failure_time): LOG.info(_('check service nova-%(topic)s on %(host)s' ' abnormal!'), locals()) LOG.debug(_('service nova-%(topic)s updated at ' '%(service_updated_time)s, now is %(now)s, ' 'service_failure_time was set to ' '%(service_failure_time)s'), locals()) abnormal_services.append(service_ref) return abnormal_services except exception.NotFound: LOG.info(_('can not find service %s in db') % topic) return True
def _live_migration_src_check(self, context, instance_ref): """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']): ec2_id = instance_ref['hostname'] raise exception.InstanceNotRunning(instance_id=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]): raise exception.VolumeServiceUnavailable() # Checking src host exists and compute node src = instance_ref['host'] services = db.service_get_all_compute_by_host(context, src) # Checking src host is alive. if not self.service_is_up(services[0]): raise exception.ComputeServiceUnavailable(host=src)
def _live_migration_src_check(self, context, instance_ref): """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']): ec2_id = instance_ref['hostname'] 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]): raise exception.Invalid(_("volume node is not alive" "(time synchronize problem?)")) # Checking src host exists and compute node src = instance_ref['host'] services = db.service_get_all_compute_by_host(context, src) # Checking src host is alive. if not self.service_is_up(services[0]): raise exception.Invalid(_("%s is not alive(time " "synchronize problem?)") % src)
def hosts_up(self, context, topic): """Return the list of hosts that have a running service for topic.""" services = db.service_get_all_by_topic(context, topic) return [ service['host'] for service in services if self.servicegroup_api.service_is_up(service) ]
def get_audit_task_logs(context, begin=None, end=None, before=None): """Returns a full log for all instance usage audit tasks on all computes. :param begin: datetime beginning of audit period to get logs for, Defaults to the beginning of the most recently completed audit period prior to the 'before' date. :param end: datetime ending of audit period to get logs for, Defaults to the ending of the most recently completed audit period prior to the 'before' date. :param before: By default we look for the audit period most recently completed before this datetime. Has no effect if both begin and end are specified. """ defbegin, defend = utils.last_completed_audit_period(before=before) if begin is None: begin = defbegin if end is None: end = defend task_logs = db.task_log_get_all(context, "instance_usage_audit", begin, end) services = db.service_get_all_by_topic(context, "compute") hosts = set(serv['host'] for serv in services) seen_hosts = set() done_hosts = set() running_hosts = set() total_errors = 0 total_items = 0 for tlog in task_logs: seen_hosts.add(tlog['host']) if tlog['state'] == "DONE": done_hosts.add(tlog['host']) if tlog['state'] == "RUNNING": running_hosts.add(tlog['host']) total_errors += tlog['errors'] total_items += tlog['task_items'] log = dict((tl['host'], dict(state=tl['state'], instances=tl['task_items'], errors=tl['errors'], message=tl['message'])) for tl in task_logs) missing_hosts = hosts - seen_hosts overall_status = "%s hosts done. %s errors." % ( 'ALL' if len(done_hosts) == len(hosts) else "%s of %s" % (len(done_hosts), len(hosts)), total_errors) return dict(period_beginning=str(begin), period_ending=str(end), num_hosts=len(hosts), num_hosts_done=len(done_hosts), num_hosts_running=len(running_hosts), num_hosts_not_run=len(missing_hosts), hosts_not_run=list(missing_hosts), total_instances=total_items, total_errors=total_errors, overall_status=overall_status, log=log)
def get_all(self, group_id): """ Returns ALL members of the given group """ LOG.debug(_('DB_Driver: get_all members of the %s group') % group_id) rs = [] ctxt = context.get_admin_context() for service in db.service_get_all_by_topic(ctxt, group_id): if self.is_up(service): rs.append(service['host']) return rs
def test_with_two_zones(self): scheduler = manager.SchedulerManager() ctxt = context.get_admin_context() service_list = [ self._create_service_model(id=1, host="host1", zone="zone1"), self._create_service_model(id=2, host="host2", zone="zone2"), self._create_service_model(id=3, host="host3", zone="zone2"), self._create_service_model(id=4, host="host4", zone="zone2"), self._create_service_model(id=5, host="host5", zone="zone2"), ] self.mox.StubOutWithMock(db, "service_get_all_by_topic") arg = IgnoreArg() db.service_get_all_by_topic(arg, arg).AndReturn(service_list) self.mox.StubOutWithMock(rpc, "cast", use_mock_anything=True) rpc.cast( ctxt, "compute.host1", {"method": "run_instance", "args": {"instance_id": "i-ffffffff", "availability_zone": "zone1"}}, ) self.mox.ReplayAll() scheduler.run_instance(ctxt, "compute", instance_id="i-ffffffff", availability_zone="zone1")
def hosts_up_with_zone(self, context, topic, zone): """Return the list of hosts that have a running service for topic and availability zone (if defined). """ if zone is None: return self.hosts_up(context, topic) services = db.service_get_all_by_topic(context, topic) return [ service.host for service in services if self.service_is_up(service) and service.availability_zone == zone ]
def hosts_up_with_zone(self, context, topic, zone): """Return the list of hosts that have a running service for topic and availability zone (if defined). """ if zone is None: return self.hosts_up(context, topic) services = db.service_get_all_by_topic(context, topic) return [service.host for service in services if self.service_is_up(service) and service.availability_zone == zone]
def _scheduler_host(self, context, alive_hosts): # get a host from alive_hosts list, to recover the vm if len(alive_hosts) == 0: raise Exception('no mova alive host for recover') compute_services = db.service_get_all_by_topic(context, 'compute') compute_hosts = [] for service in compute_services: compute_hosts.append(service['host']) while True: index = self.revcover_num % len(alive_hosts) self.revcover_num += 1 if alive_hosts[index] in compute_hosts: return alive_hosts[index]
def _check_inactive_enabled_compute_hosts(self, ctxt): """Check inactive enabled compute hosts periodically""" ctxt = context.get_admin_context() LOG.info("Checking inactive enabled compute hosts started") # Get enabled compute services from DB compute_services = db.service_get_all_by_topic(ctxt, CONF.compute_topic) # Get inactive enabled compute services inactive_services = [ service for service in compute_services if not self.servicegroup_api.service_is_up(service)] LOG.info("%s inactive enabled compute host(s) found", len(inactive_services)) # Prepare a new retry counter new_retry_counter = {} # Heal each inactive compute service for service in inactive_services: # Get the host name host = service['host'] # Create a new retry_counter if host in self.retry_counter: new_retry_counter[host] = self.retry_counter[host] + 1 else: new_retry_counter[host] = 1 # Do host evacuation if retry count of the host is exceeded if new_retry_counter[host] > CONF.saver.retry_count: utils.spawn_n(self._host_evacuate, ctxt, service) # Remove service from new retry counter del(new_retry_counter[host]) # Replace an old retry counter with new one self.retry_counter = new_retry_counter LOG.info("Checking inactive enabled compute hosts finished")
def _get_dead_hosts(self, context): ''' get the node status by nova-recover service and return all failed node :param context: :return: ''' now = timeutils.utcnow() services = db.service_get_all_by_topic(context, topic) dead_hosts = [] alive_hosts = [] for service in services: delta = now - (service['updated_at'] or service['created_at']) alive = abs(utils.total_seconds(delta)) <= FLAGS.service_down_time service_host = service['host'] if alive: alive_hosts.append(service_host) else: dead_hosts.append(service_host) return dead_hosts, alive_hosts
def test_get_abnormal_service_by_topic(self): now = datetime.datetime.strptime('2012-11-02 07:59:40', "%Y-%m-%d %H:%M:%S") normal_time = datetime.datetime.strptime('2012-11-02 07:59:36', "%Y-%m-%d %H:%M:%S") abnormal_time = datetime.datetime.strptime('2012-11-02 06:59:36', "%Y-%m-%d %H:%M:%S") service1 = {'host': 'host1', 'updated_at': normal_time} service2 = {'host': 'host2', 'updated_at': abnormal_time} normal_services = [service1] abnormal_services = [service2] self.mox.StubOutWithMock(db, 'service_get_all_by_topic') self.mox.StubOutWithMock(timeutils, 'utcnow') # got abnormal services db.service_get_all_by_topic(self.context, self.topic).AndReturn( abnormal_services) timeutils.utcnow().AndReturn(now) self.mox.ReplayAll() self.assertEqual(self.manager._get_abnormal_service_by_topic( self.context, self.topic), abnormal_services) # all services is normal self.mox.ResetAll() db.service_get_all_by_topic(self.context, self.topic).AndReturn( normal_services) timeutils.utcnow().AndReturn(now) self.mox.ReplayAll() self.assertEqual(self.manager._get_abnormal_service_by_topic( self.context, self.topic), []) # can not get any service info from db self.mox.ResetAll() db.service_get_all_by_topic(self.context, self.topic).AndRaise( exception.NotFound()) self.mox.ReplayAll() self.assertEqual(self.manager._get_abnormal_service_by_topic( self.context, self.topic), True)
def get_by_topic(cls, context, topic): db_services = db.service_get_all_by_topic(context, topic) return base.obj_make_list(context, cls(context), objects.Service, db_services)
def hosts_up(self, context, topic): """Return the list of hosts that have a running service for topic.""" services = db.service_get_all_by_topic(context, topic) return [service["host"] for service in services if self.servicegroup_api.service_is_up(service)]
def get_by_topic(cls, context, topic): db_services = db.service_get_all_by_topic(context, topic) return base.obj_make_list(context, ServiceList(), Service, db_services)
def hosts_up_with_arch(self, context, topic, request_spec): # def hosts_up_with_arch(self, context, topic, instance_id): """Figure out what is requested """ LOG.debug(_("## req: %s"), request_spec) instance_type = request_spec['instance_type'] LOG.debug(_("## it: %s"), instance_type) # instance = db.instance_get(context, instance_id) # LOG.debug(_("## instance %s"), instance) # LOG.debug(_("## instance.id %s"), instance.id) # LOG.debug(_("## instance.cpu_arch %s"), instance.cpu_arch) services = db.service_get_all_by_topic(context.elevated(), topic) LOG.debug(_("## services %s"), services) hosts = [] # from instance table wanted_vcpus = instance_type['vcpus'] wanted_memory_mb = instance_type['memory_mb'] wanted_root_gb = instance_type['root_gb'] instance_id = instance_type['id'] LOG.debug(_("## wanted-vcpus=%s"), wanted_vcpus) LOG.debug(_("## wanted-memory=%s"), wanted_memory_mb) LOG.debug(_("## wanted-hard=%s"), wanted_root_gb) LOG.debug(_("## instance_id=%s"), instance_id) # from instance_metadata table # instance_meta = db.instance_metadata_get(context, instance_id) # LOG.debug(_("## inst-meta=%s"), instance_meta) # from instance_type_extra_specs table # instance_extra = db.instance_type_extra_specs_get( \ instance_meta = db.instance_type_extra_specs_get( \ context, instance_id) LOG.debug(_("## inst-meta=%s"), instance_meta) # combine to inatance_meta # instance_meta.update(instance_extra) # LOG.debug(_("## new inst meta=%s"), instance_meta) try: wanted_cpu_arch = instance_meta['cpu_arch'] except: wanted_cpu_arch = None LOG.debug(_("## wanted-cpu-arch=%s"), wanted_cpu_arch) """Get capability from zone_manager and match cpu_arch and others """ cap = self.zone_manager.get_hosts_capabilities(context) for host, host_dict_cap in cap.iteritems(): LOG.debug(_("## host=%s"), host) for service_name_cap, service_dict_cap in \ host_dict_cap.iteritems(): if (service_name_cap != 'compute'): continue resource_cap = {} for cap, value in service_dict_cap.iteritems(): if type(value) is int: # value is int resource_cap[cap] = value elif (type(value) is not str) and \ (type(value) is not unicode): continue # string and one value elif value.find(':') == -1 and value.find(',') == -1: try: resource_cap[cap] = int(value) except: resource_cap[cap] = value # complex; multi-level key-value pairs. # example: cpu_info = { "vendor":"intel", features= # ["dia", "est"], toplogy={"core":4, "thread":1}} # only the lowest key-value pair is recorded. So, in the # previous eample, the final dict is: # resource["vendor"] = "intel", # resource["features"] = "dia, est", # resource["core"] = "4", # resource["thread"] = "1", # No key is availabel for cpu_info and topology else: # decompose capability new_key = '' new_val = '' splitted = value.split(',') for pair in splitted: if pair.find(':') != -1: # key:value pair if len(new_key) != 0: try: resource_cap[new_key] = int(new_val) except: resource_cap[new_key] = new_val nspl = pair.split(':') right = nspl[-2].rfind('"', 0, len(nspl[-2])) left = nspl[-2].rfind('"', 0, right) new_key = nspl[-2][left + 1:right] right = nspl[-1].rfind('"', 0, len(nspl[-1])) left = nspl[-1].rfind('"', 0, right) new_val = nspl[-1][left + 1:right] else: # value only right = pair.rfind('"', 0, len(pair)) left = pair.rfind('"', 0, right) if right != -1 and left != -1: new_val += "," + pair[left + 1:right] else: new_val += ", " + pair try: resource_cap[new_key] = int(new_val) except: resource_cap[new_key] = new_val # if the same architecture is found if ((wanted_cpu_arch is None) \ or (wanted_cpu_arch == resource_cap['cpu_arch'])): # basic requirements from instance_type LOG.debug(_("## *** wanted arch found: <%s> ***"), wanted_cpu_arch) LOG.debug(_("## cap vcpus = <%s>"), int(resource_cap['vcpus']) \ - int(resource_cap['vcpus_used'])) LOG.debug(_("## cap memory_mb = <%s>"), resource_cap['host_memory_free']) if wanted_vcpus > (int(resource_cap['vcpus']) \ - int(resource_cap['vcpus_used'])) \ or wanted_memory_mb > \ int(resource_cap['host_memory_free']) \ or wanted_root_gb > (int(resource_cap['disk_total']) \ - int(resource_cap['disk_used'])): flag_different = 1 else: flag_different = 0 # extra requirements from instance_type_extra_spec # or instance_metadata table for kkey in instance_meta: try: if (flag_different == 0): wanted_value = instance_meta[kkey] LOG.debug(_("## wanted-key=%s"), kkey) LOG.debug(_("## wanted-value=%s"), \ wanted_value) if (wanted_value is not None): flag_different = 1 if (resource_cap[kkey] is None): LOG.debug(_("## cap is None")) elif type(resource_cap[kkey]) is int: LOG.debug(_("## offered(int)=%s"), \ resource_cap[kkey]) if int(wanted_value) <= \ resource_cap[kkey]: LOG.debug(_("## found")) flag_different = 0 else: LOG.debug(_("**not found")) else: # get wanted list first wanted = wanted_value.split(',') # get provided list now if resource_cap[kkey].find(',') == -1: offered = [resource_cap[kkey]] else: offered = resource_cap[kkey]. \ split(',') LOG.debug(_("## offered(str)=%s"), \ offered) # check if the required are provided flag_different = 0 for want in wanted: found = 0 for item in offered: if (want == item): found = 1 break if found == 0: flag_different = 1 LOG.debug(_("**not found")) break else: LOG.debug(_("## found")) except: pass if (flag_different == 0): LOG.debug(_("##\t***** found **********=")) hosts.append(host) else: LOG.debug(_("##\t***** not found **********=")) LOG.debug(_("## hosts = %s"), hosts) return hosts
def test_live_migration_all_checks_pass(self): """Test live migration when all checks pass.""" self.mox.StubOutWithMock(db, 'instance_get') self.mox.StubOutWithMock(db, 'service_get_all_by_topic') self.mox.StubOutWithMock(utils, 'service_is_up') self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host') self.mox.StubOutWithMock(self.driver, '_get_compute_info') self.mox.StubOutWithMock(db, 'instance_get_all_by_host') self.mox.StubOutWithMock(db, 'queue_get_for') self.mox.StubOutWithMock(rpc, 'call') self.mox.StubOutWithMock(rpc, 'cast') self.mox.StubOutWithMock(db, 'instance_update') self.mox.StubOutWithMock(db, 'volume_update') self.mox.StubOutWithMock(driver, 'cast_to_compute_host') dest = 'fake_host2' block_migration = True disk_over_commit = True instance = self._live_migration_instance() db.instance_get(self.context, instance['id']).AndReturn(instance) # Source checks (volume and source compute are up) db.service_get_all_by_topic(self.context, 'volume').AndReturn( ['fake_service']) utils.service_is_up('fake_service').AndReturn(True) db.service_get_all_compute_by_host(self.context, instance['host']).AndReturn(['fake_service2']) utils.service_is_up('fake_service2').AndReturn(True) # Destination checks (compute is up, enough memory, disk) db.service_get_all_compute_by_host(self.context, dest).AndReturn(['fake_service3']) utils.service_is_up('fake_service3').AndReturn(True) # assert_compute_node_has_enough_memory() self.driver._get_compute_info(self.context, dest, 'memory_mb').AndReturn(2048) db.instance_get_all_by_host(self.context, dest).AndReturn( [dict(memory_mb=256), dict(memory_mb=512)]) # assert_compute_node_has_enough_disk() db.queue_get_for(self.context, FLAGS.compute_topic, dest).AndReturn('dest_queue1') rpc.call(self.context, 'dest_queue1', {'method': 'update_available_resource'}) self.driver._get_compute_info(self.context, dest, 'disk_available_least').AndReturn(1025) db.queue_get_for(self.context, FLAGS.compute_topic, instance['host']).AndReturn('src_queue1') rpc.call(self.context, 'src_queue1', {'method': 'get_instance_disk_info', 'args': {'instance_name': instance['name']}}).AndReturn( json.dumps([{'disk_size': 1024 * (1024 ** 3)}])) # Common checks (shared storage ok, same hypervisor,e tc) db.queue_get_for(self.context, FLAGS.compute_topic, dest).AndReturn('dest_queue') db.queue_get_for(self.context, FLAGS.compute_topic, instance['host']).AndReturn('src_queue') tmp_filename = 'test-filename' rpc.call(self.context, 'dest_queue', {'method': 'create_shared_storage_test_file'} ).AndReturn(tmp_filename) rpc.call(self.context, 'src_queue', {'method': 'check_shared_storage_test_file', 'args': {'filename': tmp_filename}}).AndReturn(False) rpc.call(self.context, 'dest_queue', {'method': 'cleanup_shared_storage_test_file', 'args': {'filename': tmp_filename}}) db.service_get_all_compute_by_host(self.context, dest).AndReturn( [{'compute_node': [{'hypervisor_type': 'xen', 'hypervisor_version': 1}]}]) # newer hypervisor version for src db.service_get_all_compute_by_host(self.context, instance['host']).AndReturn( [{'compute_node': [{'hypervisor_type': 'xen', 'hypervisor_version': 1, 'cpu_info': 'fake_cpu_info'}]}]) db.queue_get_for(self.context, FLAGS.compute_topic, dest).AndReturn('dest_queue') rpc.call(self.context, 'dest_queue', {'method': 'compare_cpu', 'args': {'cpu_info': 'fake_cpu_info'}}).AndReturn(True) db.instance_update(self.context, instance['id'], {'vm_state': vm_states.MIGRATING}) db.volume_update(self.context, instance['volumes'][0]['id'], {'status': 'migrating'}) db.volume_update(self.context, instance['volumes'][1]['id'], {'status': 'migrating'}) driver.cast_to_compute_host(self.context, instance['host'], 'live_migration', update_db=False, instance_id=instance['id'], dest=dest, block_migration=block_migration) self.mox.ReplayAll() result = self.driver.schedule_live_migration(self.context, instance_id=instance['id'], dest=dest, block_migration=block_migration, disk_over_commit=disk_over_commit) self.assertEqual(result, None)