From 087fe769dc8e025dcffda621085ee3e2e3a64f5f Mon Sep 17 00:00:00 2001 From: Stefan Walluhn Date: Fri, 9 Jul 2021 08:57:56 +0200 Subject: [PATCH 1/7] fix missing PATH when executing cmd to gather minio version --- bin/check-minio-update.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/check-minio-update.rb b/bin/check-minio-update.rb index 6ae3434..16e5cd8 100755 --- a/bin/check-minio-update.rb +++ b/bin/check-minio-update.rb @@ -73,7 +73,7 @@ def get_latest_version(checkurl, platform) end def get_local_version - stdout, stderr, status = Open3.capture3('minio --version', unsetenv_others: true) + stdout, stderr, status = Open3.capture3({'PATH' => '/usr/local/bin:/usr/bin:/bin'}, 'minio --version', :unsetenv_others => true) raise IOError, "Unable to gather local minio version: #{stderr}" unless status.success? From c65598bf03146be7e8b1d027f3cf67f5b16d97a4 Mon Sep 17 00:00:00 2001 From: Stefan Walluhn Date: Fri, 9 Jul 2021 09:06:27 +0200 Subject: [PATCH 2/7] bump dependency versions --- .gitignore | 1 + Gemfile.lock | 69 ------------------------------------- sensu-plugins-minio.gemspec | 6 ++-- 3 files changed, 4 insertions(+), 72 deletions(-) delete mode 100644 Gemfile.lock diff --git a/.gitignore b/.gitignore index 8cd7649..2abb03d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ /tmp/ /vendor/ /*.gem +Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index e70e0bd..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,69 +0,0 @@ -PATH - remote: . - specs: - sensu-plugins-minio (0.0.3) - sensu-plugin (~> 2.1) - -GEM - remote: https://rubygems.org/ - specs: - addressable (2.7.0) - public_suffix (>= 2.0.2, < 5.0) - ast (2.4.0) - crack (0.4.3) - safe_yaml (~> 1.0.0) - diff-lcs (1.3) - hashdiff (1.0.0) - jaro_winkler (1.5.3) - json (2.2.0) - mixlib-cli (1.7.0) - parallel (1.17.0) - parser (2.6.4.0) - ast (~> 2.4.0) - public_suffix (4.0.1) - rainbow (3.0.0) - rake (10.5.0) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.2) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.4) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.1) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.2) - rubocop (0.74.0) - jaro_winkler (~> 1.5.1) - parallel (~> 1.10) - parser (>= 2.6) - rainbow (>= 2.2.2, < 4.0) - ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 1.7) - ruby-progressbar (1.10.1) - safe_yaml (1.0.5) - sensu-plugin (2.7.1) - json (< 3.0.0) - mixlib-cli (~> 1.5) - unicode-display_width (1.6.0) - webmock (3.7.2) - addressable (>= 2.3.6) - crack (>= 0.3.2) - hashdiff (>= 0.4.0, < 2.0.0) - -PLATFORMS - ruby - -DEPENDENCIES - bundler (~> 1.11) - rake (~> 10.0) - rspec (~> 3.7) - rubocop (~> 0.54) - sensu-plugins-minio! - webmock (~> 3.3) - -BUNDLED WITH - 1.16.1 diff --git a/sensu-plugins-minio.gemspec b/sensu-plugins-minio.gemspec index fcc08c3..d452565 100644 --- a/sensu-plugins-minio.gemspec +++ b/sensu-plugins-minio.gemspec @@ -22,9 +22,9 @@ Gem::Specification.new do |spec| end spec.add_dependency 'sensu-plugin', '~> 2.1' - spec.add_development_dependency 'bundler', '~> 1.11' - spec.add_development_dependency 'rake', '~> 10.0' - spec.add_development_dependency 'rspec', '~> 3.7' + spec.add_development_dependency 'bundler', '~> 2.2' + spec.add_development_dependency 'rake', '~> 13.0' + spec.add_development_dependency 'rspec', '~> 3.10' spec.add_development_dependency 'rubocop', '~> 0.54' spec.add_development_dependency 'webmock', '~> 3.3' end From d2b4e34a8cdbb4bed208e363fe8486517438ac72 Mon Sep 17 00:00:00 2001 From: jonathanschlue-as Date: Wed, 14 Jul 2021 16:14:47 +0200 Subject: [PATCH 3/7] Update and checkin dependencies --- .gitignore | 1 - .ruby-version | 1 + Gemfile.lock | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 .ruby-version create mode 100644 Gemfile.lock diff --git a/.gitignore b/.gitignore index 2abb03d..8cd7649 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,3 @@ /tmp/ /vendor/ /*.gem -Gemfile.lock diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..24ba9a3 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.7.0 diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..b3ec428 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,73 @@ +PATH + remote: . + specs: + sensu-plugins-minio (0.0.3) + sensu-plugin (~> 2.1) + +GEM + remote: https://rubygems.org/ + specs: + addressable (2.8.0) + public_suffix (>= 2.0.2, < 5.0) + ast (2.4.2) + crack (0.4.5) + rexml + diff-lcs (1.4.4) + hashdiff (1.0.1) + json (2.5.1) + mixlib-cli (1.7.0) + parallel (1.20.1) + parser (3.0.2.0) + ast (~> 2.4.1) + public_suffix (4.0.6) + rainbow (3.0.0) + rake (13.0.6) + regexp_parser (2.1.1) + rexml (3.2.5) + rspec (3.10.0) + rspec-core (~> 3.10.0) + rspec-expectations (~> 3.10.0) + rspec-mocks (~> 3.10.0) + rspec-core (3.10.1) + rspec-support (~> 3.10.0) + rspec-expectations (3.10.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.10.0) + rspec-mocks (3.10.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.10.0) + rspec-support (3.10.2) + rubocop (0.93.1) + parallel (~> 1.10) + parser (>= 2.7.1.5) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8) + rexml + rubocop-ast (>= 0.6.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 2.0) + rubocop-ast (1.8.0) + parser (>= 3.0.1.1) + ruby-progressbar (1.11.0) + sensu-plugin (2.7.1) + json (< 3.0.0) + mixlib-cli (~> 1.5) + unicode-display_width (1.7.0) + webmock (3.13.0) + addressable (>= 2.3.6) + crack (>= 0.3.2) + hashdiff (>= 0.4.0, < 2.0.0) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + bundler (~> 2.2) + rake (~> 13.0) + rspec (~> 3.10) + rubocop (~> 0.54) + sensu-plugins-minio! + webmock (~> 3.3) + +BUNDLED WITH + 2.2.23 From 84c4ceec818d5753c9aa75cd7f0076bb5f58d5f5 Mon Sep 17 00:00:00 2001 From: jonathanschlue-as Date: Wed, 14 Jul 2021 16:15:02 +0200 Subject: [PATCH 4/7] Update spec to current version statement results --- spec/check-minio-update_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/check-minio-update_spec.rb b/spec/check-minio-update_spec.rb index b20cd2d..6db9756 100644 --- a/spec/check-minio-update_spec.rb +++ b/spec/check-minio-update_spec.rb @@ -7,8 +7,8 @@ describe CheckMinioUpdate do let(:status) { double } - local_version_return = "Version: 2019-09-05T23:24:38Z\nRelease-Tag: RELEASE.2019-09-05T23-24-38Z\nCommit-ID: b52a3e523cc3c4debc0ea2f86386377df5355c81" - latest_version_return = [body: '65a735f04bc1d35b4f86418226d5bbb4895cf7e1 minio.RELEASE.2019-09-05T23-24-38Z', status: 200] + local_version_return = "minio version RELEASE.2021-07-08T19-43-25Z" + latest_version_return = [body: '285ec90006a6961ebcb7dd9685acc0ebcd08f561 minio.RELEASE.2021-07-12T02-44-53Z', status: 200] before :context do CheckMinioUpdate.class_variable_set(:@@autorun, false) From 9cfb2b85b482314e79746219a2a8618b6a9cc1bb Mon Sep 17 00:00:00 2001 From: jonathanschlue-as Date: Wed, 14 Jul 2021 17:46:09 +0200 Subject: [PATCH 5/7] Refactor specs --- spec/check-minio-update_spec.rb | 119 ++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 53 deletions(-) diff --git a/spec/check-minio-update_spec.rb b/spec/check-minio-update_spec.rb index 6db9756..1f35f05 100644 --- a/spec/check-minio-update_spec.rb +++ b/spec/check-minio-update_spec.rb @@ -1,83 +1,96 @@ # frozen_string_literal: true -require 'json' require 'webmock/rspec' +require_relative '../bin/check-minio-update' -require_relative '../bin/check-minio-update.rb' +CheckMinioUpdate.class_variable_set(:@@autorun, false) describe CheckMinioUpdate do - let(:status) { double } - local_version_return = "minio version RELEASE.2021-07-08T19-43-25Z" - latest_version_return = [body: '285ec90006a6961ebcb7dd9685acc0ebcd08f561 minio.RELEASE.2021-07-12T02-44-53Z', status: 200] - - before :context do - CheckMinioUpdate.class_variable_set(:@@autorun, false) + before do + stub_checksum_request + allow(check).to(receive(:output)) + allow(Open3).to(receive(:capture3).and_return([stdout, stderr, double(:success? => success)])) end - before(:each) do - @api = stub_request( + let(:checksum_request) do + stub_request( :get, 'https://dl.min.io/server/minio/release/linux-amd64/minio.shasum' - ) + ).to_return(response) + end - @check = CheckMinioUpdate.new - @check.config[:checkurl] = 'https://dl.min.io/server/minio/release' - @check.config[:platform] = 'linux-amd64' + let(:response) do + { body: '285ec90006a6961ebcb7dd9685acc0ebcd08f561 minio.RELEASE.2021-07-08T19-43-25Z', status: 200 } + end - allow(@check).to receive(:output) + alias_method :stub_checksum_request, :checksum_request + + let(:check) do + CheckMinioUpdate.new.tap do |check| + check.config[:checkurl] = 'https://dl.min.io/server/minio/release' + check.config[:platform] = 'linux-amd64' + end end - it 'should be ok if versions are equal' do - @api.to_return(latest_version_return) - allow(status).to receive(:success?).and_return(true) - allow(Open3).to receive(:capture3).with('minio').and_return([local_version_return, nil, status]) + let(:stdout) { 'minio version RELEASE.2021-07-08T19-43-25Z' } + let(:stderr) { nil } + let(:success) { true } - expect { @check.run }.to raise_error do |error| - expect(error).to be_a SystemExit - expect(error.status).to eq 0 + context 'with matching local and remote version' do + it 'should be ok if versions are equal' do + expect { check.run }.to raise_error do |error| + expect(error).to be_a SystemExit + expect(error.status).to eq 0 + end + + expect(check).to have_received(:output).with('No new minio version available') + expect(checksum_request).to have_been_requested end - expect(@check).to have_received(:output).with('No new minio version available') - expect(@api).to have_been_requested end - it 'should be critical if versions differ' do - latest_version_return_diff = [body: '65a735f04bc1d35b4f86418226d5bbb4895cf7e1 minio.RELEASE.2019-09-11T19-53-16Z', status: 200] - @api.to_return(latest_version_return_diff) - allow(status).to receive(:success?).and_return(true) - allow(Open3).to receive(:capture3).with('minio').and_return([local_version_return, nil, status]) + context 'with different local and remote versions' do + let(:response) do + { body: '285ec90006a6961ebcb7dd9685acc0ebcd08f561 minio.RELEASE.2022-07-08T19-43-25Z', status: 200 } + end + + it 'should be critical' do + expect { check.run }.to raise_error do |error| + expect(error).to be_a SystemExit + expect(error.status).to eq 2 + end - expect { @check.run }.to raise_error do |error| - expect(error).to be_a SystemExit - expect(error.status).to eq 2 + expect(check).to have_received(:output).with('New minio version available RELEASE.2022-07-08T19-43-25Z') + expect(checksum_request).to have_been_requested end - expect(@check).to have_received(:output).with('New minio version available RELEASE.2019-09-11T19-53-16Z') - expect(@api).to have_been_requested end - it 'should be unknown if minio not found' do - @api.to_return(latest_version_return) - allow(status).to receive(:success?).and_return(false) - allow(Open3).to receive(:capture3).with('minio').and_return([nil, 'Minio not found', status]) + context 'with unknown local version' do + let(:stdout) { nil } + let(:stderr) { 'Minio not found' } + let(:success) { false } - expect { @check.run }.to raise_error do |error| - expect(error).to be_a SystemExit - expect(error.status).to eq 3 + it 'should be unknown' do + expect { check.run }.to raise_error do |error| + expect(error).to be_a SystemExit + expect(error.status).to eq 3 + end + + expect(check).to have_received(:output).with('Unable to gather local minio version: Minio not found') + expect(checksum_request).to have_been_requested end - expect(@check).to have_received(:output).with('Unable to gather local minio version: Minio not found') - expect(@api).to have_been_requested end - it 'should be unknown if release url changes ' do - not_found = [body: '404 Not Found', status: 404] - @api.to_return(not_found) - allow(status).to receive(:success?).and_return(false) - allow(Open3).to receive(:capture3).with('minio').and_return([local_version_return, nil, status]) + context 'with release url not found' do || + let(:response) { { body: '404 Not Found', status: 404 } } + + it 'should be unknown' do + expect { check.run }.to raise_error do |error| + expect(error).to be_a SystemExit + expect(error.status).to eq 3 + end - expect { @check.run }.to raise_error do |error| - expect(error).to be_a SystemExit - expect(error.status).to eq 3 + expect(check).to have_received(:output).with('Unable to gather latest minio version: 404 Not Found') + expect(checksum_request).to have_been_requested end - expect(@check).to have_received(:output).with('Unable to gather latest minio version: 404 Not Found') - expect(@api).to have_been_requested end end From 9b75ab13fcba7be0f2b88d2fd979974bc5d5d6d8 Mon Sep 17 00:00:00 2001 From: jonathanschlue-as Date: Wed, 14 Jul 2021 17:46:33 +0200 Subject: [PATCH 6/7] Pass subprocess arguments as array to provide minio version command regression --- bin/check-minio-update.rb | 2 +- spec/check-minio-update_spec.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/check-minio-update.rb b/bin/check-minio-update.rb index 16e5cd8..4dd1cc2 100755 --- a/bin/check-minio-update.rb +++ b/bin/check-minio-update.rb @@ -73,7 +73,7 @@ def get_latest_version(checkurl, platform) end def get_local_version - stdout, stderr, status = Open3.capture3({'PATH' => '/usr/local/bin:/usr/bin:/bin'}, 'minio --version', :unsetenv_others => true) + stdout, stderr, status = Open3.capture3([{'PATH' => '/usr/local/bin:/usr/bin:/bin'}, 'minio --version', :unsetenv_others => true]) raise IOError, "Unable to gather local minio version: #{stderr}" unless status.success? diff --git a/spec/check-minio-update_spec.rb b/spec/check-minio-update_spec.rb index 1f35f05..2b64be8 100644 --- a/spec/check-minio-update_spec.rb +++ b/spec/check-minio-update_spec.rb @@ -9,7 +9,8 @@ before do stub_checksum_request allow(check).to(receive(:output)) - allow(Open3).to(receive(:capture3).and_return([stdout, stderr, double(:success? => success)])) + allow(Open3).to(receive(:capture3).with(array_including('minio --version')) + .and_return([stdout, stderr, double(:success? => success)])) end let(:checksum_request) do From 2062b54916a74eeab6c3e18658e0c304916bb73b Mon Sep 17 00:00:00 2001 From: jonathanschlue-as Date: Wed, 14 Jul 2021 17:48:53 +0200 Subject: [PATCH 7/7] Pass surrounding environments PATH to local minio version command --- bin/check-minio-update.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/check-minio-update.rb b/bin/check-minio-update.rb index 4dd1cc2..a87109d 100755 --- a/bin/check-minio-update.rb +++ b/bin/check-minio-update.rb @@ -73,7 +73,7 @@ def get_latest_version(checkurl, platform) end def get_local_version - stdout, stderr, status = Open3.capture3([{'PATH' => '/usr/local/bin:/usr/bin:/bin'}, 'minio --version', :unsetenv_others => true]) + stdout, stderr, status = Open3.capture3([{'PATH' => ENV['PATH']}, 'minio --version', :unsetenv_others => true]) raise IOError, "Unable to gather local minio version: #{stderr}" unless status.success?