6
6
import unittest
7
7
from uuid import uuid4
8
8
9
+ import util
9
10
from BaseISCSI import BaseISCSISR
10
11
import SR
11
12
import SRCommand
13
+ from shared_iscsi_test_base import ISCSITestCase
12
14
from util import CommandException
13
15
14
16
15
- class TestBaseISCSI (unittest .TestCase ):
17
+ class TestBaseISCSI (ISCSITestCase ):
18
+
19
+ TEST_CLASS = 'BaseISCSI'
16
20
17
21
def setUp (self ):
18
22
self .addCleanup (mock .patch .stopall )
19
23
20
24
util_patcher = mock .patch ('BaseISCSI.util' , autospec = True )
21
25
self .mock_util = util_patcher .start ()
22
26
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 ()
23
33
24
34
self .mock_session = mock .MagicMock ()
25
35
xenapi_patcher = mock .patch ('SR.XenAPI' )
26
36
mock_xenapi = xenapi_patcher .start ()
27
37
mock_xenapi .xapi_local .return_value = self .mock_session
28
38
29
- iscsilib_patcher = mock .patch ('BaseISCSI.iscsilib' , autospec = True )
30
- self .mock_iscsilib = iscsilib_patcher .start ()
31
-
32
39
copy_patcher = mock .patch ('LVHDoISCSISR.SR.copy.deepcopy' )
33
40
self .mock_copy = copy_patcher .start ()
34
41
@@ -37,25 +44,9 @@ def deepcopy(to_copy):
37
44
38
45
self .mock_copy .side_effect = deepcopy
39
46
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
-
54
47
self .sr_uuid = str (uuid4 ())
55
48
56
- self .subject = BaseISCSISR (
57
- dummy_cmd , self .sr_uuid
58
- )
49
+ super ().setUp ()
59
50
60
51
def setup_path_mocks (self ):
61
52
self .path_contents = {}
@@ -67,24 +58,31 @@ def setup_path_mocks(self):
67
58
mock_listdir .side_effect = self .listdir
68
59
69
60
def exists (self , path ):
70
- print (f'checking existance of { path } ' )
71
61
return path in self .path_contents
72
62
73
63
def listdir (self , path ):
74
64
return self .path_contents [path ]
75
65
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
+
76
71
@mock .patch ('BaseISCSI.BaseISCSISR._initPaths' , autospec = True )
77
72
def test_attach_tgt_present_path_found (self , mock_init_paths ):
78
73
# Arrange
79
74
self .setup_path_mocks ()
80
75
self .path_contents .update (
81
76
{'/dev/disk/by-scsid/3600a098038313577792450384a4a6275' : ['sdb' ]})
82
77
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' ))
88
86
89
87
# Act
90
88
self .subject .attach (self .sr_uuid )
@@ -94,15 +92,97 @@ def test_attach_tgt_present_path_found(self, mock_init_paths):
94
92
def test_attach_tgt_present_path_not_found (self , mock_init_paths ):
95
93
# Arrange
96
94
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' ))
102
103
103
104
# Act
104
105
with self .assertRaises (SR .SROSError ) as srose :
105
106
self .subject .attach (self .sr_uuid )
106
107
107
108
# Assert
108
109
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