diff --git a/.kitchen.yml b/.kitchen.yml index e55d087d..87e3194f 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -28,6 +28,7 @@ suites: datacenter: FortMeade bind_interface: eth0 advertise_interface: eth0 + encrypt: CGXC2NsXW4AvuB4h5ODYzQ== - name: runit run_list: - recipe[consul::default] diff --git a/recipes/_service.rb b/recipes/_service.rb index b85ffb8b..df89b375 100644 --- a/recipes/_service.rb +++ b/recipes/_service.rb @@ -110,7 +110,7 @@ end copy_params = [ - :bind_addr, :datacenter, :domain, :log_level, :node_name, :advertise_addr, :enable_syslog + :bind_addr, :datacenter, :domain, :log_level, :node_name, :advertise_addr, :enable_syslog, :encrypt ] copy_params.each do |key| if node['consul'][key] diff --git a/recipes/ui.rb b/recipes/ui.rb index 53ad44ba..6104a6f0 100644 --- a/recipes/ui.rb +++ b/recipes/ui.rb @@ -19,9 +19,9 @@ install_checksum = node['consul']['checksums'].fetch(install_version) ark 'consul_ui' do - path node['consul']['ui_dir'] + path node['consul']['data_dir'] + home_dir node['consul']['ui_dir'] version node['consul']['version'] checksum install_checksum url ::URI.join(node['consul']['base_url'], "#{install_version}.zip").to_s - action :put end diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index 69908c22..422b8a5f 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -29,3 +29,7 @@ def put_ark(name) def dump_ark(name) ChefSpec::Matchers::ResourceMatcher.new(:ark, :dump, name) end + +def install_ark(name) + ChefSpec::Matchers::ResourceMatcher.new(:ark, :install, name) +end diff --git a/spec/unit/recipes/_service_spec.rb b/spec/unit/recipes/_service_spec.rb index af75c8e1..bf2fa52c 100644 --- a/spec/unit/recipes/_service_spec.rb +++ b/spec/unit/recipes/_service_spec.rb @@ -41,6 +41,8 @@ it do expect(chef_run).to create_directory('/etc/consul.d') .with(mode: 0755) + expect(chef_run).to create_directory('/var/log/consul') + .with(mode: 0755) end it do expect(chef_run).to create_user('consul service user: consul') diff --git a/spec/unit/recipes/ui_spec.rb b/spec/unit/recipes/ui_spec.rb index aa2163cb..7d96733e 100644 --- a/spec/unit/recipes/ui_spec.rb +++ b/spec/unit/recipes/ui_spec.rb @@ -3,8 +3,9 @@ describe_recipe 'consul::ui' do it { expect(chef_run).to include_recipe('ark::default') } it do - expect(chef_run).to put_ark('consul_ui') - .with(path: '/var/lib/consul/ui') + expect(chef_run).to install_ark('consul_ui') + .with(path: '/var/lib/consul') + .with(home_dir: '/var/lib/consul/ui') .with(version: '0.4.0') end end diff --git a/test/integration/default/serverspec/localhost/consul_spec.rb b/test/integration/default/serverspec/localhost/consul_spec.rb index f83de45e..3028e541 100644 --- a/test/integration/default/serverspec/localhost/consul_spec.rb +++ b/test/integration/default/serverspec/localhost/consul_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe command('which consul') do - it { should return_exit_status 0 } + its(:exit_status) { should eq 0 } its(:stdout) { should match '/usr/local/bin/consul' } end @@ -25,22 +25,27 @@ end describe command 'consul members -detailed' do - it { should return_exit_status 0 } - it { should return_stdout %r{\balive\b} } - it { should return_stdout %r{\brole=consul\b} } - it { should return_stdout %r{\bbootstrap=1\b} } + 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 - it { should return_stdout %r{\bdc=FortMeade\b} } + 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 - it { should return_exit_status 0 } + its(:exit_status) { should eq 0 } # bind_addr should only be in the config if node[:consul][:bind_addr] is set - it { should return_stdout %r{"bind_addr":\s"#{eth0_ip}"}} - it { should return_stdout %r{"advertise_addr":\s"#{eth0_ip}"}} + 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 diff --git a/test/integration/default/serverspec/spec_helper.rb b/test/integration/default/serverspec/spec_helper.rb index f9b3d8ac..c0925118 100644 --- a/test/integration/default/serverspec/spec_helper.rb +++ b/test/integration/default/serverspec/spec_helper.rb @@ -1,7 +1,6 @@ require 'serverspec' -include SpecInfra::Helper::Exec -include SpecInfra::Helper::DetectOS +set :backend, :exec RSpec.configure do |c| c.path = '/usr/local/bin:/sbin:/bin:/usr/bin' diff --git a/test/integration/ui/serverspec/localhost/consul_spec.rb b/test/integration/ui/serverspec/localhost/consul_spec.rb index bf1b7ce9..69c84958 100644 --- a/test/integration/ui/serverspec/localhost/consul_spec.rb +++ b/test/integration/ui/serverspec/localhost/consul_spec.rb @@ -6,6 +6,6 @@ eth0_ip = command("/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'").stdout.strip describe command("wget -q -O- http://#{eth0_ip}:8500/ui/index.html") do - it { should return_exit_status 0 } - its(:stdout) { should == File.read('/var/lib/consul/ui/index.html') } + its(:exit_status) { should eq 0 } + its(:stdout) { should eq File.read('/var/lib/consul/ui/index.html') } end diff --git a/test/integration/ui/serverspec/spec_helper.rb b/test/integration/ui/serverspec/spec_helper.rb index ce064a85..1f1bebea 100644 --- a/test/integration/ui/serverspec/spec_helper.rb +++ b/test/integration/ui/serverspec/spec_helper.rb @@ -1,16 +1,4 @@ -begin - require 'rspec/its' -rescue LoadError - require 'rubygems/dependency_installer' - Gem::DependencyInstaller.new.install('rspec-its') - require 'rspec/its' -end - require 'serverspec' -include SpecInfra::Helper::Exec -include SpecInfra::Helper::DetectOS - -RSpec.configure do |c| - c.path = '/usr/local/bin:/sbin:/bin:/usr/bin' -end +set :backend, :exec +set :path, '$PATH:/usr/local/bin:/sbin:/bin:/usr/bin'