From 37732de1475e5d6dc226210d4ede2703070617ba Mon Sep 17 00:00:00 2001 From: Luis Blanco Date: Mon, 4 Dec 2023 14:30:24 +0000 Subject: [PATCH 01/10] Readme directory update --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index cde9f0c..d1ff784 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,10 @@ Directory structure: ├── configuration/ │ ├── ... > OR HERE │ + ├── modules/ + │ ├── monitor + | ├── ... > OR HERE + │ └── helpers/ ├── ... ``` From 1720925d365ebd61669039340cc72c505d16d047 Mon Sep 17 00:00:00 2001 From: Luis Blanco Date: Mon, 4 Dec 2023 14:31:23 +0000 Subject: [PATCH 02/10] desc only for ssh to run spec:ssh --- Rakefile | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Rakefile b/Rakefile index f873215..8fabb29 100644 --- a/Rakefile +++ b/Rakefile @@ -6,6 +6,17 @@ require 'rspec/core/rake_task' task default: :spec task spec: 'spec:all' +task ssh: 'only:ssh' + +namespace :only do + host = ENV['TARGET_HOST'] || '10.1.209.20' + desc 'run ssh within the cluster' + RSpec::Core::RakeTask.new(:ssh) do |t| + puts "Running configuration tests on #{host} ..." + t.pattern = 'spec/services/ssh_spec.rb' + t.rspec_opts = '--format documentation' # O "--format progress" + end +end namespace :spec do host = ENV['TARGET_HOST'] || '10.1.209.20' @@ -31,4 +42,11 @@ namespace :spec do t.pattern = 'spec/modules/monitor/*_spec.rb' t.rspec_opts = '--format documentation' # O "--format progress" end + + desc 'run configuration tests' + RSpec::Core::RakeTask.new(:configuration) do |t| + puts "Running configuration tests on #{host} ..." + t.pattern = 'spec/configuration/*_spec.rb' + t.rspec_opts = '--format documentation' # O "--format progress" + end end From e03b459516fc69ec79684f1746ffb2303b811fbb Mon Sep 17 00:00:00 2001 From: Luis Blanco Date: Mon, 4 Dec 2023 14:31:57 +0000 Subject: [PATCH 03/10] check if at least 3 nodes are alive --- spec/services/ssh_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/services/ssh_spec.rb b/spec/services/ssh_spec.rb index a00e920..65dd69d 100644 --- a/spec/services/ssh_spec.rb +++ b/spec/services/ssh_spec.rb @@ -5,3 +5,12 @@ describe port(22) do it { should be_listening } end + +describe 'Cluster Nodes' do + describe command('serf members | grep -c "alive"') do + it 'There are at least 3 alive nodes' do + n_nodes = subject.stdout.to_i + expect(n_nodes).to be > 2 + end + end +end From 0009cecb06b097914561605ca7d1a674a843e786 Mon Sep 17 00:00:00 2001 From: Luis Blanco Date: Mon, 4 Dec 2023 15:15:43 +0000 Subject: [PATCH 04/10] Main host can reach every node --- spec/services/ssh_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/services/ssh_spec.rb b/spec/services/ssh_spec.rb index 65dd69d..4b07536 100644 --- a/spec/services/ssh_spec.rb +++ b/spec/services/ssh_spec.rb @@ -14,3 +14,16 @@ end end end + +describe 'Reachable nodes' do + describe command('serf members | awk \'{split($2, a, ":"); print a[1]}\'') do + its(:exit_status) { should eq 0 } + + it 'Main host can reach every node' do + target_ips = subject.stdout.chomp.split("\n") + target_ips.each do |target_ip| + expect(host(target_ip)).to be_reachable.with(:port => 22) # Cambia el puerto según el servicio que quieras comprobar + end + end + end +end From 2ddabb2a04d7fdd7c96a6bdf1b443fbc45ed751f Mon Sep 17 00:00:00 2001 From: Luis Blanco Date: Mon, 4 Dec 2023 16:13:53 +0000 Subject: [PATCH 05/10] service is up and running --- spec/services/ssh_spec.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/services/ssh_spec.rb b/spec/services/ssh_spec.rb index 4b07536..e1b869a 100644 --- a/spec/services/ssh_spec.rb +++ b/spec/services/ssh_spec.rb @@ -6,6 +6,13 @@ it { should be_listening } end +describe 'Verificación del servicio SSH (sshd)' do + describe service('sshd') do + it { should be_enabled } + it { should be_running } + end +end + describe 'Cluster Nodes' do describe command('serf members | grep -c "alive"') do it 'There are at least 3 alive nodes' do @@ -18,7 +25,6 @@ describe 'Reachable nodes' do describe command('serf members | awk \'{split($2, a, ":"); print a[1]}\'') do its(:exit_status) { should eq 0 } - it 'Main host can reach every node' do target_ips = subject.stdout.chomp.split("\n") target_ips.each do |target_ip| From ef9c8bc716293d1739f2fe8280fefd810d71bc06 Mon Sep 17 00:00:00 2001 From: Luis Blanco Date: Mon, 4 Dec 2023 17:04:28 +0000 Subject: [PATCH 06/10] target ips expected to exist --- spec/services/ssh_spec.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/services/ssh_spec.rb b/spec/services/ssh_spec.rb index e1b869a..9f259b9 100644 --- a/spec/services/ssh_spec.rb +++ b/spec/services/ssh_spec.rb @@ -17,7 +17,7 @@ describe command('serf members | grep -c "alive"') do it 'There are at least 3 alive nodes' do n_nodes = subject.stdout.to_i - expect(n_nodes).to be > 2 + expect(n_nodes).to be >= 3 end end end @@ -25,6 +25,11 @@ describe 'Reachable nodes' do describe command('serf members | awk \'{split($2, a, ":"); print a[1]}\'') do its(:exit_status) { should eq 0 } + + it 'Has at least 3 target IPs' do + expect(target_ips.length).to be >= 3 + end + it 'Main host can reach every node' do target_ips = subject.stdout.chomp.split("\n") target_ips.each do |target_ip| @@ -33,3 +38,4 @@ end end end + From 8a021ceb363c7812c11b6d94ccb40c3ab298d473 Mon Sep 17 00:00:00 2001 From: Luis Blanco Date: Thu, 7 Dec 2023 13:45:00 +0000 Subject: [PATCH 07/10] getting node list and running echo to each --- spec/services/ssh_spec.rb | 42 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/spec/services/ssh_spec.rb b/spec/services/ssh_spec.rb index 9f259b9..99e22a7 100644 --- a/spec/services/ssh_spec.rb +++ b/spec/services/ssh_spec.rb @@ -1,41 +1,39 @@ -# frozen_string_literal: true - +# frozen_string_literal: truezz<= 3 - end +NODE_LIST_DELEGATE = "red node list 2>/dev/null" +describe 'Getting node names' do + describe command NODE_LIST_DELEGATE do + its('exit_status') { should eq 0 } + its('stdout') { should_not be_empty } end end -describe 'Reachable nodes' do - describe command('serf members | awk \'{split($2, a, ":"); print a[1]}\'') do - its(:exit_status) { should eq 0 } - - it 'Has at least 3 target IPs' do - expect(target_ips.length).to be >= 3 - end +nodes = command(NODE_LIST_DELEGATE).stdout.chomp.split("\n") +describe 'Executing commands into nodes one by one' do + it 'At least one node is present' do + expect(nodes).not_to be_empty + end +end - it 'Main host can reach every node' do - target_ips = subject.stdout.chomp.split("\n") - target_ips.each do |target_ip| - expect(host(target_ip)).to be_reachable.with(:port => 22) # Cambia el puerto según el servicio que quieras comprobar - end +describe 'Executing commands into nodes one by one' do + nodes.each do |node| + it "Executing on Node: #{node}" do + result = command("red node execute #{node} 'echo SERVERSPEC'") + expect(result.exit_status).to eq(0) + expect(result.stdout).to include("#{node}") + expect(result.stdout).to include("SERVERSPEC") end end end - From f397c15596c30779d794a53096acb92ad179a3c2 Mon Sep 17 00:00:00 2001 From: Luis Blanco Date: Thu, 7 Dec 2023 14:05:25 +0000 Subject: [PATCH 08/10] refactor node_list call --- spec/services/ssh_spec.rb | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/spec/services/ssh_spec.rb b/spec/services/ssh_spec.rb index 99e22a7..0d78763 100644 --- a/spec/services/ssh_spec.rb +++ b/spec/services/ssh_spec.rb @@ -12,24 +12,15 @@ end end -NODE_LIST_DELEGATE = "red node list 2>/dev/null" -describe 'Getting node names' do - describe command NODE_LIST_DELEGATE do - its('exit_status') { should eq 0 } - its('stdout') { should_not be_empty } - end -end - -nodes = command(NODE_LIST_DELEGATE).stdout.chomp.split("\n") describe 'Executing commands into nodes one by one' do - it 'At least one node is present' do - expect(nodes).not_to be_empty + NODE_LIST = command("red node list 2>/dev/null").stdout.chomp.split("\n") + + it 'There is at least one node in the list' do + expect(NODE_LIST).not_to be_empty end -end -describe 'Executing commands into nodes one by one' do - nodes.each do |node| - it "Executing on Node: #{node}" do + NODE_LIST.each do |node| + it "Executing basic echo on Node: #{node}" do result = command("red node execute #{node} 'echo SERVERSPEC'") expect(result.exit_status).to eq(0) expect(result.stdout).to include("#{node}") @@ -37,3 +28,4 @@ end end end + From fdb3401d6b32809890eb564bd09a2dbe96e73a99 Mon Sep 17 00:00:00 2001 From: Luis Blanco Date: Thu, 7 Dec 2023 14:09:56 +0000 Subject: [PATCH 09/10] rubocop, im good boy --- spec/services/ssh_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/services/ssh_spec.rb b/spec/services/ssh_spec.rb index 0d78763..8f9b453 100644 --- a/spec/services/ssh_spec.rb +++ b/spec/services/ssh_spec.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: truezz</dev/null").stdout.chomp.split("\n") +NODE_LIST = command('red node list 2>/dev/null').stdout.chomp.split("\n") +describe 'Executing commands into nodes one by one' do it 'There is at least one node in the list' do expect(NODE_LIST).not_to be_empty end @@ -23,8 +23,8 @@ it "Executing basic echo on Node: #{node}" do result = command("red node execute #{node} 'echo SERVERSPEC'") expect(result.exit_status).to eq(0) - expect(result.stdout).to include("#{node}") - expect(result.stdout).to include("SERVERSPEC") + expect(result.stdout).to include(node.to_s) + expect(result.stdout).to include('SERVERSPEC') end end end From 110561beac089404d8559d92657380b6d201ef64 Mon Sep 17 00:00:00 2001 From: Juan Pablo Date: Tue, 19 Dec 2023 12:05:03 +0000 Subject: [PATCH 10/10] linter fixed --- spec/services/ssh_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/services/ssh_spec.rb b/spec/services/ssh_spec.rb index 8f9b453..2bdf22d 100644 --- a/spec/services/ssh_spec.rb +++ b/spec/services/ssh_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe port(22) do @@ -12,7 +13,6 @@ end end - NODE_LIST = command('red node list 2>/dev/null').stdout.chomp.split("\n") describe 'Executing commands into nodes one by one' do it 'There is at least one node in the list' do @@ -28,4 +28,3 @@ end end end -