Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GOMAXPROCS picks number of CPUs using sysconfig - Also updated Serverspec to 2.0 #52

Merged
merged 17 commits into from
Oct 25, 2014
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@
# UI attributes
default['consul']['client_addr'] = '0.0.0.0'
default['consul']['ui_dir'] = '/var/lib/consul/ui'
default['consul']['serve_ui'] = false
default['consul']['serve_ui'] = false
8 changes: 8 additions & 0 deletions recipes/_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@

case node['consul']['init_style']
when 'init'
template '/etc/sysconfig/consul' do
source 'consul-sysconfig.erb'
mode 0755
variables(
gomaxprocs: node['cpu']['total']

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

)
notifies :create, 'template[/etc/init.d/consul]', :immediately
end
template '/etc/init.d/consul' do
source 'consul-init.erb'
mode 0755
Expand Down
5 changes: 5 additions & 0 deletions spec/unit/recipes/_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
.with(group: 'root')
.with(mode: 0600)
end
it do
expect(chef_run).to create_template('/etc/sysconfig/consul')
.with(source: 'consul-sysconfig.erb')
.with(mode: 0755)
end
it do
expect(chef_run).to create_template('/etc/init.d/consul')
.with(source: 'consul-init.erb')
Expand Down
6 changes: 6 additions & 0 deletions templates/default/consul-init.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
# * Multi Datacenter
### END INIT INFO

if [ -f /etc/sysconfig/consul ]; then
. /etc/sysconfig/consul
fi

export GOMAXPROCS=${GOMAXPROCS:-2}

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.


CMD="<%= @consul_binary %> agent -config-dir <%= @config_dir %>"
NAME="consul"

Expand Down
1 change: 1 addition & 0 deletions templates/default/consul-sysconfig.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GOMAXPROCS=<%= @gomaxprocs %>
18 changes: 9 additions & 9 deletions test/integration/default/serverspec/localhost/consul_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe command('which consul') do
it { should return_exit_status 0 }
its(:exit_status) { should eq 0 }
its(:stdout) { should match '/usr/local/bin/consul' }
end

Expand All @@ -25,22 +25,22 @@
end

describe command 'consul members -detailed' do
it { should return_exit_status 0 }
it { should return_stdout %r{\balive\b} }
it { should return_stdout %r{\brole=consul\b} }
it { should return_stdout %r{\bbootstrap=1\b} }
its(:exit_status) { should eq 0 }
its(:stdout) { should match %r{\balive\b} }
its(:stdout) { should match %r{\brole=consul\b} }
its(:stdout) { should match %r{\bbootstrap=1\b}}
end

describe 'config file attributes' do
context command 'consul members -detailed' do
it { should return_stdout %r{\bdc=FortMeade\b} }
its(:stdout) { should match %r{\bdc=FortMeade\b}}
end
end

eth0_ip = command("/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'").stdout.strip
describe command("grep #{eth0_ip} /etc/consul.d/default.json") do
it { should return_exit_status 0 }
its(:exit_status) { should eq 0 }
# bind_addr should only be in the config if node[:consul][:bind_addr] is set
it { should return_stdout %r{"bind_addr":\s"#{eth0_ip}"}}
it { should return_stdout %r{"advertise_addr":\s"#{eth0_ip}"}}
its(:stdout) { should match %r{"bind_addr":\s"#{eth0_ip}"} }
its(:stdout) { should match %r{"advertise_addr":\s"#{eth0_ip}"} }
end
9 changes: 2 additions & 7 deletions test/integration/default/serverspec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
require 'serverspec'

include SpecInfra::Helper::Exec
include SpecInfra::Helper::DetectOS

RSpec.configure do |c|
c.path = '/usr/local/bin:/sbin:/bin:/usr/bin'
end
set :backend, :exec
set :path, '/usr/local/bin:/bin:/sbin:/usb/sbin:$PATH'
8 changes: 4 additions & 4 deletions test/integration/ui/serverspec/localhost/consul_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require 'spec_helper'

describe file('/var/lib/consul/ui/index.html') do
describe file('/var/lib/consul/ui/consul_ui/index.html') do

This comment was marked as outdated.

This comment was marked as outdated.

it { should be_file }
end

eth0_ip = command("/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'").stdout.strip
describe command("wget -q -O- http://#{eth0_ip}:8500/ui/index.html") do
it { should return_exit_status 0 }
its(:stdout) { should == File.read('/var/lib/consul/ui/index.html') }
describe command("wget -q -O- http://#{eth0_ip}:8500/ui/consul_ui/index.html") do
its(:exit_status) { should eq 0 }
its(:stdout) { should eq File.read('/var/lib/consul/ui/consul_ui/index.html') }
end
17 changes: 2 additions & 15 deletions test/integration/ui/serverspec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
begin
require 'rspec/its'
rescue LoadError
require 'rubygems/dependency_installer'
Gem::DependencyInstaller.new.install('rspec-its')
require 'rspec/its'
end

require 'serverspec'

include SpecInfra::Helper::Exec
include SpecInfra::Helper::DetectOS

RSpec.configure do |c|
c.path = '/usr/local/bin:/sbin:/bin:/usr/bin'
end
set :backend, :exec
set :path, '/usr/local/bin:/bin:/sbin:/usb/sbin:$PATH'