Skip to content

Commit e50c9ec

Browse files
authored
Merge pull request #112 from puppetlabs/v1.1.1
V1.1.1
2 parents 6d1130b + 4aa78a1 commit e50c9ec

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

lib/vmfloaty/abs.rb

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def self.list_active(verbose, url, _token, user)
6464
end
6565

6666
def self.get_active_requests(verbose, url, user)
67-
conn = Http.get_conn(verbose, url)
67+
conn = Http.get_conn(verbose, supported_abs_url(url))
6868
res = conn.get 'status/queue'
6969
if valid_json?(res.body)
7070
requests = JSON.parse(res.body)
@@ -105,7 +105,7 @@ def self.all_job_resources_accounted_for(allocated_resources, hosts)
105105

106106
def self.delete(verbose, url, hosts, token, user)
107107
# In ABS terms, this is a "returned" host.
108-
conn = Http.get_conn(verbose, url)
108+
conn = Http.get_conn(verbose, supported_abs_url(url))
109109
conn.headers['X-AUTH-TOKEN'] = token if token
110110

111111
FloatyLogger.info "Trying to delete hosts #{hosts}" if verbose
@@ -163,7 +163,7 @@ def self.delete(verbose, url, hosts, token, user)
163163

164164
# List available VMs in ABS
165165
def self.list(verbose, url, os_filter = nil)
166-
conn = Http.get_conn(verbose, url)
166+
conn = Http.get_conn(verbose, supported_abs_url(url))
167167

168168
os_list = []
169169

@@ -245,7 +245,7 @@ def self.retrieve(verbose, os_types, token, url, user, config, _ondemand = nil)
245245
# }
246246
# }
247247

248-
conn = Http.get_conn(verbose, url)
248+
conn = Http.get_conn(verbose, supported_abs_url(url))
249249
conn.headers['X-AUTH-TOKEN'] = token if token
250250

251251
saved_job_id = user + "-" + DateTime.now.strftime('%Q')
@@ -348,7 +348,7 @@ def self.snapshot(_verbose, _url, _hostname, _token)
348348
end
349349

350350
def self.status(verbose, url)
351-
conn = Http.get_conn(verbose, url)
351+
conn = Http.get_conn(verbose, supported_abs_url(url))
352352

353353
res = conn.get 'status'
354354

@@ -366,7 +366,7 @@ def self.query(verbose, url, job_id)
366366
return @active_hostnames if @active_hostnames && !@active_hostnames.empty?
367367

368368
# If using the cli query job_id
369-
conn = Http.get_conn(verbose, url)
369+
conn = Http.get_conn(verbose, supported_abs_url(url))
370370
queue_info_res = conn.get "status/queue/info/#{job_id}"
371371
if valid_json?(queue_info_res.body)
372372
queue_info = JSON.parse(queue_info_res.body)
@@ -411,4 +411,15 @@ def self.valid_json?(json)
411411
rescue TypeError, JSON::ParserError => e
412412
return false
413413
end
414+
415+
# when missing, adds the required api/v2 in the url
416+
def self.supported_abs_url(url)
417+
expected_ending = "api/v2"
418+
if !url.include?(expected_ending)
419+
# add a slash if missing
420+
expected_ending = "/#{expected_ending}" if url[-1] != "/"
421+
url = "#{url}#{expected_ending}"
422+
end
423+
url
424+
end
414425
end

lib/vmfloaty/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

33
class Vmfloaty
4-
VERSION = '1.0.0'
4+
VERSION = '1.1.1'
55
end
66

spec/vmfloaty/abs_spec.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
describe '#list' do
1313
it 'skips empty platforms and lists aws' do
14-
stub_request(:get, "http://foo/status/platforms/vmpooler").
14+
stub_request(:get, "http://foo/api/v2/status/platforms/vmpooler").
1515
to_return(:status => 200, :body => "", :headers => {})
16-
stub_request(:get, "http://foo/status/platforms/ondemand_vmpooler").
16+
stub_request(:get, "http://foo/api/v2/status/platforms/ondemand_vmpooler").
1717
to_return(:status => 200, :body => "", :headers => {})
18-
stub_request(:get, "http://foo/status/platforms/nspooler").
18+
stub_request(:get, "http://foo/api/v2/status/platforms/nspooler").
1919
to_return(:status => 200, :body => "", :headers => {})
2020
body = '{
2121
"aws_platforms": [
@@ -26,7 +26,7 @@
2626
"redhat-8-arm64"
2727
]
2828
}'
29-
stub_request(:get, "http://foo/status/platforms/aws").
29+
stub_request(:get, "http://foo/api/v2/status/platforms/aws").
3030
to_return(:status => 200, :body => body, :headers => {})
3131

3232

@@ -35,16 +35,16 @@
3535
expect(results).to include("amazon-6-x86_64", "amazon-7-x86_64", "amazon-7-arm64", "centos-7-x86-64-west", "redhat-8-arm64")
3636
end
3737
it 'legacy JSON string, prior to PR 306' do
38-
stub_request(:get, "http://foo/status/platforms/vmpooler").
38+
stub_request(:get, "http://foo/api/v2/status/platforms/vmpooler").
3939
to_return(:status => 200, :body => "", :headers => {})
40-
stub_request(:get, "http://foo/status/platforms/ondemand_vmpooler").
40+
stub_request(:get, "http://foo/api/v2/status/platforms/ondemand_vmpooler").
4141
to_return(:status => 200, :body => "", :headers => {})
42-
stub_request(:get, "http://foo/status/platforms/nspooler").
42+
stub_request(:get, "http://foo/api/v2/status/platforms/nspooler").
4343
to_return(:status => 200, :body => "", :headers => {})
4444
body = '{
4545
"aws_platforms": "[\"amazon-6-x86_64\",\"amazon-7-x86_64\",\"amazon-7-arm64\",\"centos-7-x86-64-west\",\"redhat-8-arm64\"]"
4646
}'
47-
stub_request(:get, "http://foo/status/platforms/aws").
47+
stub_request(:get, "http://foo/api/v2/status/platforms/aws").
4848
to_return(:status => 200, :body => body, :headers => {})
4949

5050
results = ABS.list(false, "http://foo")
@@ -125,7 +125,7 @@
125125
end
126126

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

131131
ret = ABS.get_active_requests(false, @abs_url, @test_user)
@@ -156,9 +156,9 @@
156156
end
157157

158158
it 'will delete the whole job' do
159-
stub_request(:get, 'https://abs.example.com/status/queue')
159+
stub_request(:get, 'https://abs.example.com/api/v2/status/queue')
160160
.to_return(:status => 200, :body => @active_requests_response, :headers => {})
161-
stub_request(:post, 'https://abs.example.com/return')
161+
stub_request(:post, 'https://abs.example.com/api/v2/return')
162162
.with(:body => @return_request)
163163
.to_return(:status => 200, :body => 'OK', :headers => {})
164164

0 commit comments

Comments
 (0)