forked from sous-chefs/chef-splunk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'searchhead_clustering' of https://github.com/vidkun/che…
…f-splunk into vidkun-searchhead_clustering
- Loading branch information
Showing
8 changed files
with
357 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# | ||
# Cookbook Name:: splunk | ||
# Recipe:: setup_shclustering | ||
# | ||
# Author: Ryan LeViseur <[email protected]> | ||
# Copyright (c) 2014, Chef Software, Inc <[email protected]> | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
unless node['splunk']['shclustering']['enabled'] | ||
Chef::Log.debug('The chef-splunk::setup_shclustering recipe was added to the node,') | ||
Chef::Log.debug('but the attribute to enable search head clustering was not set.') | ||
return | ||
end | ||
|
||
# ensure that the splunk service resource is available without cloning | ||
# the resource (CHEF-3694). this is so the later notification works, | ||
# especially when using chefspec to run this cookbook's specs. | ||
begin | ||
resources('service[splunk]') | ||
rescue Chef::Exceptions::ResourceNotFound | ||
service 'splunk' | ||
end | ||
|
||
include_recipe 'chef-vault' | ||
|
||
passwords = chef_vault_item('vault', "splunk_#{node.chef_environment}") | ||
splunk_auth_info = passwords['auth'] | ||
shcluster_secret = passwords['secret'] | ||
shcluster_params = node['splunk']['shclustering'] | ||
|
||
# create app directories to house our server.conf with our shcluster configuration | ||
shcluster_app_dir = "#{splunk_dir}/etc/apps/0_autogen_shcluster_config" | ||
|
||
directory shcluster_app_dir do | ||
owner node['splunk']['user']['username'] | ||
group node['splunk']['user']['username'] | ||
mode 0755 | ||
end | ||
|
||
directory "#{shcluster_app_dir}/local" do | ||
owner node['splunk']['user']['username'] | ||
group node['splunk']['user']['username'] | ||
mode 0755 | ||
end | ||
|
||
template "#{shcluster_app_dir}/local/server.conf" do | ||
source 'shclustering/server.conf.erb' | ||
mode 0600 | ||
owner node['splunk']['user']['username'] | ||
group node['splunk']['user']['username'] | ||
variables( | ||
shcluster_params: node['splunk']['shclustering'], | ||
shcluster_secret: shcluster_secret | ||
) | ||
sensitive true | ||
notifies :restart, 'service[splunk]', :immediately | ||
end | ||
|
||
# bootstrap the shcluster and elect a captain if initial_captain set to true and this is the initial shcluster build | ||
if node['splunk']['shclustering']['mode'] == 'captain' | ||
# unless shcluster members are staticly assigned via the node attribute, | ||
# try to find the other shcluster members via Chef search | ||
if shcluster_params['shcluster_members'].empty? | ||
shcluster_servers_list = [] | ||
search( # ~FC003 | ||
:node, | ||
"\ | ||
splunk_shclustering_enabled:true AND \ | ||
splunk_shclustering_label:#{node['splunk']['shclustering']['label']} AND \ | ||
chef_environment:#{node.chef_environment}" | ||
).each do |result| | ||
shcluster_servers_list << result['splunk']['shclustering']['mgmt_uri'] | ||
end | ||
else | ||
shcluster_servers_list = shcluster_params['shcluster_members'] | ||
end | ||
|
||
execute 'bootstrap-shcluster' do | ||
command "#{splunk_cmd} bootstrap shcluster-captain -servers_list '#{shcluster_servers_list.join(',')}' -auth '#{splunk_auth_info}'" | ||
not_if { ::File.exist?("#{splunk_dir}/etc/.setup_shcluster") } | ||
notifies :restart, 'service[splunk]' | ||
end | ||
end | ||
|
||
file "#{splunk_dir}/etc/.setup_shcluster" do | ||
content 'true\n' | ||
owner node['splunk']['user']['username'] | ||
group node['splunk']['user']['username'] | ||
mode 00600 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
require_relative '../spec_helper' | ||
|
||
describe 'chef-splunk::setup_shclustering' do | ||
let(:secrets) do | ||
{ | ||
'splunk__default' => { | ||
'id' => 'splunk__default', | ||
'auth' => 'admin:notarealpassword', | ||
'secret' => 'notarealsecret', | ||
}, | ||
} | ||
end | ||
|
||
let(:deployer_node) do | ||
stub_node(platform: 'ubuntu', version: '12.04') do |node| | ||
node.automatic['fqdn'] = 'deploy.cluster.example.com' | ||
node.automatic['ipaddress'] = '192.168.0.10' | ||
node.normal['dev_mode'] = true | ||
node.normal['splunk']['is_server'] = true | ||
node.normal['splunk']['shclustering']['enabled'] = true | ||
end | ||
end | ||
|
||
context 'default server settings' do | ||
let(:chef_run) do | ||
ChefSpec::ServerRunner.new do |node, server| | ||
node.normal['splunk']['is_server'] = true | ||
# Populate mock vault data bag to the server | ||
server.create_data_bag('vault', secrets) | ||
end.converge(described_recipe) | ||
end | ||
|
||
it 'does nothing' do | ||
expect(chef_run.resource_collection).to be_empty | ||
end | ||
end | ||
|
||
context 'search head cluster member settings' do | ||
let(:chef_run) do | ||
ChefSpec::ServerRunner.new do |node, server| | ||
node.normal['dev_mode'] = true | ||
node.normal['splunk']['is_server'] = true | ||
node.normal['splunk']['shclustering']['enabled'] = true | ||
node.normal['splunk']['shclustering']['deployer_url'] = "https://#{deployer_node.fqdn}:8089" | ||
node.normal['splunk']['shclustering']['mgmt_uri'] = "https://#{node['fqdn']}:8089" | ||
node.normal['splunk']['shclustering']['shcluster_members'] = [ | ||
'https://shcluster-member01:8089', | ||
'https://shcluster-member02:8089', | ||
'https://shcluster-member03:8089', | ||
] | ||
# Populate mock vault data bag to the server | ||
server.create_data_bag('vault', secrets) | ||
end.converge(described_recipe) | ||
end | ||
|
||
let(:shcluster_servers_list) do | ||
chef_run.node['splunk']['shclustering']['shcluster_members'].join(',') | ||
end | ||
|
||
it 'includes chef-vault' do | ||
expect(chef_run).to include_recipe('chef-vault::default') | ||
end | ||
|
||
it 'writes a file marker to ensure convergence' do | ||
expect(chef_run).to render_file('/opt/splunk/etc/.setup_shcluster').with_content('true\n') | ||
end | ||
|
||
it 'writes server.conf with replication port' do | ||
expect(chef_run).to render_file('/opt/splunk/etc/apps/0_autogen_shcluster_config/local/server.conf') | ||
.with_content("[replication_port://#{chef_run.node['splunk']['shclustering']['replication_port']}]") | ||
end | ||
|
||
it 'writes server.conf with a shclustering stanza' do | ||
expect(chef_run).to render_file('/opt/splunk/etc/apps/0_autogen_shcluster_config/local/server.conf') | ||
.with_content('[shclustering]') | ||
end | ||
|
||
it 'writes server.conf with the deployer url' do | ||
expect(chef_run).to render_file('/opt/splunk/etc/apps/0_autogen_shcluster_config/local/server.conf') | ||
.with_content("conf_deploy_fetch_url = #{chef_run.node['splunk']['shclustering']['deployer_url']}") | ||
end | ||
|
||
it 'writes server.conf with the node mgmt uri' do | ||
expect(chef_run).to render_file('/opt/splunk/etc/apps/0_autogen_shcluster_config/local/server.conf') | ||
.with_content("mgmt_uri = #{chef_run.node['splunk']['shclustering']['mgmt_uri']}") | ||
end | ||
|
||
it 'writes server.conf with the shcluster replication factor' do | ||
expect(chef_run).to render_file('/opt/splunk/etc/apps/0_autogen_shcluster_config/local/server.conf') | ||
.with_content("replication_factor = #{chef_run.node['splunk']['shclustering']['replication_factor']}") | ||
end | ||
|
||
it 'writes server.conf with the shcluster label' do | ||
expect(chef_run).to render_file('/opt/splunk/etc/apps/0_autogen_shcluster_config/local/server.conf') | ||
.with_content("shcluster_label = #{chef_run.node['splunk']['shclustering']['label']}") | ||
end | ||
|
||
it 'writes server.conf with the shcluster secret' do | ||
expect(chef_run).to render_file('/opt/splunk/etc/apps/0_autogen_shcluster_config/local/server.conf') | ||
.with_content("pass4SymmKey = #{secrets['splunk__default']['secret']}") | ||
end | ||
|
||
it 'does not run command to bootstrap captain' do | ||
expect(chef_run).to_not run_execute('bootstrap-shcluster') | ||
end | ||
|
||
context 'while set to captain mode' do | ||
before(:each) do | ||
chef_run.node.normal['splunk']['shclustering']['mode'] = 'captain' | ||
chef_run.converge(described_recipe) | ||
end | ||
|
||
context 'during initial chef run' do | ||
it 'runs command to bootstrap captain with correct parameters' do | ||
expect(chef_run).to run_execute('bootstrap-shcluster').with( | ||
'command' => "/opt/splunk/bin/splunk bootstrap shcluster-captain -servers_list '#{shcluster_servers_list}'\ | ||
-auth '#{secrets['splunk__default']['auth']}'" | ||
) | ||
expect(chef_run.execute('bootstrap-shcluster')).to notify('service[splunk]').to(:restart) | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.