
from __future__ import absolute_import

import logging

from vdsm.storage import constants as sc
from vdsm.storage import qemuimg

log = logging.getLogger('storage.workarounds')

VM_CONF_SIZE = 10240


def invalid_vm_conf_disk(vol):
    if (vol.getFormat() == sc.COW_FORMAT and
            vol.getCapacity() == VM_CONF_SIZE):
        info = qemuimg.info(vol.getVolumePath())
        actual_format = info['format']

        if actual_format == qemuimg.FORMAT.RAW:
            log.warning("Incorrect volume format %r has been detected"
                        " for volume %r, using the actual format %r.",
                        qemuimg.FORMAT.QCOW2,
                        vol.volUUID,
                        qemuimg.FORMAT.RAW)
            return True
    return False
