(POOLER-131) Return requested name when getting VMs

This commit updates fetch_single_vm to return the name of the template that was requested, instead of the name of the pool providing the VM to meet the request. Without this change, when an alias is used for fetching a VM, a different pool title may be returned containing the requested VMs than the user initially requested.
This commit is contained in:
kirby@puppetlabs.com 2018-09-27 12:04:01 -07:00
parent 918877918a
commit 4ba4a1dd6c
4 changed files with 16 additions and 13 deletions

View file

@ -13,6 +13,9 @@ git logs & PR history.
# [Unreleased](https://github.com/puppetlabs/vmpooler/compare/0.2.1...master) # [Unreleased](https://github.com/puppetlabs/vmpooler/compare/0.2.1...master)
### Fixed
- Return label used to request VMs when fulfilling VM requests (POOLER-131)
# [0.2.1](https://github.com/puppetlabs/vmpooler/compare/0.2.0...0.2.1) # [0.2.1](https://github.com/puppetlabs/vmpooler/compare/0.2.0...0.2.1)
### Fixed ### Fixed

View file

@ -67,9 +67,9 @@ module Vmpooler
template_backends.each do |t| template_backends.each do |t|
vm = backend.spop('vmpooler__ready__' + t) vm = backend.spop('vmpooler__ready__' + t)
return [vm, t] if vm return [vm, t, template] if vm
end end
[nil, nil] [nil, nil, nil]
end end
def return_vm_to_ready_state(template, vm) def return_vm_to_ready_state(template, vm)
@ -113,27 +113,27 @@ module Vmpooler
payload.each do |requested, count| payload.each do |requested, count|
count.to_i.times do |_i| count.to_i.times do |_i|
vm, name = fetch_single_vm(requested) vmname, vmpool, vmtemplate = fetch_single_vm(requested)
if !vm if !vmname
failed = true failed = true
metrics.increment('checkout.empty.' + requested) metrics.increment('checkout.empty.' + requested)
break break
else else
vms << [ name, vm ] vms << [ vmpool, vmname, vmtemplate ]
metrics.increment('checkout.success.' + name) metrics.increment('checkout.success.' + vmtemplate)
end end
end end
end end
if failed if failed
vms.each do |(name, vm)| vms.each do |(vmpool, vmname, vmtemplate)|
return_vm_to_ready_state(name, vm) return_vm_to_ready_state(vmpool, vmname)
end end
status 503 status 503
else else
vms.each do |(name, vm)| vms.each do |(vmpool, vmname, vmtemplate)|
account_for_starting_vm(name, vm) account_for_starting_vm(vmpool, vmname)
update_result_hosts(result, name, vm) update_result_hosts(result, vmtemplate, vmname)
end end
result['ok'] = true result['ok'] = true

View file

@ -82,7 +82,7 @@ describe Vmpooler::API::V1 do
expected = { expected = {
ok: true, ok: true,
pool1: { poolone: {
hostname: 'abcdefghijklmnop' hostname: 'abcdefghijklmnop'
} }
} }

View file

@ -63,7 +63,7 @@ describe Vmpooler::API::V1 do
expected = { expected = {
ok: true, ok: true,
pool1: { poolone: {
hostname: 'abcdefghijklmnop' hostname: 'abcdefghijklmnop'
} }
} }