Browse Source

Merge "Add database slave connection configure"

Jenkins 3 years ago
parent
commit
d921c1fdd9
3 changed files with 22 additions and 1 deletions
  1. 4
    0
      recipes/cinder-common.rb
  2. 15
    1
      spec/cinder_common_spec.rb
  3. 3
    0
      templates/default/cinder.conf.erb

+ 4
- 0
recipes/cinder-common.rb View File

@@ -33,6 +33,9 @@ end
33 33
 db_user = node['openstack']['db']['block-storage']['username']
34 34
 db_pass = get_password 'db', 'cinder'
35 35
 sql_connection = db_uri('block-storage', db_user, db_pass)
36
+if node['openstack']['endpoints']['db']['enabled_slave']
37
+  slave_connection = db_uri('block-storage', db_user, db_pass, true)
38
+end
36 39
 
37 40
 mq_service_type = node['openstack']['mq']['block-storage']['service_type']
38 41
 
@@ -100,6 +103,7 @@ template '/etc/cinder/cinder.conf' do
100 103
   mode 00640
101 104
   variables(
102 105
     sql_connection: sql_connection,
106
+    slave_connection: slave_connection,
103 107
     mq_service_type: mq_service_type,
104 108
     mq_password: mq_password,
105 109
     rabbit_hosts: rabbit_hosts,

+ 15
- 1
spec/cinder_common_spec.rb View File

@@ -275,11 +275,25 @@ describe 'openstack-block-storage::cinder-common' do
275 275
         end
276 276
 
277 277
         it 'has a db connection attribute' do
278
+          node.set['openstack']['endpoints']['db']['enabled_slave'] = false
278 279
           allow_any_instance_of(Chef::Recipe).to receive(:db_uri)
279
-            .with('block-storage', anything, '').and_return('sql_connection_value')
280
+            .and_return('sql_connection_value')
280 281
 
281 282
           expect(chef_run).to render_config_file(file.name)
282 283
             .with_section_content('database', /^connection=sql_connection_value$/)
284
+          expect(chef_run).to_not render_config_file(file.name)
285
+            .with_section_content('database', /^slave_connection=sql_connection_value$/)
286
+        end
287
+
288
+        it 'has a slave db connection attribute' do
289
+          node.set['openstack']['endpoints']['db']['enabled_slave'] = true
290
+          allow_any_instance_of(Chef::Recipe).to receive(:db_uri)
291
+            .and_return('sql_connection_value')
292
+
293
+          expect(chef_run).to render_config_file(file.name)
294
+            .with_section_content('database', /^connection=sql_connection_value$/)
295
+          expect(chef_run).to render_config_file(file.name)
296
+            .with_section_content('database', /^slave_connection=sql_connection_value$/)
283 297
         end
284 298
 
285 299
         it 'has a db backend attribute' do

+ 3
- 0
templates/default/cinder.conf.erb View File

@@ -1031,6 +1031,9 @@ connection=<%= @sql_connection %>
1031 1031
 # sql_connection_debug=0
1032 1032
 #### (IntOpt) Verbosity of SQL debugging information. 0=None,
1033 1033
 ####          100=Everything
1034
+<% if node['openstack']['endpoints']['db']['enabled_slave'] %>
1035
+slave_connection=<%= @slave_connection %>
1036
+<% end %>
1034 1037
 
1035 1038
 
1036 1039
 [keymgr]

Loading…
Cancel
Save