33from .data_list import ceph_bluestore_tool_show_label_output
44from unittest .mock import patch , Mock
55from ceph_volume .devices import raw
6+ from ceph_volume .devices .raw import list as list_command
67
78# Sample lsblk output is below that overviews the test scenario. (--json output for reader clarity)
89# - sda and all its children are used for the OS
@@ -127,12 +128,14 @@ class TestList(object):
127128 @patch ('ceph_volume.util.disk.has_bluestore_label' )
128129 @patch ('ceph_volume.process.call' )
129130 @patch ('ceph_volume.util.disk.lsblk_all' )
130- def test_raw_list (self , patched_disk_lsblk , patched_call , patched_bluestore_label , patched_get_devices ):
131+ @patch ('ceph_volume.devices.raw.list.os.path.exists' )
132+ def test_raw_list (self , patched_path_exists , patched_disk_lsblk , patched_call , patched_bluestore_label , patched_get_devices ):
131133 raw .list .logger .setLevel ("DEBUG" )
132134 patched_call .side_effect = _process_call_side_effect
133135 patched_disk_lsblk .side_effect = _lsblk_all_devices
134136 patched_bluestore_label .side_effect = _has_bluestore_label_side_effect
135137 patched_get_devices .side_effect = _devices_side_effect
138+ patched_path_exists .return_value = True
136139
137140 result = raw .list .List ([]).generate ()
138141 assert len (result ) == 3
@@ -161,13 +164,15 @@ def test_raw_list(self, patched_disk_lsblk, patched_call, patched_bluestore_labe
161164 @patch ('ceph_volume.util.disk.has_bluestore_label' )
162165 @patch ('ceph_volume.process.call' )
163166 @patch ('ceph_volume.util.disk.lsblk_all' )
164- def test_raw_list_with_OSError (self , patched_disk_lsblk , patched_call , patched_bluestore_label , patched_get_devices ):
167+ @patch ('ceph_volume.devices.raw.list.os.path.exists' )
168+ def test_raw_list_with_OSError (self , patched_path_exists , patched_disk_lsblk , patched_call , patched_bluestore_label , patched_get_devices ):
165169 def _has_bluestore_label_side_effect_with_OSError (device_path ):
166170 if device_path == "/dev/sdd" :
167171 raise OSError ('fake OSError' )
168172 return _has_bluestore_label_side_effect (device_path )
169173
170174 raw .list .logger .setLevel ("DEBUG" )
175+ patched_path_exists .return_value = True
171176 patched_disk_lsblk .side_effect = _lsblk_all_devices
172177 patched_call .side_effect = _process_call_side_effect
173178 patched_bluestore_label .side_effect = _has_bluestore_label_side_effect_with_OSError
@@ -176,3 +181,44 @@ def _has_bluestore_label_side_effect_with_OSError(device_path):
176181 result = raw .list .List ([]).generate ()
177182 assert len (result ) == 2
178183 assert {'sdb-uuid' , 'sde1-uuid' } == set (result .keys ())
184+
185+ @patch ('ceph_volume.devices.raw.list.os.path.exists' )
186+ def test_raw_list_exclude_non_existent_loop_devices (self , path_exists_patch ):
187+ def path_exists_side_effect (path ):
188+ return path in ["/dev/sda" ]
189+ path_exists_patch .side_effect = path_exists_side_effect
190+
191+ devices = [
192+ {"NAME" : "/dev/loop0" , "KNAME" : "/dev/loop0" , "PKNAME" : "" , "TYPE" : "loop" },
193+ {"NAME" : "/dev/nvme1n1" , "KNAME" : "/dev/nvme1n1" , "PKNAME" : "" , "TYPE" : "disk" },
194+ {"NAME" : "/dev/sda" , "KNAME" : "/dev/sda" , "PKNAME" : "" , "TYPE" : "disk" },
195+ ]
196+ cmd = list_command .List ([])
197+
198+ assert cmd .exclude_invalid_devices (devices ) == [
199+ {"NAME" : "/dev/sda" , "KNAME" : "/dev/sda" , "PKNAME" : "" , "TYPE" : "disk" }
200+ ]
201+
202+ @patch ("ceph_volume.devices.raw.list.List.exclude_lvm_osd_devices" , Mock ())
203+ @patch ("ceph_volume.util.device.disk.get_devices" )
204+ @patch ("ceph_volume.util.disk.has_bluestore_label" )
205+ @patch ("ceph_volume.process.call" )
206+ @patch ("ceph_volume.util.disk.lsblk_all" )
207+ def test_exclude_invalid_devices_is_called (
208+ self ,
209+ patched_disk_lsblk ,
210+ patched_call ,
211+ patched_bluestore_label ,
212+ patched_get_devices ,
213+ ):
214+ patched_disk_lsblk .side_effect = _lsblk_all_devices
215+ patched_call .side_effect = _process_call_side_effect
216+ patched_bluestore_label .side_effect = _has_bluestore_label_side_effect
217+ patched_get_devices .side_effect = _devices_side_effect
218+
219+ with patch (
220+ "ceph_volume.devices.raw.list.List.exclude_invalid_devices"
221+ ) as mock :
222+ list_command .List ([]).generate ()
223+ mock .assert_called_once ()
224+
0 commit comments