Skip to content

Commit

Permalink
Merge branch 'master' into motd_integration_test
Browse files Browse the repository at this point in the history
  • Loading branch information
rgomezborder committed Dec 4, 2024
2 parents a0fd5fe + 7c2a79c commit 63c1b13
Show file tree
Hide file tree
Showing 37 changed files with 737 additions and 65 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:
- '**/*'
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ gem 'highline'
gem 'colorize'
gem "rake"
gem 'rubocop', '>= 1.57.2'
gem 'ed25519', '>= 1.2'
gem 'bcrypt_pbkdf', '>= 1.0'
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
## 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
```
Sometimes you need to make sure that you share your public ssh key to target machine:
```
ssh-copy-id root@<target_ip>
```

## Running Tests
To run all tests, use the following command:
Expand All @@ -17,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 All @@ -28,6 +33,14 @@ To run a specific test type, use the following command:
rake spec:configuration
```

To run a specific test in a spec file, better use tags:
```
rspec --tag tag_name
To run a specific script test, use the following command:
```
rspec spec/services/cgroup_spec.rb
```
List of Available Rake Tasks:
To view the list of available Rake tasks, use the following command:
```
Expand Down Expand Up @@ -56,3 +69,8 @@ Directory structure:
└── helpers/
├── ...
```
Tag a describe to run by specific command ie:
```
describe ("Any test for this"), :tagname do
```
3 changes: 2 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 @@ -36,6 +36,7 @@ namespace :spec do
t.rspec_opts = '--format documentation' # O "--format progress"
end


desc 'run monitor tests'
RSpec::Core::RakeTask.new(:monitor_cluster) do |t|
puts "Running Monitor tests on #{host} ..."
Expand Down
70 changes: 70 additions & 0 deletions spec/configuration/ale_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# frozen_string_literal: true

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

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 }
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
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/) }
end
end
end
20 changes: 20 additions & 0 deletions spec/configuration/cgroup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,23 @@
end
end
end

describe file('/usr/lib/redborder/bin/rb_check_cgroups'), :rb_check_cgroups do
it { should exist }
it { should be_file }
it { should be_executable }
end

describe file('/usr/lib/redborder/bin/rb_check_cgroups.sh'), :rb_check_cgroups do
it { should exist }
it { should be_file }
it { should be_executable }
end

describe file('/usr/lib/redborder/scripts/rb_check_cgroups.rb'), :rb_check_cgroups 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
18 changes: 18 additions & 0 deletions spec/configuration/chef_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

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

describe file('/usr/lib/redborder/bin/rb_wakeup_chef.sh'), :rb_wakeup_chef do
it { should exist }
it { should be_file }
it { should be_executable.by_user('webui') }
end

describe 'Checking WakeUpClusterJob' do
query_psql = "echo \"SELECT * FROM stored_delayed_jobs WHERE job='RbWakeupChefClusterJob';\" | rb_psql redborder"
describe command(query_psql) do
its(:exit_status) { should eq 0 }
its(:stdout) { should_not match(/Errno::EACCES: Permission denied/) }
end
end
27 changes: 27 additions & 0 deletions spec/configuration/geoip_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require 'spec_helper'
set :os, family: 'redhat', release: '9', arch: 'x86_64'
packages = %w[
GeoIP GeoIP-GeoLite-data GeoIP-GeoLite-data-extra geoipupdate
]

describe 'Checking geoip packages family' do
packages.each do |package|
describe package(package) do
it 'is expected to be installed' do
expect(package(package).installed?).to be true
end
end
end
end

describe 'Check geoip config' do
describe file('/etc/GeoIP.conf') do
it { should exist }
it { should be_file }
its(:content) { should match(/GeoLite2-ASN/) }
its(:content) { should match(/GeoLite2-City/) }
its(:content) { should match(/GeoLite2-Country/) }
end
end
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
30 changes: 0 additions & 30 deletions spec/configuration/network_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,6 @@
end
end

# Management network
puts 'Configuration'

ip = ENV['TARGET_HOST']
puts "HOST: #{ip}"

describe 'Management network' do
it 'The Management network should contain an IP' do
expect(ip).to match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)
end
end

# Sync network
describe 'Sync network' do
sync = command('ip addr show').stdout
it 'Have a network sync' do
interfaces_with_ip = sync.scan(/inet\s+(\d+\.\d+\.\d+\.\d+)/).flatten
expect(interfaces_with_ip.length).to be >= 3
puts "OUTPUT: #{interfaces_with_ip}"
end
end

# DNS
describe 'DNS' do
resolv_content = command('cat /etc/resolv.conf').stdout
Expand All @@ -60,11 +38,3 @@
puts "OUTPUT: #{hostname}"
end
end

# IPMI
describe 'IPMI' do
ipmi_status = command('rpm -qa | grep ipmi').stdout
it 'Status IPMI' do
expect(ipmi_status).to include('ipmi')
end
end
69 changes: 69 additions & 0 deletions spec/services/ale_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# frozen_string_literal: true

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

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

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

it 'is expected to be installed' do
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
if service_status == 'enabled'
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
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 service(service) do
it { should_not be_enabled }
it { should_not be_running }
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
Loading

0 comments on commit 63c1b13

Please sign in to comment.