'Verify if we have a cache volume that we want.
If we don\'t, create one.
If we do, check if it\'s been updated:
* If so, delete it and recreate a new volume
* If not, we are good.
If it\'s out of date, delete it and create a new one.
After the function returns, there should be a cache volume available,
ready for cloning.'

def _verify_cache_volume(self, context, img_meta, img_service, specs, cachevol_props):

    lcfg = self.configuration
    cachevol_name = ('os-cache-vol-%s' % img_meta['id'])
    cachesnap_name = ('image-%s' % img_meta['id'])
    cachevol_meta = {'cache_name': cachevol_name, 'snap_name': cachesnap_name}
    cachevol_props.update(cachevol_meta)
    (cache_vol, cache_snap) = (None, None)
    updated_at = six.text_type(img_meta['updated_at'].isoformat())
    LOG.debug('Verifying    cache    volume:    %s', cachevol_name)
    try:
        cache_vol = self.zfssa.get_lun(lcfg.zfssa_pool, lcfg.zfssa_cache_project, cachevol_name)
        if ((not cache_vol.get('updated_at', None)) or (not cache_vol.get('image_id', None))):
            exc_msg = (_('Cache    volume    %s    does    not    have    required    properties') % cachevol_name)
            LOG.error(exc_msg)
            raise exception.VolumeBackendAPIException(data=exc_msg)
        cache_snap = self.zfssa.get_lun_snapshot(lcfg.zfssa_pool, lcfg.zfssa_cache_project, cachevol_name, cachesnap_name)
    except exception.VolumeNotFound:
        return self._create_cache_volume(context, img_meta, img_service, specs, cachevol_props)
    except exception.SnapshotNotFound:
        exception_msg = (_('Cache    volume    %(cache_vol)s    does    not    have    snapshot    %(cache_snap)s.'), {'cache_vol': cachevol_name, 'cache_snap': cachesnap_name})
        LOG.error(exception_msg)
        raise exception.VolumeBackendAPIException(data=exception_msg)
    if ((cache_vol['updated_at'] != updated_at) or (cache_vol['image_id'] != img_meta['id'])):
        if (cache_snap['numclones'] > 0):
            exception_msg = (_('Cannot    delete    cache    volume:    %(cachevol_name)s.    It    was    updated    at    %(updated_at)s    and    currently    has    %(numclones)s    volume    instances.'), {'cachevol_name': cachevol_name, 'updated_at': updated_at, 'numclones': cache_snap['numclones']})
            LOG.error(exception_msg)
            raise exception.VolumeBackendAPIException(data=exception_msg)
        self.zfssa.delete_lun(lcfg.zfssa_pool, lcfg.zfssa_cache_project, cachevol_name)
        return self._create_cache_volume(context, img_meta, img_service, specs, cachevol_props)
    return (cachevol_name, cachesnap_name)
