From f65ac72378a2691e735b04fb76b08a290b01c452 Mon Sep 17 00:00:00 2001 From: Darron Froese Date: Mon, 25 May 2015 12:14:25 -0600 Subject: [PATCH] Add packages install method. --- .kitchen.yml | 13 +++++ attributes/default.rb | 1 + metadata.rb | 1 + recipes/default.rb | 2 + recipes/install_packages.rb | 34 ++++++++++++ .../serverspec/localhost/consul_spec.rb | 55 +++++++++++++++++++ .../packages/serverspec/spec_helper.rb | 5 ++ 7 files changed, 111 insertions(+) create mode 100644 recipes/install_packages.rb create mode 100644 test/integration/packages/serverspec/localhost/consul_spec.rb create mode 100644 test/integration/packages/serverspec/spec_helper.rb diff --git a/.kitchen.yml b/.kitchen.yml index a1453734..ee4c48db 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -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] diff --git a/attributes/default.rb b/attributes/default.rb index cd94e67a..9af4dc3f 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -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' diff --git a/metadata.rb b/metadata.rb index 7a6fce08..5ac232a7 100644 --- a/metadata.rb +++ b/metadata.rb @@ -26,3 +26,4 @@ depends 'golang', '~> 1.4' depends 'runit' depends 'yum-repoforge' +depends 'packagecloud' diff --git a/recipes/default.rb b/recipes/default.rb index 424d1eee..05d96fbd 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -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 diff --git a/recipes/install_packages.rb b/recipes/install_packages.rb new file mode 100644 index 00000000..3b5b94e4 --- /dev/null +++ b/recipes/install_packages.rb @@ -0,0 +1,34 @@ +# +# Copyright 2014 John Bellone +# 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' diff --git a/test/integration/packages/serverspec/localhost/consul_spec.rb b/test/integration/packages/serverspec/localhost/consul_spec.rb new file mode 100644 index 00000000..aee11c01 --- /dev/null +++ b/test/integration/packages/serverspec/localhost/consul_spec.rb @@ -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 diff --git a/test/integration/packages/serverspec/spec_helper.rb b/test/integration/packages/serverspec/spec_helper.rb new file mode 100644 index 00000000..f94e0e67 --- /dev/null +++ b/test/integration/packages/serverspec/spec_helper.rb @@ -0,0 +1,5 @@ +require 'serverspec' + +RSpec.configure do |c| + c.path = '/usr/local/bin:/sbin:/bin:/usr/bin' +end