Skip to content

Commit

Permalink
lvm zap: refuse to zap mapper devices
Browse files Browse the repository at this point in the history
Fixes: http://tracker.ceph.com/issues/24504

Signed-off-by: Andrew Schoen <aschoen@redhat.com>
(cherry picked from commit 8e602d5)
  • Loading branch information
andrewschoen committed Jul 26, 2018
1 parent ce0bbc6 commit aeed88e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/ceph-volume/ceph_volume/devices/lvm/zap.py
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
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

0 comments on commit aeed88e

Please sign in to comment.