'Confirm that the evacuate scenario does not attempt a driver detach
when rebuilding an instance with volumes on a remote host'

@mock.patch.object(cinder.API, 'detach')
@mock.patch.object(compute_manager.ComputeManager, '_prep_block_device')
@mock.patch.object(driver_bdm_volume, 'driver_detach')
def test_rebuild_on_remote_host_with_volumes(self, mock_drv_detach, mock_prep, mock_detach):

    values = {'instance_uuid': self.inst.uuid, 'source_type': 'volume', 'device_name': '/dev/vdc', 'delete_on_termination': False, 'volume_id': uuids.volume_id, 'connection_info': '{}'}
    db.block_device_mapping_create(self.context, values)
    def fake_volume_get(self, context, volume):
        return {'id': 'fake_volume_id'}
    self.stub_out('nova.volume.cinder.API.get', fake_volume_get)
    result = {'detached': False}
    def fake_detach(context, volume, instance_uuid, attachment_id):
        result['detached'] = (volume == 'fake_volume_id')
    mock_detach.side_effect = fake_detach
    def fake_terminate_connection(self, context, volume, connector):
        return {}
    self.stub_out('nova.volume.cinder.API.terminate_connection', fake_terminate_connection)
    self.stub_out('nova.virt.fake.FakeDriver.instance_on_disk', (lambda *a, **ka: True))
    self._rebuild()
    bdms = db.block_device_mapping_get_all_by_instance(self.context, self.inst.uuid)
    if (not bdms):
        self.fail('BDM    entry    for    the    attached    volume    is    missing')
    for bdm in bdms:
        db.block_device_mapping_destroy(self.context, bdm['id'])
    self.assertFalse(mock_drv_detach.called)
    mock_detach.assert_called_once_with(test.MatchType(context.RequestContext), mock.ANY, mock.ANY, None)
    mock_prep.assert_called_once_with(test.MatchType(context.RequestContext), test.MatchType(objects.Instance), mock.ANY)
