Skip to content

Commit

Permalink
ABS will sometimes return null values in the /status/queue endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkergimenez committed Dec 17, 2019
1 parent 7d0a725 commit 14a9b9e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ gemspec
gem 'rake', :require => false

group :test do
gem 'pry'
gem 'rb-readline'
gem 'rspec', '~> 3.5.0'
gem 'rubocop', '~> 0.52'
gem 'webmock', '1.21.0'
Expand Down
18 changes: 13 additions & 5 deletions lib/vmfloaty/abs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,19 @@ def self.get_active_requests(verbose, url, user)
requests = JSON.parse(res.body)

ret_val = []

requests.each do |req|
next if req == 'null'

req_hash = JSON.parse(req)
next unless user == req_hash['request']['job']['user']

ret_val.push(req_hash)
begin
next unless user == req_hash['request']['job']['user']

ret_val.push(req_hash)
rescue NoMethodError
puts "Warning: couldn't parse line returned from abs/status/queue: ".yellow
end
end

ret_val
Expand Down Expand Up @@ -111,7 +119,7 @@ def self.delete(verbose, url, hosts, token, user)
jobs_to_delete.each do |job|
req_obj = {
'job_id' => job['request']['job']['id'],
'hosts' => job['allocated_resources'],
'hosts' => job['allocated_resources'],
}

puts "Deleting #{req_obj}" if verbose
Expand Down Expand Up @@ -179,8 +187,8 @@ def self.retrieve(verbose, os_types, token, url, user, options)

req_obj = {
:resources => os_types,
:job => {
:id => saved_job_id,
:job => {
:id => saved_job_id,
:tags => {
:user => user,
},
Expand Down
34 changes: 34 additions & 0 deletions spec/vmfloaty/abs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,39 @@
]
expect(ABS.all_job_resources_accounted_for(allocated_resources, hosts)).to eq(true)
end

before :each do
@abs_url = 'https://abs.example.com'
end

describe '#test_abs_status_queue_endpoint' do
before :each do
# rubocop:disable Metrics/LineLength
@active_requests_response = '
[
"{ \"state\":\"allocated\",\"last_processed\":\"2019-12-16 23:00:34 +0000\",\"allocated_resources\":[{\"hostname\":\"take-this.delivery.puppetlabs.net\",\"type\":\"win-2012r2-x86_64\",\"engine\":\"vmpooler\"}],\"audit_log\":{\"2019-12-13 16:45:29 +0000\":\"Allocated take-this.delivery.puppetlabs.net for job 1576255517241\"},\"request\":{\"resources\":{\"win-2012r2-x86_64\":1},\"job\":{\"id\":\"1576255517241\",\"tags\":{\"user\":\"test-user\"},\"user\":\"test-user\",\"time-received\":1576255519},\"priority\":1}}",
"null",
"{\"state\":\"allocated\",\"last_processed\":\"2019-12-16 23:00:34 +0000\",\"allocated_resources\":[{\"hostname\":\"not-this.delivery.puppetlabs.net\",\"type\":\"win-2012r2-x86_64\",\"engine\":\"vmpooler\"}],\"audit_log\":{\"2019-12-13 16:46:14 +0000\":\"Allocated not-this.delivery.puppetlabs.net for job 1576255565159\"},\"request\":{\"resources\":{\"win-2012r2-x86_64\":1},\"job\":{\"id\":\"1576255565159\",\"tags\":{\"user\":\"not-test-user\"},\"user\":\"not-test-user\",\"time-received\":1576255566},\"priority\":1}}"
]'
# rubocop:enable Metrics/LineLength
@token = 'utpg2i2xswor6h8ttjhu3d47z53yy47y'
@test_user = 'test-user'
end

it 'will skip a line with a null value returned from abs' do
stub_request(:get, 'https://abs.example.com/status/queue')
.to_return(:status => 200, :body => @active_requests_response, :headers => {})

ret = ABS.get_active_requests(false, @abs_url, @test_user)

expect(ret[0]).to include(
'allocated_resources' => [{
'hostname' => 'take-this.delivery.puppetlabs.net',
'type' => 'win-2012r2-x86_64',
'engine' => 'vmpooler',
}],
)
end
end
end
end

0 comments on commit 14a9b9e

Please sign in to comment.