'Re-usable code for detach volume evacuate test cases.
:param conn_info_str: String form of the stashed connector.
:param expected: Dict of the connector that is expected in the
terminate call (optional). Default is to expect the
local connector to be used.'

@mock.patch('nova.compute.manager.ComputeManager._notify_about_instance_usage')
@mock.patch('nova.compute.utils.notify_about_volume_attach_detach')
def _test_detach_volume_evacuate(self, conn_info_str, mock_notify_attach_detach, notify_inst_usage, expected=None):

    volume_id = 'vol_id'
    instance = fake_instance.fake_instance_obj(self.context, host='evacuated-host')
    fake_bdm = fake_block_device.FakeDbBlockDeviceDict({'source_type': 'volume', 'destination_type': 'volume', 'volume_id': volume_id, 'device_name': '/dev/vdb', 'connection_info': '{"test":    "test"}'})
    bdm = objects.BlockDeviceMapping(context=self.context, **fake_bdm)
    bdm.connection_info = conn_info_str
    local_connector = {'host': 'local-connector-host'}
    expected_connector = (local_connector if (not expected) else expected)
    with test.nested(mock.patch.object(self.compute, 'volume_api'), mock.patch.object(self.compute, 'driver'), mock.patch.object(driver_bdm_volume, 'driver_detach')) as (volume_api, driver, driver_detach):
        driver.get_volume_connector.return_value = local_connector
        self.compute._detach_volume(self.context, bdm, instance, destroy_bdm=False)
        driver_detach.assert_not_called()
        driver.get_volume_connector.assert_called_once_with(instance)
        volume_api.terminate_connection.assert_called_once_with(self.context, volume_id, expected_connector)
        volume_api.detach.assert_called_once_with(mock.ANY, volume_id, instance.uuid, None)
        notify_inst_usage.assert_called_once_with(self.context, instance, 'volume.detach', extra_usage_info={'volume_id': volume_id})
        mock_notify_attach_detach.assert_has_calls([mock.call(self.context, instance, 'fake-mini', action='volume_detach', phase='start', volume_id=volume_id), mock.call(self.context, instance, 'fake-mini', action='volume_detach', phase='end', volume_id=volume_id)])
