Merge pull request #621 from puppetlabs/fix_bug_in_fail_pending_vm

(maint) Fix bugs from redis and timeout notification updates.
This commit is contained in:
isaac-hammes 2023-08-24 06:28:05 -07:00 committed by GitHub
commit 1210a4d0d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 5 deletions

View file

@ -283,11 +283,9 @@ module Vmpooler
def update_user_metrics(operation, vmname) def update_user_metrics(operation, vmname)
tracer.in_span("Vmpooler::API::V3.#{__method__}") do |span| tracer.in_span("Vmpooler::API::V3.#{__method__}") do |span|
begin begin
backend.multi jenkins_build_url = backend.hget("vmpooler__vm__#{vmname}", 'tag:jenkins_build_url')
backend.hget("vmpooler__vm__#{vmname}", 'tag:jenkins_build_url') user = backend.hget("vmpooler__vm__#{vmname}", 'token:user')
backend.hget("vmpooler__vm__#{vmname}", 'token:user') poolname = backend.hget("vmpooler__vm__#{vmname}", 'template')
backend.hget("vmpooler__vm__#{vmname}", 'template')
jenkins_build_url, user, poolname = backend.exec
poolname = poolname.gsub('.', '_') poolname = poolname.gsub('.', '_')
if user if user

View file

@ -129,6 +129,8 @@ module Vmpooler
already_timed_out = time_since_clone > timeout already_timed_out = time_since_clone > timeout
timing_out_soon = time_since_clone > timeout_notification && !redis.hget("vmpooler__vm__#{vm}", 'timeout_notification') timing_out_soon = time_since_clone > timeout_notification && !redis.hget("vmpooler__vm__#{vm}", 'timeout_notification')
return true if !already_timed_out && !timing_out_soon
if already_timed_out if already_timed_out
unless exists unless exists
remove_nonexistent_vm(vm, pool, redis) remove_nonexistent_vm(vm, pool, redis)

View file

@ -275,6 +275,7 @@ EOT
it 'takes no action if VM is not cloning' do it 'takes no action if VM is not cloning' do
redis_connection_pool.with do |redis| redis_connection_pool.with do |redis|
expect(logger).to_not receive(:log)
expect(subject.fail_pending_vm(vm, pool, timeout, timeout_notification, redis)).to eq(true) expect(subject.fail_pending_vm(vm, pool, timeout, timeout_notification, redis)).to eq(true)
end end
end end
@ -282,6 +283,7 @@ EOT
it 'takes no action if VM is within timeout' do it 'takes no action if VM is within timeout' do
redis_connection_pool.with do |redis| redis_connection_pool.with do |redis|
redis.hset("vmpooler__vm__#{vm}", 'clone',Time.now.to_s) redis.hset("vmpooler__vm__#{vm}", 'clone',Time.now.to_s)
expect(logger).to_not receive(:log)
expect(subject.fail_pending_vm(vm, pool, timeout, timeout_notification, redis)).to eq(true) expect(subject.fail_pending_vm(vm, pool, timeout, timeout_notification, redis)).to eq(true)
expect(redis.sismember("vmpooler__pending__#{pool}", vm)).to be(true) expect(redis.sismember("vmpooler__pending__#{pool}", vm)).to be(true)
end end
@ -307,6 +309,7 @@ EOT
it 'calls remove_nonexistent_vm if VM has exceeded timeout and does not exist' do it 'calls remove_nonexistent_vm if VM has exceeded timeout and does not exist' do
redis_connection_pool.with do |redis| redis_connection_pool.with do |redis|
redis.hset("vmpooler__vm__#{vm}", 'clone',Date.new(2001,1,1).to_s) redis.hset("vmpooler__vm__#{vm}", 'clone',Date.new(2001,1,1).to_s)
expect(logger).to_not receive(:log)
expect(subject).to receive(:remove_nonexistent_vm).with(vm, pool, redis) expect(subject).to receive(:remove_nonexistent_vm).with(vm, pool, redis)
expect(subject.fail_pending_vm(vm, pool, timeout, timeout_notification, redis, exists: false)).to eq(true) expect(subject.fail_pending_vm(vm, pool, timeout, timeout_notification, redis, exists: false)).to eq(true)
end end