From 53e38b80b94a9557b2474cedcc46f265b4fea433 Mon Sep 17 00:00:00 2001 From: Mark Vanderwiel Date: Tue, 19 Aug 2014 12:21:29 -0500 Subject: [PATCH] Allow added sections to local_settings template Similar design to the multi backend support in block-storage. Change-Id: I6d715975429346190eb054a713c317be132656e6 Closes-Bug: #1358817 --- CHANGELOG.md | 1 + README.md | 1 + attributes/default.rb | 22 ++++++++++++++++++ spec/server_spec.rb | 30 +++++++++++++++++++++++++ spec/spec_helper.rb | 6 +++++ templates/default/local_settings.py.erb | 12 ++++++++++ 6 files changed, 72 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eae261f..8fd5be7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This file is used to list changes made in each version of the openstack-dashboar * Upgrading berkshelf from 2.0.18 to 3.1.5 * Allow enable_filewall and enable_vpn to be configured via attributes * Sync conf files with Juno +* Add optional section support for local_settings template ## 9.1 * python_packages database client attributes have been moved to the -common cookbook diff --git a/README.md b/README.md index ddf759c..e554232 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ Attributes * `openstack['dashboard']['http_port']` - Port that httpd should listen on (default: 80) * `openstack['dashboard']['https_port']` - Port that httpd should listen on for using ssl (default: 443) * `openstack['dashboard']['password_autocomplete']` - Toggle browser autocompletion for login form ('on' or 'off', default: 'on') +* `openstack['dashboard']['misc_local_settings']` - Additions to the local_settings conf file Identity -------- diff --git a/attributes/default.rb b/attributes/default.rb index 0372308..20342f0 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -178,3 +178,25 @@ default['openstack']['dashboard']['neutron']['enable_lb'] = false default['openstack']['dashboard']['neutron']['enable_quotas'] = true default['openstack']['dashboard']['neutron']['enable_firewall'] = false default['openstack']['dashboard']['neutron']['enable_vpn'] = false + +# Allow for misc sections to be added to the local_settings template +# For example: { +# 'CUSTOM_CONFIG_A' => { +# 'variable1': 'value1', +# 'variable2': 'value2' +# } +# 'CUSTOM_CONFIG_B' => { +# 'variable1': 'value1', +# 'variable2': 'value2' +# } +# } +# will generate: +# CUSTOM_CONFIG_A = { +# 'varable1': 'value1', +# 'varable2': 'value2', +# } +# CUSTOM_CONFIG_A = { +# 'varable1': 'value1', +# 'varable2': 'value2', +# } +default['openstack']['dashboard']['misc_local_settings'] = nil diff --git a/spec/server_spec.rb b/spec/server_spec.rb index c629cd0..643e6e7 100644 --- a/spec/server_spec.rb +++ b/spec/server_spec.rb @@ -98,6 +98,36 @@ describe 'openstack-dashboard::server' do expect(chef_run).to render_file(file.name).with_content(/^custom_template_banner_value$/) end + context 'misc settings' do + before do + node.set['openstack']['dashboard']['misc_local_settings'] = { + 'CUSTOM_CONFIG_A' => { + 'variable1' => 'value1', + 'variable2' => 'value2' + }, + 'CUSTOM_CONFIG_B' => { + 'variable1' => 'value1', + 'variable2' => 'value2' + } + } + end + + it 'sets misc settings properly' do + [ + ['CUSTOM_CONFIG_A = {', + ' \'variable1\': \'value1\',', + ' \'variable2\': \'value2\',', + '}'], + ['CUSTOM_CONFIG_B = {', + ' \'variable1\': \'value1\',', + ' \'variable2\': \'value2\',', + '}'] + ].each do |content| + expect(chef_run).to render_file(file.name).with_content(build_section(content)) + end + end + end + context 'debug setting' do context 'set to true' do before do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5694dd5..cb56dc7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -21,6 +21,12 @@ SUSE_OPTS = { log_level: LOG_LEVEL } +# Build a regex for a section of lines +def build_section(lines) + lines.map! { |line| Regexp.quote(line) } + /^#{lines.join('\n')}/ +end + shared_context 'dashboard_stubs' do before do allow_any_instance_of(Chef::Recipe).to receive(:memcached_servers) diff --git a/templates/default/local_settings.py.erb b/templates/default/local_settings.py.erb index 81266c3..65f5c69 100644 --- a/templates/default/local_settings.py.erb +++ b/templates/default/local_settings.py.erb @@ -589,3 +589,15 @@ mod = sys.modules['openstack_dashboard.settings'] mod.INSTALLED_APPS += ('<%= p %>', ) <% end %> <% end %> + +# Allow for misc sections to be added +<% if node["openstack"]["dashboard"]["misc_local_settings"] %> +<% node["openstack"]["dashboard"]["misc_local_settings"].each do |sec, opts| %> +<%= sec %> = { +<% opts.each do |key, value| %> + '<%= key %>': '<%= value %>', +<% end %> +} +<% end %> +<% end %> +