diff --git a/spec/configuration/ale_spec.rb b/spec/configuration/ale_spec.rb index 716da95..6b41647 100644 --- a/spec/configuration/ale_spec.rb +++ b/spec/configuration/ale_spec.rb @@ -3,41 +3,38 @@ require 'spec_helper' set :os, family: 'redhat', release: '9', arch: 'x86_64' -# TODO: only do it if ale is enabled -describe 'Check ale config' do - describe file('/etc/redborder-ale/schema.pb.rb') do - it { should exist } - it { should be_file } +is_package_installed = package('redborder-ale').installed? + +if is_package_installed + describe 'Check ale config' do + describe file('/etc/redborder-ale/schema.pb.rb') do + it { should exist } + it { should be_file } + end + + describe file('/etc/redborder-ale/config.yml') do + it { should exist } + it { should be_file } + end + + describe file('/etc/redborder-ale/rb_ale_aps.conf') do + it { should exist } + it { should be_file } + end end - describe file('/etc/redborder-ale/config.yml') do + describe file('/var/rb-ale/bin/rb_ale.rb') do it { should exist } it { should be_file } + it { should be_executable.by(:owner) } + it { should be_executable.by(:group) } + its(:content) { should match(%r{^(\s*#.*|)#!/usr/bin/env\s+ruby.*$}) } end - describe file('/etc/redborder-ale/rb_ale_aps.conf') do + describe file('/usr/bin/rb_scan_ale.rb') do it { should exist } it { should be_file } - end -end - -describe file('/var/rb-ale/bin/rb_ale.rb') do - it { should exist } - it { should be_file } - it { should be_executable.by(:owner) } - it { should be_executable.by(:group) } - its(:content) { should match(%r{^(\s*#.*|)#!/usr/bin/env\s+ruby.*$}) } -end - -describe file('/usr/bin/rb_scan_ale.rb') do - it { should exist } - it { should be_file } - it { should be_executable.by(:owner) } - it { should be_executable.by(:group) } -end - -describe 'Redborder-Ale user config' do - describe command('sudo -u redborder-ale bash -lc "ruby -v"') do - its(:stdout) { should match(/ruby 2.7.5/) } + it { should be_executable.by(:owner) } + it { should be_executable.by(:group) } end end diff --git a/spec/services/ale_spec.rb b/spec/services/ale_spec.rb index 43ec3b1..4958de0 100644 --- a/spec/services/ale_spec.rb +++ b/spec/services/ale_spec.rb @@ -8,15 +8,15 @@ package = 'redborder-ale' describe "Checking packages for #{service}..." do - describe package(package) do - before do - skip("#{package} is not installed, skipping...") unless package(package).installed? - end + describe package(package) do + before do + skip("#{package} is not installed, skipping...") unless package(package).installed? + end - it 'is expected to be installed' do - expect(package(package).installed?).to be true - end + it 'is expected to be installed' do + expect(package(package).installed?).to be true end + end end service_status = command("systemctl is-enabled #{service}").stdout.strip @@ -29,15 +29,21 @@ end end -if service_status == 'disabled' - describe "Checking #{service_status} service for #{service}..." do - describe service(service) do - it { should_not be_enabled } - it { should_not be_running } +describe 'Redborder-ale is using correct ruby setup' do + if service_status == 'enabled' + describe command('sudo -u redborder-ale which ruby') do + its(:stdout) { should match %r{/usr/lib/rvm/rubies/ruby-2.7.5/bin/ruby} } end + elsif service_status == 'disabled' + describe "Checking #{service_status} service for #{service}..." do + describe service(service) do + it { should_not be_enabled } + it { should_not be_running } + end - describe port(port) do - it { should_not be_listening } + describe port(port) do + it { should_not be_listening } + end end end end diff --git a/spec/services/logstash_spec.rb b/spec/services/logstash_spec.rb index d9ee408..a9191e3 100644 --- a/spec/services/logstash_spec.rb +++ b/spec/services/logstash_spec.rb @@ -11,6 +11,7 @@ service = 'logstash' port = 9600 HOSTNAME = command('hostname -s').stdout.chomp +PIPELINES_PATH = '/etc/logstash/pipelines.yml' describe "Checking packages for #{service}..." do packages.each do |package| @@ -26,10 +27,10 @@ end describe "Checking service status for #{service}..." do - # Building conditions - service_status = command("systemctl is-enabled #{service}").stdout.strip + pipelines = command("knife node show #{HOSTNAME} --attribute default.pipelines -F json").stdout.strip + parsed_pipelines = JSON.parse(pipelines) - if service_status == 'disabled' + if parsed_pipelines.empty? || parsed_pipelines.nil? describe service(service) do it { should_not be_enabled } it { should_not be_running } @@ -37,9 +38,7 @@ describe port(port) do it { should_not be_listening } end - end - - if service_status == 'enabled' + elsif !parsed_pipelines.empty? || !parsed_pipelines.nil? describe service(service) do it { should be_enabled } it { should be_running } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a5e0a7b..247cb12 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,7 +8,8 @@ set :disable_sudo, true # ssh setup -host = ENV['TARGET_HOST'] || '10.0.209.20' +ENV['TARGET_HOST'] ||= '10.0.209.20' +host = ENV['TARGET_HOST'] options = Net::SSH::Config.for(host) set :host, options[:host_name] || host options[:user] ||= ENV['LOGIN_USERNAME'] || 'root'