Skip to content

Commit fffc16c

Browse files
authored
Merge pull request #60 from highb/qeng-7604_add_jobid_to_delete
(QENG-7604) Add support for Job IDs to ABS delete
2 parents 5fa9c12 + 5dbe19e commit fffc16c

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

lib/vmfloaty.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,11 @@ def run # rubocop:disable Metrics/AbcSize
185185

186186
command :delete do |c|
187187
c.syntax = 'floaty delete hostname,hostname2 [options]'
188+
c.syntax += "\n floaty delete job1,job2 [options] (only supported with ABS)"
188189
c.summary = 'Schedules the deletion of a host or hosts'
189-
c.description = 'Given a comma separated list of hostnames, or --all for all vms, vmfloaty makes a request to the pooler service to schedule the deletion of those vms.'
190+
c.description = 'Given a comma separated list of hostnames, or --all for all vms, vmfloaty makes a request to the pooler service to schedule the deletion of those vms. If you are using the ABS service, you can also pass in JobIDs here. Note that passing in a Job ID will delete *all* of the hosts in the job.' # rubocop:disable Layout/LineLength
190191
c.example 'Schedules the deletion of a host or hosts', 'floaty delete myhost1,myhost2 --url http://vmpooler.example.com'
192+
c.example 'Schedules the deletion of a JobID or JobIDs', 'floaty delete 1579300120799,1579300120800 --url http://abs.example.com'
191193
c.option '--verbose', 'Enables verbose output'
192194
c.option '--service STRING', String, 'Configured pooler service name'
193195
c.option '--all', 'Deletes all vms acquired by a token'

lib/vmfloaty/abs.rb

+5
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ def self.delete(verbose, url, hosts, token, user)
100100
requests.each do |req_hash|
101101
next unless req_hash['state'] == 'allocated' || req_hash['state'] == 'filled'
102102

103+
if hosts.include? req_hash['request']['job']['id']
104+
jobs_to_delete.push(req_hash)
105+
next
106+
end
107+
103108
req_hash['allocated_resources'].each do |vm_name, _i|
104109
if hosts.include? vm_name['hostname']
105110
if all_job_resources_accounted_for(req_hash['allocated_resources'], hosts)

spec/vmfloaty/abs_spec.rb

+32-2
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@
6565

6666
describe '#test_abs_status_queue_endpoint' do
6767
before :each do
68-
# rubocop:disable Metrics/LineLength
68+
# rubocop:disable Layout/LineLength
6969
@active_requests_response = '
7070
[
7171
"{ \"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}}",
7272
"null",
7373
"{\"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}}"
7474
]'
75-
# rubocop:enable Metrics/LineLength
75+
# rubocop:enable Layout/LineLength
7676
@token = 'utpg2i2xswor6h8ttjhu3d47z53yy47y'
7777
@test_user = 'test-user'
7878
end
@@ -92,5 +92,35 @@
9292
)
9393
end
9494
end
95+
96+
describe '#test_abs_delete_jobid' do
97+
before :each do
98+
# rubocop:disable Layout/LineLength
99+
@active_requests_response = '
100+
[
101+
"{ \"state\":\"allocated\", \"last_processed\":\"2020-01-17 22:29:13 +0000\", \"allocated_resources\":[{\"hostname\":\"craggy-chord.delivery.puppetlabs.net\", \"type\":\"centos-7-x86_64\", \"engine\":\"vmpooler\"}, {\"hostname\":\"visible-revival.delivery.puppetlabs.net\", \"type\":\"centos-7-x86_64\", \"engine\":\"vmpooler\"}], \"audit_log\":{\"2020-01-17 22:28:45 +0000\":\"Allocated craggy-chord.delivery.puppetlabs.net, visible-revival.delivery.puppetlabs.net for job 1579300120799\"}, \"request\":{\"resources\":{\"centos-7-x86_64\":2}, \"job\":{\"id\":\"1579300120799\", \"tags\":{\"user\":\"test-user\"}, \"user\":\"test-user\", \"time-received\":1579300120}, \"priority\":3}}"
102+
]'
103+
@return_request = { '{"job_id":"1579300120799","hosts":{"hostname":"craggy-chord.delivery.puppetlabs.net","type":"centos-7-x86_64","engine":"vmpooler"},{"hostname":"visible-revival.delivery.puppetlabs.net","type":"centos-7-x86_64","engine":"vmpooler"}}'=>true }
104+
# rubocop:enable Layout/LineLength
105+
@token = 'utpg2i2xswor6h8ttjhu3d47z53yy47y'
106+
@test_user = 'test-user'
107+
# Job ID
108+
@hosts = ['1579300120799']
109+
end
110+
111+
it 'will delete the whole job' do
112+
stub_request(:get, 'https://abs.example.com/status/queue')
113+
.to_return(:status => 200, :body => @active_requests_response, :headers => {})
114+
stub_request(:post, 'https://abs.example.com/return')
115+
.with(:body => @return_request)
116+
.to_return(:status => 200, :body => 'OK', :headers => {})
117+
118+
ret = ABS.delete(false, @abs_url, @hosts, @token, @test_user)
119+
120+
expect(ret).to include(
121+
'craggy-chord.delivery.puppetlabs.net' => { 'ok'=>true }, 'visible-revival.delivery.puppetlabs.net' => { 'ok'=>true },
122+
)
123+
end
124+
end
95125
end
96126
end

0 commit comments

Comments
 (0)