]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
lvm zap: refuse to zap mapper devices 22764/head
authorAndrew Schoen <aschoen@redhat.com>
Thu, 28 Jun 2018 19:22:47 +0000 (14:22 -0500)
committerAndrew Schoen <aschoen@redhat.com>
Fri, 29 Jun 2018 12:56:04 +0000 (07:56 -0500)
Fixes: http://tracker.ceph.com/issues/24504
Signed-off-by: Andrew Schoen <aschoen@redhat.com>
src/ceph-volume/ceph_volume/devices/lvm/zap.py
src/ceph-volume/ceph_volume/tests/devices/test_zap.py

index ee5cdf97b6a590726df2f3c16346f44c8355c14a..b3d80a590bb9d1af259c6a3fbeae115e0399be1f 100644 (file)
@@ -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
index 5e267fca77e5978b4ebe7760ec61c34d40dbfb08..b768c6e901c97864d1a25b440b19b7655190c737 100644 (file)
@@ -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