Skip to content

Commit

Permalink
Merge pull request #92 from redBorder/bugfix/#16159_ale_config_files
Browse files Browse the repository at this point in the history
Bugfix/#16159 ale config files
  • Loading branch information
dcastro-redBorder authored Sep 2, 2024
2 parents 819817b + 857d6bc commit 3daeeca
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 22 deletions.
30 changes: 30 additions & 0 deletions spec/configuration/ale_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,36 @@
describe file('/etc/redborder-ale/config.yml') do
it { should exist }
it { should be_file }
it { should_not be_empty }
end

describe file('/etc/redborder-ale/rb_ale_aps.conf') do
it { should exist }
it { should be_file }
end

# Additional dependencies
describe file('/usr/lib64/libzmq.so') do
it { should exist }
it { should be_file }
end

describe package('zeromq-devel') do
it { should be_installed }
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 }
end

describe file('/var/rb-ale/bin/rb_ale.rb') do
Expand All @@ -37,4 +61,10 @@
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/) }
end
end
end
62 changes: 41 additions & 21 deletions spec/services/ale_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,68 @@

require 'spec_helper'
require 'set'
require 'json'
set :os, family: 'redhat', release: '9', arch: 'x86_64'

service = 'redborder-ale'
package = 'redborder-ale'
service = serv_consul = pkg = 'redborder-ale'
# port = 7779
API_ENDPOINT = 'http://localhost:8500/v1'

describe "Checking packages for #{service}..." do
describe package(package) do
describe package(pkg) do
before do
skip("#{package} is not installed, skipping...") unless package(package).installed?
skip("#{pkg} is not installed, skipping...") unless package(pkg).installed?
end

it 'is expected to be installed' do
expect(package(package).installed?).to be true
expect(package(pkg).installed?).to be true
end
end
end

service_status = command("systemctl is-enabled #{service}").stdout.strip
describe "Checking #{service_status} service for #{service}..." do
describe service(service) do
if service_status == 'enabled'
if service_status == 'enabled'
describe service(service) do
it { should be_enabled }
it { should be_running }
end
end
end

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} }
# describe port(port) do
# it { should be_listening }
# end

describe 'Registered in consul' do
service_json_cluster = command("curl -s #{API_ENDPOINT}/catalog/service/#{serv_consul} | jq -c 'group_by(.ID)[]'")
service_json_cluster = service_json_cluster.stdout.chomp.split("\n")
health_cluster = command("curl -s #{API_ENDPOINT}/health/service/#{serv_consul} | jq -r '.[].Checks[0].Status'")
health_cluster = health_cluster.stdout.chomp.split("\n")
it 'Should be at least in one node' do
# expect(service_json_cluster.size).to be > 0 # redundant check
expect(health_cluster.size).to be > 0
end
service_and_health = service_json_cluster.zip(health_cluster)
service_and_health.each do |service, health|
registered = JSON.parse(service)[0].key?('Address') && health == 'passing' # ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
end
end
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 service(service) do
it { should_not be_enabled }
it { should_not be_running }
end

describe port(port) do
it { should_not be_listening }
end
# describe port(port) do
# it { should_not be_listening }
# end

it 'Should be registered and enabled' do
registered = JSON.parse(service)[0].key?('Address') && health == 'passing' # ? true : false
expect(registered).to be true
end
end
end
6 changes: 5 additions & 1 deletion spec/services/consul_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@
it { should be_listening }
end

describe 'Registered in consul' do
# Use this block to test other services that need to be registered in consul
describe "#{service} Registered in consul" do
service_json_cluster = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -c 'group_by(.ID)[]'")
service_json_cluster = service_json_cluster.stdout.chomp.split("\n")
it "API response for #{service} should not be empty" do
expect(service_json_cluster).not_to be_empty
end
health_cluster = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'")
health_cluster = health_cluster.stdout.chomp.split("\n")
service_and_health = service_json_cluster.zip(health_cluster)
Expand Down

0 comments on commit 3daeeca

Please sign in to comment.