66import unittest
77from uuid import uuid4
88
9+ import util
910from BaseISCSI import BaseISCSISR
1011import SR
1112import SRCommand
13+ from shared_iscsi_test_base import ISCSITestCase
1214from util import CommandException
1315
1416
15- class TestBaseISCSI (unittest .TestCase ):
17+ class TestBaseISCSI (ISCSITestCase ):
18+
19+ TEST_CLASS = 'BaseISCSI'
1620
1721 def setUp (self ):
1822 self .addCleanup (mock .patch .stopall )
1923
2024 util_patcher = mock .patch ('BaseISCSI.util' , autospec = True )
2125 self .mock_util = util_patcher .start ()
2226 self .mock_util .CommandException = CommandException
27+ self .mock_util .sessions_less_than_targets = util .sessions_less_than_targets
28+ self .mock_util ._convertDNS .side_effect = lambda x : x
29+ # self.mock_util.SMlog.side_effect = print
30+
31+ scsi_util_patcher = mock .patch ('BaseISCSI.scsiutil' , autospec = True )
32+ self .mock_scsiutil = scsi_util_patcher .start ()
2333
2434 self .mock_session = mock .MagicMock ()
2535 xenapi_patcher = mock .patch ('SR.XenAPI' )
2636 mock_xenapi = xenapi_patcher .start ()
2737 mock_xenapi .xapi_local .return_value = self .mock_session
2838
29- iscsilib_patcher = mock .patch ('BaseISCSI.iscsilib' , autospec = True )
30- self .mock_iscsilib = iscsilib_patcher .start ()
31-
3239 copy_patcher = mock .patch ('LVHDoISCSISR.SR.copy.deepcopy' )
3340 self .mock_copy = copy_patcher .start ()
3441
@@ -37,25 +44,9 @@ def deepcopy(to_copy):
3744
3845 self .mock_copy .side_effect = deepcopy
3946
40- dummy_cmd = mock .create_autospec (SRCommand )
41- dummy_cmd .dconf = {
42- 'SCSIid' : '3600a098038313577792450384a4a6275' ,
43- 'target' : "10.70.89.34" ,
44- 'targetIQN' : 'iqn.2009-01.example.test:iscsi085e938a'
45- }
46- dummy_cmd .params = {
47- 'command' : 'nop' ,
48- 'session_ref' : 'test_session' ,
49- 'host_ref' : 'test_host' ,
50- 'sr_ref' : 'sr_ref'
51- }
52- dummy_cmd .cmd = None
53-
5447 self .sr_uuid = str (uuid4 ())
5548
56- self .subject = BaseISCSISR (
57- dummy_cmd , self .sr_uuid
58- )
49+ super ().setUp ()
5950
6051 def setup_path_mocks (self ):
6152 self .path_contents = {}
@@ -67,24 +58,31 @@ def setup_path_mocks(self):
6758 mock_listdir .side_effect = self .listdir
6859
6960 def exists (self , path ):
70- print (f'checking existance of { path } ' )
7161 return path in self .path_contents
7262
7363 def listdir (self , path ):
7464 return self .path_contents [path ]
7565
66+ def create_test_sr (self , sr_cmd ):
67+ self .sr_uuid = str (uuid4 ())
68+ self .subject = BaseISCSISR (
69+ sr_cmd , self .sr_uuid )
70+
7671 @mock .patch ('BaseISCSI.BaseISCSISR._initPaths' , autospec = True )
7772 def test_attach_tgt_present_path_found (self , mock_init_paths ):
7873 # Arrange
7974 self .setup_path_mocks ()
8075 self .path_contents .update (
8176 {'/dev/disk/by-scsid/3600a098038313577792450384a4a6275' : ['sdb' ]})
8277 self .mock_util ._testHost .return_value = None
83- self .mock_util .sessions_less_than_targets .return_value = False
84- self .mock_iscsilib ._checkTGT .return_value = True
85- self .mock_iscsilib .parse_IP_port .side_effect = [
86- ('tgt1' , '3260' )
87- ]
78+ self .discovery_data = {
79+ 'tgt1' : [
80+ ('tgt1:3260' , 1 , 'iqn.2009-11.com.infinidat:storage:infinibox-sn-3393' )],
81+ }
82+
83+ self .create_test_sr (self .create_sr_command (
84+ cmd = 'sr_attach' ,
85+ target_iqn = 'iqn.2009-11.com.infinidat:storage:infinibox-sn-3393' ))
8886
8987 # Act
9088 self .subject .attach (self .sr_uuid )
@@ -94,15 +92,97 @@ def test_attach_tgt_present_path_found(self, mock_init_paths):
9492 def test_attach_tgt_present_path_not_found (self , mock_init_paths ):
9593 # Arrange
9694 self .mock_util ._testHost .return_value = None
97- self .mock_util .sessions_less_than_targets .return_value = False
98- self .mock_iscsilib ._checkTGT .return_value = True
99- self .mock_iscsilib .parse_IP_port .side_effect = [
100- ('tgt1' , '3260' )
101- ]
95+ self .discovery_data = {
96+ 'tgt1' : [
97+ ('tgt1:3260' , 1 , 'iqn.2009-11.com.infinidat:storage:infinibox-sn-3393' )],
98+ }
99+
100+ self .create_test_sr (self .create_sr_command (
101+ cmd = 'sr_attach' ,
102+ target_iqn = 'iqn.2009-11.com.infinidat:storage:infinibox-sn-3393' ))
102103
103104 # Act
104105 with self .assertRaises (SR .SROSError ) as srose :
105106 self .subject .attach (self .sr_uuid )
106107
107108 # Assert
108109 self .assertEqual (107 , srose .exception .errno )
110+
111+ def test_sr_attach_multi_session (self ):
112+ # Arrange
113+ self .mock_util .find_my_pbd .return_value = 'my_pbd'
114+ additional_dconf = {
115+ 'multiSession' : '10.207.6.60,3260,iqn.2009-11.com.infinidat:storage:infinibox-sn-3393|'
116+ '10.207.3.65,3260,iqn.2009-11.com.infinidat:storage:infinibox-sn-3394|'
117+ '10.207.3.61,3260,iqn.2009-11.com.infinidat:storage:infinibox-sn-3393|'
118+ '10.207.6.61,3260,iqn.2009-11.com.infinidat:storage:infinibox-sn-3393|'
119+ '10.207.3.63,3260,iqn.2009-11.com.infinidat:storage:infinibox-sn-3394|'
120+ '10.207.6.62,3260,iqn.2009-11.com.infinidat:storage:infinibox-sn-3393|'
121+ '10.207.3.62,3260,iqn.2009-11.com.infinidat:storage:infinibox-sn-3393|'
122+ '10.207.3.60,3260,iqn.2009-11.com.infinidat:storage:infinibox-sn-3393|'
123+ '10.207.6.64,3260,iqn.2009-11.com.infinidat:storage:infinibox-sn-3394|'
124+ '10.207.6.65,3260,iqn.2009-11.com.infinidat:storage:infinibox-sn-3394|'
125+ '10.207.3.64,3260,iqn.2009-11.com.infinidat:storage:infinibox-sn-3394|'
126+ '10.207.6.63,3260,iqn.2009-11.com.infinidat:storage:infinibox-sn-3394|'
127+ }
128+
129+ tpg_data = [
130+ [
131+ ('10.207.3.60:3260' , 1 , 'iqn.2009-11.com.infinidat:storage:infinibox-sn-3393' ),
132+ ('10.207.3.61:3260' , 1 , 'iqn.2009-11.com.infinidat:storage:infinibox-sn-3393' ),
133+ ('10.207.3.62:3260' , 1 , 'iqn.2009-11.com.infinidat:storage:infinibox-sn-3393' )],
134+ [
135+ ('10.207.3.63:3260' , 1 , 'iqn.2009-11.com.infinidat:storage:infinibox-sn-3394' ),
136+ ('10.207.3.64:3260' , 1 , 'iqn.2009-11.com.infinidat:storage:infinibox-sn-3394' ),
137+ ('10.207.3.65:3260' , 1 , 'iqn.2009-11.com.infinidat:storage:infinibox-sn-3394' )],
138+ [
139+ ('10.207.6.60:3260' , 2 , 'iqn.2009-11.com.infinidat:storage:infinibox-sn-3393' ),
140+ ('10.207.6.61:3260' , 2 , 'iqn.2009-11.com.infinidat:storage:infinibox-sn-3393' ),
141+ ('10.207.6.62:3260' , 2 , 'iqn.2009-11.com.infinidat:storage:infinibox-sn-3393' )
142+ ],
143+ [
144+ ('10.207.6.63:3260' , 2 , 'iqn.2009-11.com.infinidat:storage:infinibox-sn-3394' ),
145+ ('10.207.6.64:3260' , 2 , 'iqn.2009-11.com.infinidat:storage:infinibox-sn-3394' ),
146+ ('10.207.6.65:3260' , 2 , 'iqn.2009-11.com.infinidat:storage:infinibox-sn-3394' )
147+ ]
148+ ]
149+
150+ self .discovery_data = {
151+ '10.207.3.60' : tpg_data [0 ],
152+ '10.207.3.61' : tpg_data [0 ],
153+ '10.207.3.62' : tpg_data [0 ],
154+ '10.207.3.63' : tpg_data [1 ],
155+ '10.207.3.64' : tpg_data [1 ],
156+ '10.207.3.65' : tpg_data [1 ],
157+ '10.207.6.60' : tpg_data [2 ],
158+ '10.207.6.61' : tpg_data [2 ],
159+ '10.207.6.62' : tpg_data [2 ],
160+ '10.207.6.63' : tpg_data [3 ],
161+ '10.207.6.64' : tpg_data [3 ],
162+ '10.207.6.65' : tpg_data [3 ]
163+ }
164+
165+ self .mock_scsiutil ._genHostList .return_value = [1 , 2 ]
166+ self .mock_iscsilib .get_targetIQN .return_value = 'iqn.2009-11.com.infinidat:storage:infinibox-sn-3393'
167+ self .mock_scsiutil .cacheSCSIidentifiers .return_value = [
168+ ['NONE' , '0' , '0' , '0' , '0' , '0' , '/dev/sdb' ]
169+ ]
170+ self .setup_path_mocks ()
171+ self .path_contents .update (
172+ {'/dev/iscsi/iqn.2009-11.com.infinidat:storage:infinibox-sn-3393/10.207.3.60:3260' : ['LUN0' ],
173+ '/dev/disk/by-scsid/3600a098038313577792450384a4a6275' : []})
174+
175+ # Create SR
176+ self .create_test_sr (self .create_sr_command (
177+ additional_dconf = additional_dconf ,
178+ cmd = 'sr_attach' ,
179+ multihomelist = "10.207.3.62:3260,10.207.6.61:3260,10.207.6.62:3260,10.207.6.60:3260" ,
180+ target = '10.207.3.60' ,
181+ target_iqn = 'iqn.2009-11.com.infinidat:storage:infinibox-sn-3393' ))
182+
183+ # Act
184+ self .subject .attach (self .sr_uuid )
185+
186+ # Assert
187+ self .assertEqual (1 , self .mock_iscsilib .discovery .call_count )
188+ self .assertEqual (1 , self .mock_iscsilib .login .call_count )
0 commit comments