From 4ba4a1dd6cfdc9499aaf46077943585daa518755 Mon Sep 17 00:00:00 2001 From: "kirby@puppetlabs.com" Date: Thu, 27 Sep 2018 12:04:01 -0700 Subject: [PATCH] (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. --- CHANGELOG.md | 3 +++ lib/vmpooler/api/v1.rb | 22 ++++++++++----------- spec/integration/api/v1/vm_spec.rb | 2 +- spec/integration/api/v1/vm_template_spec.rb | 2 +- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df48454..5140ca8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ git logs & PR history. # [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) ### Fixed diff --git a/lib/vmpooler/api/v1.rb b/lib/vmpooler/api/v1.rb index 434e17e..640a8f9 100644 --- a/lib/vmpooler/api/v1.rb +++ b/lib/vmpooler/api/v1.rb @@ -67,9 +67,9 @@ module Vmpooler template_backends.each do |t| vm = backend.spop('vmpooler__ready__' + t) - return [vm, t] if vm + return [vm, t, template] if vm end - [nil, nil] + [nil, nil, nil] end def return_vm_to_ready_state(template, vm) @@ -113,27 +113,27 @@ module Vmpooler payload.each do |requested, count| count.to_i.times do |_i| - vm, name = fetch_single_vm(requested) - if !vm + vmname, vmpool, vmtemplate = fetch_single_vm(requested) + if !vmname failed = true metrics.increment('checkout.empty.' + requested) break else - vms << [ name, vm ] - metrics.increment('checkout.success.' + name) + vms << [ vmpool, vmname, vmtemplate ] + metrics.increment('checkout.success.' + vmtemplate) end end end if failed - vms.each do |(name, vm)| - return_vm_to_ready_state(name, vm) + vms.each do |(vmpool, vmname, vmtemplate)| + return_vm_to_ready_state(vmpool, vmname) end status 503 else - vms.each do |(name, vm)| - account_for_starting_vm(name, vm) - update_result_hosts(result, name, vm) + vms.each do |(vmpool, vmname, vmtemplate)| + account_for_starting_vm(vmpool, vmname) + update_result_hosts(result, vmtemplate, vmname) end result['ok'] = true diff --git a/spec/integration/api/v1/vm_spec.rb b/spec/integration/api/v1/vm_spec.rb index 5399370..4615949 100644 --- a/spec/integration/api/v1/vm_spec.rb +++ b/spec/integration/api/v1/vm_spec.rb @@ -82,7 +82,7 @@ describe Vmpooler::API::V1 do expected = { ok: true, - pool1: { + poolone: { hostname: 'abcdefghijklmnop' } } diff --git a/spec/integration/api/v1/vm_template_spec.rb b/spec/integration/api/v1/vm_template_spec.rb index 72fef36..0f71395 100644 --- a/spec/integration/api/v1/vm_template_spec.rb +++ b/spec/integration/api/v1/vm_template_spec.rb @@ -63,7 +63,7 @@ describe Vmpooler::API::V1 do expected = { ok: true, - pool1: { + poolone: { hostname: 'abcdefghijklmnop' } }