mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
Merge pull request #458 from puppetlabs/fix-jenkins-and-user-usage-metrics
(DIO-541) Fix jenkins and user usage metrics
This commit is contained in:
commit
036a9ae502
3 changed files with 13 additions and 49 deletions
|
|
@ -236,12 +236,25 @@ module Vmpooler
|
|||
result
|
||||
end
|
||||
|
||||
def component_to_test(match, labels_string)
|
||||
return if labels_string.nil?
|
||||
|
||||
labels_string_parts = labels_string.split(',')
|
||||
labels_string_parts.each do |part|
|
||||
key, value = part.split('=')
|
||||
next if value.nil?
|
||||
return value if key == match
|
||||
end
|
||||
'none'
|
||||
end
|
||||
|
||||
def update_user_metrics(operation, vmname)
|
||||
backend.multi
|
||||
backend.hget("vmpooler__vm__#{vmname}", 'tag:jenkins_build_url')
|
||||
backend.hget("vmpooler__vm__#{vmname}", 'token:user')
|
||||
backend.hget("vmpooler__vm__#{vmname}", 'template')
|
||||
jenkins_build_url, user, poolname = backend.exec
|
||||
poolname = poolname.gsub('.', '_')
|
||||
|
||||
if user
|
||||
user = user.gsub('.', '_')
|
||||
|
|
|
|||
|
|
@ -478,18 +478,6 @@ module Vmpooler
|
|||
dereference_mutex(vm)
|
||||
end
|
||||
|
||||
def component_to_test(match, labels_string)
|
||||
return if labels_string.nil?
|
||||
|
||||
labels_string_parts = labels_string.split(',')
|
||||
labels_string_parts.each do |part|
|
||||
key, value = part.split('=')
|
||||
next if value.nil?
|
||||
return value if key == match
|
||||
end
|
||||
'none'
|
||||
end
|
||||
|
||||
def purge_unused_vms_and_folders
|
||||
global_purge = $config[:config]['purge_unconfigured_folders']
|
||||
providers = $config[:providers].keys
|
||||
|
|
|
|||
|
|
@ -1062,43 +1062,6 @@ EOT
|
|||
end
|
||||
end
|
||||
|
||||
describe '#component_to_test' do
|
||||
let(:matching_key) { 'LABEL_ONE' }
|
||||
let(:matching_value) { 'test' }
|
||||
let(:labels_string) { "#{matching_key}=#{matching_value},LABEL_TWO=test2,LABEL_THREE=test3" }
|
||||
let(:nonmatrix_string) { 'test,stuff,and,things' }
|
||||
|
||||
context 'when string contains a matching key' do
|
||||
it 'should print the corresponding value' do
|
||||
expect(subject.component_to_test(matching_key, labels_string)).to eq(matching_value)
|
||||
end
|
||||
|
||||
context 'when match contains no value' do
|
||||
it 'should return none' do
|
||||
expect(subject.component_to_test(matching_key, matching_key)).to eq('none')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when string contains no key value pairs' do
|
||||
it 'should return' do
|
||||
expect(subject.component_to_test(matching_key, nonmatrix_string)).to eq('none')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when labels_string is a job number' do
|
||||
it 'should return nil' do
|
||||
expect(subject.component_to_test(matching_key, '25')).to eq('none')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when labels_string is nil' do
|
||||
it 'should return nil' do
|
||||
expect(subject.component_to_test(matching_key, nil)).to be nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#purge_unused_vms_and_folders' do
|
||||
let(:config) { YAML.load(<<-EOT
|
||||
---
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue