Skip to content

Commit

Permalink
Merge branch 'master' of github.com:redBorder/redborder-serverspec-ma…
Browse files Browse the repository at this point in the history
…nager into improvement/pmacctd_test
  • Loading branch information
nilsver committed Dec 5, 2023
2 parents 5545e31 + eb73dc7 commit c131643
Show file tree
Hide file tree
Showing 10 changed files with 371 additions and 108 deletions.
5 changes: 3 additions & 2 deletions spec/services/chef_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
]

service = 'chef-client'
serv_consul = 'erchef'
config_file = '/etc/chef/client.rb'
port = 4443

Expand Down Expand Up @@ -47,8 +48,8 @@

describe 'Registered in consul' do
api_endpoint = 'http://localhost:8500/v1'
service_json = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -r '.[]'").stdout
health = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'").stdout
service_json = command("curl -s #{api_endpoint}/catalog/service/#{serv_consul} | jq -r '.[]'").stdout
health = command("curl -s #{api_endpoint}/health/service/#{serv_consul} | jq -r '.[].Checks[0].Status'").stdout
health = health.strip
registered = JSON.parse(service_json).key?('Address') && health == 'passing' ? true : false
it 'Should be registered and enabled' do
Expand Down
62 changes: 44 additions & 18 deletions spec/services/druid_broker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,59 @@
packages = %w[
redborder-druid cookbook-druid druid
]
service = 'druid-broker'
port = 8084

describe 'Checking druid-broker' do
describe "Checking packages for #{service}..." do
packages.each do |package|
describe package(package) do
it { should be_installed }
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
end
end
end

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

describe port(8084) do
it { should be_listening }
if service_status == 'enabled'
describe "Checking #{service_status} service for #{service}..." do
describe service(service) do
it { should be_enabled }
it { should be_running }
end

describe port(port) do
it { should be_listening }
end

describe 'Registered in consul' do
api_endpoint = 'http://localhost:8500/v1'
service_json = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -r '.[]'").stdout
health = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'").stdout
health = health.strip
registered = JSON.parse(service_json).key?('Address') && health == 'passing' ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
end
end
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 }
end

describe 'Registered in consul' do
service_name = 'druid-broker'
response = "curl -s http://localhost:8500/v1/catalog/service/#{service_name} | jq -r '.[].Address'"
health = "curl -s http://localhost:8500/v1/health/service/#{service_name} | jq -r '.[].Checks' | jq -r '.[].Status'"
service_health = command(health).stdout.split("\n")
ips = command(response).stdout.split("\n")
it 'Should be registered and enabled' do
expect(ips).not_to be_empty
passing_checks = service_health.to_s.chomp
expect(passing_checks).to include('passing')
describe port(port) do
it { should_not be_listening }
end
end
end
21 changes: 9 additions & 12 deletions spec/services/druid_coordinator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,30 @@
packages = %w[
redborder-druid cookbook-druid druid
]

describe 'Checking druid-coordinator' do
service = 'druid-coordinator'
describe "Checking #{service}" do
packages.each do |package|
describe package(package) do
it { should be_installed }
end
end

describe service('druid-coordinator') do
describe service(service) do
it { should be_enabled }
it { should be_running }
end

describe port(8084) do
it { should be_listening }
end

describe 'Registered in consul' do
service_name = 'druid-coordinator'
response = "curl -s http://localhost:8500/v1/catalog/service/#{service_name} | jq -r '.[].Address'"
health = "curl -s http://localhost:8500/v1/health/service/#{service_name} | jq -r '.[].Checks' | jq -r '.[].Status'"
service_health = command(health).stdout.split("\n")
ips = command(response).stdout.split("\n")
api_endpoint = 'http://localhost:8500/v1'
service_json = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -r '.[]'").stdout
health = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'").stdout
health = health.strip
registered = JSON.parse(service_json).key?('Address') && health == 'passing' ? true : false
it 'Should be registered and enabled' do
expect(ips).not_to be_empty
passing_checks = service_health.to_s.chomp
expect(passing_checks).to include('passing')
expect(registered).to be true
end
end
end
73 changes: 49 additions & 24 deletions spec/services/druid_historical_spec.rb
Original file line number Diff line number Diff line change
@@ -1,47 +1,72 @@
# frozen_string_literal: true

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

packages = %w[
redborder-druid cookbook-druid druid
]
service = 'druid-historical'
port = 8083

describe 'Checking Druid Historical Service - Basic Checks' do
packages.each do |package|
describe package(package) do
it { should be_installed }
def service_registered_and_healthy?(service)
api_endpoint = 'http://localhost:8500/v1'
service_json = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -r '.[]'").stdout
health = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'").stdout.strip
JSON.parse(service_json).any? && health == 'passing'
end

service_status = command("systemctl is-enabled #{service}").stdout.strip

if service_status == 'enabled'
describe 'Druid Historical Service Checks for Enabled Service' do
describe service(service) do
it { should be_enabled }
it { should be_running }
end
end

describe service('druid-historical') do
it { should be_enabled }
it { should be_running }
end
describe port(port) do
it { should be_listening }
end

describe 'Configuration' do
describe file('/usr/lib/druid/conf/druid/historical/jvm.config') do
it { should exist }
end

describe file('/var/log/druid/historical.log') do
its(:content) { should_not match(/ERROR/) }
end

it 'should be registered and healthy in Consul' do
expect(service_registered_and_healthy?(service)).to be true
end
end
end

describe 'Checking Druid Historical Service - Advanced Checks' do
describe 'System Dependencies' do
describe package('java-1.8.0-openjdk') do
it { should be_installed }
if service_status == 'disabled'
describe 'Druid Historical Service Checks for Disabled Service' do
describe service(service) do
it 'should not be enabled' do
expect(subject).not_to be_enabled
end

it 'should not be running' do
expect(subject).not_to be_running
end
end
end

describe 'Network and Connectivity' do
describe port(8083) do
it { should be_listening }
describe port(port) do
it 'should not be listening' do
expect(subject).not_to be_listening
end
end
end
end

describe 'Druid Historical Logs' do
describe file('/var/log/druid/historical.log') do
its(:content) { should_not match(/ERROR/) }
describe 'Checking Druid Historical Dependencies and Configuration' do
%w[redborder-druid cookbook-druid druid java-1.8.0-openjdk].each do |pkg|
describe package(pkg) do
it "#{pkg} should be installed" do
expect(subject).to be_installed
end
end
end
end
54 changes: 54 additions & 0 deletions spec/services/druid_middlemanager_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

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

packages = %w[
redborder-druid cookbook-druid druid
]

service = 'druid-middlemanager'
port = 8091

describe "Checking packages for #{service}..." do
packages.each do |package|
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
end
end
end

service_status = command("systemctl is-enabled #{service}").stdout
service_status = service_status.strip

if service_status == 'enabled'
describe "Checking #{service_status} service for #{service}..." do
describe service(service) do
it { should be_enabled }
it { should be_running }
end

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

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

0 comments on commit c131643

Please sign in to comment.