'Try to delete backup RBD image.
If the rbd image is a base image for incremental backups, it may have
snapshots. Delete the snapshot associated with backup_id and if the
image has no more snapshots, delete it. Otherwise return.
If no base name is provided try normal (full) format then diff format
image name.
If a base name is provided but does not exist, ImageNotFound will be
raised.
If the image is busy, a number of retries will be performed if
ImageBusy is received, after which the exception will be propagated to
the caller.'

def _try_delete_base_image(self, backup, base_name=None):

    retries = 3
    delay = 5
    try_diff_format = False
    volume_id = backup.volume_id
    if (base_name is None):
        try_diff_format = True
        base_name = self._get_backup_base_name(volume_id, backup.id)
        LOG.debug("Trying    diff    format    basename='%(basename)s'    for    backup    base    image    of    volume    %(volume)s.", {'basename': base_name, 'volume': volume_id})
    with rbd_driver.RADOSClient(self, backup.container) as client:
        (rbd_exists, base_name) = self._rbd_image_exists(base_name, volume_id, client, try_diff_format=try_diff_format)
        if (not rbd_exists):
            raise self.rbd.ImageNotFound((_('image    %s    not    found') % base_name))
        while (retries >= 0):
            (snap, rem) = self._delete_backup_snapshot(client, base_name, backup.id)
            if rem:
                LOG.info('Backup    base    image    of    volume    %(volume)s    still    has    %(snapshots)s    snapshots    so    skipping    base    image    delete.', {'snapshots': rem, 'volume': volume_id})
                return
            LOG.info("Deleting    backup    base    image='%(basename)s'    of    volume    %(volume)s.", {'basename': base_name, 'volume': volume_id})
            try:
                self.rbd.RBD().remove(client.ioctx, base_name)
            except self.rbd.ImageBusy:
                if (retries > 0):
                    LOG.info('Backup    image    of    volume    %(volume)s    is    busy,    retrying    %(retries)s    more    time(s)    in    %(delay)ss.', {'retries': retries, 'delay': delay, 'volume': volume_id})
                    eventlet.sleep(delay)
                else:
                    LOG.error('Max    retries    reached    deleting    backup    %(basename)s    image    of    volume    %(volume)s.', {'volume': volume_id, 'basename': base_name})
                    raise
            else:
                LOG.debug("Base    backup    image='%(basename)s'    of    volume    %(volume)s    deleted.", {'basename': base_name, 'volume': volume_id})
                retries = 0
            finally:
                retries -= 1
        src_name = utils.convert_str(volume_id)
        if (src_name in self.rbd.RBD().list(client.ioctx)):
            LOG.debug("Deleting    source    volume    snapshot    '%(snapshot)s'    for    backup    %(basename)s.", {'snapshot': snap, 'basename': base_name})
            src_rbd = self.rbd.Image(client.ioctx, src_name)
            try:
                src_rbd.remove_snap(snap)
            finally:
                src_rbd.close()
