This enables user to pass sizes like "10G", which batch now understands.
Signed-off-by: Jan Fajerski <jfajerski@suse.com>
from ceph.deployment.service_spec import ServiceSpecValidationError, ServiceSpec, PlacementSpec
try:
- from typing import Optional, List, Dict, Any
+ from typing import Optional, List, Dict, Any, Union
except ImportError:
pass
db_slots=None, # type: Optional[int]
wal_slots=None, # type: Optional[int]
osd_id_claims=None, # type: Optional[Dict[str, List[str]]]
- block_db_size=None, # type: Optional[int]
- block_wal_size=None, # type: Optional[int]
- journal_size=None, # type: Optional[int]
+ block_db_size=None, # type: Union[int, str, None]
+ block_wal_size=None, # type: Union[int, str, None]
+ journal_size=None, # type: Union[int, str, None]
service_type=None, # type: Optional[str]
unmanaged=False, # type: bool
filter_logic='AND', # type: str
self.journal_devices = journal_devices
#: Set (or override) the "bluestore_block_wal_size" value, in bytes
- self.block_wal_size = block_wal_size
+ self.block_wal_size: Union[int, str, None] = block_wal_size
#: Set (or override) the "bluestore_block_db_size" value, in bytes
- self.block_db_size = block_db_size
+ self.block_db_size: Union[int, str, None] = block_db_size
#: set journal_size in bytes
- self.journal_size = journal_size
+ self.journal_size: Union[int, str, None] = journal_size
#: Number of osd daemons per "DATA" device.
#: To fully utilize nvme devices multiple osds are required.
raise DriveGroupValidationError(
"Feature <{}> is not supported".format(applied_filter))
- for key in ('block_wal_size', 'block_db_size', 'journal_size'):
- if key in json_drive_group:
- if isinstance(json_drive_group[key], str):
- from ceph.deployment.drive_selection import SizeMatcher
- json_drive_group[key] = SizeMatcher.str_to_byte(json_drive_group[key])
-
try:
args = {k: (DeviceSelection.from_json(v) if k.endswith('_devices') else v) for k, v in
json_drive_group.items()}
raise DriveGroupValidationError(f"{self.objectstore} is not supported. Must be "
f"one of ('bluestore')")
- if self.block_wal_size is not None and type(self.block_wal_size) != int:
- raise DriveGroupValidationError('block_wal_size must be of type int')
- if self.block_db_size is not None and type(self.block_db_size) != int:
- raise DriveGroupValidationError('block_db_size must be of type int')
+ if self.block_wal_size is not None and type(self.block_wal_size) not in [int, str]:
+ raise DriveGroupValidationError('block_wal_size must be of type int or string')
+ if self.block_db_size is not None and type(self.block_db_size) not in [int, str]:
+ raise DriveGroupValidationError('block_db_size must be of type int or string')
+ if self.journal_size is not None and type(self.journal_size) not in [int, str]:
+ raise DriveGroupValidationError('journal_size must be of type int or string')
if self.filter_logic not in ['AND', 'OR']:
raise DriveGroupValidationError('filter_logic must be either <AND> or <OR>')
from ceph.deployment.inventory import Devices, Device
-from ceph.deployment.drive_group import DriveGroupSpec, DeviceSelection
+from ceph.deployment.drive_group import DriveGroupSpec, DeviceSelection, \
+ DriveGroupValidationError
from ceph.deployment import drive_selection
from ceph.deployment.service_spec import PlacementSpec
disk_format='bluestore'):
raw_sample_bluestore = {
'service_type': 'osd',
+ 'service_id': 'foo',
'placement': {'host_pattern': 'data*'},
'data_devices': {
'size': '30G:50G',
}
raw_sample_filestore = {
'service_type': 'osd',
+ 'service_id': 'foo',
'placement': {'host_pattern': 'data*'},
'objectstore': 'filestore',
'data_devices': {
if empty:
raw_sample = {
'service_type': 'osd',
+ 'service_id': 'foo',
'placement': {'host_pattern': 'data*'},
'data_devices': {
'all': True
}
dgo = DriveGroupSpec.from_json(raw_sample)
+ if disk_format == 'filestore':
+ with pytest.raises(DriveGroupValidationError):
+ dgo.validate()
+ else:
+ dgo.validate()
return dgo
return make_sample_data
def test_block_wal_size_prop(self, test_fix):
test_fix = test_fix()
- assert test_fix.block_wal_size == 5000000000
+ assert test_fix.block_wal_size == '5G'
def test_block_wal_size_prop_empty(self, test_fix):
test_fix = test_fix(empty=True)
def test_block_db_size_prop(self, test_fix):
test_fix = test_fix()
- assert test_fix.block_db_size == 10000000000
+ assert test_fix.block_db_size == '10G'
def test_block_db_size_prop_empty(self, test_fix):
test_fix = test_fix(empty=True)
def test_journal_size(self, test_fix):
test_fix = test_fix(disk_format='filestore')
- assert test_fix.journal_size == 5000000000
+ assert test_fix.journal_size == '5G'
def test_osds_per_device(self, test_fix):
test_fix = test_fix(osds_per_device='3')
testdata = [
(
- DriveGroupSpec(placement=PlacementSpec(host_pattern='*'), data_devices=DeviceSelection(all=True)),
+ DriveGroupSpec(
+ placement=PlacementSpec(host_pattern='*'),
+ service_id='foobar',
+ data_devices=DeviceSelection(all=True)),
_mk_inventory(_mk_device() * 5),
['/dev/sda', '/dev/sdb', '/dev/sdc', '/dev/sdd', '/dev/sde'], []
),
(
DriveGroupSpec(
placement=PlacementSpec(host_pattern='*'),
+ service_id='foobar',
data_devices=DeviceSelection(all=True, limit=3),
db_devices=DeviceSelection(all=True)
),
(
DriveGroupSpec(
placement=PlacementSpec(host_pattern='*'),
+ service_id='foobar',
data_devices=DeviceSelection(rotational=True),
db_devices=DeviceSelection(rotational=False)
),
(
DriveGroupSpec(
placement=PlacementSpec(host_pattern='*'),
+ service_id='foobar',
data_devices=DeviceSelection(rotational=True),
db_devices=DeviceSelection(rotational=False)
),
(
DriveGroupSpec(
placement=PlacementSpec(host_pattern='*'),
+ service_id='foobar',
data_devices=DeviceSelection(rotational=True),
db_devices=DeviceSelection(rotational=False)
),
def test_drivegroup_pattern():
- dg = DriveGroupSpec(PlacementSpec(host_pattern='node[1-3]'), data_devices=DeviceSelection(all=True))
+ dg = DriveGroupSpec(
+ PlacementSpec(host_pattern='node[1-3]'),
+ service_id='foobar',
+ data_devices=DeviceSelection(all=True))
assert dg.placement.filter_matching_hostspecs([HostSpec('node{}'.format(i)) for i in range(10)]) == ['node1', 'node2', 'node3']
def test_drive_selection():
devs = DeviceSelection(paths=['/dev/sda'])
- spec = DriveGroupSpec(PlacementSpec('node_name'), data_devices=devs)
+ spec = DriveGroupSpec(
+ PlacementSpec('node_name'),
+ service_id='foobar',
+ data_devices=devs)
assert all([isinstance(x, Device) for x in spec.data_devices.paths])
assert spec.data_devices.paths[0].path == '/dev/sda'
def test_ceph_volume_command_0():
spec = DriveGroupSpec(placement=PlacementSpec(host_pattern='*'),
+ service_id='foobar',
data_devices=DeviceSelection(all=True)
)
+ spec.validate()
inventory = _mk_inventory(_mk_device()*2)
sel = drive_selection.DriveSelection(spec, inventory)
cmd = translate.to_ceph_volume(sel, []).run()
def test_ceph_volume_command_1():
spec = DriveGroupSpec(placement=PlacementSpec(host_pattern='*'),
+ service_id='foobar',
data_devices=DeviceSelection(rotational=True),
db_devices=DeviceSelection(rotational=False)
)
+ spec.validate()
inventory = _mk_inventory(_mk_device(rotational=True)*2 + _mk_device(rotational=False)*2)
sel = drive_selection.DriveSelection(spec, inventory)
cmd = translate.to_ceph_volume(sel, []).run()
def test_ceph_volume_command_2():
spec = DriveGroupSpec(placement=PlacementSpec(host_pattern='*'),
+ service_id='foobar',
data_devices=DeviceSelection(size='200GB:350GB', rotational=True),
db_devices=DeviceSelection(size='200GB:350GB', rotational=False),
wal_devices=DeviceSelection(size='10G')
)
+ spec.validate()
inventory = _mk_inventory(_mk_device(rotational=True, size="300.00 GB")*2 +
_mk_device(rotational=False, size="300.00 GB")*2 +
_mk_device(size="10.0 GB", rotational=False)*2
def test_ceph_volume_command_3():
spec = DriveGroupSpec(placement=PlacementSpec(host_pattern='*'),
+ service_id='foobar',
data_devices=DeviceSelection(size='200GB:350GB', rotational=True),
db_devices=DeviceSelection(size='200GB:350GB', rotational=False),
wal_devices=DeviceSelection(size='10G'),
encrypted=True
)
+ spec.validate()
inventory = _mk_inventory(_mk_device(rotational=True, size="300.00 GB")*2 +
_mk_device(rotational=False, size="300.00 GB")*2 +
_mk_device(size="10.0 GB", rotational=False)*2
def test_ceph_volume_command_4():
spec = DriveGroupSpec(placement=PlacementSpec(host_pattern='*'),
+ service_id='foobar',
data_devices=DeviceSelection(size='200GB:350GB', rotational=True),
db_devices=DeviceSelection(size='200GB:350GB', rotational=False),
wal_devices=DeviceSelection(size='10G'),
osds_per_device=3,
encrypted=True
)
+ spec.validate()
inventory = _mk_inventory(_mk_device(rotational=True, size="300.00 GB")*2 +
_mk_device(rotational=False, size="300.00 GB")*2 +
_mk_device(size="10.0 GB", rotational=False)*2
def test_ceph_volume_command_5():
spec = DriveGroupSpec(placement=PlacementSpec(host_pattern='*'),
+ service_id='foobar',
data_devices=DeviceSelection(rotational=True),
objectstore='filestore'
)
+ with pytest.raises(DriveGroupValidationError):
+ spec.validate()
inventory = _mk_inventory(_mk_device(rotational=True)*2)
sel = drive_selection.DriveSelection(spec, inventory)
cmd = translate.to_ceph_volume(sel, []).run()
def test_ceph_volume_command_6():
spec = DriveGroupSpec(placement=PlacementSpec(host_pattern='*'),
+ service_id='foobar',
data_devices=DeviceSelection(rotational=False),
journal_devices=DeviceSelection(rotational=True),
journal_size='500M',
objectstore='filestore'
)
+ with pytest.raises(DriveGroupValidationError):
+ spec.validate()
inventory = _mk_inventory(_mk_device(rotational=True)*2 + _mk_device(rotational=False)*2)
sel = drive_selection.DriveSelection(spec, inventory)
cmd = translate.to_ceph_volume(sel, []).run()
def test_ceph_volume_command_7():
spec = DriveGroupSpec(placement=PlacementSpec(host_pattern='*'),
+ service_id='foobar',
data_devices=DeviceSelection(all=True),
osd_id_claims={'host1': ['0', '1']}
)
+ spec.validate()
inventory = _mk_inventory(_mk_device(rotational=True)*2)
sel = drive_selection.DriveSelection(spec, inventory)
cmd = translate.to_ceph_volume(sel, ['0', '1']).run()
def test_ceph_volume_command_8():
spec = DriveGroupSpec(placement=PlacementSpec(host_pattern='*'),
+ service_id='foobar',
data_devices=DeviceSelection(rotational=True, model='INTEL SSDS'),
db_devices=DeviceSelection(model='INTEL SSDP'),
filter_logic='OR',
osd_id_claims={}
)
+ spec.validate()
inventory = _mk_inventory(_mk_device(rotational=True, size='1.82 TB', model='ST2000DM001-1ER1') + # data
_mk_device(rotational=False, size="223.0 GB", model='INTEL SSDSC2KG24') + # data
_mk_device(rotational=False, size="349.0 GB", model='INTEL SSDPED1K375GA') # wal/db