From: Jan Fajerski Date: Mon, 7 Jan 2019 13:43:12 +0000 (+0100) Subject: ceph-volume: add default argument values to strategy X-Git-Tag: v13.2.7~217^2~14 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=292381483e51f0f41ca82d17797489454b5c289c;p=ceph.git ceph-volume: add default argument values to strategy Signed-off-by: Jan Fajerski (cherry picked from commit 5465712e4d71315ff8daac9345be6ba96d1f44c4) Conflicts: src/ceph-volume/ceph_volume/tests/devices/lvm/strategies/test_bluestore.py src/ceph-volume/ceph_volume/tests/devices/lvm/strategies/test_filestore.py pick with_auto_devices and error.value changes --- diff --git a/src/ceph-volume/ceph_volume/devices/lvm/batch.py b/src/ceph-volume/ceph_volume/devices/lvm/batch.py index 2da6aab8166..93cc5aa0bf0 100644 --- a/src/ceph-volume/ceph_volume/devices/lvm/batch.py +++ b/src/ceph-volume/ceph_volume/devices/lvm/batch.py @@ -287,7 +287,7 @@ class Batch(object): mlogger.error("Aborting because strategy changed from %s to %s after filtering" % (strategy.type(), new_strategy.type())) raise SystemExit(1) - self.strategy = strategy.with_auto_devices(unused_devices, self.args) + self.strategy = strategy.with_auto_devices(self.args, unused_devices) @decorators.needs_root def main(self): @@ -317,27 +317,23 @@ class Batch(object): if self.args.bluestore: if self.db_usable: self.strategy = strategies.bluestore.MixedType( + self.args, self.usable, - self.db_usable, - [], - self.args) + self.db_usable) else: self.strategy = strategies.bluestore.SingleType( - self.usable, - self.db_usable, - [], - self.args) + self.args, + self.usable) else: if self.journal_usable: self.strategy = strategies.filestore.MixedType( + self.args, self.usable, - self.journal_usable, - self.args) + self.journal_usable) else: self.strategy = strategies.filestore.SingleType( - self.usable, - self.journal_usable, - self.args) + self.args, + self.usable) def _filter_devices(self): diff --git a/src/ceph-volume/ceph_volume/devices/lvm/strategies/bluestore.py b/src/ceph-volume/ceph_volume/devices/lvm/strategies/bluestore.py index 31ee230070f..e5f63272bb7 100644 --- a/src/ceph-volume/ceph_volume/devices/lvm/strategies/bluestore.py +++ b/src/ceph-volume/ceph_volume/devices/lvm/strategies/bluestore.py @@ -15,14 +15,14 @@ class SingleType(Strategy): Support for all SSDs, or all HDDS """ - def __init__(self, data_devs, args): - super(SingleType, self).__init__(data_devs, [], [], args) + def __init__(self, args, data_devs): + super(SingleType, self).__init__(args, data_devs) self.validate_compute() @classmethod - def with_auto_devices(cls, devices, args): + def with_auto_devices(cls, args, devices): #SingleType only deploys standalone OSDs - return cls(devices, args) + return cls(args, devices) @staticmethod def type(): @@ -117,8 +117,8 @@ class SingleType(Strategy): class MixedType(MixedStrategy): - def __init__(self, data_devs, db_devs, wal_devs, args): - super(MixedType, self).__init__(data_devs, db_devs, wal_devs, args) + def __init__(self, args, data_devs, db_devs, wal_devs=[]): + super(MixedType, self).__init__(args, data_devs, db_devs, wal_devs) self.block_db_size = self.get_block_size() self.system_vgs = lvm.VolumeGroups() self.dbs_needed = len(self.data_devs) * self.osds_per_device @@ -126,9 +126,9 @@ class MixedType(MixedStrategy): self.validate_compute() @classmethod - def with_auto_devices(cls, devices, args): + def with_auto_devices(cls, args, devices): data_devs, db_devs = cls.split_devices_rotational(devices) - return cls(data_devs, db_devs, [], args) + return cls(args, data_devs, db_devs) @staticmethod def type(): diff --git a/src/ceph-volume/ceph_volume/devices/lvm/strategies/filestore.py b/src/ceph-volume/ceph_volume/devices/lvm/strategies/filestore.py index cf7763eb5e6..a20192a8821 100644 --- a/src/ceph-volume/ceph_volume/devices/lvm/strategies/filestore.py +++ b/src/ceph-volume/ceph_volume/devices/lvm/strategies/filestore.py @@ -28,14 +28,14 @@ class SingleType(Strategy): """ - def __init__(self, data_devs, args): - super(SingleType, self).__init__(data_devs, [], [], args) + def __init__(self, args, data_devs): + super(SingleType, self).__init__(args, data_devs) self.journal_size = get_journal_size(args) self.validate_compute() @classmethod - def with_auto_devices(cls, devices, args): - return cls(devices, args) + def with_auto_devices(cls, args, devices): + return cls(args, devices) @staticmethod def type(): @@ -167,8 +167,8 @@ class MixedType(MixedStrategy): """ - def __init__(self, data_devs, journal_devs, args): - super(MixedType, self).__init__(data_devs, journal_devs, [], args) + def __init__(self, args, data_devs, journal_devs): + super(MixedType, self).__init__(args, data_devs, journal_devs) self.blank_ssds = [] self.journals_needed = len(self.data_devs) * self.osds_per_device self.journal_size = get_journal_size(args) @@ -176,9 +176,9 @@ class MixedType(MixedStrategy): self.validate_compute() @classmethod - def with_auto_devices(cls, devices, args): + def with_auto_devices(cls, args, devices): data_devs, journal_devs = cls.split_devices_rotational(devices) - return cls(data_devs, journal_devs, args) + return cls(args, data_devs, journal_devs) @staticmethod def type(): diff --git a/src/ceph-volume/ceph_volume/devices/lvm/strategies/strategies.py b/src/ceph-volume/ceph_volume/devices/lvm/strategies/strategies.py index f8f1ca979d2..5a9d52cf159 100644 --- a/src/ceph-volume/ceph_volume/devices/lvm/strategies/strategies.py +++ b/src/ceph-volume/ceph_volume/devices/lvm/strategies/strategies.py @@ -2,7 +2,7 @@ import json class Strategy(object): - def __init__(self, data_devs, db_or_journal_devs, wal_devs, args): + def __init__(self, args, data_devs, db_or_journal_devs=[], wal_devs=[]): ''' Note that this ctor is used by both bluestore and filestore strategies to reduce code duplication. A filestore strategy will always pass an diff --git a/src/ceph-volume/ceph_volume/tests/devices/lvm/strategies/test_bluestore.py b/src/ceph-volume/ceph_volume/tests/devices/lvm/strategies/test_bluestore.py index dd3a877f217..72e936af43e 100644 --- a/src/ceph-volume/ceph_volume/tests/devices/lvm/strategies/test_bluestore.py +++ b/src/ceph-volume/ceph_volume/tests/devices/lvm/strategies/test_bluestore.py @@ -9,7 +9,7 @@ class TestSingleType(object): devices = [ fakedevice(used_by_ceph=False, is_lvm_member=False, sys_api=dict(rotational='1', size=6073740000)) ] - computed_osd = bluestore.SingleType(devices, args).computed['osds'][0] + computed_osd = bluestore.SingleType.with_auto_devices(args, devices).computed['osds'][0] assert computed_osd['data']['percentage'] == 100 assert computed_osd['data']['parts'] == 1 assert computed_osd['data']['human_readable_size'] == '5.66 GB' @@ -20,7 +20,7 @@ class TestSingleType(object): devices = [ fakedevice(used_by_ceph=False, is_lvm_member=False, sys_api=dict(rotational='0', size=6073740000)) ] - computed_osd = bluestore.SingleType(devices, args).computed['osds'][0] + computed_osd = bluestore.SingleType.with_auto_devices(args, devices).computed['osds'][0] assert computed_osd['data']['percentage'] == 100 assert computed_osd['data']['parts'] == 1 assert computed_osd['data']['human_readable_size'] == '5.66 GB' @@ -32,7 +32,7 @@ class TestSingleType(object): fakedevice(used_by_ceph=False, is_lvm_member=False, sys_api=dict(rotational='1', size=6073740000)) ] with pytest.raises(RuntimeError) as error: - bluestore.SingleType(devices, args) + bluestore.SingleType.with_auto_devices(args, devices) assert 'Unable to use device 5.66 GB /dev/sda' in str(error.value) def test_device_is_lvm_member_fails(self, fakedevice, factory): @@ -41,6 +41,7 @@ class TestSingleType(object): fakedevice(used_by_ceph=False, is_lvm_member=True, sys_api=dict(rotational='1', size=6073740000)) ] with pytest.raises(RuntimeError) as error: + bluestore.SingleType.with_auto_devices(args, devices) bluestore.SingleType(devices, args) assert 'Unable to use device, already a member of LVM' in str(error.value) @@ -57,7 +58,7 @@ class TestMixedTypeConfiguredSize(object): hdd = fakedevice(used_by_ceph=False, is_lvm_member=False, sys_api=dict(rotational='1', size=6073740000)) devices = [ssd, hdd] - osd = bluestore.MixedType(devices, args).computed['osds'][0] + osd = bluestore.MixedType.with_auto_devices(args, devices).computed['osds'][0] assert osd['data']['percentage'] == 100 assert osd['data']['human_readable_size'] == '5.66 GB' assert osd['data']['path'] == '/dev/sda' @@ -74,7 +75,7 @@ class TestMixedTypeConfiguredSize(object): devices = [ssd, hdd] with pytest.raises(RuntimeError) as error: - bluestore.MixedType(devices, args).computed['osds'][0] + bluestore.MixedType.with_auto_devices(args, devices).computed['osds'][0] expected = 'Not enough space in fast devices (5.66 GB) to create 1 x 7.22 GB block.db LV' assert expected in str(error.value) @@ -87,7 +88,7 @@ class TestMixedTypeConfiguredSize(object): devices = [ssd, hdd] with pytest.raises(RuntimeError) as error: - bluestore.MixedType(devices, args) + bluestore.MixedType.with_auto_devices(args, devices) expected = 'Unable to use device 5.66 GB /dev/sda, LVs would be smaller than 5GB' assert expected in str(error.value) @@ -101,7 +102,7 @@ class TestMixedTypeLargeAsPossible(object): hdd = fakedevice(used_by_ceph=False, is_lvm_member=False, sys_api=dict(rotational='1', size=6073740000)) devices = [ssd, hdd] - osd = bluestore.MixedType(devices, args).computed['osds'][0] + osd = bluestore.MixedType.with_auto_devices(args, devices).computed['osds'][0] assert osd['data']['percentage'] == 100 assert osd['data']['human_readable_size'] == '5.66 GB' assert osd['data']['path'] == '/dev/sda' @@ -117,7 +118,7 @@ class TestMixedTypeLargeAsPossible(object): hdd = fakedevice(used_by_ceph=False, is_lvm_member=False, sys_api=dict(rotational='1', size=60073740000)) devices = [ssd, hdd] - osd = bluestore.MixedType(devices, args).computed['osds'][0] + osd = bluestore.MixedType.with_auto_devices(args, devices).computed['osds'][0] assert osd['data']['percentage'] == 50 assert osd['data']['human_readable_size'] == '27.97 GB' assert osd['data']['path'] == '/dev/sda' @@ -134,6 +135,6 @@ class TestMixedTypeLargeAsPossible(object): devices = [ssd, hdd] with pytest.raises(RuntimeError) as error: - bluestore.MixedType(devices, args) + bluestore.MixedType.with_auto_devices(args, devices) expected = 'Unable to use device 5.66 GB /dev/sda, LVs would be smaller than 5GB' assert expected in str(error.value) diff --git a/src/ceph-volume/ceph_volume/tests/devices/lvm/strategies/test_filestore.py b/src/ceph-volume/ceph_volume/tests/devices/lvm/strategies/test_filestore.py index 5e9b661ffa7..35d9bbe609d 100644 --- a/src/ceph-volume/ceph_volume/tests/devices/lvm/strategies/test_filestore.py +++ b/src/ceph-volume/ceph_volume/tests/devices/lvm/strategies/test_filestore.py @@ -11,7 +11,7 @@ class TestSingleType(object): devices = [ fakedevice(used_by_ceph=False, is_lvm_member=False, sys_api=dict(rotational='1', size=12073740000)) ] - computed_osd = filestore.SingleType(devices, args).computed['osds'][0] + computed_osd = filestore.SingleType.with_auto_devices(args, devices).computed['osds'][0] assert computed_osd['data']['percentage'] == 55 assert computed_osd['data']['parts'] == 1 assert computed_osd['data']['human_readable_size'] == '6.24 GB' @@ -24,7 +24,7 @@ class TestSingleType(object): fakedevice(used_by_ceph=False, is_lvm_member=False, sys_api=dict(rotational='1', size=6073740000)) ] with pytest.raises(RuntimeError) as error: - filestore.SingleType(devices, args) + filestore.SingleType.with_auto_devices(args, devices) msg = "Unable to use device 5.66 GB /dev/sda, LVs would be smaller than 5GB" assert msg in str(error.value) @@ -34,7 +34,7 @@ class TestSingleType(object): devices = [ fakedevice(used_by_ceph=False, is_lvm_member=False, sys_api=dict(rotational='0', size=12073740000)) ] - computed_osd = filestore.SingleType(devices, args).computed['osds'][0] + computed_osd = filestore.SingleType.with_auto_devices(args, devices).computed['osds'][0] assert computed_osd['data']['percentage'] == 55 assert computed_osd['data']['parts'] == 1 assert computed_osd['data']['human_readable_size'] == '6.24 GB' @@ -47,7 +47,7 @@ class TestSingleType(object): fakedevice(used_by_ceph=False, is_lvm_member=False, sys_api=dict(rotational='0', size=6073740000)) ] with pytest.raises(RuntimeError) as error: - filestore.SingleType(devices, args) + filestore.SingleType.with_auto_devices(args, devices) msg = "Unable to use device 5.66 GB /dev/sda, LVs would be smaller than 5GB" assert msg in str(error.value) @@ -58,7 +58,7 @@ class TestSingleType(object): fakedevice(used_by_ceph=False, is_lvm_member=False, sys_api=dict(rotational='0', size=16073740000)) ] with pytest.raises(RuntimeError) as error: - filestore.SingleType(devices, args) + filestore.SingleType.with_auto_devices(args, devices) msg = "Unable to use device 14.97 GB /dev/sda, LVs would be smaller than 5GB" assert msg in str(error.value) @@ -69,7 +69,7 @@ class TestSingleType(object): fakedevice(used_by_ceph=False, is_lvm_member=False, sys_api=dict(rotational='1', size=16073740000)) ] with pytest.raises(RuntimeError) as error: - filestore.SingleType(devices, args) + filestore.SingleType.with_auto_devices(args, devices) msg = "Unable to use device 14.97 GB /dev/sda, LVs would be smaller than 5GB" assert msg in str(error.value) @@ -80,7 +80,7 @@ class TestSingleType(object): fakedevice(used_by_ceph=False, is_lvm_member=True, sys_api=dict(rotational='1', size=12073740000)) ] with pytest.raises(RuntimeError) as error: - filestore.SingleType(devices, args) + filestore.SingleType.with_auto_devices(args, devices) assert 'Unable to use device, already a member of LVM' in str(error.value) def test_hdd_device_with_small_configured_journal(self, fakedevice, factory, conf_ceph): @@ -90,7 +90,7 @@ class TestSingleType(object): fakedevice(used_by_ceph=False, is_lvm_member=False, sys_api=dict(rotational='1', size=6073740000)) ] with pytest.raises(RuntimeError) as error: - filestore.SingleType(devices, args) + filestore.SingleType.with_auto_devices(args, devices) msg = "journal sizes must be larger than 2GB, detected: 120.00 MB" assert msg in str(error.value) @@ -101,7 +101,7 @@ class TestSingleType(object): fakedevice(used_by_ceph=False, is_lvm_member=False, sys_api=dict(rotational='0', size=6073740000)) ] with pytest.raises(RuntimeError) as error: - filestore.SingleType(devices, args) + filestore.SingleType.with_auto_devices(args, devices) msg = "journal sizes must be larger than 2GB, detected: 120.00 MB" assert msg in str(error.value) @@ -116,7 +116,7 @@ class TestMixedType(object): fakedevice(used_by_ceph=False, is_lvm_member=False, sys_api=dict(rotational='1', size=6073740000)) ] with pytest.raises(RuntimeError) as error: - filestore.MixedType(devices, args) + filestore.MixedType.with_auto_devices(args, devices) msg = "journal sizes must be larger than 2GB, detected: 120.00 MB" assert msg in str(error.value) @@ -128,7 +128,7 @@ class TestMixedType(object): fakedevice(used_by_ceph=False, is_lvm_member=False, sys_api=dict(rotational='1', size=6073740000)) ] with pytest.raises(RuntimeError) as error: - filestore.MixedType(devices, args) + filestore.MixedType.with_auto_devices(args, devices) msg = "Not enough space in fast devices (5.66 GB) to create 1 x 6.95 GB journal LV" assert msg in str(error.value) @@ -140,7 +140,7 @@ class TestMixedType(object): fakedevice(used_by_ceph=False, is_lvm_member=True, sys_api=dict(rotational='1', size=6073740000)) ] with pytest.raises(RuntimeError) as error: - filestore.MixedType(devices, args) + filestore.MixedType.with_auto_devices(args, devices) assert 'Unable to use device, already a member of LVM' in str(error.value) def test_ssd_is_lvm_member_doesnt_fail(self, volumes, stub_vgs, fakedevice, factory, conf_ceph): @@ -161,7 +161,7 @@ class TestMixedType(object): conf_ceph(get_safe=lambda *a: '5120') args = factory(filtered_devices=[], osds_per_device=1, journal_size=None) devices = [ssd, hdd] - result = filestore.MixedType(devices, args).computed['osds'][0] + result = filestore.MixedType.with_auto_devices(args, devices).computed['osds'][0] assert result['journal']['path'] == 'vg: fast' assert result['journal']['percentage'] == 71 assert result['journal']['human_readable_size'] == '5.00 GB' @@ -193,7 +193,7 @@ class TestMixedType(object): args = factory(filtered_devices=[], osds_per_device=1, journal_size=None) devices = [ssd1, ssd2, hdd] with pytest.raises(RuntimeError) as error: - filestore.MixedType(devices, args) + filestore.MixedType.with_auto_devices(args, devices) assert 'Could not find a common VG between devices' in str(error.value) @@ -205,6 +205,6 @@ class TestMixedType(object): fakedevice(is_lvm_member=False, sys_api=dict(rotational='1', size=16073740000)) ] with pytest.raises(RuntimeError) as error: - filestore.MixedType(devices, args) + filestore.MixedType.with_auto_devices(args, devices) msg = "Not enough space in fast devices (14.97 GB) to create 2 x 14.77 GB journal LV" assert msg in str(error.value)