-
Notifications
You must be signed in to change notification settings - Fork 29
/
test_sg.py
416 lines (343 loc) · 14.1 KB
/
test_sg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# coding=utf-8
# Copyright (c) 2015 EMC Corporation.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import unicode_literals
from unittest import TestCase
from hamcrest import assert_that, equal_to, has_item, raises, instance_of, \
none, is_not, has_items, only_contains, close_to, greater_than, not_none
from storops.exception import VNXStorageGroupError, \
VNXStorageGroupNameInUseError, VNXDetachAluNotFoundError, \
VNXAluAlreadyAttachedError, VNXAluNotFoundError, VNXHluNumberInUseError, \
VNXHluAlreadyUsedError
from storops.lib.common import cache
from storops.vnx.enums import VNXSPEnum
from storops.vnx.resource.lun import VNXLun
from storops.vnx.resource.port import VNXStorageGroupHBAList
from storops.vnx.resource.sg import VNXStorageGroupList, VNXStorageGroup
from test.vnx.cli_mock import patch_cli, t_cli
from test.vnx.resource.test_lun import get_lun_list
__author__ = 'Cedric Zhuang'
@patch_cli
@cache
def get_sg_list():
return VNXStorageGroupList(t_cli())
class VNXStorageGroupListTest(TestCase):
sg_list = get_sg_list()
@patch_cli
def test_get_sg_list(self):
assert_that(self.sg_list.name,
has_items('VNX9495', 'ubuntu-server11', 'ubuntu-server7',
'ubuntu14'))
assert_that(len(self.sg_list), equal_to(4))
@patch_cli
def test_poll_property(self):
sg = self.sg_list.get('ubuntu14')
sg.poll = False
lun_list = sg.lun_list
lun = lun_list[0]
assert_that(lun_list.poll, equal_to(False))
assert_that(lun.poll, equal_to(False))
@patch_cli
def test_detach_not_existed_lun(self):
lun = VNXLun(name='y', cli=t_cli())
# raise no error
self.sg_list.detach_alu(lun)
@patch_cli
def test_get_sg_by_name(self):
sg = self.sg_list.get('ubuntu14')
assert_that(sg.name, equal_to('ubuntu14'))
@patch_cli
def test_system_lun_list_supplied(self):
lun_list = get_lun_list()
sgs = VNXStorageGroup.get(t_cli(), system_lun_list=lun_list)
assert_that(len(sgs), equal_to(4))
assert_that(lun_list.timestamp, not_none())
for sg in sgs:
assert_that(sg.lun_list.timestamp, equal_to(lun_list.timestamp))
def get_sg(name='server7'):
sg = VNXStorageGroup(name=name, cli=t_cli())
sg.shuffle_hlu = False
return sg
class VNXStorageGroupTest(TestCase):
sg_7 = get_sg()
@patch_cli
def test_properties(self):
sg = self.sg_7
assert_that(sg.name, equal_to('server7'))
assert_that(
sg.wwn,
equal_to('F6:F1:04:29:91:97:E5:11:85:E1:AE:04:FD:64:DC:17'))
assert_that(sg.shareable, equal_to(True))
assert_that(len(sg.alu_hlu_map), greater_than(1))
assert_that(sg.alu_hlu_map[10], equal_to(153))
assert_that(len(sg.hba_sp_pairs), equal_to(15))
assert_that(sg.uid, equal_to(sg.wwn))
assert_that(sg.has_alu(10), equal_to(True))
assert_that(sg.has_alu(11), equal_to(False))
assert_that(sg.has_hlu(153), equal_to(True))
assert_that(sg.has_hlu(11), equal_to(False))
assert_that(sg.existed, equal_to(True))
@patch_cli
def test_missing_tab(self):
name = 'wcmsc2-l-rh-cmp-2.hqplan.lab'
sg = VNXStorageGroup(name=name, cli=t_cli())
assert_that(len(sg.alu_hlu_map), equal_to(1))
assert_that(len(sg.hba_sp_pairs), equal_to(4))
uid = 'iqn.1994-05.com.abcdef:ghijk2-l-mn-opq-2.rstuvw.xyz:c3bf2f4cca'
port = list(filter(lambda i: i[0] == uid, sg.hba_port_list))[0][1]
assert_that(port.sp, equal_to(VNXSPEnum.SP_A))
assert_that(port.port_id, equal_to(1))
assert_that(port.host_initiator_list, has_item(uid))
@patch_cli
def test_property_hosts(self):
hosts = get_sg('~management').hosts
assert_that(len(hosts), equal_to(2))
assert_that(hosts.name,
has_items('APM00152312055-spB', 'APM00152312055-spA'))
assert_that(hosts[0].storage_group.name, equal_to('~management'))
@patch_cli
def test_property_lun_list(self):
sg = get_sg('microsoft')
sg.poll = False
lun_list = sg.lun_list
assert_that(lun_list.name, only_contains('lun4', 'lun456'))
assert_that(lun_list.poll, equal_to(False))
@patch_cli
def test_property_zero_lun_list(self):
lun_list = get_sg('os01').lun_list
assert_that(len(lun_list), equal_to(0))
@patch_cli
def test_get_sg_os01(self):
sg = VNXStorageGroup(name='os01', cli=t_cli())
assert_that(len(sg.hba_sp_pairs), equal_to(1))
assert_that(sg.hba_sp_pairs, instance_of(VNXStorageGroupHBAList))
hba = sg.hba_sp_pairs[0]
assert_that(hba.sp, equal_to(VNXSPEnum.SP_A))
assert_that(hba.uid,
equal_to('iqn.1993-08.org.debian:01:95bbe389e025'))
assert_that(hba.port_id, equal_to(4))
@patch_cli
def test_initiator_uid_list(self):
sg = get_sg('microsoft')
assert_that(len(sg.initiator_uid_list), equal_to(2))
assert_that(sg.initiator_uid_list,
has_item('iqn.1991-05.com.microsoft:abc.def.dev'))
@patch_cli
def test_hba_ports(self):
sg = self.sg_7
assert_that(len(sg.hba_port_list), equal_to(15))
assert_that(len(sg.ports), equal_to(8))
assert_that(len(sg.initiator_uid_list), equal_to(5))
@patch_cli
def test_iscsi_ports_all(self):
assert_that(len(self.sg_7.iscsi_ports), equal_to(1))
@patch_cli
def test_fc_ports_all(self):
assert_that(len(self.sg_7.fc_ports), equal_to(7))
@patch_cli
def test_get_fc_ports_with_filter_found_one(self):
ports = self.sg_7.get_fc_ports(sp=VNXSPEnum.SP_A, port_id=2)
assert_that(len(ports), equal_to(1))
port = ports[0]
assert_that(port.sp, equal_to(VNXSPEnum.SP_A))
assert_that(port.port_id, equal_to(2))
@patch_cli
def test_get_iscsi_ports_with_filter_type_not_match(self):
ports = self.sg_7.get_iscsi_ports(sp=VNXSPEnum.SP_A, port_id=2)
assert_that(len(ports), equal_to(0))
@patch_cli
def test_get_port_by_sp(self):
sg = self.sg_7
assert_that(len(sg.get_ports(sp=VNXSPEnum.SP_A)), equal_to(5))
assert_that(len(sg.get_ports(sp=VNXSPEnum.SP_B)), equal_to(3))
assert_that(len(sg.get_ports(sp=VNXSPEnum.SP_A, port_id=0)),
equal_to(1))
assert_that(len(sg.get_ports(sp=VNXSPEnum.SP_A, port_id=9)),
equal_to(0))
@patch_cli
def test_get_ports_by_wwn(self):
wwn = '20:00:00:90:FA:53:4C:D0:10:00:00:90:FA:53:4C:D0'
ports = self.sg_7.get_ports(wwn)
assert_that(len(ports), equal_to(6))
for port in ports:
assert_that(port.host_initiator_list, has_item(wwn))
@patch_cli
def test_get_ports_no_wwn(self):
ports = self.sg_7.get_ports()
assert_that(len(ports), equal_to(8))
@patch_cli
def test_attach_alu_success(self):
sg = self.sg_7
lun = VNXLun(name='x', cli=t_cli())
assert_that(sg.has_alu(0), equal_to(False))
hlu = sg.attach_alu(lun)
assert_that(sg.has_alu(0), equal_to(True))
assert_that(sg.get_hlu(0), equal_to(1))
assert_that(hlu, equal_to(1))
@patch_cli
def test_attach_alu_already_attached(self):
sg = self.sg_7
def f():
sg.attach_alu(123)
assert_that(f, raises(VNXAluAlreadyAttachedError,
'already been added'))
assert_that(sg.get_hlu(123), none())
assert_that(len(sg.get_alu_hlu_map()), equal_to(2))
@patch_cli
def test_attach_alu_hlu_used(self):
sg = self.sg_7
def f():
sg.attach_alu(123, hlu=210)
assert_that(f, VNXHluAlreadyUsedError, 'already used')
@patch_cli
def test_attach_with_hlu_alu_not_found(self):
sg = self.sg_7
def f():
sg.attach_alu(123, hlu=212)
assert_that(f, VNXAluNotFoundError, 'not a bound ALU number')
@patch_cli
def test_attach_alu_with_hlu_success(self):
sg = get_sg()
hlu_id = sg.attach_alu(2, hlu=1)
assert_that(hlu_id, equal_to(1))
assert_that(sg.has_alu(2), equal_to(True))
assert_that(sg.has_hlu(1), equal_to(True))
@patch_cli
def test_attach_alu_not_found(self):
sg = self.sg_7
def f():
sg.attach_alu(124)
assert_that(f, raises(VNXAluNotFoundError,
'not a bound ALU number'))
assert_that(sg.get_hlu(124), none())
assert_that(len(sg.get_alu_hlu_map()), equal_to(2))
@patch_cli
def test_attach_alu_already_attached_found_in_cache(self):
sg = self.sg_7
assert_that(sg.get_hlu(10), equal_to(153))
assert_that(len(sg.get_alu_hlu_map()), equal_to(2))
try:
sg.attach_alu(10)
self.fail('should have raised exception.')
except VNXAluAlreadyAttachedError:
assert_that(sg.get_hlu(10), equal_to(153))
assert_that(len(sg.get_alu_hlu_map()), equal_to(2))
@patch_cli
def test_attach_alu_hlu_in_use_retry(self):
def f():
sg = self.sg_7
sg.attach_alu(13, retry_limit=2)
assert_that(f, raises(VNXHluNumberInUseError,
'LUN Number already in use'))
@patch_cli
def test_detach_hlu_success(self):
sg = get_sg()
sg.detach_alu(10)
assert_that(sg.has_hlu(10), equal_to(False))
@patch_cli
def test_detach_hlu_not_found(self):
def f():
sg = self.sg_7
sg.detach_alu(1032)
assert_that(f, raises(VNXDetachAluNotFoundError, 'No such Host LUN'))
@patch_cli
def test_detach_hlu_not_attached(self):
def f():
sg = self.sg_7
sg.detach_alu(1033)
assert_that(f, raises(VNXDetachAluNotFoundError,
'is not attached'))
@patch_cli
def test_connect_host(self):
def f():
sg = self.sg_7
sg.connect_host('host1')
assert_that(f, raises(VNXStorageGroupError,
'Host specified is not known'))
@patch_cli
def test_disconnect_host(self):
def f():
sg = self.sg_7
sg.disconnect_host('host1')
assert_that(f, raises(VNXStorageGroupError,
'not currently connected'))
@patch_cli
def test_create_sg_name_in_use(self):
def f():
VNXStorageGroup.create('existed', t_cli())
assert_that(f, raises(VNXStorageGroupNameInUseError, 'already in use'))
@patch_cli
def test_empty_sg_property(self):
sg = VNXStorageGroup.get(t_cli(), 'sg1')
wwn = 'BB:50:E8:2F:23:01:E6:11:83:36:00:60:16:58:B3:E9'
assert_that(sg.name, equal_to('sg1'))
assert_that(sg.wwn, equal_to(wwn))
assert_that(len(sg.initiator_uid_list), equal_to(0))
assert_that(len(sg.ports), equal_to(0))
assert_that(len(sg.fc_ports), equal_to(0))
assert_that(len(sg.iscsi_ports), equal_to(0))
assert_that(len(sg.hba_sp_pairs), equal_to(0))
@patch_cli
def test_get_hlu_to_add_no_shuffle(self):
sg = get_sg()
sg.shuffle_hlu = False
assert_that(sg._get_hlu_to_add(12), equal_to(1))
sg._delete_alu(12)
assert_that(len(sg.get_alu_hlu_map()), equal_to(2))
assert_that(sg._get_hlu_to_add(12), equal_to(1))
sg._delete_alu(12)
assert_that(len(sg.get_alu_hlu_map()), equal_to(2))
@patch_cli
def test_get_hlu_to_add_shuffle(self):
sg = VNXStorageGroup.get(t_cli(), 'server7')
first = sg._get_hlu_to_add(12)
sg._delete_alu(12)
assert_that(len(sg.get_alu_hlu_map()), equal_to(2))
second = sg._get_hlu_to_add(12)
assert_that(first, is_not(equal_to(second)))
sg._delete_alu(12)
assert_that(len(sg.get_alu_hlu_map()), equal_to(2))
@patch_cli
def test_lun_list_from_shadow_copy(self):
lun_list = get_lun_list()
sg = VNXStorageGroup.get(cli=t_cli(), name='sg1',
system_lun_list=lun_list)
assert_that(len(sg.lun_list), equal_to(2))
assert_that(sg.lun_list.timestamp, equal_to(lun_list.timestamp))
sg = VNXStorageGroup.get(t_cli(), 'sg1')
@patch_cli
def test_sg_read_iops(self):
assert_that(self.sg.read_iops, equal_to(3.5))
@patch_cli
def test_sg_write_iops(self):
assert_that(self.sg.write_iops, equal_to(9.0))
@patch_cli
def test_sg_total_iops(self):
assert_that(self.sg.total_iops, equal_to(12.5))
@patch_cli
def test_sg_read_mbps(self):
assert_that(self.sg.read_mbps, equal_to(2.3 + 4.6))
@patch_cli
def test_sg_write_mbps(self):
assert_that(self.sg.write_mbps, equal_to(2.7 + 5.4))
@patch_cli
def test_sg_total_mbps(self):
assert_that(self.sg.total_mbps, equal_to(5.0 + 10.0))
@patch_cli
def test_sg_read_size_kb(self):
assert_that(self.sg.read_size_kb, close_to(2018, 1))
@patch_cli
def test_sg_write_size_kb(self):
assert_that(self.sg.write_size_kb, close_to(921, 1))