Skip to content

Commit

Permalink
Merge branch 'master' into improvement/#17692_skip_single_node_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rgomezborder committed Dec 4, 2024
2 parents c0f2da1 + eedc20b commit 49abb6e
Show file tree
Hide file tree
Showing 31 changed files with 523 additions and 98 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Layout/BlockLength:
Exclude:
- '**/*'
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
## redborder-serverspec-manager
Infrastructure integration testing for redborder-manager
Infrastructure integration testing for a redborder manager machine. The idea is to run the tests in a machine that is the validator local machine, so the target machine is affected by the tests.

## Installation
On your workstation, execute the following command in your terminal:
First, clone this repository on your workstation. Then install the gemes by executing this:
```ssh
bundle install
```
Also make sure to share your public ssh key to target machine:
Sometimes you need to make sure that you share your public ssh key to target machine:
```
ssh-copy-id root@<target_ip>
```
Expand All @@ -21,6 +21,7 @@ Optional parameters:
* TARGET_HOST: Machine where the tests will run via SSH.
* LOGIN_USERNAME: Username for SSH connection to the test machine.
* LOGIN_PASSWORD: Password for SSH connection to the test machine.
* IS_CLUSTER: Boolean to indicate if the target machine is a cluster.
* -j 10 -m: To run tests in pararell
Example with optional parameters:
```
Expand Down
9 changes: 8 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ end

namespace :spec do
host = ENV['TARGET_HOST'] || '10.1.209.20'
task all: %i[services configuration]
task all: %i[services configuration users]

desc 'run configuration tests'
RSpec::Core::RakeTask.new(:configuration) do |t|
Expand All @@ -42,4 +42,11 @@ namespace :spec do
t.pattern = 'spec/modules/monitor/*_spec.rb'
t.rspec_opts = '--format documentation' # O "--format progress"
end

desc 'run user tests'
RSpec::Core::RakeTask.new(:users) do |t|
puts "Running user tests on #{host} ..."
t.pattern = 'spec/users/*_spec.rb'
t.rspec_opts = '--format documentation' # O "--format progress"
end
end
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
2 changes: 1 addition & 1 deletion spec/configuration/geoip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'spec_helper'
set :os, family: 'redhat', release: '9', arch: 'x86_64'
packages = %w[
GeoIP GeoIP-GeoLite-data GeoIP-GeoLite-data-extra geoipupdate geoipupdate-cron
GeoIP GeoIP-GeoLite-data GeoIP-GeoLite-data-extra geoipupdate
]

describe 'Checking geoip packages family' do
Expand Down
13 changes: 13 additions & 0 deletions spec/configuration/memcached_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

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

describe 'Memcached config in webui' do
describe file('/var/www/rb-rails/config/memcached_config.yml') do
it { should exist }
it { should be_file }
it { should_not contain 'localhost' }
end
end
16 changes: 16 additions & 0 deletions spec/configuration/motd_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

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

# Verificar que existe un script MOTD en el sistema
describe file('/usr/lib/redborder/bin/motd') do
it { should exist }
it { should be_executable }
end

# Verificar la existencia del archivo MOTD en /etc/motd y su contenido
describe file('/etc/motd') do
it { should exist }
its('content') { should match(/.*redborder-repo.*/) }
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
66 changes: 22 additions & 44 deletions spec/services/chef_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,54 +28,32 @@
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 file(config_file) do
it { should exist }
it { should be_file }
end

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")
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
describe "Checking service_status for #{service}..." do
describe service(service) do
it { should be_enabled }
it { should be_running }
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 file(config_file) do
it { should exist }
it { should be_file }
end

describe file(config_file) do
it { should_not exist }
end
describe port(port) do
it { should be_listening }
end

describe port(port) do
it { should_not be_listening }
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")
service_and_health = service_json_cluster.zip(health_cluster)
service_and_health.each do |sv, health|
registered = JSON.parse(sv)[0].key?('Address') && health == 'passing' # ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
end
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
45 changes: 22 additions & 23 deletions spec/services/logstash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,37 @@
HOSTNAME = command('hostname -s').stdout.chomp
PIPELINES_PATH = '/etc/logstash/pipelines.yml'

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

describe "Checking service status for #{service}..." do
pipelines = command("knife node show #{HOSTNAME} --attribute default.pipelines -F json").stdout.strip
parsed_pipelines = JSON.parse(pipelines)
regex = '^- pipeline\.id: .*-pipeline$'
has_pipelines = command("grep --perl-regex '#{regex}' #{PIPELINES_PATH}").exit_status == 0

if parsed_pipelines.empty? || parsed_pipelines.nil?
if has_pipelines
describe service(service) do
it { should_not be_enabled }
it { should_not be_running }
it { should be_enabled }
it { should be_running }
end
describe port(port) do
it { should_not be_listening }
it { should be_listening }
end
elsif !parsed_pipelines.empty? || !parsed_pipelines.nil?

packages.each do |package|
describe package(package) do
it { should be_installed }
end
end
else
describe service(service) do
it { should be_enabled }
it { should be_running }
it { should_not be_enabled }
it { should_not be_running }
end
describe port(port) do
it { should be_listening }
it { should_not be_listening }
end

packages.each do |package|
describe package(package) do
it { should_not be_installed }
end
end
end
end
Loading

0 comments on commit 49abb6e

Please sign in to comment.