From: Dimitri Savineau Date: Thu, 26 Aug 2021 21:11:12 +0000 (-0400) Subject: ceph-volume: fix lvm activate arguments X-Git-Tag: v16.2.6~6^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F43116%2Fhead;p=ceph.git ceph-volume: fix lvm activate arguments 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 (cherry picked from commit b77ed5f99d3cb14a46bb36bb74e4136c22edf48a) --- diff --git a/src/ceph-volume/ceph_volume/devices/lvm/activate.py b/src/ceph-volume/ceph_volume/devices/lvm/activate.py index e4ac074a4f41..c864b0e9f052 100644 --- a/src/ceph-volume/ceph_volume/devices/lvm/activate.py +++ b/src/ceph-volume/ceph_volume/devices/lvm/activate.py @@ -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' % diff --git a/src/ceph-volume/ceph_volume/tests/devices/lvm/test_activate.py b/src/ceph-volume/ceph_volume/tests/devices/lvm/test_activate.py index 33e0ed32b619..46d7c3c83578 100644 --- a/src/ceph-volume/ceph_volume/tests/devices/lvm/test_activate.py +++ b/src/ceph-volume/ceph_volume/tests/devices/lvm/test_activate.py @@ -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()