]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: fix lvm activate arguments 43117/head
authorDimitri Savineau <dsavinea@redhat.com>
Thu, 26 Aug 2021 21:11:12 +0000 (17:11 -0400)
committerGuillaume Abrioux <gabrioux@redhat.com>
Thu, 9 Sep 2021 14:20:37 +0000 (16:20 +0200)
When using the `lvm activate` subcommand without any osd ID or osd FSID
then ceph-volume fails.

Currently we can either activate with:
 - both osd ID and osd FSID
 - only the osd FSID (because it's unique)

The remaining scenarios aren't covered and generate a stack trace:
 - only the osd ID
 - no osd ID nor osd FSID

This ends up with an error like:

-->  UnboundLocalError: local variable 'tags' referenced before assignment

Fixes: https://tracker.ceph.com/issues/50665
Signed-off-by: Dimitri Savineau <dsavinea@redhat.com>
(cherry picked from commit b77ed5f99d3cb14a46bb36bb74e4136c22edf48a)

src/ceph-volume/ceph_volume/devices/lvm/activate.py
src/ceph-volume/ceph_volume/tests/devices/lvm/test_activate.py

index e4ac074a4f4147e935528b94df250f68cdf823fe..c864b0e9f05289eaf3fa64101ae598691ac09c47 100644 (file)
@@ -269,6 +269,11 @@ class Activate(object):
             tags = {'ceph.osd_id': osd_id, 'ceph.osd_fsid': osd_fsid}
         elif not osd_id and osd_fsid:
             tags = {'ceph.osd_fsid': osd_fsid}
+        elif osd_id and not osd_fsid:
+            raise RuntimeError('could not activate osd.{}, please provide the '
+                               'osd_fsid too'.format(osd_id))
+        else:
+            raise RuntimeError('Please provide both osd_id and osd_fsid')
         lvs = api.get_lvs(tags=tags)
         if not lvs:
             raise RuntimeError('could not find osd.%s with osd_fsid %s' %
index 33e0ed32b619a51a00839b57f9c175c6a2a305d0..46d7c3c83578e5be9201624deb65bf68405a1117 100644 (file)
@@ -58,6 +58,18 @@ class TestActivate(object):
         with pytest.raises(RuntimeError):
             activate.Activate([]).activate(args)
 
+    def test_osd_id_no_osd_fsid(self, is_root):
+        args = Args(osd_id=42, osd_fsid=None)
+        with pytest.raises(RuntimeError) as result:
+            activate.Activate([]).activate(args)
+        assert result.value.args[0] == 'could not activate osd.42, please provide the osd_fsid too'
+
+    def test_no_osd_id_no_osd_fsid(self, is_root):
+        args = Args(osd_id=None, osd_fsid=None)
+        with pytest.raises(RuntimeError) as result:
+            activate.Activate([]).activate(args)
+        assert result.value.args[0] == 'Please provide both osd_id and osd_fsid'
+
     def test_filestore_no_systemd(self, is_root, monkeypatch, capture):
         monkeypatch.setattr('ceph_volume.configuration.load', lambda: None)
         fake_enable = Capture()