diff --git a/lib/vmpooler/api/v1.rb b/lib/vmpooler/api/v1.rb index 43f1f9a..3773e2c 100644 --- a/lib/vmpooler/api/v1.rb +++ b/lib/vmpooler/api/v1.rb @@ -354,8 +354,6 @@ module Vmpooler return result end - return result unless backend.zadd('vmpooler__provisioning__request', score, request_id) - status 201 platforms_with_aliases = [] @@ -363,8 +361,9 @@ module Vmpooler selection = evaluate_template_aliases(poolname, count) selection.map { |selected_pool, selected_pool_count| platforms_with_aliases << "#{poolname}:#{selected_pool}:#{selected_pool_count}" } end - platforms_string = platforms_with_aliases.join(',') + + return result unless backend.zadd('vmpooler__provisioning__request', score, request_id) backend.hset("vmpooler__odrequest__#{request_id}", 'requested', platforms_string) if Vmpooler::API.settings.config[:auth] and has_token? backend.hset("vmpooler__odrequest__#{request_id}", 'token:token', request.env['HTTP_X_AUTH_TOKEN']) diff --git a/lib/vmpooler/pool_manager.rb b/lib/vmpooler/pool_manager.rb index 1f13a17..1b9b0fa 100644 --- a/lib/vmpooler/pool_manager.rb +++ b/lib/vmpooler/pool_manager.rb @@ -82,7 +82,7 @@ module Vmpooler $logger.log('s', "[!] [#{pool}] '#{vm}' #{timeout} #{provider} errored while checking a pending vm : #{e}") @redis.with_metrics do |redis| request_id = redis.hget("vmpooler__vm__#{vm}", 'request_id') - fail_pending_vm(vm, pool, timeout, redis, request_id=request_id) + fail_pending_vm(vm, pool, timeout, redis) end raise end @@ -99,7 +99,7 @@ module Vmpooler if provider.vm_ready?(pool, vm) move_pending_vm_to_ready(vm, pool, redis, request_id) else - fail_pending_vm(vm, pool, timeout, redis, request_id = request_id) + fail_pending_vm(vm, pool, timeout, redis) end end end @@ -110,17 +110,18 @@ module Vmpooler $logger.log('d', "[!] [#{pool}] '#{vm}' no longer exists. Removing from pending.") end - def fail_pending_vm(vm, pool, timeout, redis, exists = true, request_id = nil) + def fail_pending_vm(vm, pool, timeout, redis, exists = true) clone_stamp = redis.hget("vmpooler__vm__#{vm}", 'clone') return true unless clone_stamp time_since_clone = (Time.now - Time.parse(clone_stamp)) / 60 if time_since_clone > timeout if exists + request_id = redis.hget("vmpooler__vm__#{vm}", 'request_id') pool_alias = redis.hget("vmpooler__vm__#{vm}", 'pool_alias') if request_id redis.multi redis.smove('vmpooler__pending__' + pool, 'vmpooler__completed__' + pool, vm) - result = redis.zadd('vmpooler__odcreate__task', 1, "#{pool_alias}:#{pool}:1:#{request_id}") if request_id + redis.zadd('vmpooler__odcreate__task', 1, "#{pool_alias}:#{pool}:1:#{request_id}") if request_id redis.exec $metrics.increment("errors.markedasfailed.#{pool}") $logger.log('d', "[!] [#{pool}] '#{vm}' marked as 'failed' after #{timeout} minutes") @@ -1296,7 +1297,7 @@ module Vmpooler check_running_pool_vms(pool['name'], provider, pool_check_response, inventory) - check_ready_pool_vms(pool['name'], provider, pool_check_response, inventory, pool['ready_ttl']) + check_ready_pool_vms(pool['name'], provider, pool_check_response, inventory, pool['ready_ttl'] || $config[:config]['ready_ttl']) check_pending_pool_vms(pool['name'], provider, pool_check_response, inventory, pool['timeout']) diff --git a/spec/unit/pool_manager_spec.rb b/spec/unit/pool_manager_spec.rb index 34d663e..c555b17 100644 --- a/spec/unit/pool_manager_spec.rb +++ b/spec/unit/pool_manager_spec.rb @@ -111,7 +111,7 @@ EOT it 'calls fail_pending_vm if host is not ready' do expect(provider).to receive(:vm_ready?).with(pool,vm).and_return(false) redis_connection_pool.with do |redis| - expect(subject).to receive(:fail_pending_vm).with(vm, pool, timeout, redis, nil) + expect(subject).to receive(:fail_pending_vm).with(vm, pool, timeout, redis) end subject._check_pending_vm(vm, pool, timeout, provider) @@ -227,7 +227,8 @@ EOT redis_connection_pool.with do |redis| redis.hset("vmpooler__vm__#{vm}", 'clone',(Time.now - 900).to_s) redis.hset("vmpooler__vm__#{vm}", 'pool_alias', pool) - subject.fail_pending_vm(vm, pool, timeout, redis, true, request_id) + redis.hset("vmpooler__vm__#{vm}", 'request_id', request_id) + subject.fail_pending_vm(vm, pool, timeout, redis, true) expect(redis.zrange('vmpooler__odcreate__task', 0, -1)).to eq(["#{pool}:#{pool}:1:#{request_id}"]) end end