forked from HewlettPackard/hpe3par_python_sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_HPE3ParClient_host.py
661 lines (526 loc) · 20.3 KB
/
test_HPE3ParClient_host.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
# (c) Copyright 2015 Hewlett Packard Enterprise Development LP
#
# 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.
"""Test class of 3PAR Client handling Host."""
from test import HPE3ParClient_base as hpe3parbase
from hpe3parclient import exceptions
# Insert colons into time string to match WWN format.
TIME2 = ""
for i in range(6):
if i % 2 == 0:
TIME2 += ":" + hpe3parbase.TIME[i]
else:
TIME2 += hpe3parbase.TIME[i]
DOMAIN = 'UNIT_TEST_DOMAIN'
HOST_NAME1 = 'HOST1_UNIT_TEST' + hpe3parbase.TIME
HOST_NAME2 = 'HOST2_UNIT_TEST' + hpe3parbase.TIME
WWN1 = "00:00:00:00:00" + TIME2
WWN2 = "11:11:11:11:11" + TIME2
IQN1 = 'iqn.1993-08.org.debian:01:00000' + hpe3parbase.TIME
IQN2 = 'iqn.bogus.org.debian:01:0000' + hpe3parbase.TIME
class HPE3ParClientHostTestCase(hpe3parbase.HPE3ParClientBaseTestCase):
def setUp(self):
super(HPE3ParClientHostTestCase, self).setUp(withSSH=True)
def tearDown(self):
try:
self.cl.deleteHost(HOST_NAME1)
except Exception:
pass
try:
self.cl.deleteHost(HOST_NAME2)
except Exception:
pass
# very last, tear down base class
super(HPE3ParClientHostTestCase, self).tearDown()
def test_1_create_host_badParams(self):
self.printHeader('create_host_badParams')
name = 'UnitTestHostBadParams'
optional = {'iSCSIPaths': 'foo bar'}
self.assertRaises(exceptions.HTTPBadRequest,
self.cl.createHost,
name,
None,
None,
optional)
self.printFooter('create_host_badParams')
def test_1_create_host_no_name(self):
self.printHeader('create_host_no_name')
optional = {'domain': 'default'}
self.assertRaises(exceptions.HTTPBadRequest,
self.cl.createHost,
None,
None,
None,
optional)
self.printFooter('create_host_no_name')
def test_1_create_host_exceed_length(self):
self.printHeader('create_host_exceed_length')
optional = {'domain': 'ThisDomainNameIsWayTooLongToMakeAnySense'}
self.assertRaises(exceptions.HTTPBadRequest,
self.cl.createHost,
HOST_NAME1,
None,
None,
optional)
self.printFooter('create_host_exceed_length')
def test_1_create_host_empty_domain(self):
self.printHeader('create_host_empty_domain')
optional = {'domain': ''}
self.assertRaises(exceptions.HTTPBadRequest,
self.cl.createHost,
HOST_NAME1,
None,
None,
optional)
self.printFooter('create_host_empty_domain')
def test_1_create_host_illegal_string(self):
self.printHeader('create_host_illegal_string')
optional = {'domain': 'doma&n'}
self.assertRaises(exceptions.HTTPBadRequest,
self.cl.createHost,
HOST_NAME1,
None,
None,
optional)
self.printFooter('create_host_illegal_string')
def test_1_create_host_param_conflict(self):
self.printHeader('create_host_param_conflict')
optional = {'domain': DOMAIN}
fc = [WWN1, WWN2]
iscsi = [IQN1, IQN2]
self.assertRaises(exceptions.HTTPBadRequest,
self.cl.createHost,
HOST_NAME1,
iscsi,
fc,
optional)
self.printFooter('create_host_param_conflict')
def test_1_create_host_wrong_type(self):
self.printHeader('create_host_wrong_type')
optional = {'domain': self.DOMAIN}
fc = ['00:00:00:00:00:00:00']
self.assertRaises(exceptions.HTTPBadRequest,
self.cl.createHost,
HOST_NAME1,
None,
fc,
optional)
self.printFooter('create_host_wrong_type')
def test_1_create_host_existent_path(self):
self.printHeader('create_host_existent_path')
optional = {'domain': DOMAIN}
fc = [WWN1, WWN2]
self.cl.createHost(HOST_NAME1, None, fc, optional)
self.assertRaises(exceptions.HTTPConflict,
self.cl.createHost,
HOST_NAME2,
None,
fc,
optional)
self.printFooter('create_host_existent_path')
def test_1_create_host_duplicate(self):
self.printHeader('create_host_duplicate')
optional = {'domain': self.DOMAIN}
self.cl.createHost(HOST_NAME1, None, None, optional)
self.assertRaises(exceptions.HTTPConflict,
self.cl.createHost,
HOST_NAME1,
None,
None,
optional)
self.printFooter('create_host_duplicate')
def test_1_create_host(self):
self.printHeader('create_host')
# add one
optional = {'domain': DOMAIN}
fc = [WWN1, WWN2]
self.cl.createHost(HOST_NAME1, None, fc, optional)
# check
host1 = self.cl.getHost(HOST_NAME1)
self.assertIsNotNone(host1)
name1 = host1.name
self.assertEqual(HOST_NAME1, name1)
# add another
iscsi = [IQN1,
IQN2]
self.cl.createHost(HOST_NAME2, iscsi, None, optional)
# check
host2 = self.cl.getHost(HOST_NAME2)
self.assertIsNotNone(host2)
name3 = host2.name
self.assertEqual(HOST_NAME2, name3)
self.printFooter('create_host')
def test_1_create_host_no_optional(self):
self.printHeader('create_host_no_optional')
# add one
fc = [WWN1, WWN2]
self.cl.createHost(HOST_NAME1, None, fc)
# check
host1 = self.cl.getHost(HOST_NAME1)
self.assertIsNotNone(host1)
name1 = host1.name
self.assertEqual(HOST_NAME1, name1)
self.printFooter('create_host_no_optional')
def test_2_delete_host_nonExist(self):
self.printHeader("delete_host_non_exist")
self.assertRaises(exceptions.HTTPNotFound,
self.cl.deleteHost,
"UnitTestNonExistHost")
self.printFooter("delete_host_non_exist")
def test_2_delete_host(self):
self.printHeader("delete_host")
optional = {'domain': DOMAIN}
fc = [WWN1, WWN2]
self.cl.createHost(HOST_NAME1, None, fc, optional)
# check
host1 = self.cl.getHost(HOST_NAME1)
self.assertIsNotNone(host1)
hosts = self.cl.getHosts()
if len(hosts) > 0:
for host in hosts:
if host.name == HOST_NAME1:
self.cl.deleteHost(host.name)
self.assertRaises(exceptions.HTTPNotFound, self.cl.getHost, HOST_NAME1)
self.printFooter("delete_host")
def test_3_get_host_bad(self):
self.printHeader("get_host_bad")
self.assertRaises(exceptions.HTTPNotFound, self.cl.getHost,
"BadHostName")
self.printFooter("get_host_bad")
def test_3_get_host_illegal(self):
self.printHeader("get_host_illegal")
self.assertRaises(exceptions.HTTPBadRequest, self.cl.getHost,
"B&dHostName")
self.printFooter("get_host_illegal")
def test_3_get_hosts(self):
self.printHeader("get_hosts")
optional = {'domain': DOMAIN}
fc = [WWN1, WWN2]
self.cl.createHost(HOST_NAME1, None, fc, optional)
iscsi = [IQN1,
IQN2]
self.cl.createHost(HOST_NAME2, iscsi, None, optional)
hosts = self.cl.getHosts()
self.assertGreaterEqual(len(hosts), 2)
host_names = [host.name for host in hosts]
self.assertIn(HOST_NAME1, host_names)
self.assertIn(HOST_NAME2, host_names)
def test_3_get_host(self):
self.printHeader("get_host")
self.assertRaises(exceptions.HTTPNotFound, self.cl.getHost, HOST_NAME1)
optional = {'domain': DOMAIN}
fc = [WWN1, WWN2]
self.cl.createHost(HOST_NAME1, None, fc, optional)
host1 = self.cl.getHost(HOST_NAME1)
self.assertEquals(host1.name, HOST_NAME1)
self.printFooter('get_host')
def test_4_modify_host(self):
self.printHeader('modify_host')
self.assertRaises(exceptions.HTTPNotFound, self.cl.getHost, HOST_NAME1)
self.assertRaises(exceptions.HTTPNotFound, self.cl.getHost, HOST_NAME2)
optional = {'domain': DOMAIN}
fc = [WWN1, WWN2]
self.cl.createHost(HOST_NAME1, None, fc, optional)
# validate host was created
host1 = self.cl.getHost(HOST_NAME1)
self.assertEquals(host1.name, HOST_NAME1)
# change host name
mod_request = {'newName': HOST_NAME2}
self.cl.modifyHost(HOST_NAME1, mod_request)
# validate host name was changed
host2 = self.cl.getHost(HOST_NAME2)
self.assertEquals(host2.name, HOST_NAME2)
# host 1 name should be history
self.assertRaises(exceptions.HTTPNotFound, self.cl.getHost, HOST_NAME1)
self.printFooter('modfiy_host')
def test_4_modify_host_no_name(self):
self.printHeader('modify_host_no_name')
mod_request = {'newName': HOST_NAME1}
self.assertRaises(
exceptions.HTTPNotFound,
self.cl.modifyHost,
None,
mod_request
)
self.printFooter('modify_host_no_name')
def test_4_modify_host_param_conflict(self):
self.printHeader('modify_host_param_conflict')
fc = [WWN1, WWN2]
iscsi = [IQN1, IQN2]
mod_request = {'newName': HOST_NAME1,
'FCWWNs': fc, 'iSCSINames': iscsi}
self.assertRaises(
exceptions.HTTPBadRequest,
self.cl.modifyHost,
HOST_NAME2,
mod_request
)
self.printFooter('modify_host_param_conflict')
def test_4_modify_host_illegal_char(self):
self.printHeader('modify_host_illegal_char')
mod_request = {'newName': 'New#O$TN@ME'}
self.assertRaises(
exceptions.HTTPBadRequest,
self.cl.modifyHost,
HOST_NAME2,
mod_request
)
self.printFooter('modify_host_illegal_char')
def test_4_modify_host_pathOperation_missing1(self):
self.printHeader('modify_host_pathOperation_missing1')
fc = [WWN1, WWN2]
mod_request = {'FCWWNs': fc}
self.assertRaises(
exceptions.HTTPBadRequest,
self.cl.modifyHost,
HOST_NAME1,
mod_request
)
self.printFooter('modify_host_pathOperation_missing1')
def test_4_modify_host_pathOperation_missing2(self):
self.printHeader('modify_host_pathOperation_missing2')
iscsi = [IQN1, IQN2]
mod_request = {'iSCSINames': iscsi}
self.assertRaises(
exceptions.HTTPBadRequest,
self.cl.modifyHost,
HOST_NAME1,
mod_request
)
self.printFooter('modify_host_pathOperation_missing2')
def test_4_modify_host_pathOperationOnly(self):
self.printHeader('modify_host_pathOperationOnly')
mod_request = {'pathOperation': 1}
self.assertRaises(
exceptions.HTTPBadRequest,
self.cl.modifyHost,
HOST_NAME2,
mod_request
)
self.printFooter('modify_host_pathOperationOnly')
def test_4_modify_host_too_long(self):
self.printHeader('modify_host_too_long')
optional = {'domain': DOMAIN}
fc = [WWN1, WWN2]
self.cl.createHost(HOST_NAME1, None, fc, optional)
mod_request = {'newName': 'ThisHostNameIsWayTooLongToMakeAnyRealSense'
'AndIsDeliberatelySo'}
self.assertRaises(
exceptions.HTTPBadRequest,
self.cl.modifyHost,
HOST_NAME1,
mod_request
)
self.printFooter('modify_host_too_long')
def test_4_modify_host_dup_newName(self):
self.printHeader('modify_host_dup_newName')
optional = {'domain': DOMAIN}
fc = [WWN1, WWN2]
self.cl.createHost(HOST_NAME1, None, fc, optional)
iscsi = [IQN1, IQN2]
self.cl.createHost(HOST_NAME2, iscsi, None, optional)
mod_request = {'newName': HOST_NAME1}
self.assertRaises(
exceptions.HTTPConflict,
self.cl.modifyHost,
HOST_NAME2,
mod_request
)
self.printFooter('modify_host_dup_newName')
def test_4_modify_host_nonExist(self):
self.printHeader('modify_host_nonExist')
mod_request = {'newName': HOST_NAME2}
self.assertRaises(
exceptions.HTTPNotFound,
self.cl.modifyHost,
HOST_NAME1,
mod_request
)
self.printFooter('modify_host_nonExist')
def test_4_modify_host_existent_path(self):
self.printHeader('modify_host_existent_path')
optional = {'domain': DOMAIN}
fc = [WWN1,
WWN2]
iscsi = [IQN1,
IQN2]
self.cl.createHost(HOST_NAME1, None, fc, optional)
self.cl.createHost(HOST_NAME2, iscsi, None, optional)
mod_request = {'pathOperation': 1,
'iSCSINames': iscsi}
self.assertRaises(
exceptions.HTTPConflict,
self.cl.modifyHost,
HOST_NAME1,
mod_request
)
self.printFooter('modify_host_existent_path')
def test_4_modify_host_nonExistent_path_iSCSI(self):
self.printHeader('modify_host_nonExistent_path_iSCSI')
optional = {'domain': DOMAIN}
iscsi = [IQN1]
self.cl.createHost(HOST_NAME1, iscsi, None, optional)
iscsi2 = [IQN2]
mod_request = {'pathOperation': 2,
'iSCSINames': iscsi2}
self.assertRaises(
exceptions.HTTPNotFound,
self.cl.modifyHost,
HOST_NAME1,
mod_request
)
self.printFooter('modify_host_nonExistent_path_iSCSI')
def test_4_modify_host_nonExistent_path_fc(self):
self.printHeader('modify_host_nonExistent_path_fc')
optional = {'domain': DOMAIN}
fc = [WWN1]
self.cl.createHost(HOST_NAME1, None, fc, optional)
fc2 = [WWN2]
mod_request = {'pathOperation': 2,
'FCWWNs': fc2}
self.assertRaises(
exceptions.HTTPNotFound,
self.cl.modifyHost,
HOST_NAME1,
mod_request
)
self.printFooter('modify_host_nonExistent_path_fc')
def test_4_modify_host_add_fc(self):
self.printHeader('modify_host_fc')
optional = {'domain': DOMAIN}
fc = [WWN1]
self.cl.createHost(HOST_NAME1, None, fc, optional)
fc2 = [WWN2]
mod_request = {'pathOperation': 1,
'FCWWNs': fc2}
self.cl.modifyHost(HOST_NAME1, mod_request)
newHost = self.cl.getHost(HOST_NAME1)
fc_paths = newHost.fcpaths
for path in fc_paths:
if path.wwn == WWN2.replace(':', ''):
self.printFooter('modify_host_add_fc')
return
self.fail('Failed to add FCWWN')
def test_4_modify_host_remove_fc(self):
self.printHeader('modify_host_remove_fc')
optional = {'domain': DOMAIN}
fc = [WWN1]
self.cl.createHost(HOST_NAME1, None, fc, optional)
mod_request = {'pathOperation': 2,
'FCWWNs': fc}
self.cl.modifyHost(HOST_NAME1, mod_request)
newHost = self.cl.getHost(HOST_NAME1)
fc_paths = newHost.fcpaths
for path in fc_paths:
if path.wwn == WWN1.replace(':', ''):
self.fail('Failed to remove FCWWN')
return
self.printFooter('modify_host_remove_fc')
def test_4_modify_host_add_iscsi(self):
self.printHeader('modify_host_add_iscsi')
optional = {'domain': DOMAIN}
iscsi = [IQN1]
self.cl.createHost(HOST_NAME1, iscsi, None, optional)
iscsi2 = [IQN2]
mod_request = {'pathOperation': 1,
'iSCSINames': iscsi2}
self.cl.modifyHost(HOST_NAME1, mod_request)
newHost = self.cl.getHost(HOST_NAME1)
iscsi_paths = newHost.iscsi_paths
for path in iscsi_paths:
print(path)
if path.name == IQN2:
self.printFooter('modify_host_add_iscsi')
return
self.fail('Failed to add iSCSI')
def test_4_modify_host_remove_iscsi(self):
self.printHeader('modify_host_remove_iscsi')
optional = {'domain': DOMAIN}
iscsi = [IQN1]
self.cl.createHost(HOST_NAME1, iscsi, None, optional)
mod_request = {'pathOperation': 2,
'iSCSINames': iscsi}
self.cl.modifyHost(HOST_NAME1, mod_request)
newHost = self.cl.getHost(HOST_NAME1)
iscsi_paths = newHost.iscsi_paths
for path in iscsi_paths:
if path.name== IQN2:
self.fail('Failed to remove iSCSI')
return
self.printFooter('modify_host_remove_iscsi')
# def test_5_query_host_iqn(self):
# self.printHeader('query_host_iqn')
# optional = {'domain': DOMAIN}
# iscsi = [IQN1]
# self.cl.createHost(HOST_NAME1, iscsi, None, optional)
#
# hosts = self.cl.queryHost(iqns=[iscsi.pop()])
# self.assertIsNotNone(hosts)
# print "===========HELLO******************==============="
# print hosts
# #self.assertEqual(1, hosts['total'])
# #self.assertEqual(hosts['members'].pop()['name'], HOST_NAME1)
#
# self.printFooter('query_host_iqn')
#
# def test_5_query_host_iqn2(self):
# # TODO test multiple iqns in one query
# pass
#
# def test_5_query_host_wwn(self):
# self.printHeader('query_host_wwn')
# optional = {'domain': DOMAIN}
# fc = [WWN1]
# self.cl.createHost(HOST_NAME1, None, fc, optional)
#
# hosts = self.cl.queryHost(wwns=[fc.pop().replace(':', '')])
# self.assertIsNotNone(hosts)
# #self.assertEqual(1, hosts['total'])
# self.assertEqual(hosts[0].name, HOST_NAME1)
#
# self.printFooter('query_host_wwn')
# def test_5_query_host_wwn2(self):
# # TODO test multiple wwns in one query
# pass
#
# def test_5_query_host_iqn_and_wwn(self):
# self.printHeader('query_host_iqn_and_wwn')
#
# optional = {'domain': DOMAIN}
# iscsi = [IQN1]
# self.cl.createHost(HOST_NAME1, iscsi, None, optional)
# fc = [WWN1]
# self.cl.createHost(HOST_NAME2, None, fc, optional)
#
# hosts = self.cl.queryHost(iqns=[IQN1],
# wwns=[WWN1.replace(':', '')])
#
# self.assertIsNotNone(hosts)
# self.assertEqual(2, hosts['total'])
# self.assertIn(HOST_NAME1, [host['name'] for host in hosts['members']])
# self.assertIn(HOST_NAME2, [host['name'] for host in hosts['members']])
# self.printFooter('query_host_iqn_and_wwn')
#
# def test_6_find_host(self):
# self.printHeader('find_host_wwn')
#
# hosts = self.cl.findHost(wwn=WWN1)
#
# if hosts is not None:
# # host found
# self.assertIsNotNone(hosts)
# else:
# # host not found
# self.assertIsNone(hosts)
#
# self.printFooter('find_host_wwn')