@@ -49,6 +49,7 @@ def setUp(self):
4949 exists_patcher = mock .patch (
5050 'sm.core.scsiutil.os.path.exists' , autospece = True )
5151 self .mock_exists = exists_patcher .start ()
52+ self .mock_exists .side_effect = self .exists
5253 self .path_map = {}
5354 realpath_patcher = mock .patch (
5455 'sm.core.scsiutil.os.path.realpath' , autospec = True )
@@ -91,8 +92,13 @@ def open(self, file_name, mode):
9192 self .mock_files [file_name ] = mock_file
9293 return mock_file
9394
95+ def exists (self , path ):
96+ return path in self .path_map
97+
9498 def test_get_size_exists_success (self ):
95- self .mock_exists .return_value = True
99+ self .path_map = {
100+ '/sys/block/sda/size' : True
101+ }
96102
97103 with mock .patch ("builtins.open" ,
98104 new_callable = mock .mock_open , read_data = '976773168' ) as m :
@@ -104,11 +110,9 @@ def test_get_size_exists_success(self):
104110 m .assert_called_with ("/sys/block/sda/size" , "r" )
105111
106112 def test_get_size_mapper_exists_success (self ):
107- self .mock_exists .return_value = True
108-
109- self .path_map [
110- "/dev/disk/by-id/scsi-360a98000534b4f4e46704c76692d6d33" ] = \
111- "/dev/sde"
113+ self .path_map = {
114+ '/sys/block/sde/size' : True ,
115+ "/dev/disk/by-id/scsi-360a98000534b4f4e46704c76692d6d33" : "/dev/sde" }
112116
113117 with mock .patch ("builtins.open" ,
114118 new_callable = mock .mock_open , read_data = '976773168' ) as m :
@@ -120,8 +124,6 @@ def test_get_size_mapper_exists_success(self):
120124 m .assert_called_with ("/sys/block/sde/size" , "r" )
121125
122126 def test_get_size_not_exists_0 (self ):
123- self .mock_exists .return_value = False
124-
125127 with mock .patch ("builtins.open" ,
126128 new_callable = mock .mock_open , read_data = '976773168' ) as m :
127129 # Nastiness due to python2 mock_open not supporting readline
@@ -159,3 +161,12 @@ def test_lun_is_thin_provisioned(self):
159161
160162 # Assert
161163 self .assertTrue (thin_provisioned )
164+
165+ def test_lun_is_thin_provisioned_not_found (self ):
166+ self .path_map = {}
167+
168+ # Act
169+ thin_provisioned = scsiutil .device_is_thin_provisioned ('360a98000534b4f4e46704c76692d6d33' )
170+
171+ # Assert
172+ self .assertFalse (thin_provisioned )
0 commit comments