Skip to content

Commit

Permalink
Added required ACL token to Windows reload action. Added windows_clie…
Browse files Browse the repository at this point in the history
…nt suite
  • Loading branch information
Graham Davison committed Jul 6, 2017
1 parent a552ae7 commit 073dfc1
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ suites:

- name: client
named_run_list: client
excludes:
- windows-2012r2

- name: git
attributes:
Expand All @@ -50,9 +52,15 @@ suites:
provider: git
excludes:
- windows-2012r2

- name: windows
attributes:
consul:
config: *default-config
includes:
- windows-2012r2

- name: windows_client
named_run_list: client
includes:
- windows-2012r2
4 changes: 4 additions & 0 deletions libraries/consul_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class ConsulService < Chef::Resource
# The location of the Consul executable.
# @return [String]
attribute(:program, kind_of: String, default: '/usr/local/bin/consul')
# @!attribute acl_token
# The ACL token. Needed to reload the Consul service on Windows
# @return [String]
attribute(:acl_token, kind_of: String, default: lazy { node['consul']['config']['acl_master_token']})

def command
"#{program} agent -config-file=#{config_file} -config-dir=#{config_dir}"
Expand Down
2 changes: 1 addition & 1 deletion libraries/consul_service_windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def action_enable
def action_reload
notifying_block do
execute 'Reload consul' do
command 'consul.exe reload'
command 'consul.exe reload' + (new_resource.acl_token ? " -token=#{new_resource.acl_token}" : '')
cwd ::File.dirname(new_resource.program)
action :run
end
Expand Down
4 changes: 3 additions & 1 deletion recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
config_file config.path
program install.consul_program

unless node.platform_family?('windows')
if node.platform_family?('windows')
acl_token node['consul']['config']['acl_master_token']
else
user node['consul']['service_user']
group node['consul']['service_group']
end
Expand Down
4 changes: 2 additions & 2 deletions test/integration/windows/windows_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
it { should be_running }
end

[8300, 8400, 8500, 8600].each do |p|
[8300, 8500, 8600].each do |p|
describe port(p) do
it { should be_listening }
end
end

describe command("#{consul_command} members -detailed") do
describe command("#{consul_command} members -detailed -token=doublesecret") do
its(:exit_status) { should eq 0 }
its(:stdout) { should include 'alive' }
its(:stdout) { should include 'role=consul' }
Expand Down
36 changes: 36 additions & 0 deletions test/integration/windows_client/default_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require_relative '../spec_helper'

consul_executable = "C:\\Program\ Files\\consul\\#{consul_version}\\consul.exe"
consul_command = "& '#{consul_executable}'"

config_file = 'C:\Program Files\consul\consul.json'
config_dir = 'C:\Program Files\consul\conf.d'

describe file(consul_executable) do
it { should be_file }
end

describe service('consul') do
it { should be_enabled }
it { should be_running }
end

[8500, 8600].each do |p|
describe port(p) do
it { should be_listening }
end
end

describe command("#{consul_command} members -detailed -token=doublesecret") do
its(:exit_status) { should eq 0 }
its(:stdout) { should include 'alive' }
its(:stdout) { should include 'role=node' }
end

describe file(config_file) do
it { should be_file }
end

describe file(config_dir) do
it { should be_directory }
end

0 comments on commit 073dfc1

Please sign in to comment.