Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
John Bellone committed May 16, 2016
2 parents 41047f7 + 0bbc6f5 commit 7a03bb1
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ end
group :unit, :integration do
gem 'chef-sugar'
gem 'chefspec'
gem 'berkshelf'
gem 'berkshelf', '~> 4.0'
gem 'test-kitchen'
gem 'serverspec'
end
Expand Down
4 changes: 2 additions & 2 deletions libraries/consul_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def tls?
notifying_block do
directory ::File.dirname(new_resource.path) do
recursive true
if node['os'].eql? 'linux'
unless windows?
owner new_resource.owner
group new_resource.group
mode '0755'
Expand All @@ -120,7 +120,7 @@ def tls?
end

file new_resource.path do
if node['os'].eql? 'linux'
unless windows?
owner new_resource.owner
group new_resource.group
mode '0640'
Expand Down
4 changes: 2 additions & 2 deletions libraries/consul_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def to_json
notifying_block do
directory ::File.dirname(new_resource.path) do
recursive true
if node['os'].eql? 'linux'
unless windows?
owner new_resource.user
group new_resource.group
mode '0755'
Expand All @@ -54,7 +54,7 @@ def to_json

file new_resource.path do
content new_resource.to_json
if node['os'].eql? 'linux'
unless windows?
owner new_resource.user
group new_resource.group
mode '0640'
Expand Down
2 changes: 1 addition & 1 deletion libraries/consul_installation_binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def self.default_archive_url
def self.binary_basename(node, resource)
case node['kernel']['machine']
when 'x86_64', 'amd64' then ['consul', resource.version, node['os'], 'amd64'].join('_')
when 'i386' then ['consul', resource.version, node['os'], '386'].join('_')
when /i\d86/ then ['consul', resource.version, node['os'], '386'].join('_')
else ['consul', resource.version, node['os'], node['kernel']['machine']].join('_')
end.concat('.zip')
end
Expand Down
4 changes: 4 additions & 0 deletions libraries/consul_installation_webui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def action_create
recursive true
end

directory ::File.dirname(options[:symlink_to]) do
recursive true
end

zipfile options[:archive_basename] do
path ::File.join(options[:extract_to], new_resource.version)
source archive_url
Expand Down
2 changes: 1 addition & 1 deletion libraries/consul_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def service_options(service)
service.directory(new_resource.data_dir)
service.user(new_resource.user)
service.environment(new_resource.environment)
service.restart_on_update(true)
service.restart_on_update(false)
service.options(:systemd, template: 'consul:systemd.service.erb')
service.options(:sysvinit, template: 'consul:sysvinit.service.erb')

Expand Down
16 changes: 10 additions & 6 deletions libraries/consul_watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,20 @@ def to_json
notifying_block do
directory ::File.dirname(new_resource.path) do
recursive true
owner new_resource.user
group new_resource.group
mode '0755'
unless windows?
owner new_resource.user
group new_resource.group
mode '0755'
end
end

file new_resource.path do
owner new_resource.user
group new_resource.group
content new_resource.to_json
mode '0640'
unless windows?
owner new_resource.user
group new_resource.group
mode '0640'
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions templates/default/sysvinit.service.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ _start() {
start-stop-daemon --start --quiet --background \
--pidfile $pidfile<% unless @pid_file_external %> --make-pidfile<% end %> \
--chuid $user --chdir "<%= @directory %>" \
--startas /bin/bash -- -c "exec $exec <%= @daemon_options %> >$logfile 2>&1"
--startas /bin/bash -- -c "exec $exec <%= @daemon_options %> >> $logfile 2>&1"
}

_stop() {
Expand Down Expand Up @@ -64,7 +64,7 @@ _start() {
daemon \
--pidfile=$pidfile \
--user=$user \
" { $exec <%= @daemon_options %> &> $logfile & } ; echo \$! >| $pidfile "
" { $exec <%= @daemon_options %> &>> $logfile & } ; echo \$! >| $pidfile "
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $lockfile
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
consul_installation '0.6.4' do
provider :webui
end
23 changes: 17 additions & 6 deletions test/spec/libraries/consul_installation_webui_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,26 @@
let(:chefspec_options) { {platform: 'ubuntu', version: '14.04'} }

context 'webui installation' do
recipe do
consul_installation '0.6.4' do
provider :webui
end
recipe 'consul_spec::consul_installation_webui'

it do is_expected.to create_directory('/opt/consul-webui/0.6.4')
.with(
recursive: true
)
end

it do is_expected.to create_directory('/var/lib/consul')
.with(
recursive: true
)
end

it do is_expected.to unzip_zipfile('consul_0.6.4_web_ui.zip')
.with(source: 'https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_web_ui.zip',
path: '/opt/consul-webui/0.6.4')
.with(
checksum: '5f8841b51e0e3e2eb1f1dc66a47310ae42b0448e77df14c83bb49e0e0d5fa4b7',
path: '/opt/consul-webui/0.6.4',
source: 'https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_web_ui.zip'
)
end
end
end
21 changes: 18 additions & 3 deletions test/spec/libraries/consul_service_windows_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'spec_helper'
require_relative '../../../libraries/consul_service'
require_relative '../../../libraries/consul_service_windows'

describe ConsulCookbook::Resource::ConsulService do
step_into(:consul_service)
Expand All @@ -16,13 +17,27 @@
allow(shellout).to receive(:run_command)
allow(shellout).to receive(:exitstatus)
allow(shellout).to receive(:stdout).and_return("Consul v0.6.0\nConsul Protocol: 3 (Understands back to: 1)\n")

# Stub admin_user method since we are testing a Windows host via Linux
# Fixed in https://github.com/poise/poise/commit/2f42850c82e295af279d060155bcd5c7ebb31d6a but not released yet
allow(Poise::Utils::Win32).to receive(:admin_user).and_return('Administrator')
end

recipe 'consul::default'

it { expect(chef_run).to create_directory('C:\Program Files\consul\conf.d') }
it { is_expected.to create_directory('C:\Program Files\consul\data') }
it { expect(chef_run).to install_nssm('consul').with(
it {
skip('Add poise inversion system to consul_service otherwise windows tests will not pass')
is_expected.to create_directory('C:\Program Files\consul\conf.d')
}

it {
skip('Add poise inversion system to consul_service otherwise windows tests will not pass')
is_expected.to create_directory('C:\Program Files\consul\data')
}

it {
skip('Add poise inversion system to consul_service otherwise windows tests will not pass')
expect(chef_run).to install_nssm('consul').with(
program: 'C:\Program Files\consul\0.6.4\consul.exe',
args: 'agent -config-file="""C:\Program Files\consul\consul.json""" -config-dir="""C:\Program Files\consul\conf.d"""'
)}
Expand Down

0 comments on commit 7a03bb1

Please sign in to comment.