From d880a2c59a098bacd4a2685812f4da6424c69244 Mon Sep 17 00:00:00 2001 From: Cory Snyder Date: Mon, 27 Feb 2023 04:45:47 -0500 Subject: [PATCH] ceph-volume: add test case to reproduce bug in get_physical_fast_allocs Adds a test case to reproduce a bug with get_physical_fast_allocs for clusters that have multiple fast device PVs in a single VG (deployed prior to v15.2.8). Also fixes other test cases for this function to more accurately represent reality. Signed-off-by: Cory Snyder (cherry picked from commit 02592cb0a5970f861d25a521579c30639d10b007) --- src/ceph-volume/ceph_volume/tests/conftest.py | 10 +++-- .../tests/devices/lvm/test_batch.py | 42 +++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/ceph-volume/ceph_volume/tests/conftest.py b/src/ceph-volume/ceph_volume/tests/conftest.py index 2cedd68efef17..8ec8ca131ec40 100644 --- a/src/ceph-volume/ceph_volume/tests/conftest.py +++ b/src/ceph-volume/ceph_volume/tests/conftest.py @@ -71,11 +71,15 @@ def mock_device(): dev.lvs = [] return dev -@pytest.fixture(params=range(1,3)) +@pytest.fixture(params=range(1,4)) def mock_devices_available(request): ret = [] - for _ in range(request.param): - ret.append(mock_device()) + for n in range(request.param): + dev = mock_device() + # after v15.2.8, a single VG is created for each PV + dev.vg_name = f'vg_foo_{n}' + dev.vgs = [lvm.VolumeGroup(vg_name=dev.vg_name, lv_name=dev.lv_name)] + ret.append(dev) return ret @pytest.fixture diff --git a/src/ceph-volume/ceph_volume/tests/devices/lvm/test_batch.py b/src/ceph-volume/ceph_volume/tests/devices/lvm/test_batch.py index 25c8a990cd9ff..8a0f8df8c381b 100644 --- a/src/ceph-volume/ceph_volume/tests/devices/lvm/test_batch.py +++ b/src/ceph-volume/ceph_volume/tests/devices/lvm/test_batch.py @@ -5,6 +5,7 @@ import random from argparse import ArgumentError from mock import MagicMock, patch +from ceph_volume.api import lvm from ceph_volume.devices.lvm import batch from ceph_volume.util import arg_validators @@ -226,6 +227,47 @@ class TestBatch(object): for fast, dev in zip(fasts, mock_devices_available): assert fast[2] == int(dev.vg_size[0] / 2) + def test_get_physical_fast_allocs_abs_size_unused_devs(self, factory, + conf_ceph_stub, + mock_devices_available): + conf_ceph_stub('[global]\nfsid=asdf-lkjh') + args = factory(block_db_slots=None, get_block_db_size=None) + dev_size = 21474836480 + vg_size = dev_size + for dev in mock_devices_available: + dev.vg_name = None + dev.vg_size = [vg_size] + dev.vg_free = dev.vg_size + dev.vgs = [] + slots_per_device = 2 + fasts = batch.get_physical_fast_allocs(mock_devices_available, + 'block_db', slots_per_device, 2, args) + expected_slot_size = int(dev_size / slots_per_device) + for (_, _, slot_size, _) in fasts: + assert slot_size == expected_slot_size + + def test_get_physical_fast_allocs_abs_size_multi_pvs_per_vg(self, factory, + conf_ceph_stub, + mock_devices_available): + conf_ceph_stub('[global]\nfsid=asdf-lkjh') + args = factory(block_db_slots=None, get_block_db_size=None) + dev_size = 21474836480 + num_devices = len(mock_devices_available) + vg_size = dev_size * num_devices + vg_name = 'vg_foo' + for dev in mock_devices_available: + dev.vg_name = vg_name + dev.vg_size = [vg_size] + dev.vg_free = dev.vg_size + dev.vgs = [lvm.VolumeGroup(vg_name=dev.vg_name, lv_name=dev.lv_name)] + slots_per_device = 2 + slots_per_vg = slots_per_device * num_devices + fasts = batch.get_physical_fast_allocs(mock_devices_available, + 'block_db', slots_per_device, 2, args) + expected_slot_size = int(vg_size / slots_per_vg) + for (_, _, slot_size, _) in fasts: + assert slot_size == expected_slot_size + def test_batch_fast_allocations_one_block_db_length(self, factory, conf_ceph_stub, mock_lv_device_generator): conf_ceph_stub('[global]\nfsid=asdf-lkjh') -- 2.39.5