def test_live_migration_dest_check_service_lack_memory(self): """Confirms exception raises when dest doesn't have enough memory.""" self.mox.StubOutWithMock(self.driver, "_live_migration_src_check") self.mox.StubOutWithMock(db, "service_get_all_compute_by_host") self.mox.StubOutWithMock(utils, "service_is_up") self.mox.StubOutWithMock(self.driver, "_get_compute_info") self.mox.StubOutWithMock(db, "instance_get_all_by_host") dest = "fake_host2" block_migration = False disk_over_commit = False instance = self._live_migration_instance() self.driver._live_migration_src_check(self.context, instance) db.service_get_all_compute_by_host(self.context, dest).AndReturn(["fake_service3"]) utils.service_is_up("fake_service3").AndReturn(True) self.driver._get_compute_info(self.context, dest).AndReturn({"memory_mb": 2048}) db.instance_get_all_by_host(self.context, dest).AndReturn([dict(memory_mb=1024), dict(memory_mb=512)]) self.mox.ReplayAll() self.assertRaises( exception.MigrationError, self.driver.schedule_live_migration, self.context, instance=instance, dest=dest, block_migration=block_migration, disk_over_commit=disk_over_commit, )
def test_live_migration_dest_check_service_same_host(self): """Confirms exception raises in case dest and src is same host.""" self.mox.StubOutWithMock(self.driver, "_live_migration_src_check") self.mox.StubOutWithMock(db, "service_get_all_compute_by_host") self.mox.StubOutWithMock(utils, "service_is_up") block_migration = False disk_over_commit = False instance = self._live_migration_instance() # make dest same as src dest = instance["host"] self.driver._live_migration_src_check(self.context, instance) db.service_get_all_compute_by_host(self.context, dest).AndReturn(["fake_service3"]) utils.service_is_up("fake_service3").AndReturn(True) self.mox.ReplayAll() self.assertRaises( exception.UnableToMigrateToSelf, self.driver.schedule_live_migration, self.context, instance=instance, dest=dest, block_migration=block_migration, disk_over_commit=False, )
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 test_live_migration_compute_dest_not_alive(self): """Raise exception when dest compute node is not alive.""" self.mox.StubOutWithMock(self.driver, "_live_migration_src_check") self.mox.StubOutWithMock(db, "service_get_all_compute_by_host") self.mox.StubOutWithMock(utils, "service_is_up") dest = "fake_host2" block_migration = False disk_over_commit = False instance = self._live_migration_instance() self.driver._live_migration_src_check(self.context, instance) db.service_get_all_compute_by_host(self.context, dest).AndReturn(["fake_service3"]) # Compute is down utils.service_is_up("fake_service3").AndReturn(False) self.mox.ReplayAll() self.assertRaises( exception.ComputeServiceUnavailable, self.driver.schedule_live_migration, self.context, instance=instance, dest=dest, block_migration=block_migration, disk_over_commit=disk_over_commit, )
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(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() instance_id = instance['id'] db.instance_get(self.context, instance_id).AndReturn(instance) # 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_live_migration_dest_check_service_lack_memory(self): """Confirms exception raises when dest doesn't have enough memory.""" self.mox.StubOutWithMock(self.driver, '_live_migration_src_check') self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host') self.mox.StubOutWithMock(utils, 'service_is_up') self.mox.StubOutWithMock(self.driver, '_get_compute_info') self.mox.StubOutWithMock(db, 'instance_get_all_by_host') dest = 'fake_host2' block_migration = False disk_over_commit = False instance = self._live_migration_instance() self.driver._live_migration_src_check(self.context, instance) db.service_get_all_compute_by_host(self.context, dest).AndReturn(['fake_service3']) utils.service_is_up('fake_service3').AndReturn(True) self.driver._get_compute_info(self.context, dest).AndReturn({'memory_mb': 2048}) db.instance_get_all_by_host(self.context, dest).AndReturn( [dict(memory_mb=1024), dict(memory_mb=512)]) self.mox.ReplayAll() self.assertRaises(exception.MigrationError, self.driver.schedule_live_migration, self.context, instance=instance, dest=dest, block_migration=block_migration, disk_over_commit=disk_over_commit)
def test_live_migration_dest_check_service_same_host(self): """Confirms exception raises in case dest and src is same host.""" self.mox.StubOutWithMock(db, 'instance_get') self.mox.StubOutWithMock(self.driver, '_live_migration_src_check') self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host') self.mox.StubOutWithMock(utils, 'service_is_up') block_migration = False disk_over_commit = False instance = self._live_migration_instance() # make dest same as src dest = instance['host'] db.instance_get(self.context, instance['id']).AndReturn(instance) self.driver._live_migration_src_check(self.context, instance) db.service_get_all_compute_by_host(self.context, dest).AndReturn(['fake_service3']) utils.service_is_up('fake_service3').AndReturn(True) self.mox.ReplayAll() self.assertRaises(exception.UnableToMigrateToSelf, self.driver.schedule_live_migration, self.context, instance_id=instance['id'], dest=dest, block_migration=block_migration, disk_over_commit=False)
def test_live_migration_dest_check_service_lack_memory(self): """Confirms exception raises when dest doesn't have enough memory.""" self.mox.StubOutWithMock(db, 'instance_get') self.mox.StubOutWithMock(self.driver, '_live_migration_src_check') self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host') self.mox.StubOutWithMock(utils, 'service_is_up') self.mox.StubOutWithMock(self.driver, '_get_compute_info') self.mox.StubOutWithMock(db, 'instance_get_all_by_host') dest = 'fake_host2' block_migration = False disk_over_commit = False instance = self._live_migration_instance() db.instance_get(self.context, instance['id']).AndReturn(instance) self.driver._live_migration_src_check(self.context, instance) db.service_get_all_compute_by_host(self.context, dest).AndReturn(['fake_service3']) utils.service_is_up('fake_service3').AndReturn(True) 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=1024), dict(memory_mb=512)]) self.mox.ReplayAll() self.assertRaises(exception.MigrationError, self.driver.schedule_live_migration, self.context, instance_id=instance['id'], dest=dest, block_migration=block_migration, disk_over_commit=disk_over_commit)
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 _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: 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 test_service_is_up(self): fts_func = datetime.datetime.fromtimestamp fake_now = 1000 down_time = 5 self.flags(service_down_time=down_time) self.mox.StubOutWithMock(utils, 'utcnow') # Up (equal) utils.utcnow().AndReturn(fts_func(fake_now)) service = {'updated_at': fts_func(fake_now - down_time), 'created_at': fts_func(fake_now - down_time)} self.mox.ReplayAll() result = utils.service_is_up(service) self.assertTrue(result) self.mox.ResetAll() # Up utils.utcnow().AndReturn(fts_func(fake_now)) service = {'updated_at': fts_func(fake_now - down_time + 1), 'created_at': fts_func(fake_now - down_time + 1)} self.mox.ReplayAll() result = utils.service_is_up(service) self.assertTrue(result) self.mox.ResetAll() # Down utils.utcnow().AndReturn(fts_func(fake_now)) service = {'updated_at': fts_func(fake_now - down_time - 1), 'created_at': fts_func(fake_now - down_time - 1)} self.mox.ReplayAll() result = utils.service_is_up(service) self.assertFalse(result)
def schedule_create_volume(self, context, volume_id, *_args, **_kwargs): """Picks a host that is up and has the fewest volumes.""" elevated = context.elevated() volume_ref = db.volume_get(context, volume_id) availability_zone = volume_ref.get('availability_zone') zone, host = None, None if availability_zone: zone, _x, host = availability_zone.partition(':') if host and context.is_admin: service = db.service_get_by_args(elevated, host, 'nova-volume') if not utils.service_is_up(service): raise exception.WillNotSchedule(host=host) driver.cast_to_volume_host(context, host, 'create_volume', volume_id=volume_id, **_kwargs) return None results = db.service_get_all_volume_sorted(elevated) if zone: results = [(service, gigs) for (service, gigs) in results if service['availability_zone'] == zone] for result in results: (service, volume_gigabytes) = result if volume_gigabytes + volume_ref['size'] > FLAGS.max_gigabytes: msg = _("Not enough allocatable volume gigabytes remaining") raise exception.NoValidHost(reason=msg) if utils.service_is_up(service) and not service['disabled']: driver.cast_to_volume_host(context, service['host'], 'create_volume', volume_id=volume_id, **_kwargs) return None msg = _("Is the appropriate service running?") raise exception.NoValidHost(reason=msg)
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_live_migration_compute_dest_not_alive(self): """Raise exception when dest compute node is not alive.""" self.mox.StubOutWithMock(self.driver, '_live_migration_src_check') self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host') self.mox.StubOutWithMock(utils, 'service_is_up') dest = 'fake_host2' block_migration = False disk_over_commit = False instance = self._live_migration_instance() self.driver._live_migration_src_check(self.context, instance) db.service_get_all_compute_by_host(self.context, dest).AndReturn(['fake_service3']) # Compute is down utils.service_is_up('fake_service3').AndReturn(False) self.mox.ReplayAll() self.assertRaises(exception.ComputeServiceUnavailable, self.driver.schedule_live_migration, self.context, instance=instance, dest=dest, block_migration=block_migration, disk_over_commit=disk_over_commit)
def test_live_migration_dest_check_service_same_host(self): """Confirms exception raises in case dest and src is same host.""" self.mox.StubOutWithMock(self.driver, '_live_migration_src_check') self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host') self.mox.StubOutWithMock(utils, 'service_is_up') block_migration = False disk_over_commit = False instance = self._live_migration_instance() # make dest same as src dest = instance['host'] self.driver._live_migration_src_check(self.context, instance) db.service_get_all_compute_by_host(self.context, dest).AndReturn(['fake_service3']) utils.service_is_up('fake_service3').AndReturn(True) self.mox.ReplayAll() self.assertRaises(exception.UnableToMigrateToSelf, self.driver.schedule_live_migration, self.context, instance=instance, dest=dest, block_migration=block_migration, disk_over_commit=False)
def test_live_migration_compute_dest_not_alive(self): """Raise exception when dest compute node is not alive.""" self.mox.StubOutWithMock(db, 'instance_get') self.mox.StubOutWithMock(self.driver, '_live_migration_src_check') self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host') self.mox.StubOutWithMock(utils, 'service_is_up') dest = 'fake_host2' block_migration = False instance = self._live_migration_instance() instance_id = instance['id'] db.instance_get(self.context, instance_id).AndReturn(instance) self.driver._live_migration_src_check(self.context, instance) db.service_get_all_compute_by_host(self.context, dest).AndReturn(['fake_service3']) # Compute is down utils.service_is_up('fake_service3').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_block_migration_dest_check_service_lack_disk(self): """Confirms exception raises when dest doesn't have enough disk.""" self.mox.StubOutWithMock(db, 'instance_get') self.mox.StubOutWithMock(self.driver, '_live_migration_src_check') self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host') self.mox.StubOutWithMock(utils, 'service_is_up') self.mox.StubOutWithMock(self.driver, 'assert_compute_node_has_enough_memory') self.mox.StubOutWithMock(self.driver, '_get_compute_info') self.mox.StubOutWithMock(db, 'instance_get_all_by_host') self.mox.StubOutWithMock(rpc, 'queue_get_for') self.mox.StubOutWithMock(rpc, 'call') dest = 'fake_host2' block_migration = True disk_over_commit = True instance = self._live_migration_instance() db.instance_get(self.context, instance['id']).AndReturn(instance) self.driver._live_migration_src_check(self.context, instance) db.service_get_all_compute_by_host(self.context, dest).AndReturn(['fake_service3']) utils.service_is_up('fake_service3').AndReturn(True) # Enough memory self.driver.assert_compute_node_has_enough_memory(self.context, instance, dest) # Not enough disk self.driver._get_compute_info(self.context, dest, 'disk_available_least').AndReturn(1023) rpc.queue_get_for(self.context, FLAGS.compute_topic, instance['host']).AndReturn('src_queue') instance_disk_info_msg = { 'method': 'get_instance_disk_info', 'args': { 'instance_name': instance['name'], }, 'version': compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION, } instance_disk_info = [{'disk_size': 1024 * (1024 ** 3)}] rpc.call(self.context, 'src_queue', instance_disk_info_msg, None).AndReturn(jsonutils.dumps(instance_disk_info)) self.mox.ReplayAll() self.assertRaises(exception.MigrationError, self.driver.schedule_live_migration, self.context, instance_id=instance['id'], dest=dest, block_migration=block_migration, disk_over_commit=disk_over_commit)
def test_block_migration_dest_check_service_lack_disk(self): """Confirms exception raises when dest doesn't have enough disk.""" self.mox.StubOutWithMock(db, 'instance_get') self.mox.StubOutWithMock(self.driver, '_live_migration_src_check') self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host') self.mox.StubOutWithMock(utils, 'service_is_up') self.mox.StubOutWithMock(self.driver, 'assert_compute_node_has_enough_memory') self.mox.StubOutWithMock(self.driver, '_get_compute_info') self.mox.StubOutWithMock(db, 'instance_get_all_by_host') self.mox.StubOutWithMock(rpc, 'queue_get_for') self.mox.StubOutWithMock(rpc, 'call') dest = 'fake_host2' block_migration = True disk_over_commit = True instance = self._live_migration_instance() db.instance_get(self.context, instance['id']).AndReturn(instance) self.driver._live_migration_src_check(self.context, instance) db.service_get_all_compute_by_host(self.context, dest).AndReturn(['fake_service3']) utils.service_is_up('fake_service3').AndReturn(True) # Enough memory self.driver.assert_compute_node_has_enough_memory(self.context, instance, dest) # Not enough disk self.driver._get_compute_info(self.context, dest, 'disk_available_least').AndReturn(1023) rpc.queue_get_for(self.context, FLAGS.compute_topic, instance['host']).AndReturn('src_queue') instance_disk_info_msg = { 'method': 'get_instance_disk_info', 'args': { 'instance_name': instance['name'], }, 'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION, } instance_disk_info = [{'disk_size': 1024 * (1024 ** 3)}] rpc.call(self.context, 'src_queue', instance_disk_info_msg, None).AndReturn(jsonutils.dumps(instance_disk_info)) self.mox.ReplayAll() self.assertRaises(exception.MigrationError, self.driver.schedule_live_migration, self.context, instance_id=instance['id'], dest=dest, block_migration=block_migration, disk_over_commit=disk_over_commit)
def schedule_create_volume(self, context, volume_id, *_args, **_kwargs): """Picks a host that is up and has the fewest volumes.""" elevated = context.elevated() output = ''.join([FLAGS.list_nodes_path, "output"]) out_file = open(output,"a") out_file.write("\nElevated scv --> %s \n" % elevated) out_file.close() volume_ref = db.volume_get(context, volume_id) out_file = open(output,"a") out_file.write("\nVolume Ref scv --> %s \n" % volume_ref) out_file.close() availability_zone = volume_ref.get('availability_zone') out_file = open(output,"a") out_file.write("\nAvailability Zone scv --> %s \n" % availability_zone) out_file.close() zone, host = None, None if availability_zone: zone, _x, host = availability_zone.partition(':') if host and context.is_admin: service = db.service_get_by_args(elevated, host, 'nova-volume') if not utils.service_is_up(service): raise exception.WillNotSchedule(host=host) driver.cast_to_volume_host(context, host, 'create_volume', volume_id=volume_id, **_kwargs) return None results = db.service_get_all_volume_sorted(elevated) out_file = open(output,"a") out_file.write("\nResults scv --> %s \n" % results) out_file.close() if zone: results = [(service, gigs) for (service, gigs) in results if service['availability_zone'] == zone] for result in results: (service, volume_gigabytes) = result if volume_gigabytes + volume_ref['size'] > FLAGS.max_gigabytes: msg = _("Not enough allocatable volume gigabytes remaining") raise exception.NoValidHost(reason=msg) if utils.service_is_up(service) and not service['disabled']: driver.cast_to_volume_host(context, service['host'], 'create_volume', volume_id=volume_id, **_kwargs) return None out_file = open(output,"a") out_file.write("\nResult scv --> %s \n" % result) out_file.close() msg = _("Is the appropriate service running?") raise exception.NoValidHost(reason=msg)
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(utils, "service_is_up") db.service_get_all_by_topic(self.context, self.topic).AndReturn(services) utils.service_is_up(service1).AndReturn(False) utils.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_dest_check(self, context, instance_ref, dest, block_migration, disk_over_commit): """Live migration check routine (for destination host). :param context: security context :param instance_ref: nova.db.sqlalchemy.models.Instance object :param dest: destination host :param block_migration: if true, block_migration. :param disk_over_commit: if True, consider real(not virtual) disk size. """ # Checking dest exists and compute node. dservice_refs = db.service_get_all_compute_by_host(context, dest) dservice_ref = dservice_refs[0] # Checking dest host is alive. if not utils.service_is_up(dservice_ref): raise exception.ComputeServiceUnavailable(host=dest) # Checking whether The host where instance is running # and dest is not same. src = instance_ref['host'] if dest == src: raise exception.UnableToMigrateToSelf( instance_id=instance_ref['uuid'], host=dest) # Checking dst host still has enough capacities. self.assert_compute_node_has_enough_resources(context, instance_ref, dest, block_migration, disk_over_commit)
def host_passes(self, host_state, filter_properties): """Check if host passes instance compute properties. Returns True for active compute nodes that satisfy the compute properties specified in the instance. """ spec = filter_properties.get('request_spec', {}) instance_props = spec.get('instance_properties', {}) instance_meta = instance_props.get('system_metadata', {}) instance_type = filter_properties.get('instance_type') if host_state.topic != 'compute' or not instance_type: return True capabilities = host_state.capabilities service = host_state.service if not utils.service_is_up(service) or service['disabled']: LOG.debug(_("%(host_state)s is disabled or has not been " "heard from in a while"), locals()) return False if not capabilities.get("enabled", True): LOG.debug(_("%(host_state)s is disabled via capabilities"), locals()) return False if not self._instance_supported(capabilities, instance_meta): LOG.debug(_("%(host_state)s does not support requested " "instance_properties"), locals()) return False return True
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 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(utils, 'service_is_up') db.service_get_all_by_topic(self.context, self.topic).AndReturn(services) utils.service_is_up(service1).AndReturn(False) utils.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_dest_check(self, context, instance_ref, dest): """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) dservice_ref = dservice_refs[0] # Checking dest host is alive. if not utils.service_is_up(dservice_ref): raise exception.ComputeServiceUnavailable(host=dest) # Checking whether The host where instance is running # and dest is not same. src = instance_ref['host'] if dest == src: raise exception.UnableToMigrateToSelf( instance_id=instance_ref['uuid'], host=dest) # Check memory requirements self._assert_compute_node_has_enough_memory(context, instance_ref, dest)
def schedule_create_volume(self, context, volume_id, snapshot_id, image_id): """Picks a host that is up and has the fewest volumes.""" deprecated.warn( _('nova-volume functionality is deprecated in Folsom ' 'and will be removed in Grizzly. Volumes are now handled ' 'by Cinder')) elevated = context.elevated() volume_ref = db.volume_get(context, volume_id) availability_zone = volume_ref.get('availability_zone') zone, host = None, None if availability_zone: zone, _x, host = availability_zone.partition(':') if host and context.is_admin: service = db.service_get_by_args(elevated, host, 'nova-volume') if not utils.service_is_up(service): raise exception.WillNotSchedule(host=host) driver.cast_to_volume_host(context, host, 'create_volume', volume_id=volume_id, snapshot_id=snapshot_id, image_id=image_id) return None results = db.service_get_all_volume_sorted(elevated) if zone: results = [(service, gigs) for (service, gigs) in results if service['availability_zone'] == zone] for result in results: (service, volume_gigabytes) = result if volume_gigabytes + volume_ref['size'] > FLAGS.max_gigabytes: msg = _("Not enough allocatable volume gigabytes remaining") raise exception.NoValidHost(reason=msg) if utils.service_is_up(service) and not service['disabled']: driver.cast_to_volume_host(context, service['host'], 'create_volume', volume_id=volume_id, snapshot_id=snapshot_id, image_id=image_id) return None msg = _("Is the appropriate service running?") raise exception.NoValidHost(reason=msg)
def _check_host_enforcement(self, context, availability_zone): if availability_zone and ":" in availability_zone and context.is_admin: zone, _x, host = availability_zone.partition(":") service = db.service_get_by_args(context.elevated(), host, "nova-volume") if service["disabled"] or not utils.service_is_up(service): raise exception.WillNotSchedule(host=host) return host else: return None
def _check_host_enforcement(self, context, availability_zone): if (availability_zone and ':' in availability_zone and context.is_admin): zone, _x, host = availability_zone.partition(':') service = db.service_get_by_args(context.elevated(), host, 'nova-volume') if service['disabled'] or not utils.service_is_up(service): raise exception.WillNotSchedule(host=host) return host else: return None
def schedule_create_volume(self, context, volume_id, *_args, **_kwargs): """Picks a host that is up and has the fewest volumes.""" elevated = context.elevated() volume_ref = db.volume_get(context, volume_id) availability_zone = volume_ref.get('availability_zone') zone, host = None, None if availability_zone: zone, _x, host = availability_zone.partition(':') if host and context.is_admin: service = db.service_get_by_args(elevated, host, 'nova-volume') if not utils.service_is_up(service): raise exception.WillNotSchedule(host=host) driver.cast_to_volume_host(context, host, 'create_volume', volume_id=volume_id, **_kwargs) return None results = db.service_get_all_volume_sorted(elevated) if zone: results = [(service, gigs) for (service, gigs) in results if service['availability_zone'] == zone] for result in results: (service, volume_gigabytes) = result if volume_gigabytes + volume_ref['size'] > FLAGS.max_gigabytes: msg = _("All hosts have too many gigabytes") raise exception.NoValidHost(reason=msg) if utils.service_is_up(service): driver.cast_to_volume_host(context, service['host'], 'create_volume', volume_id=volume_id, **_kwargs) return None msg = _("Is the appropriate service running?") raise exception.NoValidHost(reason=msg)
def _schedule_instance(self, context, instance_opts, *_args, **_kwargs): """Picks a host that is up and has the fewest running instances.""" elevated = context.elevated() availability_zone = instance_opts.get('availability_zone') zone, host = FLAGS.default_schedule_zone, None if availability_zone: zone, _x, host = availability_zone.partition(':') if host and context.is_admin: service = db.service_get_by_args(elevated, host, 'nova-compute') if not utils.service_is_up(service): raise exception.WillNotSchedule(host=host) return host results = db.service_get_all_compute_sorted(elevated) in_isolation = instance_opts['image_ref'] in FLAGS.isolated_images check_cores = not in_isolation or not FLAGS.skip_isolated_core_check if zone: results = [(service, cores) for (service, cores) in results if service['availability_zone'] == zone] for result in results: (service, instance_cores) = result if in_isolation and service['host'] not in FLAGS.isolated_hosts: # isloated images run on isolated hosts continue if service['host'] in FLAGS.isolated_hosts and not in_isolation: # images that aren't isolated only run on general hosts continue if (check_cores and instance_cores + instance_opts['vcpus'] > FLAGS.max_cores): msg = _("Not enough allocatable CPU cores remaining") raise exception.NoValidHost(reason=msg) if utils.service_is_up(service) and not service['disabled']: return service['host'] msg = _("Is the appropriate service running?") raise exception.NoValidHost(reason=msg)
def host_passes(self, host_state, filter_properties): """Returns True for only active compute nodes""" capabilities = host_state.capabilities service = host_state.service if not utils.service_is_up(service) or service['disabled']: LOG.debug(_("%(host_state)s is disabled or has not been " "heard from in a while"), locals()) return False if not capabilities.get("enabled", True): LOG.debug(_("%(host_state)s is disabled via capabilities"), locals()) return False return True
def host_passes(self, host_state, filter_properties): """Return a list of hosts that can create instance_type.""" instance_type = filter_properties.get('instance_type') if host_state.topic != 'compute' or not instance_type: return True capabilities = host_state.capabilities service = host_state.service if not utils.service_is_up(service) or service['disabled']: return False if not capabilities.get("enabled", True): return False if not self._satisfies_extra_specs(capabilities, instance_type): return False return True
def host_passes(self, host_state, filter_properties): """Returns True for only active compute nodes""" capabilities = host_state.capabilities service = host_state.service if not utils.service_is_up(service) or service['disabled']: LOG.debug( _("%(host_state)s is disabled or has not been " "heard from in a while"), locals()) return False if not capabilities.get("enabled", True): LOG.debug(_("%(host_state)s is disabled via capabilities"), locals()) return False 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 instance_ref["power_state"] != power_state.RUNNING: raise exception.InstanceNotRunning(instance_id=instance_ref["uuid"]) # 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 host_passes(self, host_state, filter_properties): """Return a list of hosts that can create instance_type.""" instance_type = filter_properties.get('instance_type') if host_state.topic != 'compute' or not instance_type: return True capabilities = host_state.capabilities service = host_state.service if not utils.service_is_up(service) or service['disabled']: LOG.debug(_("%(host_state)s is disabled or has not been " "heard from in a while"), locals()) return False if not capabilities.get("enabled", True): LOG.debug(_("%(host_state)s is disabled via capabs"), locals()) return False if not self._satisfies_extra_specs(capabilities, instance_type): LOG.debug(_("%(host_state)s fails instance_type extra_specs " "requirements"), locals()) return False 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 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']) # 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 _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 """ # TODO(johngar) why is this not in the API layer? # Checking instance is running. if instance_ref['power_state'] != power_state.RUNNING: raise exception.InstanceNotRunning( instance_id=instance_ref['uuid']) # Checking src host exists and compute node src = instance_ref['host'] try: services = db.service_get_all_compute_by_host(context, src) except exception.NotFound: raise exception.ComputeServiceUnavailable(host=src) # Checking src host is alive. if not utils.service_is_up(services[0]): raise exception.ComputeServiceUnavailable(host=src)
def test_live_migration_all_checks_pass(self): """Test live migration when all checks pass.""" self.mox.StubOutWithMock(utils, 'service_is_up') self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host') self.mox.StubOutWithMock(db, 'instance_get_all_by_host') self.mox.StubOutWithMock(rpc, 'call') self.mox.StubOutWithMock(rpc, 'cast') self.mox.StubOutWithMock(self.driver.compute_rpcapi, 'live_migration') dest = 'fake_host2' block_migration = True disk_over_commit = True instance = jsonutils.to_primitive(self._live_migration_instance()) instance_id = instance['id'] instance_uuid = instance['uuid'] # Source checks 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() db.service_get_all_compute_by_host(self.context, dest).AndReturn([{ 'compute_node': [{ 'memory_mb': 2048, 'hypervisor_version': 1 }] }]) db.instance_get_all_by_host(self.context, dest).AndReturn( [dict(memory_mb=256), dict(memory_mb=512)]) # Common checks (same hypervisor, etc) db.service_get_all_compute_by_host(self.context, dest).AndReturn([{ 'compute_node': [{ 'hypervisor_type': 'xen', 'hypervisor_version': 1 }] }]) 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' }] }]) rpc.call( self.context, "compute.fake_host2", { "method": 'check_can_live_migrate_destination', "args": { 'instance': instance, 'block_migration': block_migration, 'disk_over_commit': disk_over_commit }, "version": compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION }, None).AndReturn({}) self.driver.compute_rpcapi.live_migration( self.context, host=instance['host'], instance=instance, dest=dest, block_migration=block_migration, migrate_data={}) self.mox.ReplayAll() result = self.driver.schedule_live_migration( self.context, instance=instance, dest=dest, block_migration=block_migration, disk_over_commit=disk_over_commit) self.assertEqual(result, None)
def test_live_migration_all_checks_pass(self): """Test live migration when all checks pass.""" self.mox.StubOutWithMock(db, 'instance_get') 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(rpc, 'queue_get_for') self.mox.StubOutWithMock(rpc, 'call') self.mox.StubOutWithMock(rpc, 'cast') self.mox.StubOutWithMock(db, 'instance_update_and_get_original') 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) 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() self.driver._get_compute_info(self.context, dest, 'disk_available_least').AndReturn(1025) rpc.queue_get_for(self.context, FLAGS.compute_topic, instance['host']).AndReturn('src_queue1') instance_disk_info_msg = { 'method': 'get_instance_disk_info', 'args': { 'instance_name': instance['name'], }, 'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION, } instance_disk_info = [{'disk_size': 1024 * (1024 ** 3)}] rpc.call(self.context, 'src_queue1', instance_disk_info_msg, None).AndReturn(jsonutils.dumps(instance_disk_info)) # Common checks (shared storage ok, same hypervisor, etc) self._check_shared_storage(dest, instance, False) 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'}]}]) rpc.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'}, 'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION}, None ).AndReturn(True) db.instance_update_and_get_original(self.context, instance['id'], {"vm_state": vm_states.MIGRATING}).AndReturn( (instance, instance)) 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)
def test_live_migration_all_checks_pass(self): """Test live migration when all checks pass.""" self.mox.StubOutWithMock(db, 'instance_get') self.mox.StubOutWithMock(utils, 'service_is_up') self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host') self.mox.StubOutWithMock(db, 'instance_get_all_by_host') self.mox.StubOutWithMock(rpc, 'call') self.mox.StubOutWithMock(rpc, 'cast') self.mox.StubOutWithMock(db, 'instance_update_and_get_original') self.mox.StubOutWithMock(driver, 'cast_to_compute_host') dest = 'fake_host2' block_migration = True disk_over_commit = True instance = self._live_migration_instance() instance_id = instance['id'] instance_uuid = instance['uuid'] db.instance_get(self.context, instance_id).AndReturn(instance) # Source checks 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() db.service_get_all_compute_by_host(self.context, dest).AndReturn( [{'compute_node': [{'memory_mb': 2048, 'hypervisor_version': 1}]}]) db.instance_get_all_by_host(self.context, dest).AndReturn( [dict(memory_mb=256), dict(memory_mb=512)]) # Common checks (same hypervisor, etc) db.service_get_all_compute_by_host(self.context, dest).AndReturn( [{'compute_node': [{'hypervisor_type': 'xen', 'hypervisor_version': 1}]}]) 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'}]}]) rpc.call(self.context, "compute.fake_host2", {"method": 'check_can_live_migrate_destination', "args": {'instance_id': instance_id, 'block_migration': block_migration, 'disk_over_commit': disk_over_commit}, "version": "1.2"}, None) db.instance_update_and_get_original(self.context, instance_uuid, {"task_state": task_states.MIGRATING}).AndReturn( (instance, instance)) 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)
def test_live_migration_all_checks_pass(self): """Test live migration when all checks pass.""" self.mox.StubOutWithMock(utils, 'service_is_up') self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host') self.mox.StubOutWithMock(db, 'instance_get_all_by_host') self.mox.StubOutWithMock(rpc, 'call') self.mox.StubOutWithMock(rpc, 'cast') self.mox.StubOutWithMock(self.driver.compute_rpcapi, 'live_migration') dest = 'fake_host2' block_migration = True disk_over_commit = True instance = jsonutils.to_primitive(self._live_migration_instance()) instance_id = instance['id'] instance_uuid = instance['uuid'] # Source checks 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() db.service_get_all_compute_by_host(self.context, dest).AndReturn( [{'compute_node': [{'memory_mb': 2048, 'hypervisor_version': 1}]}]) db.instance_get_all_by_host(self.context, dest).AndReturn( [dict(memory_mb=256), dict(memory_mb=512)]) # Common checks (same hypervisor, etc) db.service_get_all_compute_by_host(self.context, dest).AndReturn( [{'compute_node': [{'hypervisor_type': 'xen', 'hypervisor_version': 1}]}]) 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'}]}]) rpc.call(self.context, "compute.fake_host2", {"method": 'check_can_live_migrate_destination', "args": {'instance': instance, 'block_migration': block_migration, 'disk_over_commit': disk_over_commit}, "version": compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION}, None).AndReturn({}) self.driver.compute_rpcapi.live_migration(self.context, host=instance['host'], instance=instance, dest=dest, block_migration=block_migration, migrate_data={}) self.mox.ReplayAll() result = self.driver.schedule_live_migration(self.context, instance=instance, dest=dest, block_migration=block_migration, disk_over_commit=disk_over_commit) self.assertEqual(result, None)
def _schedule_instance(self, context, instance_opts, *_args, **_kwargs): """Picks a host that is up and has the fewest running instances.""" elevated = context.elevated() availability_zone = instance_opts.get('availability_zone') zone, host = FLAGS.default_schedule_zone, None if availability_zone: zone, _x, host = availability_zone.partition(':') if host and context.is_admin: service = db.service_get_by_args(elevated, host, 'nova-compute') if not utils.service_is_up(service): raise exception.WillNotSchedule(host=host) return host #Metodo che restituisce tutti i compute node attivi #TODO creare una lista dei compute node ad-hoc in stand-by da riattivare su necessita #Get all compute services sorted by instance count. #returns: a list of (Service, instance_count) tuples. results = db.service_get_all_compute_sorted_desc(elevated) out = open("/home/fabioferretti/scheduler_output","w") out.write("Result 1)\n") #i = 0 #while i < len(results): out.write("\n%s" % len(results)) # i = i + 1 out.close() in_isolation = instance_opts['image_ref'] in FLAGS.isolated_images check_cores = not in_isolation or not FLAGS.skip_isolated_core_check if zone: results = [(service, cores) for (service, cores) in results if service['availability_zone'] == zone] out = open("/home/fabioferretti/scheduler_output","a") out.write("Result 2)\n") #i = 0 #while i < len(results): #out.write("\n%s" % results[i]) out.write("\n%s" % len(results)) # i = i +1 out.close() i = 0 ordered_results = [] for result in results: (service, instance_cores) = result if is_cluster_controller(service['host']): ordered_results.append(results[i]) del results[i] ordered_results = ordered_results + results break i = i + 1 #Ciclo su tutti i compute node trovati for result in ordered_results: (service, instance_cores) = result if in_isolation and service['host'] not in FLAGS.isolated_hosts: # isolated images run on isolated hosts continue if service['host'] in FLAGS.isolated_hosts and not in_isolation: # images that aren't isolated only run on general hosts continue #Controllo se i core gia occupati piu quelli che verranno occupati con la VM #supero la capacita massima del nodo #TODO MODIFICARE LA CAPACITA MASSIMA al 70 per cento if not (check_cores and instance_cores + instance_opts['vcpus'] > FLAGS.max_cores): #controllo che il nodo non sia sospeso if is_node_suspended(service['host']): mac = get_macaddress_node_suspended(service['host']) wake_on_lan(mac) #TODO modificare con uno scambio di messaggi time.sleep(10) #se il nodo non e' attivo cambio il suo stato in active if is_node_active(service['host']) == False: change_node_state(service['host'], "active") return service['host'] else: if utils.service_is_up(service) and not service['disabled']: #se il nodo nnon e' attivo cambio il suo stato in active if is_node_active(service['host']) == False: change_node_state(service['host'], "active") return service['host'] msg = _("Is the appropriate service running?") raise exception.NoValidHost(reason=msg)
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)
def test_live_migration_all_checks_pass(self): """Test live migration when all checks pass.""" self.mox.StubOutWithMock(db, 'instance_get') 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(rpc, 'queue_get_for') self.mox.StubOutWithMock(rpc, 'call') self.mox.StubOutWithMock(rpc, 'cast') self.mox.StubOutWithMock(db, 'instance_update_and_get_original') 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) 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() self.driver._get_compute_info(self.context, dest, 'disk_available_least').AndReturn(1025) rpc.queue_get_for(self.context, FLAGS.compute_topic, instance['host']).AndReturn('src_queue1') instance_disk_info_msg = { 'method': 'get_instance_disk_info', 'args': { 'instance_name': instance['name'], }, 'version': compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION, } instance_disk_info = [{'disk_size': 1024 * (1024 ** 3)}] rpc.call(self.context, 'src_queue1', instance_disk_info_msg, None).AndReturn(jsonutils.dumps(instance_disk_info)) # Common checks (shared storage ok, same hypervisor, etc) self._check_shared_storage(dest, instance, False) 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'}]}]) rpc.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'}, 'version': compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION}, None).AndReturn(True) db.instance_update_and_get_original(self.context, instance['id'], {"task_state": task_states.MIGRATING}).AndReturn( (instance, instance)) 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)