def test_find_destination_retry_with_invalid_livem_checks(self):
    self.flags(migrate_max_retries=1)
    self.mox.StubOutWithMock(compute_utils, 'get_image_metadata')
    self.mox.StubOutWithMock(scheduler_utils, 'build_request_spec')
    self.mox.StubOutWithMock(scheduler_utils, 'setup_instance_group')
    self.mox.StubOutWithMock(self.task.scheduler_client, 'select_destinations')
    self.mox.StubOutWithMock(self.task, '_check_compatible_with_source_hypervisor')
    self.mox.StubOutWithMock(self.task, '_call_livem_checks_on_host')
    compute_utils.get_image_metadata(self.context, self.task.image_api, self.instance_image, self.instance).AndReturn('image')
    scheduler_utils.build_request_spec(self.context, mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({})
    scheduler_utils.setup_instance_group(self.context, {}, {'ignore_hosts': [self.instance_host]})
    self.task.scheduler_client.select_destinations(self.context, mox.IgnoreArg(), mox.IgnoreArg()).AndReturn([{'host': 'host1'}])
    self.task._check_compatible_with_source_hypervisor('host1')
    self.task._call_livem_checks_on_host('host1').AndRaise(exception.Invalid)
    scheduler_utils.setup_instance_group(self.context, {}, {'ignore_hosts': [self.instance_host, 'host1']})
    self.task.scheduler_client.select_destinations(self.context, mox.IgnoreArg(), mox.IgnoreArg()).AndReturn([{'host': 'host2'}])
    self.task._check_compatible_with_source_hypervisor('host2')
    self.task._call_livem_checks_on_host('host2')
    self.mox.ReplayAll()
    self.assertEqual('host2', self.task._find_destination())
def test_find_destination_retry_with_invalid_livem_checks(self):
    self.flags(migrate_max_retries=1)
    self.mox.StubOutWithMock(compute_utils, 'get_image_metadata')
    self.mox.StubOutWithMock(scheduler_utils, 'build_request_spec')
    self.mox.StubOutWithMock(scheduler_utils, 'setup_instance_group')
    self.mox.StubOutWithMock(self.task.scheduler_client, 'select_destinations')
    self.mox.StubOutWithMock(self.task, '_check_compatible_with_source_hypervisor')
    self.mox.StubOutWithMock(self.task, '_call_livem_checks_on_host')
    compute_utils.get_image_metadata(self.context, self.task.image_api, self.instance_image, self.instance).AndReturn('image')
    scheduler_utils.build_request_spec(self.context, mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({})
    scheduler_utils.setup_instance_group(self.context, {}, {'ignore_hosts': [self.instance_host]})
    self.task.scheduler_client.select_destinations(self.context, mox.IgnoreArg(), mox.IgnoreArg()).AndReturn([{'host': 'host1'}])
    self.task._check_compatible_with_source_hypervisor('host1')
    self.task._call_livem_checks_on_host('host1').AndRaise(exception.Invalid)
    scheduler_utils.setup_instance_group(self.context, {}, {'ignore_hosts': [self.instance_host, 'host1']})
    self.task.scheduler_client.select_destinations(self.context, mox.IgnoreArg(), mox.IgnoreArg()).AndReturn([{'host': 'host2'}])
    self.task._check_compatible_with_source_hypervisor('host2')
    self.task._call_livem_checks_on_host('host2')
    self.mox.ReplayAll()
    self.assertEqual('host2', self.task._find_destination())