-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_emc_vnxe.py
2417 lines (2186 loc) · 106 KB
/
test_emc_vnxe.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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) 2014 - 2015 EMC Corporation, Inc.
# 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.
import urllib2
import mock
from cinder import exception
from cinder import test
from cinder.tests.unit import fake_constants as fake
from cinder.tests.unit import fake_snapshot
from cinder.tests.unit import fake_volume
from cinder.tests.unit.consistencygroup import fake_consistencygroup
from cinder.volume import configuration as conf
from cinder.volume import volume_types
from cinder.volume.drivers.dell_emc import emc_vnxe
from cinder.volume.drivers.dell_emc.emc_vnxe import EMCVNXeDriver
from cinder.volume.drivers.dell_emc.emc_vnxe import EMCVNXeRESTClient
GiB = 1024 * 1024 * 1024
VERSION = emc_vnxe.VERSION
class EMCVNXeDriverTestData(object):
storage_pool_name_default = 'StoragePool00'
storage_pool_id_default = 'pool_1'
resp_get_pool_by_name = {
'entries': [
{'content': {'id': storage_pool_id_default,
'name': storage_pool_name_default,
'sizeTotal': 28185722880,
'sizeFree': 17985175552}}]}
@staticmethod
def req_get_pool_by_name(name, fields=None):
url = '/api/types/pool/instances?filter=%s' % \
urllib2.quote('name eq "%s"' % name)
url += (('&fields=%s' % ','.join(fields)) if fields else "")
return mock.call(url)
@staticmethod
def req_get_pool_by_id(id, fields=None):
url = '/api/instances/pool/%(obj_id)s' % \
{'obj_id': id}
if fields:
url += '?fields=%s' % (','.join(fields))
return mock.call(url)
resp_get_pool_by_id = {
'content': {'id': storage_pool_id_default,
'name': storage_pool_name_default,
'sizeTotal': 28185722880,
'sizeFree': 17985175552}}
new_resp_get_pool_by_id = {
'content': {'id': storage_pool_id_default,
'name': storage_pool_name_default,
'sizeTotal': 2147483678,
'sizeFree': 1073741824}}
storage_serial_number_default = 'FCNCH0972C7F2A'
resp_get_basic_system_info = {
'entries': [
{'content': {'id': '0',
'name': storage_serial_number_default,
'softwareVersion': '3.0.0'}}]}
@staticmethod
def req_get_basic_system_info(fields=None):
url = '/api/types/basicSystemInfo/instances'
url += (('?fields=%s' % ','.join(fields)) if fields else "")
return mock.call(url)
resp_get_get_iscsi_portals = {
'entries': [
{'content':
{'id': 'if_4',
'ipAddress': '10.108.127.43',
'ethernetPort': {'id': 'spa_iom_0_eth0'},
'iscsiNode': {'id': 'iscsinode_spa_iom_0_eth0'}}},
{'content':
{'id': 'if_5',
'ipAddress': '10.108.127.44',
'ethernetPort': {'id': 'spb_iom_0_eth0'},
'iscsiNode': {'id': 'iscsinode_spb_iom_0_eth0'}}}]}
new_resp_get_get_iscsi_portals = {
'entries': [
{'content':
{'id': 'if_4',
'ipAddress': '10.108.127.45',
'ethernetPort': {'id': 'spa_iom_0_eth0'},
'iscsiNode': {'id': 'iscsinode_spa_iom_0_eth0'}}},
{'content':
{'id': 'if_5',
'ipAddress': '10.108.127.46',
'ethernetPort': {'id': 'spb_iom_0_eth0'},
'iscsiNode': {'id': 'iscsinode_spb_iom_0_eth0'}}}]}
@staticmethod
def req_get_get_iscsi_portals(fields=None):
url = '/api/types/iscsiPortal/instances'
url += (('?fields=%s' % ','.join(fields)) if fields else "")
return mock.call(url)
resp_get_iscsi_nodes = {
'entries': [
{'content':
{'id': 'iscsinode_spa_iom_0_eth0',
'name': 'iqn.1992-04.com.emc:cx.fcnch0972c7f2a.a4'}},
{'content':
{'id': 'iscsinode_spb_iom_0_eth0',
'name': 'iqn.1992-04.com.emc:cx.fcnch0972c7f2a.b4'}}]}
@staticmethod
def req_get_get_iscsi_nodes(fields=None):
url = '/api/types/iscsiNode/instances'
url += (('?fields=%s' % ','.join(fields)) if fields else "")
return mock.call(url)
iscsi_targets = {'a': [('iqn.1992-04.com.emc:cx.fcnch0972c7f2a.a4',
'10.108.127.43', 'if_4')],
'b': [('iqn.1992-04.com.emc:cx.fcnch0972c7f2a.b4',
'10.108.127.44', 'if_5')]}
n_iscsi_targets = {'a': [('iqn.1992-04.com.emc:cx.fcnch0972c7f2a.a4',
'10.108.127.45', 'if_4')],
'b': [('iqn.1992-04.com.emc:cx.fcnch0972c7f2a.b4',
'10.108.127.46', 'if_5')]}
@staticmethod
def get_iscsi_iqns(td, sp=None):
iqns = []
if sp is not None:
iqns.extend([tgt[0] for tgt in td.iscsi_targets[sp]])
else:
for r in ('a', 'b'):
iqns.extend([tgt[0] for tgt in td.iscsi_targets[r]])
return iqns
@staticmethod
def get_iscsi_portals(td, sp=None):
portals = []
if sp is not None:
portals.extend(
['{}:3260'.format(tgt[1]) for tgt in td.iscsi_targets[sp]])
else:
for r in ('a', 'b'):
portals.extend(
['{}:3260'.format(tgt[1]) for tgt in td.iscsi_targets[r]])
return portals
lun_id_default = 'sv_1'
lun_data_default = {'id': lun_id_default,
'name': 'volume-xxx',
'type': 2,
'pool': {'id': storage_pool_id_default},
'currentNode': 0,
'hostAccess': []}
resp_create_lun = {'content': {'storageResource': {'id': lun_id_default}}}
resp_create_lun_err = {'errorCode': 131149836, 'httpStatusCode': 405,
'messages': {'en-US': 'The action associated with \
the provided URL is not supported. \
(Error Code:0x7d1300c)'}}
@staticmethod
def req_create_lun(pool_id, name, size, is_thin):
url = '/api/types/storageResource/action/createLun'
body = {'lunParameters': {'isThinEnabled': is_thin,
'pool': {'id': pool_id},
'size': size},
'name': name,
'description': name}
return mock.call(url, body)
resp_delete_lun_ok = {}
resp_resource_nonexistent = {
'errorCode': 131149829, 'httpStatusCode': 404,
'messages': [{'en-US':
'The requested resource does not exist.'
' (Error Code:0x7d13005)'}],
}
resp_delete_lun_has_snap = {'errorCode': 100666391, 'httpStatusCode': 409,
'messages': {'en-US': 'The resource cannot be \
deleted because it has one or more snapshots. \
To delete the resource anyway, \
specify the force delete option. \
(Error Code:0x6000c17)'}}
@staticmethod
def req_delete_lun(lun_id, force_snap_deletion=False):
url = '/api/instances/storageResource/' + lun_id
body = {'forceSnapDeletion': force_snap_deletion}
return mock.call(url, body, 'DELETE')
@staticmethod
def req_expose_lun(lun_id, host_ids, accesses):
url = '/api/instances/storageResource/sv_1/action/modifyLun'
body = {'lunParameters':
{'hostAccess': [{'host': {'id': host_id},
'accessMask': access}
for host_id, access in
zip(host_ids, accesses)]}}
return mock.call(url, body)
resp_get_lun_by_id_default = {
'content': {'id': lun_id_default,
'currentNode': 0,
'defaultNode': 1,
'name': 'volume-x',
'pool': {'id': storage_pool_id_default},
'hostAccess': [],
'type': 2}}
resp_get_lun_by_id_for_manage_exist = {
'content': {'id': lun_id_default,
'currentNode': 0,
'defaultNode': 1,
'name': 'volume-x',
'pool': {'id': storage_pool_id_default},
'sizeTotal': 1073741824}}
resp_get_lun_by_name_for_manage_exist = {
'entries': [{
'content':
{'id': lun_id_default,
'currentNode': 0,
'defaultNode': 1,
'name': 'volume-x',
'pool': {'id': storage_pool_id_default},
'sizeTotal': 1073741824}}]}
resp_get_lun_not_in_manage_pool = {
'content': {'id': lun_id_default,
'currentNode': 0,
'defaultNode': 1,
'name': 'volume-x',
'pool': {'id': 'fakepoolid'},
'sizeTotal': 1073741824}}
resp_get_lun_by_id_err = {
"error": {"errorCode": 131149829,
"httpStatusCode": 404,
"messages": [{"en-US": "The requested resource \
does not exist. (Error Code:0x7d13005)"}],
"created": "2014-04-11T06:08:19.102Z"}}
resp_hide_lun_error = {'errorCode': 100666391, 'httpStatusCode': 409,
'messages': {'en-US': 'Failed to hide volume \
from host. (Error Code:)'}}
resp_modify_name_exist_error = {
'errorCode': 108007456,
'httpStatusCode': 422,
'messages':
[{'en-US': 'The user requested modification of '
'the storage resource but the system found that there '
'is nothing to modify. (Error Code:0x6701020)'}]}
resp_modify_name_error = {'errorCode': 108007746,
'httpStatusCode': 422,
'messages':
[{'en-US': 'fakeerror '}]}
@staticmethod
def req_get_lun_by_id(lun_id, fields=('id', 'type', 'name', 'currentNode',
'hostAccess', 'pool')):
url = '/api/instances/lun/%s' % lun_id
if fields:
url += (('?fields=%s' % ','.join(fields)) if fields else "")
return mock.call(url)
@staticmethod
def req_get_lun_by_name(name, fields=None):
url = '/api/types/lun/instances?filter=%s' % \
urllib2.quote('name eq "%s"' % name)
url += (('&fields=%s' % ','.join(fields)) if fields else "")
return mock.call(url)
@staticmethod
def req_modify_lun_name(lun_id, new_name, fields=None):
url = '/api/instances/storageResource/%s/action/modifyLun' % lun_id
body = {'name': new_name}
return mock.call(url, body)
resp_get_fc_ports = {
'entries': [
{'content':
{'id': 'spa_iom_0_fc0',
'wwn': '50:06:01:60:88:E0:00:1E:50:06:01:64:08:E0:00:1E',
'storageProcessorId': {'id': 'spa'}}},
{'content':
{'id': 'spa_iom_0_fc1',
'wwn': '50:06:01:60:88:E0:00:1E:50:06:01:65:08:E0:00:1E',
'storageProcessorId': {'id': 'spa'}}},
{'content':
{'id': 'spb_iom_0_fc0',
'wwn': '50:06:01:60:88:E0:00:1E:50:06:01:6C:08:E0:00:1E',
'storageProcessorId': {'id': 'spb'}}},
{'content':
{'id': 'spb_iom_0_fc1',
'wwn': '50:06:01:60:88:E0:00:1E:50:06:01:6D:08:E0:00:1E',
'storageProcessorId': {'id': 'spb'}}}]}
n_resp_get_fc_ports = {
'entries': [
{'content':
{'id': 'spa_iom_0_fc0',
'wwn': '50:06:01:60:88:E0:00:1E:50:06:01:64:08:E0:00:1F',
'storageProcessorId': {'id': 'spa'}}},
{'content':
{'id': 'spa_iom_0_fc1',
'wwn': '50:06:01:60:88:E0:00:1E:50:06:01:65:08:E0:00:1F',
'storageProcessorId': {'id': 'spa'}}},
{'content':
{'id': 'spb_iom_0_fc0',
'wwn': '50:06:01:60:88:E0:00:1E:50:06:01:6C:08:E0:00:1F',
'storageProcessorId': {'id': 'spb'}}},
{'content':
{'id': 'spb_iom_0_fc1',
'wwn': '50:06:01:60:88:E0:00:1E:50:06:01:6D:08:E0:00:1F',
'storageProcessorId': {'id': 'spb'}}}]}
@staticmethod
def req_get_fc_ports(fields):
url = '/api/types/fcPort/instances'
url += (('?fields=%s' % ','.join(fields)) if fields else "")
return mock.call(url)
spa_iom_0_fc0 = ('5006016088E0001E', '5006016408E0001E',
'spa_iom_0_fc0')
spa_iom_0_fc1 = ('5006016088E0001E', '5006016508E0001E',
'spa_iom_0_fc1')
spb_iom_0_fc0 = ('5006016088E0001E', '5006016C08E0001E',
'spb_iom_0_fc0')
spb_iom_0_fc1 = ('5006016088E0001E', '5006016D08E0001E',
'spb_iom_0_fc1')
fc_targets = {'a': [spa_iom_0_fc0,
spa_iom_0_fc1],
'b': [spb_iom_0_fc0,
spb_iom_0_fc1]}
n_spa_iom_0_fc0 = ('5006016088E0001E', '5006016408E0001F',
'spa_iom_0_fc0')
n_spa_iom_0_fc1 = ('5006016088E0001E', '5006016508E0001F',
'spa_iom_0_fc1')
n_spb_iom_0_fc0 = ('5006016088E0001E', '5006016C08E0001F',
'spb_iom_0_fc0')
n_spb_iom_0_fc1 = ('5006016088E0001E', '5006016D08E0001F',
'spb_iom_0_fc1')
n_fc_targets = {'a': [n_spa_iom_0_fc0,
n_spa_iom_0_fc1],
'b': [n_spb_iom_0_fc0,
n_spb_iom_0_fc1]}
test_existing_ref = {'source-id': lun_id_default}
os_vol_default = {
'name': 'vol1',
'size': 1,
'volume_name': 'vol1',
'id': lun_id_default,
'provider_auth': None,
'project_id': 'project',
'display_name': 'vol1',
'display_description': 'test volume',
'volume_type_id': None,
'host': 'fakehost@fackbe#%s' % storage_pool_name_default,
'provider_location': 'system^%(sys)s|type^%(type)s|id^%(id)s' %
{'sys': storage_serial_number_default,
'type': 'lun',
'id': lun_id_default}}
os_vol_for_manage_existing = {
'name': 'vol1',
'size': 1,
'volume_name': 'vol1',
'id': '1',
'provider_auth': None,
'project_id': 'project',
'display_name': 'vol1',
'display_description': 'test volume',
'volume_type_id': None,
'host': 'fakehost@fackbe#%s' % storage_pool_name_default,
'provider_location': 'system^%(sys)s|type^%(type)s|id^%(id)s' %
{'sys': storage_serial_number_default,
'type': 'lun',
'id': lun_id_default}}
os_vol_rw = {
'name': 'vol1',
'size': 1,
'volume_name': 'vol1',
'id': '1',
'provider_auth': None,
'project_id': 'project',
'display_name': 'vol1',
'display_description': 'test volume',
'volume_type_id': None,
'host': 'fakehost@fackbe#%s' % storage_pool_name_default,
'volume_admin_metadata': [{'key': 'attached_mode', 'value': 'rw'},
{'key': 'readonly', 'value': 'False'}],
'provider_location': 'system^%(sys)s|type^%(type)s|id^%(id)s' %
{'sys': storage_serial_number_default,
'type': 'lun',
'id': lun_id_default}}
os_vol_ro = {
'name': 'vol1',
'size': 1,
'volume_name': 'vol1',
'id': '1',
'provider_auth': None,
'project_id': 'project',
'display_name': 'vol1',
'display_description': 'test volume',
'volume_type_id': None,
'host': 'fakehost@fackbe#%s' % storage_pool_name_default,
'volume_admin_metadata': [{'key': 'readonly', 'value': 'True'}],
'provider_location': 'system^%(sys)s|type^%(type)s|id^%(id)s' %
{'sys': storage_serial_number_default,
'type': 'lun',
'id': lun_id_default}}
os_vol_with_type = {
'name': 'vol1',
'size': 1,
'volume_name': 'vol1',
'id': '1',
'provider_auth': None,
'project_id': 'project',
'display_name': 'vol1',
'display_description': 'test volume',
'volume_type_id': 'volume_type_id_xxx',
'host': 'fakehost@fackbe#%s' % storage_pool_name_default,
'provider_location': 'system^%(sys)s|type^%(type)s|id^%(id)s' %
{'sys': storage_serial_number_default,
'type': 'lun',
'id': lun_id_default}}
iscsi_initiator_iqn_default = 'iqn.1993-08.org.debian:01:ee4a92e19d0'
fc_initator_node_wwn1 = '12:34:56:78:90:AB:CD:E1'
fc_initator_node_wwn2 = '12:34:56:78:90:AB:CD:E2'
fc_initator_port_wwn1 = '12:34:56:78:90:AB:CD:E1'
fc_initator_port_wwn2 = '12:34:56:78:90:AB:CD:E2'
fc_initator_wwn1 = ':'.join((fc_initator_node_wwn1,
fc_initator_port_wwn1))
fc_initator_wwn2 = ':'.join((fc_initator_node_wwn2,
fc_initator_port_wwn2))
os_connector_default = {
'initiator': iscsi_initiator_iqn_default,
'ip': '10.0.0.161',
'host': 'openstack-161',
'wwnns': [fc_initator_node_wwn1.lower().replace(':', ''),
fc_initator_node_wwn2.lower().replace(':', '')],
'wwpns': [fc_initator_port_wwn1.lower().replace(':', ''),
fc_initator_port_wwn2.lower().replace(':', '')]}
os_connector_missing_host = {
'initiator': iscsi_initiator_iqn_default,
'ip': '10.0.0.161',
'host': '',
'wwnns': [fc_initator_node_wwn1.lower().replace(':', ''),
fc_initator_node_wwn2.lower().replace(':', '')],
'wwpns': [fc_initator_port_wwn1.lower().replace(':', ''),
fc_initator_port_wwn2.lower().replace(':', '')]}
mapping = {
"test": {
'initiator_port_wwn_list':
os_connector_default['wwpns'],
'target_port_wwn_list':
[spa_iom_0_fc0[1], spb_iom_0_fc0[1],
spa_iom_0_fc1[1], spb_iom_0_fc1[1]]}}
host_name_default = "openstack-161"
host_id_default = 'Host_1'
resp_get_initiator_by_uid_empty = {
'entries': []}
resp_get_initiator_by_uid_iscsi_default = {
'entries': [
{'content':
{'id': 'HostInitiator_11',
'initiatorId': iscsi_initiator_iqn_default,
'parentHost': {'id': host_id_default}}}]}
resp_get_initiator_by_uid_fc_default = {
'entries': [
{'content':
{'id': 'HostInitiator_21',
'initiatorId': fc_initator_wwn1,
'parentHost': {'id': host_id_default}}},
{'content':
{'id': 'HostInitiator_22',
'initiatorId': fc_initator_wwn2,
'parentHost': {'id': host_id_default}}}]}
resp_get_initiator_by_uid_iscsi_orphan = {
'entries': [
{'content':
{'id': 'HostInitiator_11',
'initiatorId': iscsi_initiator_iqn_default}}]}
@staticmethod
def req_get_host_by_name(hostname, fields=None):
url = '/api/types/host/instances?filter=%s' % \
urllib2.quote('name eq "%s"' % hostname)
url += (('&fields=%s' % ','.join(fields)) if fields else "")
return mock.call(url)
resp_get_host_by_name_default = {
'entries': [
{'content':
{'id': 'Host_1'}}]}
@staticmethod
def resp_get_host_by_name(host_id):
return {
"entries": [{
"content": {
"address": "test",
"name": "test",
"id": host_id,
"type": 1,
"storageResources": [],
"vms": [],
"hostIPPorts": [],
"hostLUNs": []
}
}]
}
resq_get_host_unexist = {"entryCount": 0,
"entries": []}
@staticmethod
def req_create_host(hostname):
url = '/api/types/host/instances'
body = {'type': EMCVNXeRESTClient.HostTypeEnum_HostManual,
'name': hostname}
return mock.call(url, body)
resp_create_host_default = {
'content': {'id': host_id_default}}
@staticmethod
def resp_create_host(hostid):
return {"content": {
"id": hostid}}
@staticmethod
def req_register_initiators(initiator_id, host_id):
url = '/api/instances/hostInitiator/%s/action/register' % initiator_id
body = {'host': {'id': host_id}}
return mock.call(url, body)
@staticmethod
def req_create_initiators(initiator_uid, host_id):
url = '/api/types/hostInitiator/instances'
body = {'host': {'id': host_id},
'initiatorType': 2 if initiator_uid.lower().find('iqn') == 0
else 1,
'initiatorWWNorIqn': initiator_uid}
return mock.call(url, body)
resp_create_initiators = {
'content': {'id': 'HostInitiator_21'}}
@staticmethod
def req_get_initiator_by_uid(uid, fields=None):
url = '/api/types/hostInitiator/instances?filter=%s' % \
urllib2.quote('initiatorId eq "%s"' % uid)
url += (('&fields=%s' % ','.join(fields)) if fields else "")
return mock.call(url)
resp_get_initiator_by_uid_fc_wwn1 = {
'entries': [{
'content': {
'id': 'HostInitiator_21',
'initiatorId': fc_initator_wwn1,
'parentHost': {'id': host_id_default}}}]}
resp_get_initiator_by_uid_fc_wwn2 = {
'entries': [
{'content': {
'id': 'HostInitiator_22',
'initiatorId': fc_initator_wwn2,
'parentHost': {'id': host_id_default}}}]}
hlu_default = 1
resp_get_host_lun_by_ends_default = {
'entries': [
{'content':
{'id': '_'.join((host_id_default, lun_id_default, 'prod')),
'hlu': hlu_default}}]}
resp_get_host_lun_by_ends_none = {
'entries': []}
@staticmethod
def req_get_host_lun_by_ends(host_id, lun_id, use_type, fields):
url = '/api/types/hostLUN/instances?filter=%s' % \
urllib2.quote('id lk "%%%(host)s_%(lun)s%%" and '
'type eq "%(type)s"'
% {'host': host_id,
'lun': lun_id,
'type': use_type})
url += (('&fields=%s' % ','.join(fields)) if fields else "")
return mock.call(url)
@staticmethod
def req_get_host_by_id(hostid, fields=None):
url = '/api/instances/host/%s' % hostid
url += (('?fields=%s' % ','.join(fields)) if fields else "")
return mock.call(url)
resp_get_host_by_id = {
"content": {
"address": "fake.addr.com",
"name": host_name_default,
"id": host_id_default,
"type": 5,
"storageResources": [],
"vms": [],
"hostIPPorts": [],
"hostLUNs": [],
"fcHostInitiators": [{"id": "HostInitiator_21"},
{"id": "HostInitiator_22"}],
"iscsiHostInitiators": []}}
@staticmethod
def req_create_initiator_fc(initiator_uid, host_id):
url = '/api/types/hostInitiator/instances'
body = {'host': {'id': host_id},
'initiatorType': 1,
'initiatorWWNorIqn': initiator_uid}
return mock.call(url, body)
@staticmethod
def resp_create_initiator_fc(initiator_id):
return {"content": {"id": initiator_id}}
@staticmethod
def req_get_initiator_paths_by_initiator_id(initiator_id, fields):
url = '/api/types/hostInitiatorPath/instances?filter=%s' % \
urllib2.quote('id lk "%s%%"' % initiator_id)
url += (('&fields=%s' % ','.join(fields)) if fields else "")
return mock.call(url)
@staticmethod
def resp_get_initiator_paths_by_initiator_id_fc(
initiator_id, isLoggedin=True, port=spa_iom_0_fc1):
return {'entries': [{"content": {
"id": initiator_id + "_02%3A00%3A00%3A05",
"fcPort": {"id": port[2]},
"hostUUID": "5188d80b-f71b-d2f4-9396-0025b5500001",
"registrationType": 1,
"isLoggedIn": isLoggedin,
"hostPushName": "nc9083201.drm.lab.emc.com",
"sessionIds": ["128585"],
"initiator": {"id": initiator_id}}}]}
resp_get_initiator_paths_by_initiator_id_no_path_fc = \
{'entries': []}
@staticmethod
def req_register_initiator(initiator_id, host_id):
url = '/api/instances/hostInitiator/%s/action/register' % initiator_id
body = {'host': {'id': host_id}}
return mock.call(url, body)
resp_register_initiator = {"entryCount": 0,
"entries": []}
@staticmethod
def req_hide_lun(lun_id, host_access_list):
url = '/api/instances/storageResource/%s/action/modifyLun' % \
lun_id
body = {'lunParameters': {'hostAccess': host_access_list}}
return mock.call(url, body)
connection_info_fc_default = {
'driver_volume_type': 'fibre_channel',
'data': {
'target_discovered': True,
'target_lun': hlu_default,
'volume_id': os_vol_default['id'],
'target_wwn': ['5006016508E0001E']}
}
@staticmethod
def connection_info_fc(accessible_targets):
return {
'driver_volume_type': 'fibre_channel',
'data': {
'target_discovered': True,
'target_lun': TD.hlu_default,
'volume_id': TD.os_vol_default['id'],
'target_wwn': map(lambda entry: entry[1],
accessible_targets)
}
}
@staticmethod
def connection_info_fc_auto_zoning(target_wwn, init_map):
return {
'driver_volume_type': 'fibre_channel',
'data': {
'target_discovered': True,
'target_lun': TD.hlu_default,
'volume_id': TD.os_vol_default['id'],
'target_wwn': target_wwn,
'initiator_target_map': init_map
}
}
@staticmethod
def req_extend_lun(lun_id, size):
url = '/api/instances/storageResource/%s/action/modifyLun' % lun_id
body = {'lunParameters': {'size': size}}
return mock.call(url, body)
HostLUNAccessEnum_Production = \
EMCVNXeRESTClient.HostLUNAccessEnum_Production
HostLUNAccessEnum_NoAccess = \
EMCVNXeRESTClient.HostLUNAccessEnum_NoAccess
HostLUNTypeEnum_LUN = EMCVNXeRESTClient.HostLUNTypeEnum_LUN
###############################################
# Test data to run the cg related unit test
###############################################
test_cgsnapshot = {
'consistencygroup_id': 'consistencygroup_id',
'id': 'cgsnapshot_id',
'status': 'available',
'description': 'test_cgsnapshot'}
test_cg = {
'availability_zone': 'nova',
'cgsnapshot_id': None,
'created_at': None,
'deleted': False,
'deleted_at': None,
'description': None,
'host': "FakeHost",
'id': '1',
'name': None,
'project_id': '3',
'source_cgid': None,
'status': "deleting",
'updated_at': None,
'user_id': '2',
'volume_type_id': None}
@staticmethod
def volumes_in_group(count=1):
volumes = []
for i in range(count):
volumes.append(TD.os_vol_default)
return volumes
###############################################
# Test data to run the snap related unit test
###############################################
test_vol_for_snapshot = {
'name': 'snapshot1',
'size': 1,
'id': '4444',
'volume_name': 'vol1',
'volume_size': 1,
'project_id': 'project',
'display_description': 'snapshot test',
'volume': {'provider_location': 'type^lun|system^BC-H1166-spb|id^sv_1',
'name': 'volume-name'}}
test_snapshot_data = {
'name': 'snapshot1',
'size': 1,
'id': '4444',
'volume_name': 'vol1',
'volume_size': 1,
'project_id': 'project',
'display_description': 'snapshot test',
'provider_location': 'type^lun|system^BC-H1166-spb|id^12345678'}
test_snapshot_with_invalid_id = {
'name': 'snapshot1',
'size': 1,
'id': '4444',
'volume_name': 'vol1',
'volume_size': 1,
'project_id': 'project',
'display_description': 'snapshot test',
'volume': {'provider_location': 'type^lun|system^BC-H1166-spb|id^',
'name': 'volume-name'}}
resp_create_snap = {'content': {'id': '12345678'}}
fake_error_return = \
{"errorCode": 131149825,
"httpStatusCode": 500,
"messages":
[{"en-US": "The system encountered an unexpected error. Record "
"the error and go to 'Support > Need more help? > "
"Live Chat to chat with EMC support personnel. "
"If this option is not available, contact your service"
" provider. (Error Code:0x7d13001)"}],
"created": "2014-05-19T06:18:04.525Z"}
@staticmethod
def req_create_consistencygroup(group_id, group_desc=None):
url = '/api/types/storageResource/action/createLunGroup'
resp_create_group = {'name': group_id}
if group_desc:
resp_create_group['description'] = group_desc
return mock.call(url, resp_create_group)
@staticmethod
def req_delete_consistencygroup(group_id, force_snap_deletion=False):
cg_delete_url = '/api/instances/storageResource/%s' % group_id
data = {'forceSnapDeletion': force_snap_deletion}
return mock.call(cg_delete_url, data, 'DELETE')
@staticmethod
def req_get_group_by_name(group_name, fields=None):
url = '/api/types/storageResource/instances?filter=name%20eq%20%22' \
+ group_name + '%22&fields=id'
return mock.call(url)
@staticmethod
def req_get_snap_by_name(snap_name, fields=None):
url = '/api/types/snap/instances?filter=name%20eq%20%22' \
+ snap_name + '%22&fields=id'
return mock.call(url)
@staticmethod
def req_update_consistencygroup(group_id, add_luns, remove_luns):
url = '/api/instances/storageResource/%s/action/modifyLunGroup' \
% group_id
add_data = [{"lun": {"id": add_id}}
for add_id in add_luns] if add_luns else []
remove_data = [{"lun": {"id": remove_id}}
for remove_id in remove_luns] if remove_luns else []
req_data = {'lunAdd': add_data,
'lunRemove': remove_data}
return mock.call(url, req_data)
resp_create_consistencygroup = {
'content': {'storageResource': {'id': 'res_1'}}}
resp_get_group_by_name = {'entries': [{'content': {'id': 'res_1'}}]}
resp_update_consistencygroup = {}
@staticmethod
def req_create_snap(lun_id, snap_name, snap_desc=None):
url = '/api/types/snap/instances'
resp_create_snap = {'storageResource': {'id': lun_id},
'name': snap_name}
if snap_desc:
resp_create_snap['description'] = snap_desc
return mock.call(url, resp_create_snap)
@staticmethod
def req_delete_snap(snap_id):
delete_snap_url = '/api/instances/snap/%s' % snap_id
return mock.call(delete_snap_url, None, 'DELETE')
@staticmethod
def req_get_pools(fields):
get_pools_url = ('/api/types/pool/instances?'
'fields=%s' % ','.join(fields))
return mock.call(get_pools_url)
resp_get_pools = {
'entries': [
{'content': {'id': storage_pool_id_default,
'name': storage_pool_name_default,
'sizeTotal': 28185722880,
'sizeFree': 17985175552,
'sizeSubscribed': 10185722880}},
{'content': {'id': 'pool_2',
'name': 'StoragePool01',
'sizeTotal': 28185722880,
'sizeFree': 17985175552,
'sizeSubscribed': 10185722880}}]}
new_resp_get_pools = {
'entries': [
{'content': {'id': storage_pool_id_default,
'name': storage_pool_name_default,
'sizeTotal': 2147483678,
'sizeFree': 1073741824,
'sizeSubscribed': 10185722880}},
{'content': {'id': 'pool_2',
'name': 'StoragePool01',
'sizeTotal': 28185722880,
'sizeFree': 17985175552,
'sizeSubscribed': 10185722880}}]}
@staticmethod
def req_get_licenses(fields):
get_licenses_url = ('/api/types/license/instances?'
'fields=%s' % ','.join(fields))
return mock.call(get_licenses_url)
resp_get_licenses = {
'entries': [
{'content': {'id': 'VNXE_PROVISION',
'isValid': True}},
{'content': {'id': 'SNAP',
'isValid': True}}]}
TD = EMCVNXeDriverTestData
class RequestSideEffect(object):
def __init__(self):
self.actions = []
self.started = False
def append(self, err=None, resp=None, ex=None):
if not self.started:
self.actions.append((err, resp, ex))
def __call__(self, rel_url, req_data=None, method=None,
*args, **kwargs):
if not self.started:
self.started = True
self.actions.reverse()
item = self.actions.pop()
if item[2]:
raise item[2]
else:
return item[0:2]
class EMCVNXeDriverTestCase(test.TestCase):
def setUp(self):
super(EMCVNXeDriverTestCase, self).setUp()
self.configuration = conf.Configuration(None)
self.configuration.append_config_values = mock.Mock(return_value=0)
self.configuration.san_ip = '10.0.0.1'
conf_safe_get_map = {
'storage_pool_names': TD.storage_pool_name_default,
'zoning_mode': None}
self.configuration.safe_get = mock.Mock(
side_effect=lambda a: conf_safe_get_map[a]
if a in conf_safe_get_map else None)
self.configuration.san_login = 'sysadmin'
self.configuration.san_password = 'sysadmin'
self.driver = None
@staticmethod
def load_provider_location(provider_location):
pl_dict = {}
for item in provider_location.split('|'):
k_v = item.split('^')
if len(k_v) == 2 and k_v[0]:
pl_dict[k_v[0]] = k_v[1]
return pl_dict
class EMCVNXeiSCSIDriverTestCase(EMCVNXeDriverTestCase):
def setUp(self):
super(EMCVNXeiSCSIDriverTestCase, self).setUp()
self.configuration.storage_protocol = 'iSCSI'
hook = RequestSideEffect()
hook.append(None, TD.resp_get_basic_system_info)
hook.append(None, TD.resp_get_pools)
hook.append(None, TD.resp_get_iscsi_nodes)
hook.append(None, TD.resp_get_get_iscsi_portals)
EMCVNXeRESTClient._request = mock.Mock(side_effect=hook)
self.driver = EMCVNXeDriver(configuration=self.configuration)
expected_calls = [
TD.req_get_basic_system_info(('name', 'softwareVersion')),
TD.req_get_pools(('name', 'id')),
TD.req_get_get_iscsi_nodes(('id', 'name')),
TD.req_get_get_iscsi_portals(('id', 'ipAddress',
'ethernetPort', 'iscsiNode'))]
EMCVNXeRESTClient._request.assert_has_calls(expected_calls)