From 283dea62a7be186ce51deafc37ca03bbc8e62f93 Mon Sep 17 00:00:00 2001 From: "kirby@puppetlabs.com" Date: Tue, 17 Mar 2020 11:16:18 -0700 Subject: [PATCH 1/2] (POOLER-156) Detect redis connection failures This commit adds detection for redis connection failures to pool_manager. When a connection fails the error will be raised to executeforcing the connection to be re-established. Without this change, when a redis connection fails, it generates a redis connection error, which is swallowed by a rescue for StandardError, preventing the manager application component from recovering in the case of a redis connection failure. --- lib/vmpooler/pool_manager.rb | 5 +++++ spec/unit/pool_manager_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/vmpooler/pool_manager.rb b/lib/vmpooler/pool_manager.rb index 4c887d3..f3b7a39 100644 --- a/lib/vmpooler/pool_manager.rb +++ b/lib/vmpooler/pool_manager.rb @@ -822,6 +822,8 @@ module Vmpooler loop_count += 1 end end + rescue Redis::CannotConnectError => e + raise rescue StandardError => e $logger.log('s', "[!] [#{pool['name']}] Error while checking the pool: #{e}") raise @@ -1310,6 +1312,9 @@ module Vmpooler loop_count += 1 end end + rescue Redis::CannotConnectError => e + $logger.log('s', "Cannot connect to the redis server: #{e}") + raise end end end diff --git a/spec/unit/pool_manager_spec.rb b/spec/unit/pool_manager_spec.rb index a4f7f26..ced1cb3 100644 --- a/spec/unit/pool_manager_spec.rb +++ b/spec/unit/pool_manager_spec.rb @@ -2792,6 +2792,16 @@ EOT subject.execute!(maxloop,0) end end + + context 'when redis server connection is not available' do + let(:maxloop) { 2 } + it 'should log a failure and raise the error' do + expect(redis).to receive(:set).with('vmpooler__tasks__clone', 0).and_raise(Redis::CannotConnectError) + expect(logger).to receive(:log).with('s', 'Cannot connect to the redis server: Redis::CannotConnectError') + + expect{subject.execute!(maxloop,0)}.to raise_error Redis::CannotConnectError + end + end end describe "#sleep_with_wakeup_events" do @@ -2987,6 +2997,18 @@ EOT end end + context 'when redis connection fails' do + let(:maxloop) { 2 } + let(:loop_delay) { 1 } + + it 'should raise the error' do + allow(subject).to receive(:_check_pool).and_raise(Redis::CannotConnectError) + expect(logger).to receive(:log).with('d', "[*] [#{pool}] starting worker thread") + + expect{subject.check_pool(pool_object,maxloop,loop_delay,loop_delay)}.to raise_error Redis::CannotConnectError + end + end + context 'delays between loops configured in the pool configuration' do let(:maxloop) { 2 } let(:loop_delay) { 1 } From 7597185fa47a9faa613cd2aaa7c4c7371faecc34 Mon Sep 17 00:00:00 2001 From: "kirby@puppetlabs.com" Date: Tue, 17 Mar 2020 11:24:03 -0700 Subject: [PATCH 2/2] Fix reference to unused e to satisfy rubocop --- docker/docker-compose.yml | 6 ++++++ lib/vmpooler/pool_manager.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 55e3383..e508cbd 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -9,6 +9,9 @@ services: - type: bind source: ${PWD}/vmpooler.yaml target: /etc/vmpooler/vmpooler.yaml + - type: bind + source: ${PWD}/providers.yaml + target: /etc/vmpooler/providers.yaml ports: - "4567:4567" networks: @@ -17,6 +20,9 @@ services: - VMPOOLER_DEBUG=true # for use of dummy auth - VMPOOLER_CONFIG_FILE=/etc/vmpooler/vmpooler.yaml - REDIS_SERVER=redislocal + - EXTRA_CONFIG=/etc/vmpooler/providers.yaml + - LOGFILE=/dev/stdout + - LDAP_PORT=636 image: vmpooler-local depends_on: - redislocal diff --git a/lib/vmpooler/pool_manager.rb b/lib/vmpooler/pool_manager.rb index f3b7a39..c6aff25 100644 --- a/lib/vmpooler/pool_manager.rb +++ b/lib/vmpooler/pool_manager.rb @@ -822,7 +822,7 @@ module Vmpooler loop_count += 1 end end - rescue Redis::CannotConnectError => e + rescue Redis::CannotConnectError raise rescue StandardError => e $logger.log('s', "[!] [#{pool['name']}] Error while checking the pool: #{e}")