From 88899d451367e5819fe84ecfb505f5e958f18bc7 Mon Sep 17 00:00:00 2001 From: "kirby@puppetlabs.com" Date: Tue, 7 Jul 2020 14:19:28 -0700 Subject: [PATCH] Correctly handle multiple pools of same alias in ondemand checkout This commit updates the method used for chceking the status of an ondemand request to ensure that if multiple aliases are used to fulfill a request that they are correctly presented as a single pool again when everything is ready. Without this change it is possible for only one group of an aliased pool to show up in pending or completed requests. --- lib/vmpooler/api/v1.rb | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/vmpooler/api/v1.rb b/lib/vmpooler/api/v1.rb index c957f28..8c150ff 100644 --- a/lib/vmpooler/api/v1.rb +++ b/lib/vmpooler/api/v1.rb @@ -986,7 +986,12 @@ module Vmpooler result['ready'] = true Parsing.get_platform_pool_count(request_hash['requested']) do |platform_alias, pool, _count| instances = backend.smembers("vmpooler__#{request_id}__#{platform_alias}__#{pool}") - result[platform_alias] = { 'hostname': instances } + + if result.key?(platform_alias) + result[platform_alias][:hostname] = result[platform_alias][:hostname] + instances + else + result[platform_alias] = { 'hostname': instances } + end end result['domain'] = config['domain'] if config['domain'] status 200 @@ -999,10 +1004,17 @@ module Vmpooler else Parsing.get_platform_pool_count(request_hash['requested']) do |platform_alias, pool, count| instance_count = backend.scard("vmpooler__#{request_id}__#{platform_alias}__#{pool}") - result[platform_alias] = { - 'ready': instance_count.to_s, - 'pending': (count.to_i - instance_count.to_i).to_s - } + instances_pending = count.to_i - instance_count.to_i + + if result.key?(platform_alias) && result[platform_alias].key?(:ready) + result[platform_alias][:ready] = (result[platform_alias][:ready].to_i + instance_count).to_s + result[platform_alias][:pending] = (result[platform_alias][:pending].to_i + instances_pending).to_s + else + result[platform_alias] = { + 'ready': instance_count.to_s, + 'pending': instances_pending.to_s + } + end end end