Merge pull request #394 from mattkirby/pooler_186

(POOLER-186) Fix template alias evaluation with backend weight of 0
This commit is contained in:
Heath Seals 2020-08-05 18:50:34 -05:00 committed by GitHub
commit cef050b129
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 12 deletions

View file

@ -89,18 +89,16 @@ module Vmpooler
template_backends += aliases
weighted_pools = get_pool_weights(template_backends)
pickup = Pickup.new(weighted_pools) if weighted_pools.count == template_backends.count
count.to_i.times do
if pickup
if weighted_pools.count > 1 && weighted_pools.count == template_backends.count
pickup = Pickup.new(weighted_pools)
count.to_i.times do
selection << pickup.pick
else
end
else
count.to_i.times do
selection << template_backends.sample
end
end
else
count.to_i.times do
selection << template
end
end
count_selection(selection)

View file

@ -24,15 +24,19 @@ describe Vmpooler::API::V1 do
'vm_lifetime_auth' => 2,
'max_ondemand_instances_per_request' => 50,
'backend_weight' => {
'compute1' => 5
'compute1' => 5,
'compute2' => 0
}
},
pools: [
{'name' => 'pool1', 'size' => 0},
{'name' => 'pool2', 'size' => 0, 'clone_target' => 'compute1'},
{'name' => 'pool1', 'size' => 0, 'clone_target' => 'compute1'},
{'name' => 'pool2', 'size' => 0, 'clone_target' => 'compute2'},
{'name' => 'pool3', 'size' => 0, 'clone_target' => 'compute1'}
],
alias: { 'poolone' => ['pool1'] },
alias: {
'poolone' => ['pool1'],
'pool2' => ['pool1']
},
pool_names: [ 'pool1', 'pool2', 'pool3', 'poolone' ]
}
}
@ -92,6 +96,22 @@ describe Vmpooler::API::V1 do
post "#{prefix}/ondemandvm", '{"poolone":"1"}'
end
context 'with a backend of 0 weight' do
before(:each) do
config[:config]['backend_weight']['compute1'] = 0
end
it 'sets the platform string in redis for the request to indicate the selected platforms' do
expect(redis).to receive(:hset).with("vmpooler__odrequest__#{uuid}", 'requested', 'pool1:pool1:1')
post "#{prefix}/ondemandvm", '{"pool1":"1"}'
end
end
it 'sets the platform string in redis for the request to indicate the selected platforms using weight' do
expect(redis).to receive(:hset).with("vmpooler__odrequest__#{uuid}", 'requested', 'pool2:pool1:1')
post "#{prefix}/ondemandvm", '{"pool2":"1"}'
end
context 'with domain set in the config' do
let(:domain) { 'example.com' }
before(:each) do