Skip to content

Commit

Permalink
Add packages install method.
Browse files Browse the repository at this point in the history
  • Loading branch information
darron committed May 25, 2015
1 parent b532f1c commit f65ac72
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ suites:
attributes:
consul:
install_method: source
- name: packages
run_list:
- recipe[consul::default]
attributes:
consul:
datacenter: FortMeade
bind_interface: eth0
advertise_interface: eth0
encrypt: CGXC2NsXW4AvuB4h5ODYzQ==
install_method: packages
excludes:
- centos-7.0
- centos-6.5
- name: runit
run_list:
- recipe[consul::default]
Expand Down
1 change: 1 addition & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
'0.5.1_web_ui' => 'ad883aa52e1c0136ab1492bbcedad1210235f26d59719fb6de3ef6464f1ff3b1',
}
default['consul']['source_revision'] = 'master'
default['consul']['use_packagecloud_repo'] = true

# Service attributes
default['consul']['service_mode'] = 'bootstrap'
Expand Down
1 change: 1 addition & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@
depends 'golang', '~> 1.4'
depends 'runit'
depends 'yum-repoforge'
depends 'packagecloud'
2 changes: 2 additions & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
include_recipe 'consul::install_binary'
when 'source'
include_recipe 'consul::install_source'
when 'packages'
include_recipe 'consul::install_packages'
else
Chef::Application.fatal!("[consul::default] unknown install method, method=#{node['consul']['install_method']}")
end
34 changes: 34 additions & 0 deletions recipes/install_packages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Copyright 2014 John Bellone <jbellone@bloomberg.net>
# Copyright 2014 Bloomberg Finance L.P.
#
# 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.
#
# NOTE: This is only supported for Ubuntu 12.04LTS and 14.04LTS.

if node['consul']['use_packagecloud_repo']

packagecloud_repo "darron/consul" do
type "deb"
end

packagecloud_repo "darron/consul-webui" do
type "deb"
end

end

package 'consul'
package 'consul-webui'

include_recipe 'consul::_service'
55 changes: 55 additions & 0 deletions test/integration/packages/serverspec/localhost/consul_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require 'spec_helper'

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

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

describe file('/etc/consul.d') do
it { should be_directory }
end

describe file('/var/lib/consul') do
it { should be_directory }
end

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

describe command 'consul members -detailed' do
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
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
its(:exit_status) { should eq 0 }
# bind_addr should only be in the config if node[:consul][:bind_addr] is set
its(:stdout) { should match %r{"bind_addr":\s"#{eth0_ip}"}}
its(:stdout) { should match %r{"advertise_addr":\s"#{eth0_ip}"}}
end

describe command('grep encrypt /etc/consul.d/default.json') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match %r{"encrypt":\s"([^\"]*)"} }
end

describe file('/var/lib/consul/ui/index.html') do
it { should be_file }
end
5 changes: 5 additions & 0 deletions test/integration/packages/serverspec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'serverspec'

RSpec.configure do |c|
c.path = '/usr/local/bin:/sbin:/bin:/usr/bin'
end

0 comments on commit f65ac72

Please sign in to comment.