7 from ceph
.deployment
import drive_selection
, translate
8 from ceph
.deployment
.hostspec
import HostSpec
, SpecValidationError
9 from ceph
.deployment
.inventory
import Device
10 from ceph
.deployment
.service_spec
import PlacementSpec
11 from ceph
.tests
.utils
import _mk_inventory
, _mk_device
12 from ceph
.deployment
.drive_group
import DriveGroupSpec
, DeviceSelection
, \
13 DriveGroupValidationError
15 @pytest.mark
.parametrize("test_input",
19 service_id: testing_drivegroup
21 host_pattern: hostname
29 service_id: testing_drivegroup
31 host_pattern: hostname
37 def test_DriveGroup(test_input
):
38 dg
= DriveGroupSpec
.from_json(yaml
.safe_load(test_input
))
39 assert dg
.service_id
== 'testing_drivegroup'
40 assert all([isinstance(x
, Device
) for x
in dg
.data_devices
.paths
])
41 assert dg
.data_devices
.paths
[0].path
== '/dev/sda'
43 @pytest.mark
.parametrize("match,test_input",
46 re
.escape('Service Spec is not an (JSON or YAML) object. got "None"'),
50 'Failed to validate OSD spec "<unnamed>": `placement` required',
56 'Failed to validate OSD spec "mydg.data_devices": device selection cannot be empty', """
66 'Failed to validate OSD spec "mydg": filter_logic must be either <AND> or <OR>', """
77 'Failed to validate OSD spec "mydg": `data_devices` element is required.', """
88 'Failed to validate OSD spec "mydg.db_devices": Filtering for `unknown_key` is not supported', """
99 'Failed to validate OSD spec "mydg": Feature `unknown_key` is not supported', """
111 def test_DriveGroup_fail(match
, test_input
):
112 with pytest
.raises(SpecValidationError
, match
=match
):
113 osd_spec
= DriveGroupSpec
.from_json(yaml
.safe_load(test_input
))
117 def test_drivegroup_pattern():
119 PlacementSpec(host_pattern
='node[1-3]'),
121 data_devices
=DeviceSelection(all
=True))
122 assert dg
.placement
.filter_matching_hostspecs([HostSpec('node{}'.format(i
)) for i
in range(10)]) == ['node1', 'node2', 'node3']
125 def test_drive_selection():
126 devs
= DeviceSelection(paths
=['/dev/sda'])
127 spec
= DriveGroupSpec(
128 PlacementSpec('node_name'),
131 assert all([isinstance(x
, Device
) for x
in spec
.data_devices
.paths
])
132 assert spec
.data_devices
.paths
[0].path
== '/dev/sda'
134 with pytest
.raises(DriveGroupValidationError
, match
='exclusive'):
135 ds
= DeviceSelection(paths
=['/dev/sda'], rotational
=False)
139 def test_ceph_volume_command_0():
140 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
142 data_devices
=DeviceSelection(all
=True)
145 inventory
= _mk_inventory(_mk_device()*2)
146 sel
= drive_selection
.DriveSelection(spec
, inventory
)
147 cmds
= translate
.to_ceph_volume(sel
, []).run()
148 assert all(cmd
== 'lvm batch --no-auto /dev/sda /dev/sdb --yes --no-systemd' for cmd
in cmds
), f
'Expected {cmd} in {cmds}'
151 def test_ceph_volume_command_1():
152 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
154 data_devices
=DeviceSelection(rotational
=True),
155 db_devices
=DeviceSelection(rotational
=False)
158 inventory
= _mk_inventory(_mk_device(rotational
=True)*2 + _mk_device(rotational
=False)*2)
159 sel
= drive_selection
.DriveSelection(spec
, inventory
)
160 cmds
= translate
.to_ceph_volume(sel
, []).run()
161 assert all(cmd
== ('lvm batch --no-auto /dev/sda /dev/sdb '
162 '--db-devices /dev/sdc /dev/sdd --yes --no-systemd') for cmd
in cmds
), f
'Expected {cmd} in {cmds}'
165 def test_ceph_volume_command_2():
166 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
168 data_devices
=DeviceSelection(size
='200GB:350GB', rotational
=True),
169 db_devices
=DeviceSelection(size
='200GB:350GB', rotational
=False),
170 wal_devices
=DeviceSelection(size
='10G')
173 inventory
= _mk_inventory(_mk_device(rotational
=True, size
="300.00 GB")*2 +
174 _mk_device(rotational
=False, size
="300.00 GB")*2 +
175 _mk_device(size
="10.0 GB", rotational
=False)*2
177 sel
= drive_selection
.DriveSelection(spec
, inventory
)
178 cmds
= translate
.to_ceph_volume(sel
, []).run()
179 assert all(cmd
== ('lvm batch --no-auto /dev/sda /dev/sdb '
180 '--db-devices /dev/sdc /dev/sdd --wal-devices /dev/sde /dev/sdf '
181 '--yes --no-systemd') for cmd
in cmds
), f
'Expected {cmd} in {cmds}'
184 def test_ceph_volume_command_3():
185 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
187 data_devices
=DeviceSelection(size
='200GB:350GB', rotational
=True),
188 db_devices
=DeviceSelection(size
='200GB:350GB', rotational
=False),
189 wal_devices
=DeviceSelection(size
='10G'),
193 inventory
= _mk_inventory(_mk_device(rotational
=True, size
="300.00 GB")*2 +
194 _mk_device(rotational
=False, size
="300.00 GB")*2 +
195 _mk_device(size
="10.0 GB", rotational
=False)*2
197 sel
= drive_selection
.DriveSelection(spec
, inventory
)
198 cmds
= translate
.to_ceph_volume(sel
, []).run()
199 assert all(cmd
== ('lvm batch --no-auto /dev/sda /dev/sdb '
200 '--db-devices /dev/sdc /dev/sdd '
201 '--wal-devices /dev/sde /dev/sdf --dmcrypt '
202 '--yes --no-systemd') for cmd
in cmds
), f
'Expected {cmd} in {cmds}'
205 def test_ceph_volume_command_4():
206 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
208 data_devices
=DeviceSelection(size
='200GB:350GB', rotational
=True),
209 db_devices
=DeviceSelection(size
='200GB:350GB', rotational
=False),
210 wal_devices
=DeviceSelection(size
='10G'),
211 block_db_size
='500M',
212 block_wal_size
='500M',
217 inventory
= _mk_inventory(_mk_device(rotational
=True, size
="300.00 GB")*2 +
218 _mk_device(rotational
=False, size
="300.00 GB")*2 +
219 _mk_device(size
="10.0 GB", rotational
=False)*2
221 sel
= drive_selection
.DriveSelection(spec
, inventory
)
222 cmds
= translate
.to_ceph_volume(sel
, []).run()
223 assert all(cmd
== ('lvm batch --no-auto /dev/sda /dev/sdb '
224 '--db-devices /dev/sdc /dev/sdd --wal-devices /dev/sde /dev/sdf '
225 '--block-wal-size 500M --block-db-size 500M --dmcrypt '
226 '--osds-per-device 3 --yes --no-systemd') for cmd
in cmds
), f
'Expected {cmd} in {cmds}'
229 def test_ceph_volume_command_5():
230 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
232 data_devices
=DeviceSelection(rotational
=True),
233 objectstore
='filestore'
235 with pytest
.raises(DriveGroupValidationError
):
237 inventory
= _mk_inventory(_mk_device(rotational
=True)*2)
238 sel
= drive_selection
.DriveSelection(spec
, inventory
)
239 cmds
= translate
.to_ceph_volume(sel
, []).run()
240 assert all(cmd
== 'lvm batch --no-auto /dev/sda /dev/sdb --filestore --yes --no-systemd' for cmd
in cmds
), f
'Expected {cmd} in {cmds}'
243 def test_ceph_volume_command_6():
244 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
246 data_devices
=DeviceSelection(rotational
=False),
247 journal_devices
=DeviceSelection(rotational
=True),
249 objectstore
='filestore'
251 with pytest
.raises(DriveGroupValidationError
):
253 inventory
= _mk_inventory(_mk_device(rotational
=True)*2 + _mk_device(rotational
=False)*2)
254 sel
= drive_selection
.DriveSelection(spec
, inventory
)
255 cmds
= translate
.to_ceph_volume(sel
, []).run()
256 assert all(cmd
== ('lvm batch --no-auto /dev/sdc /dev/sdd '
257 '--journal-size 500M --journal-devices /dev/sda /dev/sdb '
258 '--filestore --yes --no-systemd') for cmd
in cmds
), f
'Expected {cmd} in {cmds}'
261 def test_ceph_volume_command_7():
262 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
264 data_devices
=DeviceSelection(all
=True),
265 osd_id_claims
={'host1': ['0', '1']}
268 inventory
= _mk_inventory(_mk_device(rotational
=True)*2)
269 sel
= drive_selection
.DriveSelection(spec
, inventory
)
270 cmds
= translate
.to_ceph_volume(sel
, ['0', '1']).run()
271 assert all(cmd
== 'lvm batch --no-auto /dev/sda /dev/sdb --osd-ids 0 1 --yes --no-systemd' for cmd
in cmds
), f
'Expected {cmd} in {cmds}'
274 def test_ceph_volume_command_8():
275 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
277 data_devices
=DeviceSelection(rotational
=True, model
='INTEL SSDS'),
278 db_devices
=DeviceSelection(model
='INTEL SSDP'),
283 inventory
= _mk_inventory(_mk_device(rotational
=True, size
='1.82 TB', model
='ST2000DM001-1ER1') + # data
284 _mk_device(rotational
=False, size
="223.0 GB", model
='INTEL SSDSC2KG24') + # data
285 _mk_device(rotational
=False, size
="349.0 GB", model
='INTEL SSDPED1K375GA') # wal/db
287 sel
= drive_selection
.DriveSelection(spec
, inventory
)
288 cmds
= translate
.to_ceph_volume(sel
, []).run()
289 assert all(cmd
== 'lvm batch --no-auto /dev/sda /dev/sdb --db-devices /dev/sdc --yes --no-systemd' for cmd
in cmds
), f
'Expected {cmd} in {cmds}'
292 def test_ceph_volume_command_9():
293 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
295 data_devices
=DeviceSelection(all
=True),
296 data_allocate_fraction
=0.8
299 inventory
= _mk_inventory(_mk_device()*2)
300 sel
= drive_selection
.DriveSelection(spec
, inventory
)
301 cmds
= translate
.to_ceph_volume(sel
, []).run()
302 assert all(cmd
== 'lvm batch --no-auto /dev/sda /dev/sdb --data-allocate-fraction 0.8 --yes --no-systemd' for cmd
in cmds
), f
'Expected {cmd} in {cmds}'
304 def test_raw_ceph_volume_command_0():
305 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
307 data_devices
=DeviceSelection(rotational
=True),
308 db_devices
=DeviceSelection(rotational
=False),
312 inventory
= _mk_inventory(_mk_device(rotational
=True) + # data
313 _mk_device(rotational
=True) + # data
314 _mk_device(rotational
=False) + # db
315 _mk_device(rotational
=False) # db
317 exp_cmds
= ['raw prepare --bluestore --data /dev/sda --block.db /dev/sdc', 'raw prepare --bluestore --data /dev/sdb --block.db /dev/sdd']
318 sel
= drive_selection
.DriveSelection(spec
, inventory
)
319 cmds
= translate
.to_ceph_volume(sel
, []).run()
320 assert all(cmd
in exp_cmds
for cmd
in cmds
), f
'Expected {exp_cmds} to match {cmds}'
322 def test_raw_ceph_volume_command_1():
323 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
325 data_devices
=DeviceSelection(rotational
=True),
326 db_devices
=DeviceSelection(rotational
=False),
330 inventory
= _mk_inventory(_mk_device(rotational
=True) + # data
331 _mk_device(rotational
=True) + # data
332 _mk_device(rotational
=False) # db
334 sel
= drive_selection
.DriveSelection(spec
, inventory
)
335 with pytest
.raises(ValueError):
336 cmds
= translate
.to_ceph_volume(sel
, []).run()