def test_loop_device_is_device(self, fake_call, device_info):
data = {"/dev/loop0": {"foo": "bar"}}
lsblk = {"TYPE": "loop"}
- os.environ["CEPH_VOLUME_USE_LOOP_DEVICES"] = "1"
+ os.environ["CEPH_VOLUME_ALLOW_LOOP_DEVICES"] = "1"
device_info(devices=data, lsblk=lsblk)
disk = device.Device("/dev/loop0")
assert disk.is_device is True
- del os.environ["CEPH_VOLUME_USE_LOOP_DEVICES"]
+ del os.environ["CEPH_VOLUME_ALLOW_LOOP_DEVICES"]
def test_device_is_rotational(self, fake_call, device_info):
data = {"/dev/sda": {"rotational": "1"}}
result = "%s" % size.tb
assert "%s" % size.tb == "%s" % size.terabytes
assert result == "1027.00 TB"
+
+
+class TestAllowLoopDevsWarning(object):
+ def test_loop_dev_warning(self, fake_call, caplog):
+ assert disk.allow_loop_devices() is False
+ assert not caplog.records
+ os.environ['CEPH_VOLUME_ALLOW_LOOP_DEVICES'] = "y"
+ assert disk.allow_loop_devices() is True
+ log = caplog.records[0]
+ assert log.levelname == "WARNING"
+ assert "will never be supported in production" in log.message
from ceph_volume.util import disk, system
from ceph_volume.util.lsmdisk import LSMDisk
from ceph_volume.util.constants import ceph_disk_guids
+from ceph_volume.util.disk import allow_loop_devices
logger = logging.getLogger(__name__)
device_type = dev.get('TYPE', '')
# always check is this is an lvm member
valid_types = ['part', 'disk']
- if os.environ.get("CEPH_VOLUME_USE_LOOP_DEVICES", False):
+ if allow_loop_devices():
valid_types.append('loop')
if device_type in valid_types:
self._set_lvm_membership()
api = self.blkid_api
if api:
valid_types = ['disk', 'device', 'mpath']
- if os.environ.get("CEPH_VOLUME_USE_LOOP_DEVICES", False):
+ if allow_loop_devices():
valid_types.append('loop')
return self.device_type in valid_types
return False
if not dev.startswith('/dev/'):
return False
if dev[len('/dev/'):].startswith('loop'):
- if os.environ.get("CEPH_VOLUME_USE_LOOP_DEVICES", False) is False:
+ if not allow_loop_devices():
return False
- logger.info(
- "Allowing the use of loop devices since "
- "CEPH_VOLUME_USE_LOOP_DEVICES is set."
- )
# fallback to stat
return _stat_is_device(os.lstat(dev).st_mode)
return [re.split(r'\s+', line) for line in stdout]
+class AllowLoopDevices(object):
+ allow = False
+ warned = False
+
+ @classmethod
+ def __call__(cls):
+ val = os.environ.get("CEPH_VOLUME_ALLOW_LOOP_DEVICES", "false").lower()
+ if val not in ("false", 'no', '0'):
+ cls.allow = True
+ if not cls.warned:
+ logger.warning(
+ "CEPH_VOLUME_ALLOW_LOOP_DEVICES is set in your "
+ "environment, so we will allow the use of unattached loop"
+ " devices as disks. This feature is intended for "
+ "development purposes only and will never be supported in"
+ " production. Issues filed based on this behavior will "
+ "likely be ignored."
+ )
+ cls.warned = True
+ return cls.allow
+
+
+allow_loop_devices = AllowLoopDevices()
+
+
def get_block_devs_sysfs(_sys_block_path='/sys/block', _sys_dev_block_path='/sys/dev/block'):
# First, get devices that are _not_ partitions
result = list()
basename = get_file_contents(os.path.join(dm_dir_path, 'name'))
name = os.path.join("/dev/mapper", basename)
if dev.startswith('loop'):
- if os.environ.get("CEPH_VOLUME_USE_LOOP_DEVICES", False) is False:
+ if not allow_loop_devices():
continue
# Skip loop devices that are not attached
if not os.path.exists(os.path.join(_sys_block_path, dev, 'loop')):
block_devs = get_block_devs_sysfs(_sys_block_path)
block_types = ['disk', 'mpath']
- if os.environ.get("CEPH_VOLUME_USE_LOOP_DEVICES", False) is not False:
+ if allow_loop_devices():
block_types.append('loop')
for block in block_devs: