From ddfa46f053a240e93d6bca4e020a644294eabae1 Mon Sep 17 00:00:00 2001 From: Luis Blanco Date: Fri, 24 May 2024 16:25:06 +0100 Subject: [PATCH 1/6] where topics are defined is a file with good permissions --- spec/configuration/logstash_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 spec/configuration/logstash_spec.rb diff --git a/spec/configuration/logstash_spec.rb b/spec/configuration/logstash_spec.rb new file mode 100644 index 0000000..9a52740 --- /dev/null +++ b/spec/configuration/logstash_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' +set :os, family: 'redhat', release: '9', arch: 'x86_64' + +describe 'Check logstash config' do + describe file('/etc/kafka/topics_definitions.yml') do + it { should exist } + it { should be_file } + it { should be_readable } + it { should be_writable.by_user('kafka') } + it { should_not be_writable.by('others') } + it { should_not be_executable } + end +end From 7defa7f047d8d3c396e1d1848bfe500adaa24cbe Mon Sep 17 00:00:00 2001 From: Luis Blanco Date: Fri, 24 May 2024 16:41:26 +0100 Subject: [PATCH 2/6] rename and add the check of some pipelines --- .../{logstash_spec.rb => kafka_spec.rb} | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) rename spec/configuration/{logstash_spec.rb => kafka_spec.rb} (55%) diff --git a/spec/configuration/logstash_spec.rb b/spec/configuration/kafka_spec.rb similarity index 55% rename from spec/configuration/logstash_spec.rb rename to spec/configuration/kafka_spec.rb index 9a52740..910a3dd 100644 --- a/spec/configuration/logstash_spec.rb +++ b/spec/configuration/kafka_spec.rb @@ -2,6 +2,19 @@ require 'spec_helper' set :os, family: 'redhat', release: '9', arch: 'x86_64' +pipelines = %w[ + rb_event rb_event_post + rb_monitor rb_monitor_post + rb_loc rb_locne rb_loc_post rb_loc_post_discard rb_location + rb_mobile + rb_radius + rb_nmsp + rb_metrics + rb_state rb_state_post + rb_vault rb_vault_post + rb_http2k_sync + sflow +] describe 'Check logstash config' do describe file('/etc/kafka/topics_definitions.yml') do @@ -11,5 +24,8 @@ it { should be_writable.by_user('kafka') } it { should_not be_writable.by('others') } it { should_not be_executable } + pipelines.each do |pipeline| + it { should contain pipeline } + end end end From d006dee69284a7ca169977eead9c312e51623de8 Mon Sep 17 00:00:00 2001 From: Luis Blanco Date: Mon, 24 Jun 2024 14:16:45 +0100 Subject: [PATCH 3/6] lint identation --- spec/configuration/kafka_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/configuration/kafka_spec.rb b/spec/configuration/kafka_spec.rb index 910a3dd..d1571d6 100644 --- a/spec/configuration/kafka_spec.rb +++ b/spec/configuration/kafka_spec.rb @@ -25,7 +25,7 @@ it { should_not be_writable.by('others') } it { should_not be_executable } pipelines.each do |pipeline| - it { should contain pipeline } + it { should contain pipeline } end end end From 4f2b1ba04f525815510f13a7548103fbe6fd5612 Mon Sep 17 00:00:00 2001 From: Rafael Gomez Date: Wed, 4 Dec 2024 15:05:38 +0000 Subject: [PATCH 4/6] Fix IS_CLUSTER variable --- spec/configuration/network_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/configuration/network_spec.rb b/spec/configuration/network_spec.rb index abaa49b..20558a1 100644 --- a/spec/configuration/network_spec.rb +++ b/spec/configuration/network_spec.rb @@ -31,7 +31,7 @@ sync = command('ip addr show').stdout it 'Have a network sync' do interfaces_with_ip = sync.scan(/inet\s+(\d+\.\d+\.\d+\.\d+)/).flatten - if ENV['IS_CLUSTER'] + if ENV['IS_CLUSTER'] == "true" expect(interfaces_with_ip.length).to be >= 3 else skip 'One node does not need sync interface' From 6943dd607536daf41850fb21287ec9a435e184ed Mon Sep 17 00:00:00 2001 From: Rafael Gomez Date: Wed, 4 Dec 2024 15:05:50 +0000 Subject: [PATCH 5/6] Update readme file --- README.md | 84 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index ef87428..4319236 100644 --- a/README.md +++ b/README.md @@ -1,76 +1,82 @@ ## redborder-serverspec-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 + First, clone this repository on your workstation. Then install the gemes by executing this: -```ssh + +```cmd bundle install ``` + Sometimes you need to make sure that you share your public ssh key to target machine: -``` + +```cmd ssh-copy-id root@ ``` ## Running Tests + To run all tests, use the following command: -``` + +```cmd rake spec ``` 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: -``` -TARGET_HOST="10.1.209.50" LOGIN_USERNAME="root" LOGIN_PASSWORD="redborder" rake spec + +- **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: + +```cmd +IS_CLUSTER="false" TARGET_HOST="10.1.209.50" LOGIN_USERNAME="root" LOGIN_PASSWORD="redborder" rake spec ``` To run a specific test type, use the following command: -``` + +```cmd rake spec:configuration ``` To run a specific test in a spec file, better use tags: -``` + +```cmd rspec --tag tag_name -To run a specific script test, use the following command: ``` -rspec spec/services/cgroup_spec.rb + +To run a specific script test, use the following command: + +```cmd +rspec spec/services/cgroup_spec.rb ``` List of Available Rake Tasks: -To view the list of available Rake tasks, use the following command: -``` + +```cmd rake -T ``` ## Developing tests -On creating a new test, is important to follow the Rakefile structure as the directory structure. +When creating a new test, it is important to follow the directory structure outlined in the Rakefile. This structure helps maintain organization and clarity within the test suite. Directory structure: -``` -└── spec/ - ├── spec_helper.rb - │ - ├── services/ - │ ├── ... > PUT YOUR TESTS HERE - │ - ├── configuration/ - │ ├── ... > OR HERE - │ - ├── modules/ - │ ├── monitor - | ├── ... > OR HERE - │ - └── helpers/ - ├── ... -``` -Tag a describe to run by specific command ie: -``` -describe ("Any test for this"), :tagname do -``` +```conf +spec/ +├── spec_helper.rb +├── services/ +│ ├── ... # Place your service-related tests here +├── configuration/ +│ ├── ... # Place your configuration-related tests here +├── modules/ +│ ├── monitor/ +│ ├── ... # Place your module-related tests here +└── helpers/ + ├── ... # Place your helper-related tests here +``` \ No newline at end of file From 522c24a913c1c1d5a45b9cc775f2c2fbe0e9e4d1 Mon Sep 17 00:00:00 2001 From: Rafael Gomez Date: Wed, 4 Dec 2024 15:06:49 +0000 Subject: [PATCH 6/6] Fix linter --- spec/configuration/network_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/configuration/network_spec.rb b/spec/configuration/network_spec.rb index 20558a1..4047359 100644 --- a/spec/configuration/network_spec.rb +++ b/spec/configuration/network_spec.rb @@ -31,7 +31,7 @@ sync = command('ip addr show').stdout it 'Have a network sync' do interfaces_with_ip = sync.scan(/inet\s+(\d+\.\d+\.\d+\.\d+)/).flatten - if ENV['IS_CLUSTER'] == "true" + if ENV['IS_CLUSTER'] == 'true' expect(interfaces_with_ip.length).to be >= 3 else skip 'One node does not need sync interface'