5 from ceph
.deployment
import drive_selection
, translate
6 from ceph
.deployment
.hostspec
import HostSpec
7 from ceph
.deployment
.inventory
import Device
8 from ceph
.deployment
.service_spec
import PlacementSpec
, ServiceSpecValidationError
9 from ceph
.tests
.utils
import _mk_inventory
, _mk_device
10 from ceph
.deployment
.drive_group
import DriveGroupSpec
, DeviceSelection
, \
11 DriveGroupValidationError
13 @pytest.mark
.parametrize("test_input",
18 'service_type': 'osd',
19 'service_id': 'testing_drivegroup',
20 'placement': {'host_pattern': 'hostname'},
21 'data_devices': {'paths': ['/dev/sda']}
26 def test_DriveGroup(test_input
):
27 dg
= [DriveGroupSpec
.from_json(inp
) for inp
in test_input
][0]
28 assert dg
.placement
.filter_matching_hostspecs([HostSpec('hostname')]) == ['hostname']
29 assert dg
.service_id
== 'testing_drivegroup'
30 assert all([isinstance(x
, Device
) for x
in dg
.data_devices
.paths
])
31 assert dg
.data_devices
.paths
[0].path
== '/dev/sda'
33 @pytest.mark
.parametrize("test_input",
59 def test_DriveGroup_fail(test_input
):
60 with pytest
.raises(ServiceSpecValidationError
):
61 DriveGroupSpec
.from_json(test_input
)
65 def test_drivegroup_pattern():
67 PlacementSpec(host_pattern
='node[1-3]'),
69 data_devices
=DeviceSelection(all
=True))
70 assert dg
.placement
.filter_matching_hostspecs([HostSpec('node{}'.format(i
)) for i
in range(10)]) == ['node1', 'node2', 'node3']
73 def test_drive_selection():
74 devs
= DeviceSelection(paths
=['/dev/sda'])
75 spec
= DriveGroupSpec(
76 PlacementSpec('node_name'),
79 assert all([isinstance(x
, Device
) for x
in spec
.data_devices
.paths
])
80 assert spec
.data_devices
.paths
[0].path
== '/dev/sda'
82 with pytest
.raises(DriveGroupValidationError
, match
='exclusive'):
83 DeviceSelection(paths
=['/dev/sda'], rotational
=False)
86 def test_ceph_volume_command_0():
87 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
89 data_devices
=DeviceSelection(all
=True)
92 inventory
= _mk_inventory(_mk_device()*2)
93 sel
= drive_selection
.DriveSelection(spec
, inventory
)
94 cmd
= translate
.to_ceph_volume(sel
, []).run()
95 assert cmd
== 'lvm batch --no-auto /dev/sda /dev/sdb --yes --no-systemd'
98 def test_ceph_volume_command_1():
99 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
101 data_devices
=DeviceSelection(rotational
=True),
102 db_devices
=DeviceSelection(rotational
=False)
105 inventory
= _mk_inventory(_mk_device(rotational
=True)*2 + _mk_device(rotational
=False)*2)
106 sel
= drive_selection
.DriveSelection(spec
, inventory
)
107 cmd
= translate
.to_ceph_volume(sel
, []).run()
108 assert cmd
== ('lvm batch --no-auto /dev/sda /dev/sdb '
109 '--db-devices /dev/sdc /dev/sdd --yes --no-systemd')
112 def test_ceph_volume_command_2():
113 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
115 data_devices
=DeviceSelection(size
='200GB:350GB', rotational
=True),
116 db_devices
=DeviceSelection(size
='200GB:350GB', rotational
=False),
117 wal_devices
=DeviceSelection(size
='10G')
120 inventory
= _mk_inventory(_mk_device(rotational
=True, size
="300.00 GB")*2 +
121 _mk_device(rotational
=False, size
="300.00 GB")*2 +
122 _mk_device(size
="10.0 GB", rotational
=False)*2
124 sel
= drive_selection
.DriveSelection(spec
, inventory
)
125 cmd
= translate
.to_ceph_volume(sel
, []).run()
126 assert cmd
== ('lvm batch --no-auto /dev/sda /dev/sdb '
127 '--db-devices /dev/sdc /dev/sdd --wal-devices /dev/sde /dev/sdf '
128 '--yes --no-systemd')
131 def test_ceph_volume_command_3():
132 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
134 data_devices
=DeviceSelection(size
='200GB:350GB', rotational
=True),
135 db_devices
=DeviceSelection(size
='200GB:350GB', rotational
=False),
136 wal_devices
=DeviceSelection(size
='10G'),
140 inventory
= _mk_inventory(_mk_device(rotational
=True, size
="300.00 GB")*2 +
141 _mk_device(rotational
=False, size
="300.00 GB")*2 +
142 _mk_device(size
="10.0 GB", rotational
=False)*2
144 sel
= drive_selection
.DriveSelection(spec
, inventory
)
145 cmd
= translate
.to_ceph_volume(sel
, []).run()
146 assert cmd
== ('lvm batch --no-auto /dev/sda /dev/sdb '
147 '--db-devices /dev/sdc /dev/sdd '
148 '--wal-devices /dev/sde /dev/sdf --dmcrypt '
149 '--yes --no-systemd')
152 def test_ceph_volume_command_4():
153 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
155 data_devices
=DeviceSelection(size
='200GB:350GB', rotational
=True),
156 db_devices
=DeviceSelection(size
='200GB:350GB', rotational
=False),
157 wal_devices
=DeviceSelection(size
='10G'),
158 block_db_size
='500M',
159 block_wal_size
='500M',
164 inventory
= _mk_inventory(_mk_device(rotational
=True, size
="300.00 GB")*2 +
165 _mk_device(rotational
=False, size
="300.00 GB")*2 +
166 _mk_device(size
="10.0 GB", rotational
=False)*2
168 sel
= drive_selection
.DriveSelection(spec
, inventory
)
169 cmd
= translate
.to_ceph_volume(sel
, []).run()
170 assert cmd
== ('lvm batch --no-auto /dev/sda /dev/sdb '
171 '--db-devices /dev/sdc /dev/sdd --wal-devices /dev/sde /dev/sdf '
172 '--block-wal-size 500M --block-db-size 500M --dmcrypt '
173 '--osds-per-device 3 --yes --no-systemd')
176 def test_ceph_volume_command_5():
177 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
179 data_devices
=DeviceSelection(rotational
=True),
180 objectstore
='filestore'
182 with pytest
.raises(DriveGroupValidationError
):
184 inventory
= _mk_inventory(_mk_device(rotational
=True)*2)
185 sel
= drive_selection
.DriveSelection(spec
, inventory
)
186 cmd
= translate
.to_ceph_volume(sel
, []).run()
187 assert cmd
== 'lvm batch --no-auto /dev/sda /dev/sdb --filestore --yes --no-systemd'
190 def test_ceph_volume_command_6():
191 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
193 data_devices
=DeviceSelection(rotational
=False),
194 journal_devices
=DeviceSelection(rotational
=True),
196 objectstore
='filestore'
198 with pytest
.raises(DriveGroupValidationError
):
200 inventory
= _mk_inventory(_mk_device(rotational
=True)*2 + _mk_device(rotational
=False)*2)
201 sel
= drive_selection
.DriveSelection(spec
, inventory
)
202 cmd
= translate
.to_ceph_volume(sel
, []).run()
203 assert cmd
== ('lvm batch --no-auto /dev/sdc /dev/sdd '
204 '--journal-size 500M --journal-devices /dev/sda /dev/sdb '
205 '--filestore --yes --no-systemd')
208 def test_ceph_volume_command_7():
209 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
211 data_devices
=DeviceSelection(all
=True),
212 osd_id_claims
={'host1': ['0', '1']}
215 inventory
= _mk_inventory(_mk_device(rotational
=True)*2)
216 sel
= drive_selection
.DriveSelection(spec
, inventory
)
217 cmd
= translate
.to_ceph_volume(sel
, ['0', '1']).run()
218 assert cmd
== 'lvm batch --no-auto /dev/sda /dev/sdb --osd-ids 0 1 --yes --no-systemd'
221 def test_ceph_volume_command_8():
222 spec
= DriveGroupSpec(placement
=PlacementSpec(host_pattern
='*'),
224 data_devices
=DeviceSelection(rotational
=True, model
='INTEL SSDS'),
225 db_devices
=DeviceSelection(model
='INTEL SSDP'),
230 inventory
= _mk_inventory(_mk_device(rotational
=True, size
='1.82 TB', model
='ST2000DM001-1ER1') + # data
231 _mk_device(rotational
=False, size
="223.0 GB", model
='INTEL SSDSC2KG24') + # data
232 _mk_device(rotational
=False, size
="349.0 GB", model
='INTEL SSDPED1K375GA') # wal/db
234 sel
= drive_selection
.DriveSelection(spec
, inventory
)
235 cmd
= translate
.to_ceph_volume(sel
, []).run()
236 assert cmd
== 'lvm batch --no-auto /dev/sda /dev/sdb --db-devices /dev/sdc --yes --no-systemd'