Skip to content

Commit

Permalink
Merge pull request ceph#22764 from ceph/wip-rm24504
Browse files Browse the repository at this point in the history
ceph-volume: refuse to zap mapper devices

Reviewed-by: Alfredo Deza
  • Loading branch information
alfredodeza authored Jul 3, 2018
2 parents 85d78a8 + 8e602d5 commit d62fa58
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/ceph-volume/ceph_volume/devices/lvm/zap.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def __init__(self, argv):
@decorators.needs_root
def zap(self, args):
device = args.device
if disk.is_mapper_device(device):
terminal.error("Refusing to zap the mapper device: {}".format(device))
raise SystemExit(1)
lv = api.get_lv_from_argument(device)
if lv:
# we are zapping a logical volume
Expand Down
11 changes: 10 additions & 1 deletion src/ceph-volume/ceph_volume/tests/devices/test_zap.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ def test_main_shows_full_help(self, capsys):
lvm.zap.Zap(argv=['--help']).main()
stdout, stderr = capsys.readouterr()
assert 'optional arguments' in stdout
assert 'positional arguments' in stdout

@pytest.mark.parametrize('device_name', [
'/dev/mapper/foo',
'/dev/dm-0',
])
def test_can_not_zap_mapper_device(self, capsys, is_root, device_name):
with pytest.raises(SystemExit):
lvm.zap.Zap(argv=[device_name]).main()
stdout, stderr = capsys.readouterr()
assert 'Refusing to zap' in stdout
6 changes: 5 additions & 1 deletion src/ceph-volume/ceph_volume/util/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ def get_partitions_facts(sys_block_path):
return partition_metadata


def is_mapper_device(device_name):
return device_name.startswith(('/dev/mapper', '/dev/dm-'))


def get_devices(_sys_block_path='/sys/block', _dev_path='/dev', _mapper_path='/dev/mapper'):
"""
Captures all available devices from /sys/block/, including its partitions,
Expand Down Expand Up @@ -391,7 +395,7 @@ def get_devices(_sys_block_path='/sys/block', _dev_path='/dev', _mapper_path='/d
diskname = mapper_devs.get(block) or dev_devs.get(block)

# If the mapper device is a logical volume it gets excluded
if diskname.startswith(('/dev/mapper', '/dev/dm-')):
if is_mapper_device(diskname):
if lvm.is_lv(diskname):
continue

Expand Down

0 comments on commit d62fa58

Please sign in to comment.