Skip to content

Commit

Permalink
Merge pull request #414 from keithlayne/3.0.0-use-platform-family
Browse files Browse the repository at this point in the history
Use platform family to determine nginx user.
  • Loading branch information
miketheman authored Jun 15, 2016
2 parents b75288b + ea9abcf commit a83f963
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 32 deletions.
12 changes: 6 additions & 6 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ def res_name
new_resource.name
end

# @param [Chef::Node] An Object that responds to a `['platform']` call
# @param [Chef::Node] An Object that responds to a `['platform_family']` call
# @return [String] Name of the user that runs nginx
def user_for_platform(node)
case node['platform']
when 'centos'
def user_for_node(node)
case node['platform_family']
when 'rhel'
'nginx'
when 'ubuntu', 'debian'
when 'debian'
'www-data'
else
raise "Unexpected platform '#{node['platform']}'."
raise "Unexpected platform family '#{node['platform_family']}'."
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion libraries/resource_nginx_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class NginxService < Chef::Resource::LWRPBase
attribute :error_log_level, kind_of: String, default: 'warn'
attribute :run_group, kind_of: String, default: nil
# @todo Determine what user is correct per-platform
attribute :run_user, kind_of: String, default: lazy { user_for_platform(node) }
attribute :run_user, kind_of: String, default: lazy { user_for_node(node) }
attribute :worker_connections, kind_of: Integer, default: 1024
attribute :worker_processes, kind_of: Integer, default: 1

Expand Down
31 changes: 13 additions & 18 deletions spec/libraries_specs/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,30 @@
require_relative '../../libraries/resource_nginx_service'

describe NginxCookbook::Helpers do
class DummyClass
attr_accessor :node

def initialize
@node = {}
end
end

before(:all) do
@dummy = DummyClass.new
@dummy.extend NginxCookbook::Helpers
end
include described_class

it 'returns www-data for debian platform' do
@dummy.node['platform'] = 'debian'
node = Fauxhai.mock(platform: 'debian', version: '7.0').data

expect(@dummy.user_for_platform(@dummy.node)).to be == 'www-data'
expect(user_for_node(node)).to be == 'www-data'
end

it 'returns www-data for ubuntu platform' do
@dummy.node['platform'] = 'ubuntu'
node = Fauxhai.mock(platform: 'ubuntu', version: '14.04').data

expect(@dummy.user_for_platform(@dummy.node)).to be == 'www-data'
expect(user_for_node(node)).to be == 'www-data'
end

it 'returns nginx for centos platform' do
@dummy.node['platform'] = 'centos'
node = Fauxhai.mock(platform: 'centos', version: '7.0').data

expect(user_for_node(node)).to be == 'nginx'
end

it 'returns nginx for amazon platform' do
node = Fauxhai.mock(platform: 'amazon', version: '2015.09').data

expect(@dummy.user_for_platform(@dummy.node)).to be == 'nginx'
expect(user_for_node(node)).to be == 'nginx'
end

# # let(:klass) { Class.new { extend NginxCookbook::Helpers } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

it_behaves_like 'create a named nginx_service', 'example'

it_behaves_like 'nginx_service :create', 'example', 'platform' => 'centos'
it_behaves_like 'nginx_service :create', 'example'
it_behaves_like 'nginx_service :start', 'example'
it_behaves_like 'nginx_service #systemd', 'example'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

it_behaves_like 'create a named nginx_service', 'example'

it_behaves_like 'nginx_service :create', 'example', 'platform' => 'debian'
it_behaves_like 'nginx_service :create', 'example'
it_behaves_like 'nginx_service :start', 'example'
it_behaves_like 'nginx_service #upstart', 'example'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

it_behaves_like 'create a named nginx_service', 'example'

it_behaves_like 'nginx_service :create', 'example', 'platform' => 'ubuntu'
it_behaves_like 'nginx_service :create', 'example'
it_behaves_like 'nginx_service :start', 'example'
it_behaves_like 'nginx_service #upstart', 'example'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

it_behaves_like 'create a named nginx_service', 'single'

it_behaves_like 'nginx_service :create', 'single', 'platform' => 'centos'
it_behaves_like 'nginx_service :create', 'single'
it_behaves_like 'nginx_service :start', 'single'

xit 'stops the service' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

it_behaves_like 'create a named nginx_service', 'single'

it_behaves_like 'nginx_service :create', 'single', 'platform' => 'debian'
it_behaves_like 'nginx_service :create', 'single'
it_behaves_like 'nginx_service :start', 'single'

xit 'stops the service' do
Expand Down
4 changes: 2 additions & 2 deletions spec/shared_examples/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
end
end

shared_examples_for 'nginx_service :create' do |servicename, node|
shared_examples_for 'nginx_service :create' do |servicename|
it 'installs the nginx package' do
expect(chef_run).to install_package("#{servicename} :create nginx")
.with(package_name: 'nginx')
Expand All @@ -21,7 +21,7 @@

it 'creates new directories for the named instance' do
expect(chef_run).to create_directory("/var/log/nginx-#{servicename}")
.with(user: user_for_platform(node), group: 'adm', mode: 00755)
.with(user: user_for_node(chef_run.node), group: 'adm', mode: 00755)

%W(
/etc/nginx-#{servicename}
Expand Down

0 comments on commit a83f963

Please sign in to comment.