From aeed88e3de77b010b98dad7941a060e58b99d0f2 Mon Sep 17 00:00:00 2001 From: Andrew Schoen Date: Thu, 26 Jul 2018 14:14:00 -0500 Subject: [PATCH] lvm zap: refuse to zap mapper devices Fixes: http://tracker.ceph.com/issues/24504 Signed-off-by: Andrew Schoen (cherry picked from commit 8e602d52657d50888a83963148334deb1f8d4e1c) --- src/ceph-volume/ceph_volume/devices/lvm/zap.py | 3 +++ src/ceph-volume/ceph_volume/tests/devices/test_zap.py | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ceph-volume/ceph_volume/devices/lvm/zap.py b/src/ceph-volume/ceph_volume/devices/lvm/zap.py index 904759dd5be8b..65af440bf2f9b 100644 --- a/src/ceph-volume/ceph_volume/devices/lvm/zap.py +++ b/src/ceph-volume/ceph_volume/devices/lvm/zap.py @@ -49,6 +49,9 @@ class Zap(object): @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 diff --git a/src/ceph-volume/ceph_volume/tests/devices/test_zap.py b/src/ceph-volume/ceph_volume/tests/devices/test_zap.py index 5e267fca77e59..b768c6e901c97 100644 --- a/src/ceph-volume/ceph_volume/tests/devices/test_zap.py +++ b/src/ceph-volume/ceph_volume/tests/devices/test_zap.py @@ -14,4 +14,13 @@ class TestZap(object): 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 -- 2.39.5