/
test_gpfs.py
1550 lines (1399 loc) · 76.3 KB
/
test_gpfs.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 IBM Corp. 2013 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 os
import shutil
import tempfile
import mock
from oslo.config import cfg
from oslo.utils import units
from oslo_concurrency import processutils
from cinder import context
from cinder import exception
from cinder.image import image_utils
from cinder.openstack.common import log as logging
from cinder import test
from cinder import utils
from cinder.volume import configuration as conf
from cinder.volume.drivers.ibm import gpfs
from cinder.volume import volume_types
from mock import patch
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
class FakeQemuImgInfo(object):
def __init__(self):
self.file_format = None
self.backing_file = None
class GPFSDriverTestCase(test.TestCase):
driver_name = "cinder.volume.drivers.gpfs.GPFSDriver"
context = context.get_admin_context()
def _execute_wrapper(self, cmd, *args, **kwargs):
try:
kwargs.pop('run_as_root')
except KeyError:
pass
return utils.execute(cmd, *args, **kwargs)
def setUp(self):
super(GPFSDriverTestCase, self).setUp()
self.volumes_path = tempfile.mkdtemp(prefix="gpfs_")
self.images_dir = '%s/images' % self.volumes_path
self.addCleanup(self._cleanup, self.images_dir, self.volumes_path)
if not os.path.exists(self.volumes_path):
os.mkdir(self.volumes_path)
if not os.path.exists(self.images_dir):
os.mkdir(self.images_dir)
self.image_id = '70a599e0-31e7-49b7-b260-868f441e862b'
self.driver = gpfs.GPFSDriver(configuration=conf.Configuration(None))
self.driver.set_execute(self._execute_wrapper)
self.driver._cluster_id = '123456'
self.driver._gpfs_device = '/dev/gpfs'
self.driver._storage_pool = 'system'
self.flags(volume_driver=self.driver_name,
gpfs_mount_point_base=self.volumes_path)
self.context = context.get_admin_context()
self.context.user_id = 'fake'
self.context.project_id = 'fake'
CONF.gpfs_images_dir = self.images_dir
def _cleanup(self, images_dir, volumes_path):
try:
os.rmdir(images_dir)
os.rmdir(volumes_path)
except OSError:
pass
def test_different(self):
self.assertTrue(gpfs._different((True, False)))
self.assertFalse(gpfs._different((True, True)))
self.assertFalse(gpfs._different(None))
def test_sizestr(self):
self.assertEqual(gpfs._sizestr('10'), '10G')
@patch('cinder.utils.execute')
def test_get_gpfs_state_ok(self, mock_exec):
mock_exec.return_value = ('mmgetstate::HEADER:version:reserved:'
'reserved:nodeName:nodeNumber:state:quorum:'
'nodesUp:totalNodes:remarks:cnfsState:\n'
'mmgetstate::0:1:::devstack:3:active:2:3:3:'
'quorum node:(undefined):', '')
self.assertEqual(True, self.driver._get_gpfs_state().splitlines()[1].
startswith('mmgetstate::0:1:::devstack'))
@patch('cinder.utils.execute')
def test_get_gpfs_state_fail_mmgetstate(self, mock_exec):
mock_exec.side_effect = processutils.ProcessExecutionError(
stdout='test', stderr='test')
self.assertRaises(exception.VolumeBackendAPIException,
self.driver._get_gpfs_state)
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._get_gpfs_state')
def test_check_gpfs_state_ok(self, mock_get_gpfs_state):
mock_get_gpfs_state.return_value = ('mmgetstate::HEADER:version:'
'reserved:reserved:nodeName:'
'nodeNumber:state:quorum:nodesUp:'
'totalNodes:remarks:cnfsState:\n'
'mmgetstate::0:1:::devstack:3:'
'active:2:3:3:'
'quorum node:(undefined):')
self.driver._check_gpfs_state()
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._get_gpfs_state')
def test_check_gpfs_state_fail_not_active(self, mock_get_gpfs_state):
mock_get_gpfs_state.return_value = ('mmgetstate::HEADER:version:'
'reserved:reserved:nodeName:'
'nodeNumber:state:quorum:nodesUp:'
'totalNodes:remarks:cnfsState:\n'
'mmgetstate::0:1:::devstack:3:'
'arbitrating:2:3:3:'
'quorum node:(undefined):')
self.assertRaises(exception.VolumeBackendAPIException,
self.driver._check_gpfs_state)
@patch('cinder.utils.execute')
def test_get_fs_from_path_ok(self, mock_exec):
mock_exec.return_value = ('Filesystem 1K-blocks '
'Used Available Use%% Mounted on\n'
'%s 10485760 531968 9953792'
' 6%% /gpfs0' % self.driver._gpfs_device,
'')
self.assertEqual(self.driver._gpfs_device,
self.driver._get_filesystem_from_path('/gpfs0'))
@patch('cinder.utils.execute')
def test_get_fs_from_path_fail_path(self, mock_exec):
mock_exec.return_value = ('Filesystem 1K-blocks '
'Used Available Use% Mounted on\n'
'test 10485760 531968 '
'9953792 6% /gpfs0', '')
self.assertNotEqual(self.driver._gpfs_device,
self.driver._get_filesystem_from_path('/gpfs0'))
@patch('cinder.utils.execute')
def test_get_fs_from_path_fail_raise(self, mock_exec):
mock_exec.side_effect = processutils.ProcessExecutionError(
stdout='test', stderr='test')
self.assertRaises(exception.VolumeBackendAPIException,
self.driver._get_filesystem_from_path, '/gpfs0')
@patch('cinder.utils.execute')
def test_get_gpfs_cluster_id_ok(self, mock_exec):
mock_exec.return_value = ('mmlsconfig::HEADER:version:reserved:'
'reserved:configParameter:value:nodeList:\n'
'mmlsconfig::0:1:::clusterId:%s::'
% self.driver._cluster_id, '')
self.assertEqual(self.driver._cluster_id,
self.driver._get_gpfs_cluster_id())
@patch('cinder.utils.execute')
def test_get_gpfs_cluster_id_fail_id(self, mock_exec):
mock_exec.return_value = ('mmlsconfig::HEADER.:version:reserved:'
'reserved:configParameter:value:nodeList:\n'
'mmlsconfig::0:1:::clusterId:test::', '')
self.assertNotEqual(self.driver._cluster_id,
self.driver._get_gpfs_cluster_id())
@patch('cinder.utils.execute')
def test_get_gpfs_cluster_id_fail_raise(self, mock_exec):
mock_exec.side_effect = processutils.ProcessExecutionError(
stdout='test', stderr='test')
self.assertRaises(exception.VolumeBackendAPIException,
self.driver._get_gpfs_cluster_id)
@patch('cinder.utils.execute')
def test_get_fileset_from_path_ok(self, mock_exec):
mock_exec.return_value = ('file name: /gpfs0\n'
'metadata replication: 1 max 2\n'
'data replication: 1 max 2\n'
'immutable: no\n'
'appendOnly: no\n'
'flags:\n'
'storage pool name: system\n'
'fileset name: root\n'
'snapshot name:\n'
'Windows attributes: DIRECTORY', '')
self.driver._get_fileset_from_path('')
@patch('cinder.utils.execute')
def test_get_fileset_from_path_fail_mmlsattr(self, mock_exec):
mock_exec.side_effect = processutils.ProcessExecutionError(
stdout='test', stderr='test')
self.assertRaises(exception.VolumeBackendAPIException,
self.driver._get_fileset_from_path, '')
@patch('cinder.utils.execute')
def test_get_fileset_from_path_fail_find_fileset(self, mock_exec):
mock_exec.return_value = ('file name: /gpfs0\n'
'metadata replication: 1 max 2\n'
'data replication: 1 max 2\n'
'immutable: no\n'
'appendOnly: no\n'
'flags:\n'
'storage pool name: system\n'
'*** name: root\n'
'snapshot name:\n'
'Windows attributes: DIRECTORY', '')
self.assertRaises(exception.VolumeBackendAPIException,
self.driver._get_fileset_from_path, '')
@patch('cinder.utils.execute')
def test_verify_gpfs_pool_ok(self, mock_exec):
mock_exec.return_value = ('Storage pools in file system at \'/gpfs0\':'
'\n'
'Name Id BlkSize Data '
'Meta '
'Total Data in (KB) Free Data in (KB) '
'Total Meta in (KB) Free Meta in (KB)\n'
'system 0 256 KB yes '
'yes '
' 10485760 9953792 ( 95%) '
'10485760 9954560 ( 95%)', '')
self.assertTrue(self.driver._gpfs_device,
self.driver._verify_gpfs_pool('/dev/gpfs'))
@patch('cinder.utils.execute')
def test_verify_gpfs_pool_fail_pool(self, mock_exec):
mock_exec.return_value = ('Storage pools in file system at \'/gpfs0\':'
'\n'
'Name Id BlkSize Data '
'Meta '
'Total Data in (KB) Free Data in (KB) '
'Total Meta in (KB) Free Meta in (KB)\n'
'test 0 256 KB yes '
'yes'
' 10485760 9953792 ( 95%)'
' 10485760 9954560 ( 95%)', '')
self.assertTrue(self.driver._gpfs_device,
self.driver._verify_gpfs_pool('/dev/gpfs'))
@patch('cinder.utils.execute')
def test_verify_gpfs_pool_fail_raise(self, mock_exec):
mock_exec.side_effect = processutils.ProcessExecutionError(
stdout='test', stderr='test')
self.assertFalse(self.driver._verify_gpfs_pool('/dev/gpfs'))
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._verify_gpfs_pool')
@patch('cinder.utils.execute')
def test_update_volume_storage_pool_ok(self, mock_exec, mock_verify_pool):
mock_verify_pool.return_value = True
self.assertTrue(self.driver._update_volume_storage_pool('', 'system'))
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._verify_gpfs_pool')
@patch('cinder.utils.execute')
def test_update_volume_storage_pool_ok_pool_none(self,
mock_exec,
mock_verify_pool):
mock_verify_pool.return_value = True
self.assertTrue(self.driver._update_volume_storage_pool('', None))
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._verify_gpfs_pool')
@patch('cinder.utils.execute')
def test_update_volume_storage_pool_fail_pool(self,
mock_exec,
mock_verify_pool):
mock_verify_pool.return_value = False
self.assertRaises(exception.VolumeBackendAPIException,
self.driver._update_volume_storage_pool,
'',
'system')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._verify_gpfs_pool')
@patch('cinder.utils.execute')
def test_update_volume_storage_pool_fail_mmchattr(self,
mock_exec,
mock_verify_pool):
mock_exec.side_effect = processutils.ProcessExecutionError(
stdout='test', stderr='test')
mock_verify_pool.return_value = True
self.assertFalse(self.driver._update_volume_storage_pool('', 'system'))
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.'
'_get_filesystem_from_path')
@patch('cinder.utils.execute')
def test_get_gpfs_fs_release_level_ok(self,
mock_exec,
mock_fs_from_path):
mock_exec.return_value = ('mmlsfs::HEADER:version:reserved:reserved:'
'deviceName:fieldName:data:remarks:\n'
'mmlsfs::0:1:::gpfs:filesystemVersion:14.03 '
'(4.1.0.0):\n'
'mmlsfs::0:1:::gpfs:filesystemVersionLocal:'
'14.03 (4.1.0.0):\n'
'mmlsfs::0:1:::gpfs:filesystemVersionManager'
':14.03 (4.1.0.0):\n'
'mmlsfs::0:1:::gpfs:filesystemVersion'
'Original:14.03 (4.1.0.0):\n'
'mmlsfs::0:1:::gpfs:filesystemHighest'
'Supported:14.03 (4.1.0.0):', '')
mock_fs_from_path.return_value = '/dev/gpfs'
self.assertEqual(('/dev/gpfs', 1403),
self.driver._get_gpfs_fs_release_level(''))
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.'
'_get_filesystem_from_path')
@patch('cinder.utils.execute')
def test_get_gpfs_fs_release_level_fail_mmlsfs(self,
mock_exec,
mock_fs_from_path):
mock_exec.side_effect = processutils.ProcessExecutionError(
stdout='test', stderr='test')
mock_fs_from_path.return_value = '/dev/gpfs'
self.assertRaises(exception.VolumeBackendAPIException,
self.driver._get_gpfs_fs_release_level, '')
@patch('cinder.utils.execute')
def test_get_gpfs_cluster_release_level_ok(self, mock_exec):
mock_exec.return_value = ('mmlsconfig::HEADER:version:reserved:'
'reserved:configParameter:value:nodeList:\n'
'mmlsconfig::0:1:::minReleaseLevel:1403::',
'')
self.assertEqual(1403, self.driver._get_gpfs_cluster_release_level())
@patch('cinder.utils.execute')
def test_get_gpfs_cluster_release_level_fail_mmlsconfig(self, mock_exec):
mock_exec.side_effect = processutils.ProcessExecutionError(
stdout='test', stderr='test')
self.assertRaises(exception.VolumeBackendAPIException,
self.driver._get_gpfs_cluster_release_level)
@patch('cinder.utils.execute')
def test_is_gpfs_path_fail_mmlsattr(self, mock_exec):
mock_exec.side_effect = processutils.ProcessExecutionError(
stdout='test', stderr='test')
self.assertRaises(exception.VolumeBackendAPIException,
self.driver._is_gpfs_path, '/dummy/path')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._get_fileset_from_path')
@patch('cinder.utils.execute')
def test_is_same_fileset_ok(self,
mock_exec,
mock_get_fileset_from_path):
mock_get_fileset_from_path.return_value = True
self.assertTrue(self.driver._is_same_fileset('', ''))
mock_get_fileset_from_path.side_effect = [True, False]
self.assertFalse(self.driver._is_same_fileset('', ''))
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._get_available_capacity')
@patch('cinder.utils.execute')
def test_same_cluster_ok(self, mock_exec, mock_avail_capacity):
mock_avail_capacity.return_value = (10192683008, 10737418240)
stats = self.driver.get_volume_stats()
loc = stats['location_info']
cap = {'location_info': loc}
host = {'host': 'foo', 'capabilities': cap}
self.assertTrue(self.driver._same_cluster(host))
locinfo = stats['location_info'] + '_'
loc = locinfo
cap = {'location_info': loc}
host = {'host': 'foo', 'capabilities': cap}
self.assertFalse(self.driver._same_cluster(host))
@patch('cinder.utils.execute')
def test_set_rw_permission(self, mock_exec):
self.driver._set_rw_permission('')
@patch('cinder.utils.execute')
def test_can_migrate_locally(self, mock_exec):
host = {'host': 'foo', 'capabilities': ''}
self.assertEqual(self.driver._can_migrate_locally(host), None)
loc = 'GPFSDriver:%s' % self.driver._cluster_id
cap = {'location_info': loc}
host = {'host': 'foo', 'capabilities': cap}
self.assertEqual(self.driver._can_migrate_locally(host), None)
loc = 'GPFSDriver_:%s:testpath' % self.driver._cluster_id
cap = {'location_info': loc}
host = {'host': 'foo', 'capabilities': cap}
self.assertEqual(self.driver._can_migrate_locally(host), None)
loc = 'GPFSDriver:%s:testpath' % (self.driver._cluster_id + '_')
cap = {'location_info': loc}
host = {'host': 'foo', 'capabilities': cap}
self.assertEqual(self.driver._can_migrate_locally(host), None)
loc = 'GPFSDriver:%s:testpath' % self.driver._cluster_id
cap = {'location_info': loc}
host = {'host': 'foo', 'capabilities': cap}
self.assertEqual(self.driver._can_migrate_locally(host), 'testpath')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._verify_gpfs_pool')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.'
'_get_filesystem_from_path')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._get_gpfs_cluster_id')
@patch('cinder.utils.execute')
def test_do_setup_ok(self,
mock_exec,
mock_get_gpfs_cluster_id,
mock_get_filesystem_from_path,
mock_verify_gpfs_pool):
ctxt = self.context
mock_get_gpfs_cluster_id.return_value = self.driver._cluster_id
mock_get_filesystem_from_path.return_value = '/dev/gpfs'
mock_verify_gpfs_pool.return_value = True
self.driver.do_setup(ctxt)
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._verify_gpfs_pool')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.'
'_get_filesystem_from_path')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._get_gpfs_cluster_id')
@patch('cinder.utils.execute')
def test_do_setup_fail_get_cluster_id(self,
mock_exec,
mock_get_gpfs_cluster_id,
mock_get_filesystem_from_path,
mock_verify_gpfs_pool):
ctxt = self.context
mock_get_gpfs_cluster_id.side_effect = (
processutils.ProcessExecutionError(stdout='test', stderr='test'))
mock_get_filesystem_from_path.return_value = '/dev/gpfs'
mock_verify_gpfs_pool.return_value = True
self.assertRaises(exception.VolumeBackendAPIException,
self.driver.do_setup, ctxt)
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._verify_gpfs_pool')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.'
'_get_filesystem_from_path')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._get_gpfs_cluster_id')
@patch('cinder.utils.execute')
def test_do_setup_fail_get_fs_from_path(self,
mock_exec,
mock_get_gpfs_cluster_id,
mock_get_fs_from_path,
mock_verify_gpfs_pool):
ctxt = self.context
mock_get_gpfs_cluster_id.return_value = self.driver._cluster_id
mock_get_fs_from_path.side_effect = (
processutils.ProcessExecutionError(stdout='test', stderr='test'))
mock_verify_gpfs_pool.return_value = True
self.assertRaises(exception.VolumeBackendAPIException,
self.driver.do_setup, ctxt)
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._verify_gpfs_pool')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.'
'_get_filesystem_from_path')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._get_gpfs_cluster_id')
@patch('cinder.utils.execute')
def test_do_setup_fail_volume(self,
mock_exec,
mock_get_gpfs_cluster_id,
mock_get_filesystem_from_path,
mock_verify_gpfs_pool):
ctxt = self.context
mock_get_gpfs_cluster_id. return_value = self.driver._cluster_id
mock_get_filesystem_from_path.return_value = '/dev/gpfs'
mock_verify_gpfs_pool.return_value = False
self.assertRaises(exception.VolumeBackendAPIException,
self.driver.do_setup, ctxt)
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._check_gpfs_state')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._is_gpfs_path')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.'
'_get_gpfs_fs_release_level')
def test_check_for_setup_error_fail_conf(self,
mock_get_gpfs_fs_rel_lev,
mock_is_gpfs_path,
mock_check_gpfs_state):
fake_fs = '/dev/gpfs'
fake_fs_release = 1400
fake_cluster_release = 1201
# fail configuration.gpfs_mount_point_base is None
org_value = self.driver.configuration.gpfs_mount_point_base
self.flags(volume_driver=self.driver_name, gpfs_mount_point_base=None)
mock_get_gpfs_fs_rel_lev.return_value = (fake_fs, fake_fs_release)
self.assertRaises(exception.VolumeBackendAPIException,
self.driver.check_for_setup_error)
self.flags(volume_driver=self.driver_name,
gpfs_mount_point_base=org_value)
# fail configuration.gpfs_images_share_mode not in
# ['copy_on_write', 'copy']
org_value = self.driver.configuration.gpfs_images_share_mode
self.flags(volume_driver=self.driver_name,
gpfs_images_share_mode='copy_on_read')
self.assertRaises(exception.VolumeBackendAPIException,
self.driver.check_for_setup_error)
self.flags(volume_driver=self.driver_name,
gpfs_images_share_mode=org_value)
# fail configuration.gpfs_images_share_mode and
# configuration.gpfs_images_dir is None
org_value_share_mode = self.driver.configuration.gpfs_images_share_mode
self.flags(volume_driver=self.driver_name,
gpfs_images_share_mode='copy')
org_value_dir = CONF.gpfs_images_dir
CONF.gpfs_images_dir = None
self.assertRaises(exception.VolumeBackendAPIException,
self.driver.check_for_setup_error)
self.flags(volume_driver=self.driver_name,
gpfs_images_share_mode=org_value_share_mode)
CONF.gpfs_images_dir = org_value_dir
# fail configuration.gpfs_images_share_mode == 'copy_on_write' and not
# _same_filesystem(configuration.gpfs_mount_point_base,
# configuration.gpfs_images_dir)
org_value = self.driver.configuration.gpfs_images_share_mode
self.flags(volume_driver=self.driver_name,
gpfs_images_share_mode='copy_on_write')
with mock.patch('cinder.volume.drivers.ibm.gpfs._same_filesystem',
return_value=False):
self.assertRaises(exception.VolumeBackendAPIException,
self.driver.check_for_setup_error)
self.flags(volume_driver=self.driver_name,
gpfs_images_share_mode=org_value)
# fail self.configuration.gpfs_images_share_mode == 'copy_on_write' and
# not self._is_same_fileset(self.configuration.gpfs_mount_point_base,
# self.configuration.gpfs_images_dir)
org_value = self.driver.configuration.gpfs_images_share_mode
self.flags(volume_driver=self.driver_name,
gpfs_images_share_mode='copy_on_write')
with mock.patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.'
'_is_same_fileset', return_value=False):
self.assertRaises(exception.VolumeBackendAPIException,
self.driver.check_for_setup_error)
self.flags(volume_driver=self.driver_name,
gpfs_images_share_mode=org_value)
# fail directory is None
org_value_share_mode = self.driver.configuration.gpfs_images_share_mode
self.flags(volume_driver=self.driver_name,
gpfs_images_share_mode=None)
org_value_dir = CONF.gpfs_images_dir
CONF.gpfs_images_dir = None
with mock.patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.'
'_get_gpfs_cluster_release_level',
return_value=fake_cluster_release):
self.driver.check_for_setup_error()
self.flags(volume_driver=self.driver_name,
gpfs_images_share_mode=org_value_share_mode)
CONF.gpfs_images_dir = org_value_dir
# fail directory.startswith('/')
org_value_mount = self.driver.configuration.gpfs_mount_point_base
self.flags(volume_driver=self.driver_name,
gpfs_mount_point_base='_' + self.volumes_path)
org_value_dir = CONF.gpfs_images_dir
CONF.gpfs_images_dir = None
with mock.patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.'
'_get_gpfs_cluster_release_level',
return_value=fake_cluster_release):
self.assertRaises(exception.VolumeBackendAPIException,
self.driver.check_for_setup_error)
self.flags(volume_driver=self.driver_name,
gpfs_mount_point_base=org_value_mount)
CONF.gpfs_images_dir = org_value_dir
# fail os.path.isdir(directory)
org_value_mount = self.driver.configuration.gpfs_mount_point_base
self.flags(volume_driver=self.driver_name,
gpfs_mount_point_base=self.volumes_path + '_')
org_value_dir = CONF.gpfs_images_dir
CONF.gpfs_images_dir = None
with mock.patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.'
'_get_gpfs_cluster_release_level',
return_value=fake_cluster_release):
self.assertRaises(exception.VolumeBackendAPIException,
self.driver.check_for_setup_error)
self.flags(volume_driver=self.driver_name,
gpfs_mount_point_base=org_value_mount)
CONF.gpfs_images_dir = org_value_dir
# fail not cluster release level >= GPFS_CLONE_MIN_RELEASE
org_fake_cluster_release = fake_cluster_release
fake_cluster_release = 1105
org_value_mount = self.driver.configuration.gpfs_mount_point_base
self.flags(volume_driver=self.driver_name,
gpfs_mount_point_base=self.volumes_path)
org_value_dir = CONF.gpfs_images_dir
CONF.gpfs_images_dir = None
with mock.patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.'
'_get_gpfs_cluster_release_level',
return_value=fake_cluster_release):
with mock.patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.'
'_get_gpfs_fs_release_level',
return_value=(fake_fs, fake_fs_release)):
self.assertRaises(exception.VolumeBackendAPIException,
self.driver.check_for_setup_error)
fake_cluster_release = org_fake_cluster_release
# fail not fs release level >= GPFS_CLONE_MIN_RELEASE
org_fake_fs_release = fake_fs_release
fake_fs_release = 1105
org_value_mount = self.driver.configuration.gpfs_mount_point_base
self.flags(volume_driver=self.driver_name,
gpfs_mount_point_base=self.volumes_path)
org_value_dir = CONF.gpfs_images_dir
CONF.gpfs_images_dir = None
with mock.patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.'
'_get_gpfs_cluster_release_level',
return_value=fake_cluster_release):
with mock.patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.'
'_get_gpfs_fs_release_level',
return_value=(fake_fs, fake_fs_release)):
self.assertRaises(exception.VolumeBackendAPIException,
self.driver.check_for_setup_error)
self.flags(volume_driver=self.driver_name,
gpfs_mount_point_base=org_value_mount)
CONF.gpfs_images_dir = org_value_dir
fake_fs_release = org_fake_fs_release
@patch('cinder.utils.execute')
def test_create_sparse_file(self, mock_exec):
self.driver._create_sparse_file('', 100)
@patch('cinder.utils.execute')
def test_allocate_file_blocks(self, mock_exec):
self.driver._allocate_file_blocks(os.path.join(self.images_dir,
'test'), 1)
@patch('cinder.utils.execute')
def test_gpfs_change_attributes(self, mock_exec):
options = []
options.extend(['-T', 'test'])
self.driver._gpfs_change_attributes(options, self.images_dir)
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._mkfs')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._gpfs_change_attributes')
def test_set_volume_attributes(self, mock_change_attributes, mock_mkfs):
metadata = [dict([('key', 'data_pool_name'), ('value', 'test')]),
dict([('key', 'replicas'), ('value', 'test')]),
dict([('key', 'dio'), ('value', 'test')]),
dict([('key', 'write_affinity_depth'), ('value', 'test')]),
dict([('key', 'block_group_factor'), ('value', 'test')]),
dict([('key', 'write_affinity_failure_group'),
('value', 'test')]),
dict([('key', 'test'),
('value', 'test')]),
dict([('key', 'fstype'),
('value', 'test')]),
dict([('key', 'fslabel'),
('value', 'test')]),
dict([('key', 'test'),
('value', 'test')])]
self.driver._set_volume_attributes('', '', metadata)
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._gpfs_change_attributes')
def test_set_volume_attributes_no_attributes(self, mock_change_attributes):
metadata = []
org_value = self.driver.configuration.gpfs_storage_pool
self.flags(volume_driver=self.driver_name, gpfs_storage_pool='system')
self.driver._set_volume_attributes('', '', metadata)
self.flags(volume_driver=self.driver_name,
gpfs_storage_pool=org_value)
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._gpfs_change_attributes')
def test_set_volume_attributes_no_options(self, mock_change_attributes):
metadata = []
org_value = self.driver.configuration.gpfs_storage_pool
self.flags(volume_driver=self.driver_name, gpfs_storage_pool='')
self.driver._set_volume_attributes('', '', metadata)
self.flags(volume_driver=self.driver_name,
gpfs_storage_pool=org_value)
@patch('cinder.utils.execute')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._allocate_file_blocks')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._set_volume_attributes')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._set_rw_permission')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._create_sparse_file')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.local_path')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._verify_gpfs_path_state')
def test_create_volume(self,
mock_gpfs_path_state,
mock_local_path,
mock_sparse_file,
mock_rw_permission,
mock_set_volume_attributes,
mock_allocate_file_blocks,
mock_exec):
mock_local_path.return_value = 'test'
volume = {}
volume['size'] = 1000
value = {}
value['value'] = 'test'
org_value = self.driver.configuration.gpfs_sparse_volumes
self.flags(volume_driver=self.driver_name, gpfs_sparse_volumes=False)
self.driver.create_volume(volume)
self.flags(volume_driver=self.driver_name,
gpfs_sparse_volumes=org_value)
@patch('cinder.utils.execute')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._allocate_file_blocks')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._set_volume_attributes')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._set_rw_permission')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._create_sparse_file')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.local_path')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._verify_gpfs_path_state')
def test_create_volume_no_sparse_volume(self,
mock_gpfs_path_state,
mock_local_path,
mock_sparse_file,
mock_rw_permission,
mock_set_volume_attributes,
mock_allocate_file_blocks,
mock_exec):
mock_local_path.return_value = 'test'
volume = {}
volume['size'] = 1000
value = {}
value['value'] = 'test'
org_value = self.driver.configuration.gpfs_sparse_volumes
self.flags(volume_driver=self.driver_name, gpfs_sparse_volumes=True)
self.driver.create_volume(volume)
self.flags(volume_driver=self.driver_name,
gpfs_sparse_volumes=org_value)
@patch('cinder.utils.execute')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._allocate_file_blocks')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._set_volume_attributes')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._set_rw_permission')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._create_sparse_file')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.local_path')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._verify_gpfs_path_state')
def test_create_volume_with_metadata(self,
mock_gpfs_path_state,
mock_local_path,
mock_sparse_file,
mock_rw_permission,
mock_set_volume_attributes,
mock_allocate_file_blocks,
mock_exec):
mock_local_path.return_value = 'test'
volume = {}
volume['size'] = 1000
value = {}
value['value'] = 'test'
mock_set_volume_attributes.return_value = True
metadata = [{'key': 'fake_key', 'value': 'fake_value'}]
org_value = self.driver.configuration.gpfs_sparse_volumes
self.flags(volume_driver=self.driver_name, gpfs_sparse_volumes=False)
self.driver.create_volume(volume)
self.assertEqual(True, self.driver._set_volume_attributes(volume,
'test', metadata))
self.flags(volume_driver=self.driver_name,
gpfs_sparse_volumes=org_value)
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._resize_volume_file')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._set_volume_attributes')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._gpfs_redirect')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._set_rw_permission')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._create_gpfs_copy')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.local_path')
def test_create_volume_from_snapshot(self,
mock_local_path,
mock_create_gpfs_copy,
mock_rw_permission,
mock_gpfs_redirect,
mock_set_volume_attributes,
mock_resize_volume_file):
mock_resize_volume_file.return_value = 5 * units.Gi
volume = {}
volume['size'] = 1000
self.assertEqual(self.driver.create_volume_from_snapshot(volume, ''),
{'size': 5.0})
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._resize_volume_file')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._set_volume_attributes')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._gpfs_redirect')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._set_rw_permission')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._create_gpfs_copy')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.local_path')
def test_create_volume_from_snapshot_metadata(self,
mock_local_path,
mock_create_gpfs_copy,
mock_rw_permission,
mock_gpfs_redirect,
mock_set_volume_attributes,
mock_resize_volume_file):
mock_resize_volume_file.return_value = 5 * units.Gi
volume = {}
volume['size'] = 1000
mock_set_volume_attributes.return_value = True
metadata = [{'key': 'fake_key', 'value': 'fake_value'}]
self.assertEqual(True, self.driver._set_volume_attributes(volume,
'test', metadata))
self.assertEqual(self.driver.create_volume_from_snapshot(volume, ''),
{'size': 5.0})
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._resize_volume_file')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._set_volume_attributes')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._set_rw_permission')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._create_gpfs_clone')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.local_path')
def test_create_cloned_volume(self,
mock_local_path,
mock_create_gpfs_clone,
mock_rw_permission,
mock_set_volume_attributes,
mock_resize_volume_file):
mock_resize_volume_file.return_value = 5 * units.Gi
volume = {}
volume['size'] = 1000
self.assertEqual(self.driver.create_cloned_volume(volume, ''),
{'size': 5.0})
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._resize_volume_file')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._set_volume_attributes')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._set_rw_permission')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._create_gpfs_clone')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.local_path')
def test_create_cloned_volume_with_metadata(self,
mock_local_path,
mock_create_gpfs_clone,
mock_rw_permission,
mock_set_volume_attributes,
mock_resize_volume_file):
mock_resize_volume_file.return_value = 5 * units.Gi
volume = {}
volume['size'] = 1000
mock_set_volume_attributes.return_value = True
metadata = [{'key': 'fake_key', 'value': 'fake_value'}]
self.assertEqual(True, self.driver._set_volume_attributes(volume,
'test', metadata))
self.assertEqual(self.driver.create_cloned_volume(volume, ''),
{'size': 5.0})
@patch('cinder.utils.execute')
def test_delete_gpfs_file_ok(self, mock_exec):
mock_exec.side_effect = [('Parent Depth Parent inode File name\n'
'------ ----- -------------- ---------\n'
' no 2 148488 '
'/gpfs0/test.txt', ''),
('', ''),
('', '')]
self.driver._delete_gpfs_file(self.images_dir)
self.driver._delete_gpfs_file(self.images_dir + '_')
mock_exec.side_effect = [('Parent Depth Parent inode File name\n'
'------ ----- -------------- ---------\n'
' '
'/gpfs0/test.txt', ''),
('', '')]
self.driver._delete_gpfs_file(self.images_dir)
@patch('os.path.exists')
@patch('cinder.utils.execute')
def test_delete_gpfs_file_ok_parent(self, mock_exec, mock_path_exists):
mock_path_exists.side_effect = [True, False, False,
True, False, False,
True, False, False]
mock_exec.side_effect = [('Parent Depth Parent inode File name\n'
'------ ----- -------------- ---------\n'
' no 2 148488 '
'/gpfs0/test.txt', ''),
('/gpfs0/test.snap\ntest', ''),
('', '')]
self.driver._delete_gpfs_file(self.images_dir)
mock_exec.side_effect = [('Parent Depth Parent inode File name\n'
'------ ----- -------------- ---------\n'
' no 2 148488 '
'/gpfs0/test.txt', ''),
('/gpfs0/test.ts\ntest', ''),
('', '')]
self.driver._delete_gpfs_file(self.images_dir)
mock_exec.side_effect = [('Parent Depth Parent inode File name\n'
'------ ----- -------------- ---------\n'
' no 2 148488 '
'/gpfs0/test.txt', ''),
('/gpfs0/test.txt\ntest', ''),
('', '')]
self.driver._delete_gpfs_file(self.images_dir)
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._delete_gpfs_file')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.local_path')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._verify_gpfs_path_state')
def test_delete_volume(self,
mock_verify_gpfs_path_state,
mock_local_path,
mock_delete_gpfs_file):
self.driver.delete_volume('')
@patch('cinder.utils.execute')
def test_gpfs_redirect_ok(self, mock_exec):
org_value = self.driver.configuration.gpfs_max_clone_depth
self.flags(volume_driver=self.driver_name, gpfs_max_clone_depth=1)
mock_exec.side_effect = [('Parent Depth Parent inode File name\n'
'------ ----- -------------- ---------\n'
' no 2 148488 '
'/gpfs0/test.txt', ''),
('', '')]
self.assertEqual(True, self.driver._gpfs_redirect(''))
self.flags(volume_driver=self.driver_name, gpfs_max_clone_depth=1)
mock_exec.side_effect = [('Parent Depth Parent inode File name\n'
'------ ----- -------------- ---------\n'
' no 1 148488 '
'/gpfs0/test.txt', ''),
('', '')]
self.assertEqual(False, self.driver._gpfs_redirect(''))
self.flags(volume_driver=self.driver_name,
gpfs_max_clone_depth=org_value)
@patch('cinder.utils.execute')
def test_gpfs_redirect_fail_depth(self, mock_exec):
org_value = self.driver.configuration.gpfs_max_clone_depth
self.flags(volume_driver=self.driver_name, gpfs_max_clone_depth=0)
mock_exec.side_effect = [('Parent Depth Parent inode File name\n'
'------ ----- -------------- ---------\n'
' no 2 148488 '
'/gpfs0/test.txt', ''),
('', '')]
self.assertEqual(False, self.driver._gpfs_redirect(''))
self.flags(volume_driver=self.driver_name,
gpfs_max_clone_depth=org_value)
@patch('cinder.utils.execute')
def test_gpfs_redirect_fail_match(self, mock_exec):
org_value = self.driver.configuration.gpfs_max_clone_depth
self.flags(volume_driver=self.driver_name, gpfs_max_clone_depth=1)
mock_exec.side_effect = [('Parent Depth Parent inode File name\n'
'------ ----- -------------- ---------\n'
' 148488 '
'/gpfs0/test.txt', ''),
('', '')]
self.assertEqual(False, self.driver._gpfs_redirect(''))
self.flags(volume_driver=self.driver_name,
gpfs_max_clone_depth=org_value)
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._create_gpfs_snap')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._create_gpfs_copy')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._gpfs_redirect')
@patch('cinder.utils.execute')
def test_create_gpfs_clone(self,
mock_exec,
mock_redirect,
mock_cr_gpfs_cp,
mock_cr_gpfs_snap):
mock_redirect.return_value = True
self.driver._create_gpfs_clone('', '')
mock_redirect.side_effect = [True, False]
self.driver._create_gpfs_clone('', '')
@patch('cinder.utils.execute')
def test_create_gpfs_copy(self, mock_exec):
self.driver._create_gpfs_copy('', '')
@patch('cinder.utils.execute')
def test_create_gpfs_snap(self, mock_exec):
self.driver._create_gpfs_snap('')
self.driver._create_gpfs_snap('', '')
@patch('cinder.utils.execute')
def test_is_gpfs_parent_file_ok(self, mock_exec):
mock_exec.side_effect = [('Parent Depth Parent inode File name\n'
'------ ----- -------------- ---------\n'
' yes 2 148488 '
'/gpfs0/test.txt', ''),
('Parent Depth Parent inode File name\n'
'------ ----- -------------- ---------\n'
' no 2 148488 '
'/gpfs0/test.txt', '')]
self.assertEqual(True, self.driver._is_gpfs_parent_file(''))
self.assertEqual(False, self.driver._is_gpfs_parent_file(''))
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._gpfs_redirect')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._set_rw_permission')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._create_gpfs_snap')
@patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver.local_path')
def test_create_snapshot(self,
mock_local_path,
mock_create_gpfs_snap,
mock_set_rw_permission,
mock_gpfs_redirect):
org_value = self.driver.configuration.gpfs_mount_point_base
self.flags(volume_driver=self.driver_name,
gpfs_mount_point_base=self.volumes_path)