@@ -59,6 +59,33 @@ def __init__(self, extra_dconf=None):
5959 self .dconf .update (extra_dconf or {})
6060
6161
62+ class NonInitingMultiLUNISCSISR (ISCSISR .ISCSISR ):
63+ def __init__ (self , node1 , node2 ):
64+ self .mpath = "false"
65+ self .dconf = {
66+ 'target' : node1 ['ip' ],
67+ 'localIQN' : 'localIQN' ,
68+ 'targetIQN' : node1 ['iqn' ]
69+ }
70+
71+ self .dconf .update ({})
72+ self .target = node1 ['ip' ]
73+ self .port = node1 ['port' ]
74+ self .targetIQN = node1 ['iqn' ]
75+ self .attached = True
76+ self .multihomed = True
77+ extra_adapter = "%s:%d" % (node2 ['ip' ], node2 ['port' ])
78+ self .adapter = {
79+ extra_adapter : None
80+ }
81+
82+ def _synchroniseAddrList (self , * args , ** kwargs ):
83+ pass
84+
85+ def _init_adapters (self ):
86+ pass
87+
88+
6289class TestVdiTypeSetting (TestBase ):
6390
6491 @mock .patch ('ISCSISR.iscsilib.discovery' )
@@ -82,3 +109,68 @@ def test_vdi_type_modified_by_force_tapdisk(self):
82109 self .load_iscsi_sr (iscsi_sr = iscsi_sr )
83110
84111 self .assertEquals ('aio' , iscsi_sr .sr_vditype )
112+
113+
114+ class TestMultiLUNISCSISR (unittest .TestCase ):
115+
116+ def setUp (self ):
117+ self .node1 = {
118+ 'ip' : '127.0.0.1' ,
119+ 'port' : 3260 ,
120+ 'iqn' : 'IQN'
121+ }
122+ self .node2 = {
123+ 'ip' : '127.0.0.2' ,
124+ 'port' : 8080 ,
125+ 'iqn' : 'IQN' ,
126+ 'tpgt' : 'TPGT'
127+ }
128+ self .node_records = [(
129+ "%s:%d" % (self .node2 ['ip' ], self .node2 ['port' ]),
130+ self .node2 ['tpgt' ],
131+ self .node2 ['iqn' ]
132+ )]
133+
134+ def assertActiveNodeEquals (self , node , iscsi_sr ):
135+ node_ip_port = "%s:%d" % (node ['ip' ], node ['port' ])
136+ node_path = '/dev/iscsi/%s/%s' % (node ['iqn' ], node_ip_port )
137+
138+ self .assertEquals (node_path , iscsi_sr .path )
139+ self .assertEquals (node_ip_port , iscsi_sr .tgtidx )
140+ self .assertEquals (node_ip_port , iscsi_sr .address )
141+
142+ @mock .patch ('ISCSISR.os.path.exists' )
143+ @mock .patch ('ISCSISR.iscsilib.get_node_records' )
144+ def test_initPaths_actual_path_is_active (
145+ self ,
146+ mock_get_node_records ,
147+ mock_exists ):
148+ mock_get_node_records .return_value = self .node_records
149+ mock_exists .return_value = True
150+
151+ iscsi_sr = NonInitingMultiLUNISCSISR (self .node1 , self .node2 )
152+
153+ iscsi_sr ._initPaths ()
154+
155+ self .assertActiveNodeEquals (self .node1 , iscsi_sr )
156+
157+ @mock .patch ('ISCSISR.os.path.exists' )
158+ @mock .patch ('ISCSISR.iscsilib.get_node_records' )
159+ def test_initPaths_active_path_detection (
160+ self ,
161+ mock_get_node_records ,
162+ mock_exists ):
163+ mock_get_node_records .return_value = self .node_records
164+
165+ def fake_exists (path ):
166+ if self .node1 ['ip' ] in path :
167+ return False
168+ return True
169+
170+ mock_exists .side_effect = fake_exists
171+
172+ iscsi_sr = NonInitingMultiLUNISCSISR (self .node1 , self .node2 )
173+
174+ iscsi_sr ._initPaths ()
175+
176+ self .assertActiveNodeEquals (self .node2 , iscsi_sr )
0 commit comments