Skip to content

Commit

Permalink
Merge pull request #57 from mikkergimenez/check_for_blank_lines_retur…
Browse files Browse the repository at this point in the history
…ned_from_abs_status_queue

ABS will sometimes return null values in the /status/queue endpoint
  • Loading branch information
highb authored Dec 17, 2019
2 parents 7d0a725 + 2c456f1 commit e6bd405
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 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
12 changes: 10 additions & 2 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
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 e6bd405

Please sign in to comment.