summaryrefslogtreecommitdiff
path: root/spec/cinder_common_spec.rb
blob: 616643366e73ce2a42c7e9e4729602ffd6ad8777 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
# encoding: utf-8
#
# Cookbook Name:: openstack-block-storage

require_relative 'spec_helper'

describe 'openstack-block-storage::cinder-common' do
  describe 'ubuntu' do
    let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
    let(:node) { runner.node }
    let(:chef_run) do
      node.set['openstack']['mq']['host'] = '127.0.0.1'
      node.set['openstack']['mq']['block-storage']['rabbit']['notification_topic'] = 'rabbit_topic'

      runner.converge(described_recipe)
    end

    include_context 'block-storage-stubs'

    it 'upgrades the cinder-common package' do
      expect(chef_run).to upgrade_package 'cinder-common'
    end

    describe '/etc/cinder' do
      let(:dir) { chef_run.directory('/etc/cinder') }

      it 'should create the /etc/cinder directory' do
        expect(chef_run).to create_directory(dir.name)
      end

      it 'has proper owner' do
        expect(dir.owner).to eq('cinder')
        expect(dir.group).to eq('cinder')
      end

      it 'has proper modes' do
        expect(sprintf('%o', dir.mode)).to eq '750'
      end
    end

    describe 'cinder.conf' do
      let(:file) { chef_run.template('/etc/cinder/cinder.conf') }
      let(:test_pass) { 'test_pass' }
      before do
        allow_any_instance_of(Chef::Recipe).to receive(:get_password)
          .with('user', anything)
          .and_return(test_pass)
      end

      it 'should create the cinder.conf template' do
        expect(chef_run).to create_template(file.name)
      end

      it 'has proper owner' do
        expect(file.owner).to eq('cinder')
        expect(file.group).to eq('cinder')
      end

      it 'has proper modes' do
        expect(sprintf('%o', file.mode)).to eq '640'
      end

      context 'keystone authtoken attributes with default values' do
        it 'sets memcached server(s)' do
          expect(chef_run).not_to render_file(file.name).with_content(/^memcached_servers = $/)
        end

        it 'sets memcache security strategy' do
          expect(chef_run).not_to render_file(file.name).with_content(/^memcache_security_strategy = $/)
        end

        it 'sets memcache secret key' do
          expect(chef_run).not_to render_file(file.name).with_content(/^memcache_secret_key = $/)
        end

        it 'sets cafile' do
          expect(chef_run).not_to render_file(file.name).with_content(/^cafile = $/)
        end

        it 'sets insecure' do
          expect(chef_run).to render_file(file.name).with_content(/^insecure = false$/)
        end

        it 'sets token hash algorithms' do
          expect(chef_run).to render_file(file.name).with_content(/^hash_algorithms = md5$/)
        end
      end

      context 'keystone authtoken attributes' do
        it 'has signing_dir' do
          node.set['openstack']['block-storage']['api']['auth']['cache_dir'] = 'auth_cache_dir'

          expect(chef_run).to render_file(file.name).with_content(/^signing_dir = auth_cache_dir$/)
        end

        it 'sets memcached server(s)' do
          node.set['openstack']['block-storage']['api']['auth']['memcached_servers'] = 'localhost:11211'
          expect(chef_run).to render_file(file.name).with_content(/^memcached_servers = localhost:11211$/)
        end

        it 'sets memcache security strategy' do
          node.set['openstack']['block-storage']['api']['auth']['memcache_security_strategy'] = 'MAC'
          expect(chef_run).to render_file(file.name).with_content(/^memcache_security_strategy = MAC$/)
        end

        it 'sets memcache secret key' do
          node.set['openstack']['block-storage']['api']['auth']['memcache_secret_key'] = '0123456789ABCDEF'
          expect(chef_run).to render_file(file.name).with_content(/^memcache_secret_key = 0123456789ABCDEF$/)
        end

        it 'sets cafile' do
          node.set['openstack']['block-storage']['api']['auth']['cafile'] = 'dir/to/path'
          expect(chef_run).to render_file(file.name).with_content(%r{^cafile = dir/to/path$})
        end

        it 'sets insecure' do
          node.set['openstack']['block-storage']['api']['auth']['insecure'] = true
          expect(chef_run).to render_file(file.name).with_content(/^insecure = true$/)
        end

        it 'sets token hash algorithms' do
          node.set['openstack']['block-storage']['api']['auth']['hash_algorithms'] = 'sha2'
          expect(chef_run).to render_file(file.name).with_content(/^hash_algorithms = sha2$/)
        end

        context 'endpoint related' do

          it 'has auth_uri' do
            expect(chef_run).to render_file(file.name).with_content(%r(^auth_uri = http://127.0.0.1:5000/v2.0$))
          end

          it 'has identity_uri' do
            expect(chef_run).to render_file(file.name).with_content(%r(^identity_uri = http://127.0.0.1:35357/$))
          end
        end

        it 'has no auth_version when auth_version is v2.0' do
          node.set['openstack']['block-storage']['api']['auth']['version'] = 'v2.0'

          expect(chef_run).not_to render_file(file.name).with_content(/^auth_version = v2.0$/)
        end

        it 'has auth_version when auth version is not v2.0' do
          node.set['openstack']['block-storage']['api']['auth']['version'] = 'v3.0'

          expect(chef_run).to render_file(file.name).with_content(/^auth_version = v3.0$/)
        end

        it 'has an admin tenant name' do
          node.set['openstack']['block-storage']['service_tenant_name'] = 'tenant_name'

          expect(chef_run).to render_file(file.name).with_content(/^admin_tenant_name = tenant_name$/)
        end

        it 'has an admin user' do
          node.set['openstack']['block-storage']['service_user'] = 'username'

          expect(chef_run).to render_file(file.name).with_content(/^admin_user = username$/)
        end

        it 'has an admin password' do
          # (fgimenez) the get_password mocking is set in spec/spec_helper.rb
          expect(chef_run).to render_file(file.name).with_content(/^admin_password = cinder-pass$/)
        end
      end

      context 'template contents' do

        context 'commonly named attributes' do
          %w(debug verbose host notification_driver
             storage_availability_zone quota_volumes quota_gigabytes quota_driver
             volume_name_template snapshot_name_template osapi_volume_workers
             use_default_quota_class quota_snapshots no_snapshot_gb_quota
             control_exchange max_gigabytes).each do |attr_key|
            it "has a #{attr_key} attribute" do
              node.set['openstack']['block-storage'][attr_key] = "#{attr_key}_value"

              expect(chef_run).to render_config_file(file.name).with_section_content('DEFAULT', /^#{attr_key}=#{attr_key}_value$/)
            end
          end
        end

        context 'backup swift backend contents' do
          before do
            node.set['openstack']['block-storage']['backup']['enabled'] = true
            node.set['openstack']['block-storage']['backup']['driver'] = 'cinder.backup.drivers.swift'
          end

          it 'has default attributes' do
            %w(swift_catalog_info=object-store:swift:publicURL
               backup_swift_auth=per_user
               backup_swift_auth_version=1
               backup_swift_container=volumebackups
               backup_swift_object_size=52428800
               backup_swift_block_size=32768
               backup_swift_retry_attempts=3
               backup_swift_retry_backoff=2
               backup_swift_enable_progress_timer=True).each do |attr|
              expect(chef_run).to render_config_file(file.name).with_section_content('DEFAULT', /^#{attr}$/)
            end
          end

          it 'has override attributes' do
            %w(url
               auth
               auth_version
               tenant
               user
               key
               container
               object_size
               block_size
               retry_attempts
               retry_backoff
               enable_progress_timer).each do |attr|
              node.set['openstack']['block-storage']['backup']['swift'][attr] = "backup_swift_#{attr}"
              expect(chef_run).to render_config_file(file.name).with_section_content('DEFAULT', /^backup_swift_#{attr}=backup_swift_#{attr}$/)
            end
          end

          it 'has a custom catalog_info' do
            node.set['openstack']['block-storage']['backup']['swift']['catalog_info'] = 'swift_catalog_info'
            expect(chef_run).to render_config_file(file.name).with_section_content('DEFAULT', /^swift_catalog_info=swift_catalog_info$/)
          end
        end

        context 'rdb driver' do
          # FIXME(galstrom21): this block needs to check all of the default
          #   rdb_* configuration options
          it 'has default rbd_* options set' do
            node.set['openstack']['block-storage']['volume'] = {
              'driver' => 'cinder.volume.drivers.rbd.RBDDriver'
            }
            expect(chef_run).to render_file(file.name).with_content(/^rbd_/)
            expect(chef_run).not_to render_file(file.name).with_content(/^netapp_/)
          end
        end

        it 'has a lock_path attribute' do
          expect(chef_run).to render_config_file(file.name).with_section_content('oslo_concurrency', %r(^lock_path=/var/lib/cinder/lock$))
        end

        it 'does not have unique host id by default' do
          expect(chef_run).not_to render_config_file(file.name).with_section_content('DEFAULT', /^host=/)
        end

        context 'netapp driver' do
          # FIXME(galstrom21): this block needs to check all of the default
          #   netapp_* configuration options
          it 'has default netapp_* options set' do
            node.set['openstack']['block-storage']['volume'] = {
              'driver' => 'cinder.volume.drivers.netapp.NetAppISCSIDriver'
            }
            expect(chef_run).to render_file(file.name).with_content(/^netapp_/)
            expect(chef_run).not_to render_file(file.name).with_content(/^rbd_/)
          end
        end

        context 'syslog use' do
          it 'sets the log_config value when syslog is in use' do
            node.set['openstack']['block-storage']['syslog']['use'] = true

            expect(chef_run).to render_file(file.name)
              .with_content(%r{^log_config = /etc/openstack/logging.conf$})
          end

          it 'sets the log_file value when syslog is not in use' do
            node.set['openstack']['block-storage']['syslog']['use'] = false

            expect(chef_run).to render_file(file.name)
              .with_content(%r{^log_file = /var/log/cinder/cinder.log$})
          end
        end

        it 'has a db connection attribute' do
          allow_any_instance_of(Chef::Recipe).to receive(:db_uri)
            .with('block-storage', anything, '').and_return('sql_connection_value')

          expect(chef_run).to render_config_file(file.name)
            .with_section_content('database', /^connection=sql_connection_value$/)
        end

        it 'has a db backend attribute' do
          expect(chef_run).to render_config_file(file.name).with_section_content('database', /^backend=sqlalchemy$/)
        end

        it 'has a volume_driver attribute' do
          node.set['openstack']['block-storage']['volume']['driver'] = 'volume_driver_value'
          expect(chef_run).to render_file(file.name).with_content(/^volume_driver=volume_driver_value$/)
        end

        it 'has a state_path attribute' do
          node.set['openstack']['block-storage']['volume']['state_path'] = 'state_path_value'
          expect(chef_run).to render_file(file.name).with_content(/^state_path=state_path_value$/)
        end

        context 'glance endpoint' do
          it 'has a glance_api_servers attribute' do
            expect(chef_run).to render_file(file.name).with_content(%r{^glance_api_servers=http://127.0.0.1:9292$})
          end

          it 'has glance_api_version attribute' do
            expect(chef_run).to render_file(file.name).with_content(/^glance_api_version=1$/)
          end

          it 'has a glance_api_insecure attribute' do
            expect(chef_run).to render_file(file.name).with_content(/^glance_api_insecure=false$/)
          end

          it 'sets insecure for glance' do
            node.set['openstack']['block-storage']['image']['glance_api_insecure'] = true
            expect(chef_run).to render_file(file.name).with_content(/^glance_api_insecure=true$/)
          end

          it 'has a glance_ca_certificates_file attribute' do
            expect(chef_run).to render_file(file.name).with_content(/^glance_ca_certificates_file=$/)
          end

          it 'sets glance_ca_certificates_file attribute' do
            node.set['openstack']['block-storage']['image']['glance_ca_certificates_file'] = 'dir/to/path'
            expect(chef_run).to render_file(file.name).with_content(%r{^glance_ca_certificates_file=dir/to/path$})
          end

          it 'has a glance host attribute' do
            expect(chef_run).to render_file(file.name).with_content(/^glance_host=127.0.0.1$/)
          end

          it 'has a glance port attribute' do
            expect(chef_run).to render_file(file.name).with_content(/^glance_port=9292$/)
          end
        end

        it 'has a api_rate_limit attribute' do
          node.set['openstack']['block-storage']['api']['ratelimit'] = 'api_rate_limit_value'
          expect(chef_run).to render_file(file.name).with_content(/^api_rate_limit=api_rate_limit_value$/)
        end

        context 'cinder endpoint' do
          it 'has osapi_volume_listen set' do
            expect(chef_run).to render_file(file.name).with_content(/^osapi_volume_listen=127.0.0.1$/)
          end

          it 'has osapi_volume_listen_port set' do
            expect(chef_run).to render_file(file.name).with_content(/^osapi_volume_listen_port=8776$/)
          end

          it 'has default api version set' do
            [/^enable_v1_api=False$/,
             /^enable_v2_api=True$/].each do |line|
              expect(chef_run).to render_config_file(file.name).with_section_content('DEFAULT', line)
            end
          end

          it 'has override api version set' do
            node.set['openstack']['block-storage']['enable_v1_api'] = 'True'
            node.set['openstack']['block-storage']['enable_v2_api'] = 'False'
            [/^enable_v1_api=True$/,
             /^enable_v2_api=False$/].each do |line|
              expect(chef_run).to render_config_file(file.name).with_section_content('DEFAULT', line)
            end
          end
        end

        it 'has a rpc_backend attribute' do
          node.set['openstack']['block_storage']['rpc_backend'] = 'rpc_backend_value'
          expect(chef_run).to render_file(file.name).with_content(/^rpc_backend=rpc_backend_value$/)
        end

        it 'has default RPC/AMQP options set' do
          [/^rpc_backend=cinder.openstack.common.rpc.impl_kombu$/,
           /^rpc_thread_pool_size=64$/,
           /^rpc_response_timeout=60$/].each do |line|
            expect(chef_run).to render_file(file.name).with_content(line)
          end
        end

        context 'rabbitmq as mq service' do
          before do
            node.set['openstack']['mq']['block-storage']['service_type'] = 'rabbitmq'
          end

          it 'has default RPC/AMQP options set' do
            [/^rpc_conn_pool_size=30$/,
             /^amqp_durable_queues=false$/,
             /^amqp_auto_delete=false$/].each do |line|
              expect(chef_run).to render_config_file(file.name).with_section_content('oslo_messaging_rabbit', line)
            end
          end

          context 'ha attributes' do
            before do
              node.set['openstack']['mq']['block-storage']['rabbit']['ha'] = true
            end

            it 'has a rabbit_hosts attribute' do
              allow_any_instance_of(Chef::Recipe).to receive(:rabbit_servers)
                .and_return('rabbit_servers_value')

              expect(chef_run).to render_config_file(file.name).with_section_content('oslo_messaging_rabbit', /^rabbit_hosts=rabbit_servers_value$/)
            end

            %w(host port).each do |attr|
              it "does not have rabbit_#{attr} attribute" do
                expect(chef_run).not_to render_config_file(file.name).with_section_content('oslo_messaging_rabbit', /^rabbit_#{attr}=/)
              end
            end
          end

          context 'non ha attributes' do
            before do
              node.set['openstack']['mq']['block-storage']['rabbit']['ha'] = false
            end

            %w(host port).each do |attr|
              it "has rabbit_#{attr} attribute" do
                node.set['openstack']['mq']['block-storage']['rabbit'][attr] = "rabbit_#{attr}_value"
                expect(chef_run).to render_config_file(file.name).with_section_content('oslo_messaging_rabbit', /^rabbit_#{attr}=rabbit_#{attr}_value$/)
              end
            end

            it 'does not have a rabbit_hosts attribute' do
              expect(chef_run).not_to render_config_file(file.name).with_section_content('oslo_messaging_rabbit', /^rabbit_hosts=/)
            end
          end

          %w(use_ssl userid).each do |attr|
            it "has rabbit_#{attr}" do
              node.set['openstack']['mq']['block-storage']['rabbit'][attr] = "rabbit_#{attr}_value"
              expect(chef_run).to render_config_file(file.name).with_section_content('oslo_messaging_rabbit', /^rabbit_#{attr}=rabbit_#{attr}_value$/)
            end
          end

          it 'has rabbit_password' do
            expect(chef_run).to render_config_file(file.name).with_section_content('oslo_messaging_rabbit', /^rabbit_password=#{test_pass}$/)
          end

          it 'has rabbit_virtual_host' do
            node.set['openstack']['mq']['block-storage']['rabbit']['vhost'] = 'vhost_value'
            expect(chef_run).to render_config_file(file.name).with_section_content('oslo_messaging_rabbit', /^rabbit_virtual_host=vhost_value$/)
          end

          it 'does not have kombu ssl version set' do
            expect(chef_run).not_to render_config_file(file.name).with_section_content('oslo_messaging_rabbit', /^kombu_ssl_version=TLSv1.2$/)
          end

          it 'sets kombu ssl version' do
            node.set['openstack']['mq']['block-storage']['rabbit']['use_ssl'] = true
            node.set['openstack']['mq']['block-storage']['rabbit']['kombu_ssl_version'] = 'TLSv1.2'

            expect(chef_run).to render_config_file(file.name).with_section_content('oslo_messaging_rabbit', /^kombu_ssl_version=TLSv1.2$/)
          end
        end

        context 'qpid as mq service' do
          before do
            node.set['openstack']['mq']['block-storage']['service_type'] = 'qpid'
          end

          it 'has default RPC/AMQP options set' do
            [/^rpc_conn_pool_size=30$/,
             /^amqp_durable_queues=false$/,
             /^amqp_auto_delete=false$/].each do |line|
              expect(chef_run).to render_config_file(file.name).with_section_content('oslo_messaging_qpid', line)
            end
          end

          %w(port username sasl_mechanisms reconnect reconnect_timeout reconnect_limit
             reconnect_interval_min reconnect_interval_max reconnect_interval heartbeat protocol
             tcp_nodelay).each do |attr|
            it "has qpid_#{attr} attribute" do
              node.set['openstack']['mq']['block-storage']['qpid'][attr] = "qpid_#{attr}_value"
              expect(chef_run).to render_config_file(file.name).with_section_content('oslo_messaging_qpid', /^qpid_#{attr}=qpid_#{attr}_value$/)
            end
          end

          it 'has qpid_hostname' do
            node.set['openstack']['mq']['block-storage']['qpid']['host'] = 'qpid_host_value'
            expect(chef_run).to render_config_file(file.name).with_section_content('oslo_messaging_qpid', /^qpid_hostname=qpid_host_value$/)
          end

          it 'has qpid_password' do
            expect(chef_run).to render_config_file(file.name).with_section_content('oslo_messaging_qpid', /^qpid_password=#{test_pass}$/)
          end

          it 'has default qpid topology version' do
            expect(chef_run).to render_config_file(file.name).with_section_content('oslo_messaging_qpid', /^qpid_topology_version=1$/)
          end

          it 'has qpid notification_topics' do
            node.set['openstack']['mq']['block-storage']['qpid']['notification_topic'] = 'qpid_notification_topic_value'
            expect(chef_run).to render_config_file(file.name).with_section_content('oslo_messaging_qpid', /^notification_topics=qpid_notification_topic_value$/)
          end
        end

        context 'lvm settings' do
          before do
            node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.lvm.LVMVolumeDriver'
          end

          %w(group clear clear_size).each do |attr|
            it "has lvm volume_#{attr} attribute" do
              node.set['openstack']['block-storage']['volume']["volume_#{attr}"] = "volume_#{attr}_value"
              expect(chef_run).to render_file(file.name).with_content(/^volume_#{attr}=volume_#{attr}_value$/)
            end
          end
        end

        context 'commonly named volume attributes' do
          %w(iscsi_ip_address iscsi_port iscsi_helper volumes_dir).each do |attr|
            it "has volume related #{attr} attribute" do
              node.set['openstack']['block-storage']['volume'][attr] = "common_volume_#{attr}_value"
              expect(chef_run).to render_file(file.name).with_content(/^#{attr}=common_volume_#{attr}_value$/)
            end
          end
        end

        context 'rbd attributes' do
          before do
            node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.rbd.RBDDriver'
          end

          it 'has a rbd_pool attribute' do
            node.set['openstack']['block-storage']['rbd']['cinder']['pool'] = 'cinder_value'
            expect(chef_run).to render_file(file.name).with_content(/^rbd_pool=cinder_value$/)
          end
          it 'has a rbd_user attribute' do
            node.set['openstack']['block-storage']['rbd']['user'] = 'rbd_user_value'
            expect(chef_run).to render_file(file.name).with_content(/^rbd_user=rbd_user_value$/)
          end
          it 'has a rbd_secret_uuid attribute' do
            node.set['openstack']['block-storage']['rbd']['secret_uuid'] = 'rbd_secret_uuid_value'
            expect(chef_run).to render_file(file.name).with_content(/^rbd_secret_uuid=rbd_secret_uuid_value$/)
          end
        end

        it 'has volume_driver attribute' do
          node.set['openstack']['block-storage']['volume']['driver'] = 'volume_driver_value'
          expect(chef_run).to render_file(file.name).with_content(/^volume_driver=volume_driver_value$/)
        end

        context 'netapp ISCSI settings' do
          before do
            node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.netapp.NetAppISCSIDriver'
          end

          %w(login password).each do |attr|
            it "has a netapp_#{attr} attribute" do
              node.set['openstack']['block-storage']['netapp']["dfm_#{attr}"] = "dfm_#{attr}_value"
              expect(chef_run).to render_file(file.name).with_content(/^netapp_#{attr}=dfm_#{attr}_value$/)
            end
          end

          %w(hostname port).each do |attr|
            it "has a netapp_server_#{attr} attribute" do
              node.set['openstack']['block-storage']['netapp']["dfm_#{attr}"] = "dfm_#{attr}_value"
              expect(chef_run).to render_file(file.name).with_content(/^netapp_server_#{attr}=dfm_#{attr}_value$/)
            end
          end

          it 'has a netapp_storage_service attribute' do
            node.set['openstack']['block-storage']['netapp']['storage_service'] = 'netapp_storage_service_value'
            expect(chef_run).to render_file(file.name).with_content(/^netapp_storage_service=netapp_storage_service_value$/)
          end
        end

        context 'netapp direct7 mode nfs settings' do
          let(:hostnames) { %w(hostname1 hostname2 hostname3) }
          before do
            node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.netapp.nfs.NetAppDirect7modeNfsDriver'
            node.set['openstack']['block-storage']['netapp']['netapp_server_hostname'] = hostnames
          end

          %w(mount_point_base shares_config).each do |attr_key|
            it "has a nfs_#{attr_key} attribute" do
              node.set['openstack']['block-storage']['nfs'][attr_key] = "netapp_nfs_#{attr_key}_value"
              expect(chef_run).to render_file(file.name).with_content(/^nfs_#{attr_key}=netapp_nfs_#{attr_key}_value$/)
            end
          end

          it 'has netapp server_hostname attributes' do
            hostnames.each do |hostname|
              expect(chef_run).to render_file(file.name).with_content(/^netapp_server_hostname=#{hostname}$/)
            end
          end

          it 'has a netapp_server_port attribute' do
            node.set['openstack']['block-storage']['netapp']['netapp_server_port'] = 'netapp_server_port_value'
            expect(chef_run).to render_file(file.name).with_content(/^netapp_server_port=netapp_server_port_value$/)
          end

          %w(login password).each do |attr|
            it "has a netapp_#{attr} attribute" do
              node.set['openstack']['block-storage']['netapp']["netapp_server_#{attr}"] = "netapp_#{attr}_value"
              expect(chef_run).to render_file(file.name).with_content(/^netapp_#{attr}=netapp_#{attr}_value$/)
            end
          end

          %w(disk_util sparsed_volumes).each do |attr|
            it "has a nfs_#{attr} attribute" do
              node.set['openstack']['block-storage']['nfs']["nfs_#{attr}"] = "netapp_nfs_#{attr}_value"
              expect(chef_run).to render_file(file.name).with_content(/^nfs_#{attr}=netapp_nfs_#{attr}_value$/)
            end
          end
        end

        context 'ibmnas settings' do
          before do
            node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.ibm.ibmnas.IBMNAS_NFSDriver'
          end

          %w(mount_point_base shares_config).each do |attr|
            it "has a ibmnas_#{attr} attribute" do
              node.set['openstack']['block-storage']['ibmnas'][attr] = "ibmnas_#{attr}_value"
              expect(chef_run).to render_file(file.name).with_content(/^nfs_#{attr}=ibmnas_#{attr}_value$/)
            end
          end

          it 'has a nfs_sparsed_volumes attribute' do
            node.set['openstack']['block-storage']['ibmnas']['nfs_sparsed_volumes'] = 'ibmnas_nfs_sparsed_volumes_value'
            expect(chef_run).to render_file(file.name).with_content(/^nfs_sparsed_volumes=ibmnas_nfs_sparsed_volumes_value$/)
          end

          %w(nas_ip nas_login nas_ssh_port ibmnas_platform_type).each do |attr|
            it "has a ibmnas #{attr} attribute" do
              node.set['openstack']['block-storage']['ibmnas'][attr] = "ibmnas_#{attr}_value"
              expect(chef_run).to render_file(file.name).with_content(/^#{attr}=ibmnas_#{attr}_value$/)
            end
          end

          it 'has a default attributes' do
            %w(nas_ip=127.0.0.1
               nas_login=admin
               nas_password=test_pass
               nas_ssh_port=22
               ibmnas_platform_type=v7ku
               nfs_sparsed_volumes=true
               nfs_mount_point_base=/mnt/cinder-volumes
               nfs_shares_config=/etc/cinder/nfs_shares.conf).each do |attr|
              expect(chef_run).to render_file(file.name).with_content(/^#{attr}$/)
            end
          end
        end

        context 'storwize settings' do
          before do
            node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.ibm.storwize_svc.StorwizeSVCDriver'
          end

          it 'has a default attribute' do
            %w(san_ip=127.0.0.1
               san_private_key=/v7000_rsa
               storwize_svc_volpool_name=volpool
               storwize_svc_vol_rsize=2
               storwize_svc_vol_warning=0
               storwize_svc_vol_autoexpand=true
               storwize_svc_vol_grainsize=256
               storwize_svc_vol_compression=false
               storwize_svc_vol_easytier=true
               storwize_svc_vol_iogrp=0
               storwize_svc_flashcopy_timeout=120
               storwize_svc_connection_protocol=iSCSI
               storwize_svc_iscsi_chap_enabled=true
               storwize_svc_multihostmap_enabled=true
               storwize_svc_allow_tenant_qos=false).each do |attr|
              expect(chef_run).to render_file(file.name).with_content(/^#{attr}$/)
            end
          end

          it 'has a overridden attribute' do
            %w(san_ip
               san_private_key
               storwize_svc_volpool_name
               storwize_svc_vol_rsize
               storwize_svc_vol_warning
               storwize_svc_vol_autoexpand
               storwize_svc_vol_grainsize
               storwize_svc_vol_compression
               storwize_svc_vol_easytier
               storwize_svc_vol_iogrp
               storwize_svc_flashcopy_timeout
               storwize_svc_connection_protocol
               storwize_svc_multihostmap_enabled
               storwize_svc_allow_tenant_qos
               storwize_svc_stretched_cluster_partner).each do |attr|
              node.set['openstack']['block-storage']['storwize'][attr] = "storwize_#{attr}_value"
              expect(chef_run).to render_file(file.name).with_content(/^#{attr}=storwize_#{attr}_value$/)
            end
          end

          context 'storwize with login and password' do
            it 'has a login and password' do
              node.set['openstack']['block-storage']['storwize']['san_private_key'] = ''
              %w(san_login=admin
                 san_password=test_pass
                 san_private_key=).each do |attr|
                expect(chef_run).to render_file(file.name).with_content(/^#{attr}$/)
              end
            end
          end

          context 'storwize with iSCSI connection protocol' do
            before do
              node.set['openstack']['block-storage']['storwize']['storwize_svc_connection_protocol'] = 'iSCSI'
            end

            it 'has a iscsi chap enabled attribute' do
              node.set['openstack']['block-storage']['storwize']['storwize_svc_iscsi_chap_enabled'] = 'storwize_svc_iscsi_chap_enabled_value'
              expect(chef_run).to render_file(file.name).with_content(/^storwize_svc_iscsi_chap_enabled=storwize_svc_iscsi_chap_enabled_value$/)
            end

            it 'does not have a multipath enabled attribute' do
              expect(chef_run).not_to render_file(file.name).with_content(/^storwize_svc_multipath_enabled=/)
            end
          end

          context 'storwize without iSCSI connection protocol' do
            before do
              node.set['openstack']['block-storage']['storwize']['storwize_svc_connection_protocol'] = 'non-iSCSI'
            end

            it 'does not have a iscsi chap enabled attribute' do
              expect(chef_run).not_to render_file(file.name).with_content(/^storwize_svc_iscsi_enabled=/)
            end

            it 'has a multipath enabled attribute' do
              node.set['openstack']['block-storage']['storwize']['storwize_svc_multipath_enabled'] = 'storwize_svc_multipath_enabled_value'
              expect(chef_run).to render_file(file.name).with_content(/^storwize_svc_multipath_enabled=storwize_svc_multipath_enabled_value$/)
            end
          end
        end

        context 'solidfire settings' do
          before do
            node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.solidfire.SolidFire'
          end

          it 'has solidfire sf_emulate set' do
            node.set['openstack']['block-storage']['solidfire']['sf_emulate'] = 'test'
            expect(chef_run).to render_file(file.name).with_content(/^sf_emulate_512=test$/)
          end

          it 'has solidfire password' do
            expect(chef_run).to render_file(file.name).with_content(/^san_password=test_pass$/)
          end

          %w(san_login san_ip).each do |attr|
            it "has solidfire #{attr} set" do
              node.set['openstack']['block-storage']['solidfire'][attr] = "solidfire_#{attr}_value"
              expect(chef_run).to render_file(file.name).with_content(/^#{attr}=solidfire_#{attr}_value$/)
            end
          end

          it 'does not have iscsi_ip_prefix not specified' do
            node.set['openstack']['block-storage']['solidfire']['iscsi_ip_prefix'] = nil
            expect(chef_run).to_not render_file(file.name).with_content(/^iscsi_ip_prefix=/)
          end

          it 'does have iscsi_ip_prefix when specified' do
            chef_run.node.set['openstack']['block-storage']['solidfire']['iscsi_ip_prefix'] = '203.0.113.*'
            expect(chef_run).to render_file(file.name).with_content(/^iscsi_ip_prefix=203.0.113.*$/)
          end
        end

        context 'flashsystem settings' do
          before do
            node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.ibm.flashsystem.FlashSystemDriver'
          end

          it 'has flashsystem password' do
            expect(chef_run).to render_config_file(file.name).with_section_content('DEFAULT', /^san_password=test_pass$/)
          end

          it 'has a default attribute' do
            %w(san_ip=127.0.0.1
               flashsystem_connection_protocol=FC
               flashsystem_multihostmap_enabled=true).each do |attr|
              expect(chef_run).to render_config_file(file.name).with_section_content('DEFAULT', /^#{attr}$/)
            end
          end

          it 'has a overridden attribute' do
            %w(san_ip
               flashsystem_connection_protocol
               flashsystem_multihostmap_enabled).each do |attr|
              node.set['openstack']['block-storage']['flashsystem'][attr] = "flashsystem_#{attr}_value"
              expect(chef_run).to render_config_file(file.name).with_section_content('DEFAULT', /^#{attr}=flashsystem_#{attr}_value$/)
            end
          end

          context 'FlashSystem with FC connection protocol' do
            before do
              node.set['openstack']['block-storage']['storwize']['flashsystem_connection_protocol'] = 'FC'
            end

            it 'has a multipath enabled attribute' do
              node.set['openstack']['block-storage']['flashsystem']['flashsystem_multipath_enabled'] = 'flashsystem_multipath_enabled_value'
              expect(chef_run).to render_config_file(file.name).with_section_content('DEFAULT', /^flashsystem_multipath_enabled=flashsystem_multipath_enabled_value$/)
            end
          end
        end

        context 'emc settings' do
          before do
            node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.emc.emc_smis_iscsi.EMCSMISISCSIDriver'
          end

          %w(iscsi_target_prefix cinder_emc_config_file).each do |attr|
            it "has emc #{attr} set" do
              node.set['openstack']['block-storage']['emc'][attr] = "emc_#{attr}_value"
              expect(chef_run).to render_file(file.name).with_content(/^#{attr}=emc_#{attr}_value$/)
            end
          end
        end

        context 'vmware vmdk settings' do
          before do
            node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver'
            %w(vmware_host_ip vmware_host_username
               vmware_api_retry_count vmware_task_poll_interval vmware_volume_folder
               vmware_image_transfer_timeout_secs vmware_max_objects_retrieval).each do |attr|
              node.set['openstack']['block-storage']['vmware'][attr] = "vmware_#{attr}_value"
            end
          end

          it 'has vmware attributes set' do
            node['openstack']['block-storage']['vmware'].each do |attr, val|
              expect(chef_run).to render_file(file.name).with_content(/^#{attr} = #{val}$/)
            end
          end

          it 'has password set which is from databag' do
            expect(chef_run).to render_file(file.name).with_content(/^vmware_host_password = vmware_secret_name$/)
          end

          it 'has no wsdl_location line without the attribute' do
            node.set['openstack']['block-storage']['vmware']['vmware_wsdl_location'] = nil
            expect(chef_run).not_to render_file(file.name).with_content(/^vmware_wsdl_location = /)
          end

          it 'has wsdl_location line with attribute present' do
            node.set['openstack']['block-storage']['vmware']['vmware_wsdl_location'] = 'http://127.0.0.1/wsdl'
            expect(chef_run).to render_file(file.name).with_content(%r(^vmware_wsdl_location = http://127.0.0.1/wsdl$))
          end
        end

        context 'gpfs settings' do
          before do
            node.set['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.ibm.gpfs.GPFSDriver'
          end

          %w(gpfs_mount_point_base gpfs_max_clone_depth
             gpfs_sparse_volumes gpfs_storage_pool).each do |attr|
            it "has gpfs #{attr} set" do
              node.set['openstack']['block-storage']['gpfs'][attr] = "gpfs_#{attr}_value"
              expect(chef_run).to render_file(file.name).with_content(/^#{attr} = gpfs_#{attr}_value$/)
            end
          end

          it 'has no gpfs_images_dir line without the attribute' do
            node.set['openstack']['block-storage']['gpfs']['gpfs_images_dir'] = nil
            expect(chef_run).not_to render_file(file.name).with_content(/^gpfs_images_dir = /)
            expect(chef_run).not_to render_file(file.name).with_content(/^gpfs_images_share_mode = /)
          end

          it 'has gpfs_images_dir line with attribute present' do
            node.set['openstack']['block-storage']['gpfs']['gpfs_images_dir'] = 'gpfs_images_dir_value'
            expect(chef_run).to render_file(file.name).with_content(/^gpfs_images_dir = gpfs_images_dir_value$/)
            expect(chef_run).to render_file(file.name).with_content(/^gpfs_images_share_mode = copy_on_write$/)
          end

          it 'templates misc_cinder array correctly' do
            node.set['openstack']['block-storage']['misc_cinder'] = ['# Comments', 'MISC=OPTION']
            expect(chef_run).to render_file(file.name).with_content(
              /^# Comments$/)
            expect(chef_run).to render_file(file.name).with_content(
              /^MISC=OPTION$/)
          end
        end

        context 'multiple backend settings' do
          before do
            node.set['openstack']['block-storage']['volume']['multi_backend'] = {
              'lvm' => {
                'volume_driver' => 'cinder.volume.drivers.lvm.LVMVolumeDriver',
                'volume_backend_name' => 'lvmdrv'
              },
              'rbd' => {
                'volume_driver' => 'cinder.volume.drivers.rbd.RBDDriver',
                'volume_backend_name' => 'rbddrv'
              },
              'netapp_iscsi' => {
                'volume_driver' => 'cinder.volume.drivers.netapp.NetAppISCSIDriver',
                'multi_netapp_iscsi' => 'multi-netapp'
              },
              'netapp_nfs' => {
                'volume_driver' => 'cinder.volume.drivers.netapp.nfs.NetAppDirect7modeNfsDriver',
                'volume_backend_name' => 'netappnfsdrv',
                'multi_netapp_nfs' => 'multi-netapp'
              },
              'ibmnas' => {
                'volume_driver' => 'cinder.volume.drivers.ibm.ibmnas.IBMNAS_NFSDriver',
                'multi_ibmnas' => 'multi-ibmnas'
              },
              'ibmsvc' => {
                'volume_driver' => 'cinder.volume.drivers.ibm.storwize_svc.StorwizeSVCDriver',
                'multi_ibmsvc' => 'multi-ibmsvc'
              },
              'solidfire' => {
                'volume_driver' => 'cinder.volume.drivers.solidfire.SolidFire',
                'multi_solidfire' => 'multi-solidfire'
              },
              'emciscsi' => {
                'volume_driver' => 'cinder.volume.drivers.emc.emc_smis_iscsi.EMCSMISISCSIDriver',
                'multi_emciscsi' => 'multi-emciscsi'
              },
              'vmware' => {
                'volume_driver' => 'cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver',
                'multi_vmware' => 'multi-vmware'
              },
              'gpfs' => {
                'volume_driver' => 'cinder.volume.drivers.ibm.gpfs.GPFSDriver',
                'multi_gpfs' => 'multi-gpfs'
              }
            }
            node.set['openstack']['block-storage']['volume']['volume_group'] = 'multi-lvm-group'
            node.set['openstack']['block-storage']['volume']['default_volume_type'] = 'some-type-name'
            node.set['openstack']['block-storage']['rbd']['cinder']['pool'] = 'multi-rbd-pool'
            node.set['openstack']['block-storage']['netapp']['dfm_login'] = 'multi-netapp-login'
            node.set['openstack']['block-storage']['netapp']['netapp_server_hostname'] = ['netapp-host-1', 'netapp-host-2']
            node.set['openstack']['block-storage']['netapp']['netapp_server_port'] = 'multi-netapp-port'
            node.set['openstack']['block-storage']['ibmnas']['shares_config'] = 'multi-ibmnas-share'
            node.set['openstack']['block-storage']['storwize']['storwize_svc_volpool_name'] = 'multi-svc-volpool'
            node.set['openstack']['block-storage']['solidfire']['sf_emulate'] = 'multi-sf-true'
            node.set['openstack']['block-storage']['emc']['cinder_emc_config_file'] = 'multi-emc-conf'
            node.set['openstack']['block-storage']['vmware']['vmware_host_ip'] = 'multi-vmware-ip'
            node.set['openstack']['block-storage']['gpfs']['gpfs_mount_point_base'] = 'multi-gpfs-mnt'
          end

          it 'enable multiple backends' do
            expect(chef_run).to render_file(file.name).with_content(/^enabled_backends = lvm,rbd,netapp_iscsi,netapp_nfs,ibmnas,ibmsvc,solidfire,emciscsi,vmware,gpfs$/)

            expect(chef_run).to render_file(file.name).with_content(/^\[lvm\]$/)
            expect(chef_run).to render_file(file.name).with_content(/^volume_driver = cinder\.volume\.drivers\.lvm\.LVMVolumeDriver$/)

            expect(chef_run).to render_file(file.name).with_content(/^\[rbd\]$/)
            expect(chef_run).to render_file(file.name).with_content(/^volume_driver = cinder\.volume\.drivers\.rbd\.RBDDriver$/)

            expect(chef_run).to render_file(file.name).with_content(/^\[netapp_iscsi\]$/)
            expect(chef_run).to render_file(file.name).with_content(/^volume_driver = cinder\.volume\.drivers\.netapp\.NetAppISCSIDriver$/)

            expect(chef_run).to render_file(file.name).with_content(/^netapp_server_hostname=netapp-host-1$/)
            expect(chef_run).to render_file(file.name).with_content(/^netapp_server_hostname=netapp-host-2$/)
            expect(chef_run).to render_file(file.name).with_content(/^\[netapp_nfs\]$/)
            expect(chef_run).to render_file(file.name).with_content(/^volume_driver = cinder\.volume\.drivers\.netapp\.nfs\.NetAppDirect7modeNfsDriver$/)

            expect(chef_run).to render_file(file.name).with_content(/^\[ibmnas\]$/)
            expect(chef_run).to render_file(file.name).with_content(/^volume_driver = cinder\.volume\.drivers\.ibm\.ibmnas\.IBMNAS_NFSDriver$/)

            expect(chef_run).to render_file(file.name).with_content(/^\[ibmsvc\]$/)
            expect(chef_run).to render_file(file.name).with_content(/^volume_driver = cinder\.volume\.drivers\.ibm\.storwize_svc\.StorwizeSVCDriver$/)

            expect(chef_run).to render_file(file.name).with_content(/^\[solidfire\]$/)
            expect(chef_run).to render_file(file.name).with_content(/^volume_driver = cinder\.volume\.drivers\.solidfire\.SolidFire$/)

            expect(chef_run).to render_file(file.name).with_content(/^\[emciscsi\]$/)
            expect(chef_run).to render_file(file.name).with_content(/^volume_driver = cinder\.volume\.drivers\.emc\.emc_smis_iscsi\.EMCSMISISCSIDriver$/)

            expect(chef_run).to render_file(file.name).with_content(/^\[vmware\]$/)
            expect(chef_run).to render_file(file.name).with_content(/^volume_driver = cinder\.volume\.drivers\.vmware\.vmdk\.VMwareVcVmdkDriver$/)

            expect(chef_run).to render_file(file.name).with_content(/^\[gpfs\]$/)
            expect(chef_run).to render_file(file.name).with_content(/^volume_driver = cinder\.volume\.drivers\.ibm\.gpfs\.GPFSDriver$/)
          end

          it 'set lvm option' do
            expect(chef_run).to render_file(file.name).with_content(/^volume_group=multi-lvm-group$/)
          end

          it 'set default_volume_type option' do
            expect(chef_run).to render_file(file.name).with_content(/^default_volume_type=some-type-name$/)
          end

          it 'set rbd option' do
            expect(chef_run).to render_file(file.name).with_content(/^rbd_pool=multi-rbd-pool$/)
          end

          it 'set netapp_iscsi option' do
            expect(chef_run).to render_file(file.name).with_content(/^netapp_login=multi-netapp-login$/)
          end

          it 'set netapp_nfs option' do
            expect(chef_run).to render_file(file.name).with_content(/^netapp_server_port=multi-netapp-port$/)
          end

          it 'set ibmnas option' do
            expect(chef_run).to render_file(file.name).with_content(/^nfs_shares_config=multi-ibmnas-share$/)
          end

          it 'set ibmsvc option' do
            expect(chef_run).to render_file(file.name).with_content(/^storwize_svc_volpool_name=multi-svc-volpool$/)
          end

          it 'set solidfire option' do
            expect(chef_run).to render_file(file.name).with_content(/^sf_emulate_512=multi-sf-true$/)
          end

          it 'set emciscsi option' do
            expect(chef_run).to render_file(file.name).with_content(/^cinder_emc_config_file=multi-emc-conf$/)
          end

          it 'set vmware option' do
            expect(chef_run).to render_file(file.name).with_content(/^vmware_host_ip = multi-vmware-ip$/)
          end

          it 'set gpfs option' do
            expect(chef_run).to render_file(file.name).with_content(/^gpfs_mount_point_base = multi-gpfs-mnt$/)
          end

        end

        it 'no multiple backends configured' do
          expect(chef_run).to_not render_file(file.name).with_content(/^enabled_backends = [\w\W]+$/)
        end

        it 'does not set default_volume_type' do
          expect(chef_run).to_not render_file(file.name).with_content(/^default_volume_type=.+$/)
        end
      end
    end

    describe '/var/lib/cinder/lock' do
      let(:dir) { chef_run.directory('/var/lib/cinder/lock') }

      it 'should create the /var/lib/cinder/lock directory' do
        expect(chef_run).to create_directory(dir.name)
      end

      it 'has proper owner' do
        expect(dir.owner).to eq('cinder')
        expect(dir.group).to eq('cinder')
      end

      it 'has proper modes' do
        expect(sprintf('%o', dir.mode)).to eq '755'
      end
    end

    describe 'rootwrap.conf' do
      let(:file) { chef_run.template('/etc/cinder/rootwrap.conf') }

      it 'creates the /etc/cinder/rootwrap.conf file' do
        expect(chef_run).to create_template(file.name).with(
          user: 'root',
          group: 'root',
          mode: 0644
        )
      end

      context 'template contents' do
        it 'shows the custom banner' do
          node.set['openstack']['block-storage']['custom_template_banner'] = 'banner'

          expect(chef_run).to render_file(file.name)
          .with_content(/^banner$/)
        end

        it 'sets the default attributes' do
          [
            %r(^filters_path=/etc/cinder/rootwrap.d,/usr/share/cinder/rootwrap$),
            %r(^exec_dirs=/sbin,/usr/sbin,/bin,/usr/bin$),
            /^use_syslog=False$/,
            /^syslog_log_facility=syslog$/,
            /^syslog_log_level=ERROR$/
          ].each do |line|
            expect(chef_run).to render_file(file.name).with_content(line)
          end
        end
      end
    end
  end
end