Merge pull request #244 from puppetlabs/POOLER-92

(POOLER-92) Add the alias information in the API status page for each…
This commit is contained in:
mattkirby 2017-10-20 09:07:25 -07:00 committed by GitHub
commit abdc86f164
3 changed files with 95 additions and 5 deletions

View file

@ -0,0 +1,74 @@
---
:providers:
:dummy:
filename: '/tmp/dummy-backing.yaml'
:redis:
server: 'localhost'
:auth:
provider: 'dummy'
:tagfilter:
url: '(.*)\/'
:config:
site_name: 'vmpooler'
logfile: '/Users/samuel/workspace/vmpooler/vmpooler.log'
task_limit: 10
timeout: 15
vm_checktime: 15
vm_lifetime: 12
vm_lifetime_auth: 24
allowed_tags:
- 'created_by'
- 'project'
domain: 'company.com'
prefix: 'poolvm-'
:pools:
- name: 'debian-7-i386'
alias: [ 'debian-7-32' ]
template: 'Templates/debian-7-i386'
folder: 'Pooled VMs/debian-7-i386'
datastore: 'vmstorage'
size: 5
timeout: 15
ready_ttl: 1440
provider: dummy
- name: 'debian-7-i386-stringalias'
alias: 'debian-7-32-stringalias'
template: 'Templates/debian-7-i386'
folder: 'Pooled VMs/debian-7-i386'
datastore: 'vmstorage'
size: 5
timeout: 15
ready_ttl: 1440
provider: dummy
- name: 'debian-7-x86_64'
alias: [ 'debian-7-64', 'debian-7-amd64' ]
template: 'Templates/debian-7-x86_64'
folder: 'Pooled VMs/debian-7-x86_64'
datastore: 'vmstorage'
size: 5
timeout: 15
ready_ttl: 1440
provider: dummy
- name: 'debian-7-i386-noalias'
template: 'Templates/debian-7-i386'
folder: 'Pooled VMs/debian-7-i386'
datastore: 'vmstorage'
size: 5
timeout: 15
ready_ttl: 1440
provider: dummy
- name: 'debian-7-x86_64-alias-otherpool-extended'
alias: [ 'debian-7-x86_64' ]
template: 'Templates/debian-7-x86_64'
folder: 'Other Pooled VMs/debian-7-x86_64'
datastore: 'other-vmstorage'
size: 5
timeout: 15
ready_ttl: 1440
provider: dummy

View file

@ -199,6 +199,7 @@ module Vmpooler
running = backend.scard('vmpooler__running__' + pool['name']).to_i running = backend.scard('vmpooler__running__' + pool['name']).to_i
pending = backend.scard('vmpooler__pending__' + pool['name']).to_i pending = backend.scard('vmpooler__pending__' + pool['name']).to_i
max = pool['size'] max = pool['size']
aka = pool['alias']
result[:pools][pool['name']] = { result[:pools][pool['name']] = {
ready: ready, ready: ready,
@ -207,6 +208,10 @@ module Vmpooler
max: max max: max
} }
if aka
result[:pools][pool['name']][:alias] = aka
end
# for backwards compatibility, include separate "empty" stats in "status" block # for backwards compatibility, include separate "empty" stats in "status" block
if ready == 0 if ready == 0
result[:status][:empty] ||= [] result[:status][:empty] ||= []

View file

@ -32,10 +32,10 @@ describe Vmpooler::API::V1 do
'vm_lifetime_auth' => 2, 'vm_lifetime_auth' => 2,
}, },
pools: [ pools: [
{'name' => 'pool1', 'size' => 5}, {'name' => 'pool1', 'size' => 5, 'alias' => ['poolone', 'poolun']},
{'name' => 'pool2', 'size' => 10} {'name' => 'pool2', 'size' => 10},
], {'name' => 'pool3', 'size' => 10, 'alias' => 'NotArray'}
alias: { 'poolone' => 'pool1' }, ]
} }
} }
@ -98,13 +98,24 @@ describe Vmpooler::API::V1 do
expect(result["pools"]["pool2"]["pending"]).to be(4) expect(result["pools"]["pool2"]["pending"]).to be(4)
end end
it 'returns aliases if configured in the pool' do
get "#{prefix}/status/"
# of course /status doesn't conform to the weird standard everything else uses...
expect(last_response.header['Content-Type']).to eq('application/json')
result = JSON.parse(last_response.body)
expect(result["pools"]["pool1"]["alias"]).to eq(['poolone', 'poolun'])
expect(result["pools"]["pool2"]["alias"]).to be(nil)
expect(result["pools"]["pool3"]["alias"]).to eq('NotArray')
end
it '(for v1 backwards compatibility) lists any empty pools in the status section' do it '(for v1 backwards compatibility) lists any empty pools in the status section' do
get "#{prefix}/status/" get "#{prefix}/status/"
# of course /status doesn't conform to the weird standard everything else uses... # of course /status doesn't conform to the weird standard everything else uses...
expect(last_response.header['Content-Type']).to eq('application/json') expect(last_response.header['Content-Type']).to eq('application/json')
result = JSON.parse(last_response.body) result = JSON.parse(last_response.body)
expect(result["status"]["empty"].sort).to eq(["pool1", "pool2"]) expect(result["status"]["empty"].sort).to eq(["pool1", "pool2", "pool3"])
end end
end end
end end