diff --git a/spec/account_spec.rb b/spec/account_spec.rb index 85360b8..21d3f1a 100644 --- a/spec/account_spec.rb +++ b/spec/account_spec.rb @@ -45,14 +45,15 @@ describe 'openstack-object-storage::account-server' do ) end - { 'bind_ip' => '0.0.0.0', - 'bind_port' => '6002', - 'log_statsd_default_sample_rate' => '1', - 'log_statsd_metric_prefix' => 'openstack.swift.Fauxhai' }.each do |k, v| - it "sets the #{k}" do - expect(chef_run).to render_file(file.name).with_content(/^#{Regexp.quote("#{k} = #{v}")}$/) + describe 'default attribute values' do + it_behaves_like 'a common swift server default attribute values checker', 'account' + + it 'uses default attribute value for bind_port' do + expect(chef_run.node['openstack']['object-storage']['network']['account-bind-port']).to eq('6002') end end + + it_behaves_like 'a common swift server configurator', 'account' end end end diff --git a/spec/common_spec.rb b/spec/common_spec.rb index 53f86d6..fd3c86a 100644 --- a/spec/common_spec.rb +++ b/spec/common_spec.rb @@ -85,8 +85,26 @@ describe 'openstack-object-storage::common' do ) end - it 'template contents' do - skip 'TODO: implement' + describe 'default attribute values' do + it 'uses default attribute value for platform service_prefix' do + expect(chef_run.node['openstack']['object-storage']['platform']['service_prefix']).to eq('') + end + + it 'uses default attribute value for git_builder_ip' do + expect(chef_run.node['openstack']['object-storage']['git_builder_ip']).to eq('127.0.0.1') + end + end + + describe 'template contents' do + it 'uses the builder_ip variable' do + node.set['openstack']['object-storage']['git_builder_ip'] = 'git_builder_ip_value' + expect(chef_run).to render_file(file.name).with_content(%r(git clone git://git_builder_ip_value/rings /etc/swift/rings)) + end + + it 'uses the service_prefix variable' do + node.set['openstack']['object-storage']['platform']['service_prefix'] = 'service_prefix_' + expect(chef_run).to render_file(file.name).with_content(/service service_prefix_swift-\$\{d\}-replicator restart$/) + end end end end diff --git a/spec/container_spec.rb b/spec/container_spec.rb index d29f715..8cc583a 100644 --- a/spec/container_spec.rb +++ b/spec/container_spec.rb @@ -6,7 +6,6 @@ describe 'openstack-object-storage::container-server' do let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) } let(:node) { runner.node } let(:chef_run) do - node.set['openstack']['object-storage']['container-server']['allowed_sync_hosts'] = ['host1', 'host2', 'host3'] node.set['openstack']['object-storage']['disk_enum_expr'] = "[{ 'sda' => {}}]" node.set['openstack']['object-storage']['disk_test_filter'] = [ 'candidate =~ /sd[^a]/ or candidate =~ /hd[^a]/ or candidate =~ /vd[^a]/ or candidate =~ /xvd[^a]/', @@ -25,36 +24,12 @@ describe 'openstack-object-storage::container-server' do end it 'starts swift container services on boot' do + node.set['openstack']['object-storage']['container-server']['allowed_sync_hosts'] = %w(host1 host2) %w{swift-container swift-container-auditor swift-container-replicator swift-container-updater swift-container-sync}.each do |svc| expect(chef_run).to enable_service(svc) end end - describe '/etc/swift/container-server.conf' do - let(:file) { chef_run.template('/etc/swift/container-server.conf') } - - it 'creates account-server.conf' do - expect(chef_run).to create_template(file.name).with( - user: 'swift', - group: 'swift', - mode: 0600 - ) - end - - it 'has allowed sync hosts' do - expect(chef_run).to render_file(file.name).with_content('allowed_sync_hosts = host1,host2,host3') - end - - { 'bind_ip' => '0.0.0.0', - 'bind_port' => '6001', - 'log_statsd_default_sample_rate' => '1', - 'log_statsd_metric_prefix' => 'openstack.swift.Fauxhai' }.each do |k, v| - it "sets the #{k}" do - expect(chef_run).to render_file(file.name).with_content(/^#{Regexp.quote("#{k} = #{v}")}$/) - end - end - end - describe 'container sync' do let(:file) { chef_run.cookbook_file('/etc/init/swift-container-sync.conf') } let(:link) { chef_run.link('/etc/init.d/swift-container-sync') } @@ -75,12 +50,49 @@ describe 'openstack-object-storage::container-server' do describe '/etc/swift/container-server.conf' do let(:file) { chef_run.template('/etc/swift/container-server.conf') } - before do - node.set['openstack']['object-storage']['container-server']['allowed_sync_hosts'] = [] + describe 'default attribute values' do + it_behaves_like 'a common swift server default attribute values checker', 'container' + + it 'for bind_port' do + expect(chef_run.node['openstack']['object-storage']['network']['container-bind-port']).to eq('6001') + end + + it 'for allowed_sync_hosts' do + expect(chef_run.node['openstack']['object-storage']['container-server']['allowed_sync_hosts']).to eq([]) + end end - it 'has no allowed_sync_hosts on empty lists' do - expect(chef_run).not_to render_file(file.name).with_content(/^allowed_sync_hots =/) + describe 'template contents' do + it_behaves_like 'a common swift server configurator', 'container' + + it 'sets allowed_sync_hosts when present' do + node.set['openstack']['object-storage']['container-server']['allowed_sync_hosts'] = %w(host1 host2) + expect(chef_run).to render_file(file.name).with_content(/^allowed_sync_hosts = host1,host2$/) + end + + it 'does not set allowed_sync_hosts when not present' do + node.set['openstack']['object-storage']['container-server']['allowed_sync_hosts'] = false + expect(chef_run).not_to render_file(file.name).with_content(/^allowed_sync_hosts = $/) + end + + context 'container-sync' do + it 'sets sync_proxy when present' do + node.set['openstack']['object-storage']['container-server']['container-sync']['sync_proxy'] = 'sync_proxy_value' + expect(chef_run).to render_file(file.name).with_content(/^sync_proxy = sync_proxy_value$/) + end + + it 'does not set allowed_sync_hosts when not present' do + node.set['openstack']['object-storage']['container-server']['container-sync']['sync_proxy'] = false + expect(chef_run).not_to render_file(file.name).with_content(/^sync_proxy = $/) + end + + %w(log_name log_facility log_level interval container_time).each do |attr| + it "sets the container-sync #{attr} attribute" do + node.set['openstack']['object-storage']['container-server']['container-sync'][attr] = "#{attr}_value" + expect(chef_run).to render_file(file.name).with_content(/^#{attr} = #{attr}_value$/) + end + end + end end end end diff --git a/spec/management_spec.rb b/spec/management_spec.rb index 3d88e56..8cd64ee 100644 --- a/spec/management_spec.rb +++ b/spec/management_spec.rb @@ -26,8 +26,62 @@ describe 'openstack-object-storage::management-server' do ) end - it 'template contents' do - skip 'TODO: implement' + describe 'default attribute values' do + it 'uses default attribute value for auth_url' do + expect(chef_run.node['openstack']['object-storage']['auth_url']).to eq('http://127.0.0.1:8080/auth/v1.0') + end + + it 'uses default attribute value for swift_secret_databag_name' do + expect(chef_run.node['openstack']['object-storage']['swift_secret_databag_name']).to be_nil + end + + it 'uses default attribute value for dispersion auth_user' do + expect(chef_run.node['openstack']['object-storage']['dispersion']['auth_user']).to eq('test:test') + end + + it 'uses default attribute value for dispersion auth_key' do + expect(chef_run.node['openstack']['object-storage']['dispersion']['auth_key']).to eq('test') + end + end + + describe 'template contents' do + it 'sets the auth_url' do + node.set['openstack']['object-storage']['auth_url'] = 'auth_url_value' + expect(chef_run).to render_file(file.name).with_content(/^auth_url = auth_url_value$/) + end + + context 'with databag' do + let(:swift_secrets) do + { 'dispersion_auth_user' => 'dispersion_auth_user_value', + 'dispersion_auth_key' => 'dispersion_auth_key_value' } + end + + before do + node.set['openstack']['object-storage']['swift_secret_databag_name'] = 'swift_secret_databag_name_value' + allow(Chef::EncryptedDataBagItem).to receive(:load) + .with('secrets', 'swift_secret_databag_name_value') + .and_return(swift_secrets) + end + + %w(user key).each do |attr| + it "sets the auth_#{attr}" do + expect(chef_run).to render_file(file.name).with_content(/^auth_#{attr} = dispersion_auth_#{attr}_value$/) + end + end + end + + context 'without databag' do + before do + node.set['openstack']['object-storage']['swift_secret_databag_name'] = nil + end + + %w(user key).each do |attr| + it "sets the auth_#{attr}" do + node.set['openstack']['object-storage']['dispersion']["auth_#{attr}"] = "auth_#{attr}_value" + expect(chef_run).to render_file(file.name).with_content(/^auth_#{attr} = auth_#{attr}_value$/) + end + end + end end end @@ -42,10 +96,59 @@ describe 'openstack-object-storage::management-server' do ) end - it 'has expected statsd host' do - expect(chef_run).to render_file(file.name).with_content( - "self.statsd_host = '127.0.0.1'" - ) + describe 'default attribute values' do + it 'uses default attribute value for statsd_host' do + expect(chef_run.node['openstack']['object-storage']['statistics']['statsd_host']).to eq('127.0.0.1') + end + + it 'uses default attribute value for statsd_port' do + expect(chef_run.node['openstack']['object-storage']['statistics']['statsd_port']).to eq('8125') + end + + it 'uses default attribute value for statsd_prefix' do + expect(chef_run.node['openstack']['object-storage']['statistics']['statsd_prefix']).to eq('openstack.swift') + end + + it 'uses default attribute value for enable_dispersion_report' do + expect(chef_run.node['openstack']['object-storage']['statistics']['enable_dispersion_report']).to eq(true) + end + + it 'uses default attribute value for enable_recon_report' do + expect(chef_run.node['openstack']['object-storage']['statistics']['enable_recon_report']).to eq(true) + end + + it 'uses default attribute value for enable_disk_report' do + expect(chef_run.node['openstack']['object-storage']['statistics']['enable_disk_report']).to eq(true) + end + + %w(account container object).each do |server_type| + it "uses default attribute value for recon_#{server_type}_cache" do + expect(chef_run.node['openstack']['object-storage']['statistics']["recon_#{server_type}_cache"]).to eq("/var/cache/swift/#{server_type}.recon") + end + end + end + + describe 'template contents' do + %w(statsd_host statsd_prefix recon_account_cache recon_container_cache recon_object_cache).each do |attr| + it "sets the #{attr} attribute" do + node.set['openstack']['object-storage']['statistics'][attr] = "#{attr}_value" + expect(chef_run).to render_file(file.name).with_content(/self\.#{attr}\s*= '#{attr}_value'$/) + end + end + + it 'sets the statsd_port attribute' do + node.set['openstack']['object-storage']['statistics']['statsd_port'] = 'statsd_port_value' + expect(chef_run).to render_file(file.name).with_content(/self\.statsd_port\s*= statsd_port_value$/) + end + + %w(enable_dispersion_report enable_recon_report enable_disk_report).each do |attr| + [true, false].each do |value| + it "sets the #{attr} attribute to #{value}" do + node.set['openstack']['object-storage']['statistics'][attr] = value + expect(chef_run).to render_file(file.name).with_content(/self\.#{attr}\s*= #{value.to_s.capitalize}$/) + end + end + end end end end diff --git a/spec/object_spec.rb b/spec/object_spec.rb index 70457b4..ad30e3e 100644 --- a/spec/object_spec.rb +++ b/spec/object_spec.rb @@ -47,14 +47,15 @@ describe 'openstack-object-storage::object-server' do ) end - { 'bind_ip' => '0.0.0.0', - 'bind_port' => '6000', - 'log_statsd_default_sample_rate' => '1', - 'log_statsd_metric_prefix' => 'openstack.swift.Fauxhai' }.each do |k, v| - it "sets the #{k}" do - expect(chef_run).to render_file(file.name).with_content(/^#{Regexp.quote("#{k} = #{v}")}$/) + describe 'default attribute values' do + it_behaves_like 'a common swift server default attribute values checker', 'object' + + it 'uses default attribute value for bind_port' do + expect(chef_run.node['openstack']['object-storage']['network']['object-bind-port']).to eq('6000') end end + + it_behaves_like 'a common swift server configurator', 'object' end end end diff --git a/spec/proxy_spec.rb b/spec/proxy_spec.rb index 56860b2..39412e5 100644 --- a/spec/proxy_spec.rb +++ b/spec/proxy_spec.rb @@ -41,80 +41,285 @@ describe 'openstack-object-storage::proxy-server' do ) end - it 'has proper pipeline in template' do - array = [ - /^pipeline = catch_errors healthcheck cache ratelimit swauth proxy-logging proxy-server$/, - /^workers = 5$/ - ] - array.each do |content| - expect(chef_run).to render_file(file.name).with_content(content) - end - end + describe 'default attribute values' do + it_behaves_like 'a common swift server default attribute values checker', 'proxy' - context 'with domain_remap enabled' do - before do - node.set['openstack']['object-storage']['domain_remap']['enabled'] = true + it 'uses default attribute value for bind_port' do + expect(chef_run.node['openstack']['object-storage']['network']['proxy-bind-port']).to eq('8080') end - it 'has proper pipeline in template' do - array = [ - /^pipeline = catch_errors healthcheck cache ratelimit domain_remap swauth proxy-logging proxy-server$/, - /^storage_domain = example.com$/, - /^path_root = v1$/, - /^reseller_prefixes = AUTH$/ - ] - array.each do |content| - expect(chef_run).to render_file(file.name).with_content(content) + it 'uses default attribute value for authmode' do + expect(chef_run.node['openstack']['object-storage']['authmode']).to eq('swauth') + end + + %w(tempurl formpost domain_remap staticweb).each do |attr| + it "uses default attribute value for #{attr} enabled" do + expect(chef_run.node['openstack']['object-storage'][attr]['enabled']).to eq(false) end end - end - context 'with formpost enabled' do - before do - node.set['openstack']['object-storage']['formpost']['enabled'] = true - end - - it 'has proper pipeline in template' do - array = [ - /^pipeline = catch_errors healthcheck cache ratelimit formpost swauth proxy-logging proxy-server$/ - ] - array.each do |content| - expect(chef_run).to render_file(file.name).with_content(content) + %w(swift_url swauth_url).each do |attr| + it "uses default attribute value for #{attr}" do + expect(chef_run.node['openstack']['object-storage'][attr]).to eq('http://127.0.0.1:8080/v1/') end end - end - context 'with staticweb enabled' do - before do - node.set['openstack']['object-storage']['staticweb']['enabled'] = true + it 'uses default attribute value for container-server allowed_sync_hosts' do + expect(chef_run.node['openstack']['object-storage']['container-server']['allowed_sync_hosts']).to eq([]) end - it 'has proper pipeline in template' do - array = [ - /^pipeline = catch_errors healthcheck cache ratelimit swauth staticweb proxy-logging proxy-server$/, - /^cache_timeout = 300$/ - ] - array.each do |content| - expect(chef_run).to render_file(file.name).with_content(content) + it 'uses default attribute value for domain_remap log_name' do + expect(chef_run.node['openstack']['object-storage']['domain_remap']['log_name']).to eq('domain_remap') + end + + it 'uses default attribute value for domain_remap log_facility' do + expect(chef_run.node['openstack']['object-storage']['domain_remap']['log_facility']).to eq('LOG_LOCAL0') + end + + it 'uses default attribute value for domain_remap log_level' do + expect(chef_run.node['openstack']['object-storage']['domain_remap']['log_level']).to eq('INFO') + end + + it 'uses default attribute value for domain_remap log_headers' do + expect(chef_run.node['openstack']['object-storage']['domain_remap']['log_headers']).to eq('False') + end + + it 'uses default attribute value for domain_remap storage_admin' do + expect(chef_run.node['openstack']['object-storage']['domain_remap']['storage_domain']).to eq('example.com') + end + + it 'uses default attribute value for domain_remap path_root' do + expect(chef_run.node['openstack']['object-storage']['domain_remap']['path_root']).to eq('v1') + end + + it 'uses default attribute value for domain_remap reseller_prefixes' do + expect(chef_run.node['openstack']['object-storage']['domain_remap']['reseller_prefixes']).to eq('AUTH') + end + + it 'uses default attribute value for staticweb cache_timeout' do + expect(chef_run.node['openstack']['object-storage']['staticweb']['cache_timeout']).to eq(300) + end + + it 'uses default attribute value for staticweb log_name' do + expect(chef_run.node['openstack']['object-storage']['staticweb']['log_name']).to be_nil + end + + it 'uses default attribute value for staticweb log_facility' do + expect(chef_run.node['openstack']['object-storage']['staticweb']['log_facility']).to eq('LOG_LOCAL0') + end + + it 'uses default attribute value for staticweb log_level' do + expect(chef_run.node['openstack']['object-storage']['staticweb']['log_level']).to eq('INFO') + end + + it 'uses default attribute value for staticweb access_log_name' do + expect(chef_run.node['openstack']['object-storage']['staticweb']['access_log_name']).to eq('staticweb') + end + + it 'uses default attribute value for staticweb access_log_facility' do + expect(chef_run.node['openstack']['object-storage']['staticweb']['access_log_facility']).to eq('LOG_LOCAL0') + end + + it 'uses default attribute value for staticweb access_log_level' do + expect(chef_run.node['openstack']['object-storage']['staticweb']['access_log_level']).to eq('INFO') + end + + it 'uses default attribute value for staticweb log_headers' do + expect(chef_run.node['openstack']['object-storage']['staticweb']['log_headers']).to eq('False') + end + + it 'uses default attribute value for tempurl incoming_remove_headers' do + expect(chef_run.node['openstack']['object-storage']['tempurl']['incoming_remove_headers']).to eq('x-timestamp') + end + + it 'uses default attribute value for tempurl incoming_allow_headers' do + expect(chef_run.node['openstack']['object-storage']['tempurl']['incoming_allow_headers']).to eq('') + end + + it 'uses default attribute value for tempurl outgoing_remove_headers' do + expect(chef_run.node['openstack']['object-storage']['tempurl']['outgoing_remove_headers']).to eq('x-object-meta-*') + end + + it 'uses default attribute value for tempurl outgoing_allow_headers' do + expect(chef_run.node['openstack']['object-storage']['tempurl']['outgoing_allow_headers']).to eq('x-object-meta-public-*') + end + end + + describe 'template contents' do + it_behaves_like 'a common swift server configurator', 'proxy' + + context 'workers' do + it 'sets the number of workers' do + chef_run.node.automatic['cpu']['total'] = 8 + expect(chef_run).to render_file(file.name).with_content(/^workers = 7$/) + end + + it 'sets the minimum numnber of workers' do + chef_run.node.automatic['cpu']['total'] = 0 + expect(chef_run).to render_file(file.name).with_content(/^workers = 1$/) end end - end - context 'with tempurl enabled' do - before do - node.set['openstack']['object-storage']['tempurl']['enabled'] = true + context 'pipeline' do + %w(domain_remap formpost staticweb).each do |pipeline_item| + it "includes #{pipeline_item} in the pipeline when present" do + node.set['openstack']['object-storage'][pipeline_item]['enabled'] = true + expect(chef_run).to render_file(file.name).with_content(/^pipeline = .*#{pipeline_item}.*$/) + end + + it "does not include #{pipeline_item} in the pipeline when not present" do + node.set['openstack']['object-storage'][pipeline_item]['enabled'] = false + expect(chef_run).not_to render_file(file.name).with_content(/^pipeline = .*#{pipeline_item}.*$/) + end + end + + it 'includes the tempurl element when it is enabled and authmode is swauth' do + node.set['openstack']['object-storage']['authmode'] = 'swauth' + node.set['openstack']['object-storage']['tempurl']['enabled'] = true + expect(chef_run).to render_file(file.name).with_content(/^pipeline = .*tempurl.*$/) + end + + it 'does not include the tempurl element when it is disabled' do + node.set['openstack']['object-storage']['tempurl']['enabled'] = false + expect(chef_run).not_to render_file(file.name).with_content(/^pipeline = .*tempurl.*$/) + end + + it 'does not includes the tempurl element when authmode is not swauth' do + node.set['openstack']['object-storage']['authmode'] = 'not_swauth' + expect(chef_run).not_to render_file(file.name).with_content(/^pipeline = .*tempurl.*$/) + end + + it 'includes keystone related items when authmode is keystone' do + node.set['openstack']['object-storage']['authmode'] = 'keystone' + expect(chef_run).to render_file(file.name).with_content(/^pipeline = .*authtoken keystoneauth.*$/) + end + + it 'does not include keystone related items when authmode is not keystone' do + node.set['openstack']['object-storage']['authmode'] = 'not_keystone' + expect(chef_run).not_to render_file(file.name).with_content(/^pipeline = .*authtoken keystoneauth.*$/) + end + + it 'includes swauth item when authmode is swauth' do + node.set['openstack']['object-storage']['authmode'] = 'swauth' + expect(chef_run).to render_file(file.name).with_content(/^pipeline = .*swauth.*$/) + end + + it 'does not include swauth item when authmode is not swauth' do + node.set['openstack']['object-storage']['authmode'] = 'not_swauth' + expect(chef_run).not_to render_file(file.name).with_content(/^pipeline = .*swauth.*$/) + end end - it 'has proper pipeline in template' do - array = [ - /^pipeline = catch_errors healthcheck cache ratelimit tempurl swauth proxy-logging proxy-server$/, - /^incoming_remove_headers = x-timestamp$/, - /^incoming_allow_headers = $/, - 'outgoing_remove_headers = x-object-meta-*', - 'outgoing_allow_headers = x-object-meta-public-*' - ] - array.each do |content| - expect(chef_run).to render_file(file.name).with_content(content) + it 'sets account_autocreate when authmode is keystone' do + node.set['openstack']['object-storage']['authmode'] = 'keystone' + expect(chef_run).to render_file(file.name).with_content(/^account_autocreate = true$/) + end + + it 'does not set account_autocreate when authmode is not keystone' do + node.set['openstack']['object-storage']['authmode'] = 'not_keystone' + expect(chef_run).not_to render_file(file.name).with_content(/^account_autocreate = true$/) + end + + context 'swauth enabled' do + before do + node.set['openstack']['object-storage']['authmode'] = 'swauth' + end + + it 'sets allow_account_management attribute when authmode is swauth' do + expect(chef_run).to render_file(file.name).with_content(/^allow_account_management = true$/) + end + + it 'sets the default_swift_cluster attribute' do + node.set['openstack']['object-storage']['swift_url'] = 'swift_url_value' + node.set['openstack']['object-storage']['swauth_url'] = 'swauth_url_value' + expect(chef_run).to render_file(file.name).with_content(/^default_swift_cluster = local#swift_url_value#swauth_url_value$/) + end + + it 'sets allow_overrides when tempurl is enabled' do + node.set['openstack']['object-storage']['tempurl']['enabled'] = true + expect(chef_run).to render_file(file.name).with_content(/^allow_overrides = true$/) + end + + it 'does not set allow_overrides when tempurl is disabled' do + node.set['openstack']['object-storage']['tempurl']['enabled'] = false + expect(chef_run).not_to render_file(file.name).with_content(/^allow_overrides = true$/) + end + + it 'sets allowed_sync_hosts when present' do + node.set['openstack']['object-storage']['container-server']['allowed_sync_hosts'] = %w(host1 host2) + expect(chef_run).to render_file(file.name).with_content(/^allowed_sync_hosts = host1,host2$/) + end + + it 'does not set allowed_sync_hosts when not present' do + node.set['openstack']['object-storage']['container-server']['allowed_sync_hosts'] = nil + expect(chef_run).not_to render_file(file.name).with_content(/^allowed_sync_hosts = $/) + end + end + + context 'swauth disabled' do + before do + node.set['openstack']['object-storage']['authmode'] = 'not_swauth' + end + + it 'sets allow_account_management attribute when authmode is not swauth' do + expect(chef_run).to render_file(file.name).with_content(/^allow_account_management = false$/) + end + + it 'does not set the default_swift_cluster attribute' do + expect(chef_run).not_to render_file(file.name).with_content(/^default_swift_cluster = local.*$/) + end + + it 'does not set allow_overrides when tempurl is enabled' do + node.set['openstack']['object-storage']['tempurl']['enabled'] = true + expect(chef_run).not_to render_file(file.name).with_content(/^allow_overrides = true$/) + end + + it 'does not set allowed_sync_hosts when present' do + node.set['openstack']['object-storage']['container-server']['allowed_sync_hosts'] = %w(host1 host2) + expect(chef_run).not_to render_file(file.name).with_content(/^allowed_sync_hosts = host1,host2$/) + end + end + + it 'sets the memcache_servers attribute' do + expect(chef_run).to render_file(file.name).with_content(/^memcache_servers = 127.0.0.1:11211$/) + end + + context 'domain_remap' do + %w(log_name log_facility log_level log_headers).each do |attr| + it "sets the #{attr} attribute" do + node.set['openstack']['object-storage']['domain_remap'][attr] = "#{attr}_value" + expect(chef_run).to render_file(file.name).with_content(/^set #{attr} = #{attr}_value$/) + end + end + + %w(storage_domain path_root reseller_prefixes).each do |attr| + it "sets the #{attr} attribute" do + node.set['openstack']['object-storage']['domain_remap'][attr] = "#{attr}_value" + expect(chef_run).to render_file(file.name).with_content(/^#{attr} = #{attr}_value$/) + end + end + end + + context 'staticweb' do + it 'sets the cache_timeout attribute' do + node.set['openstack']['object-storage']['staticweb']['cache_timeout'] = 'cache_timeout_value' + expect(chef_run).to render_file(file.name).with_content(/^cache_timeout = cache_timeout_value$/) + end + + %w(log_name log_facility log_level access_log_name access_log_facility access_log_level log_headers).each do |attr| + it "sets the #{attr} attribute" do + node.set['openstack']['object-storage']['staticweb'][attr] = "#{attr}_value" + expect(chef_run).to render_file(file.name).with_content(/^set #{attr} = #{attr}_value$/) + end + end + end + + context 'tempurl' do + %w(incoming_remove_headers incoming_allow_headers outgoing_remove_headers outgoing_allow_headers).each do |attr| + it "sets the #{attr} attribute" do + node.set['openstack']['object-storage']['tempurl'][attr] = "#{attr}_value" + expect(chef_run).to render_file(file.name).with_content(/^#{attr} = #{attr}_value$/) + end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c6d47be..405985a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -87,3 +87,52 @@ shared_examples 'keystone-authmode' do end end end + +shared_examples 'a common swift server configurator' do |server_type| + %w(ip port).each do |attr| + it "sets the bind_#{attr} attr" do + node.set['openstack']['object-storage']['network']["#{server_type}-bind-#{attr}"] = "#{attr}_value" + expect(chef_run).to render_file(file.name).with_content(/^bind_#{attr} = #{attr}_value$/) + end + end + + context 'statistics enabled' do + before do + node.set['openstack']['object-storage']['statistics']['enabled'] = true + end + + it 'sets the log_statsd_default_sample_rate attribute' do + node.set['openstack']['object-storage']['statistics']['sample_rate'] = 'sample_rate_value' + expect(chef_run).to render_file(file.name).with_content(/^log_statsd_default_sample_rate = sample_rate_value$/) + end + + it 'sets the log_statsd_metric_prefix attribute' do + node.set['openstack']['object-storage']['statistics']['statsd_prefix'] = 'statsd_prefix_value' + chef_run.node.automatic['hostname'] = 'myhostname' + expect(chef_run).to render_file(file.name).with_content(/^log_statsd_metric_prefix = statsd_prefix_value\.myhostname$/) + end + end + + it 'does not show statistic related attributed when disabled' do + node.set['openstack']['object-storage']['statistics']['enabled'] = false + expect(chef_run).not_to render_file(file.name).with_content(/^log_statsd_host = localhost$/) + end +end + +shared_examples 'a common swift server default attribute values checker' do |server_type| + it 'bind_ip' do + expect(chef_run.node['openstack']['object-storage']['network']["#{server_type}-bind-ip"]).to eq('0.0.0.0') + end + + it 'log_statsd_default_sample_rate' do + expect(chef_run.node['openstack']['object-storage']['statistics']['sample_rate']).to eq(1) + end + + it 'statsd_prefix' do + expect(chef_run.node['openstack']['object-storage']['statistics']['statsd_prefix']).to eq('openstack.swift') + end + + it 'hostname' do + expect(chef_run.node['hostname']).to eq('Fauxhai') + end +end diff --git a/templates/default/proxy-server.conf.erb b/templates/default/proxy-server.conf.erb index 1b42fdf..c4be372 100644 --- a/templates/default/proxy-server.conf.erb +++ b/templates/default/proxy-server.conf.erb @@ -108,7 +108,7 @@ use = egg:swift#proxy # account_autocreate = false allow_account_management = <%= account_management %> -<% if pipeline.include?("keystone") -%> +<% if pipeline.include?("keystoneauth") -%> account_autocreate = true <% end %> @@ -123,7 +123,7 @@ default_swift_cluster = local#<%= node['openstack']['object-storage']['swift_url <% if pipeline.include?("tempurl") -%> allow_overrides = true <% end %> -<% if node['openstack']['object-storage']['container-server']['allowed_sync_hosts'] -%> +<% if node['openstack']['object-storage']['container-server']['allowed_sync_hosts'].any? -%> allowed_sync_hosts = <%= node['openstack']['object-storage']['container-server']['allowed_sync_hosts'].join(",") %> <% end %> <% end %>