vmfloaty 0.10.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,7 +22,7 @@ class NonstandardPooler
22
22
  status['reserved_hosts'] || []
23
23
  end
24
24
 
25
- def self.retrieve(verbose, os_type, token, url, _user, _options)
25
+ def self.retrieve(verbose, os_type, token, url, _user, _options, ondemand = nil, _continue = nil)
26
26
  conn = Http.get_conn(verbose, url)
27
27
  conn.headers['X-AUTH-TOKEN'] = token if token
28
28
 
@@ -28,7 +28,7 @@ class Pooler
28
28
  vms
29
29
  end
30
30
 
31
- def self.retrieve(verbose, os_type, token, url, _user, _options, ondemand = nil)
31
+ def self.retrieve(verbose, os_type, token, url, _user, _options, ondemand = nil, _continue = nil)
32
32
  # NOTE:
33
33
  # Developers can use `Utils.generate_os_hash` to
34
34
  # generate the os_type param.
@@ -60,10 +60,10 @@ class Pooler
60
60
  while check_ondemandvm(verbose, request_id, url) == false
61
61
  return false if (Time.now - start_time).to_i > timeout
62
62
 
63
- STDOUT.puts "waiting for request #{request_id} to be fulfilled"
63
+ FloatyLogger.info "waiting for request #{request_id} to be fulfilled"
64
64
  sleep 5
65
65
  end
66
- STDOUT.puts "The request has been fulfilled"
66
+ FloatyLogger.info "The request has been fulfilled"
67
67
  check_ondemandvm(verbose, request_id, url)
68
68
  end
69
69
 
@@ -7,11 +7,13 @@ require 'vmfloaty/ssh'
7
7
 
8
8
  class Service
9
9
  attr_reader :config
10
+ attr_accessor :silent
10
11
 
11
12
  def initialize(options, config_hash = {})
12
13
  options ||= Commander::Command::Options.new
13
14
  @config = Utils.get_service_config config_hash, options
14
15
  @service_object = Utils.get_service_object @config['type']
16
+ @silent = false
15
17
  end
16
18
 
17
19
  def method_missing(method_name, *args, &block)
@@ -36,7 +38,7 @@ class Service
36
38
 
37
39
  def user
38
40
  unless @config['user']
39
- puts "Enter your #{@config['url']} service username:"
41
+ FloatyLogger.info "Enter your #{@config['url']} service username:"
40
42
  @config['user'] = STDIN.gets.chomp
41
43
  end
42
44
  @config['user']
@@ -44,7 +46,7 @@ class Service
44
46
 
45
47
  def token
46
48
  unless @config['token']
47
- puts 'No token found. Retrieving a token...'
49
+ FloatyLogger.info 'No token found. Retrieving a token...'
48
50
  @config['token'] = get_new_token(nil)
49
51
  end
50
52
  @config['token']
@@ -75,10 +77,10 @@ class Service
75
77
  @service_object.list_active verbose, url, token, user
76
78
  end
77
79
 
78
- def retrieve(verbose, os_types, use_token = true, ondemand = nil)
79
- puts 'Requesting a vm without a token...' unless use_token
80
+ def retrieve(verbose, os_types, use_token = true, ondemand = nil, continue = nil)
81
+ FloatyLogger.info 'Requesting a vm without a token...' unless use_token
80
82
  token_value = use_token ? token : nil
81
- @service_object.retrieve verbose, os_types, token_value, url, user, @config, ondemand
83
+ @service_object.retrieve verbose, os_types, token_value, url, user, @config, ondemand, continue
82
84
  end
83
85
 
84
86
  def wait_for_request(verbose, requestid)
@@ -91,27 +93,19 @@ class Service
91
93
  begin
92
94
  token_value = token || get_new_token(verbose)
93
95
  rescue TokenError => e
94
- STDERR.puts e
95
- STDERR.puts 'Could not get token... requesting vm without a token anyway...'
96
+ FloatyLogger.error e
97
+ FloatyLogger.info 'Could not get token... requesting vm without a token anyway...'
96
98
  end
97
99
  end
98
100
  Ssh.ssh(verbose, self, host_os, token_value)
99
101
  end
100
102
 
101
- def pretty_print_running(verbose, hostnames = [])
102
- if hostnames.empty?
103
- puts 'You have no running VMs.'
104
- else
105
- puts 'Running VMs:'
106
- @service_object.pretty_print_hosts(verbose, hostnames, url)
107
- end
108
- end
109
-
110
103
  def query(verbose, hostname)
111
104
  @service_object.query verbose, url, hostname
112
105
  end
113
106
 
114
107
  def modify(verbose, hostname, modify_hash)
108
+ maybe_use_vmpooler
115
109
  @service_object.modify verbose, url, hostname, token, modify_hash
116
110
  end
117
111
 
@@ -124,18 +118,35 @@ class Service
124
118
  end
125
119
 
126
120
  def summary(verbose)
121
+ maybe_use_vmpooler
127
122
  @service_object.summary verbose, url
128
123
  end
129
124
 
130
125
  def snapshot(verbose, hostname)
126
+ maybe_use_vmpooler
131
127
  @service_object.snapshot verbose, url, hostname, token
132
128
  end
133
129
 
134
130
  def revert(verbose, hostname, snapshot_sha)
131
+ maybe_use_vmpooler
135
132
  @service_object.revert verbose, url, hostname, token, snapshot_sha
136
133
  end
137
134
 
138
135
  def disk(verbose, hostname, disk)
136
+ maybe_use_vmpooler
139
137
  @service_object.disk(verbose, url, hostname, token, disk)
140
138
  end
139
+
140
+ # some methods do not exist for ABS, and if possible should target the Pooler service
141
+ def maybe_use_vmpooler
142
+ if @service_object == ABS # this is not an instance
143
+ if !self.silent
144
+ FloatyLogger.info "The service in use is ABS, but the requested method should run against vmpooler directly, using fallback_vmpooler config from ~/.vmfloaty.yml"
145
+ self.silent = true
146
+ end
147
+
148
+ @config = Utils.get_vmpooler_service_config(@config['vmpooler_fallback'])
149
+ @service_object = Pooler
150
+ end
151
+ end
141
152
  end
@@ -3,6 +3,7 @@
3
3
  require 'vmfloaty/abs'
4
4
  require 'vmfloaty/nonstandard_pooler'
5
5
  require 'vmfloaty/pooler'
6
+ require 'vmfloaty/conf'
6
7
 
7
8
  class Utils
8
9
  # TODO: Takes the json response body from an HTTP GET
@@ -45,7 +46,10 @@ class Utils
45
46
 
46
47
  result = {}
47
48
 
48
- STDOUT.puts "response body is #{response_body}"
49
+ # ABS has a job_id associated with hosts so pass that along
50
+ abs_job_id = response_body.delete('job_id')
51
+ result['job_id'] = abs_job_id unless abs_job_id.nil?
52
+
49
53
  filtered_response_body = response_body.reject { |key, _| key == 'request_id' || key == 'ready' }
50
54
  filtered_response_body.each do |os, value|
51
55
  hostnames = Array(value['hostname'])
@@ -58,7 +62,8 @@ class Utils
58
62
 
59
63
  def self.format_host_output(hosts)
60
64
  hosts.flat_map do |os, names|
61
- names.map { |name| "- #{name} (#{os})" }
65
+ # Assume hosts are stored in Arrays and ignore everything else
66
+ names.map { |name| "- #{name} (#{os})" } if names.is_a? Array
62
67
  end.join("\n")
63
68
  end
64
69
 
@@ -79,41 +84,96 @@ class Utils
79
84
  os_types
80
85
  end
81
86
 
82
- def self.pretty_print_hosts(verbose, service, hostnames = [])
87
+ def self.print_fqdn_for_host(service, hostname, host_data)
88
+ case service.type
89
+ when 'ABS'
90
+ abs_hostnames = []
91
+
92
+ host_data['allocated_resources'].each do |vm_name, _i|
93
+ abs_hostnames << vm_name['hostname']
94
+ end
95
+
96
+ puts abs_hostnames.join("\n")
97
+ when 'Pooler'
98
+ puts "#{hostname}.#{host_data['domain']}"
99
+ when 'NonstandardPooler'
100
+ puts host_data['fqdn']
101
+ else
102
+ raise "Invalid service type #{service.type}"
103
+ end
104
+ end
105
+
106
+ def self.pretty_print_hosts(verbose, service, hostnames = [], print_to_stderr = false, indent = 0)
107
+ output_target = print_to_stderr ? $stderr : $stdout
108
+
109
+ fetched_data = self.get_host_data(verbose, service, hostnames)
110
+ fetched_data.each do |hostname, host_data|
111
+ case service.type
112
+ when 'ABS'
113
+ # For ABS, 'hostname' variable is the jobID
114
+ #
115
+ # Create a vmpooler service to query each hostname there so as to get the metadata too
116
+
117
+ output_target.puts "- [JobID:#{host_data['request']['job']['id']}] <#{host_data['state']}>"
118
+ host_data['allocated_resources'].each do |allocated_resources, _i|
119
+ if (allocated_resources['engine'] == "vmpooler" || allocated_resources['engine'] == 'ondemand') && service.config["vmpooler_fallback"]
120
+ vmpooler_service = service.clone
121
+ vmpooler_service.silent = true
122
+ vmpooler_service.maybe_use_vmpooler
123
+ self.pretty_print_hosts(verbose, vmpooler_service, allocated_resources['hostname'].split('.')[0], print_to_stderr, indent+2)
124
+ else
125
+ #TODO we could add more specific metadata for the other services, nspooler and aws
126
+ output_target.puts " - #{allocated_resources['hostname']} (#{allocated_resources['type']})"
127
+ end
128
+ end
129
+ when 'Pooler'
130
+ tag_pairs = []
131
+ tag_pairs = host_data['tags'].map { |key, value| "#{key}: #{value}" } unless host_data['tags'].nil?
132
+ duration = "#{host_data['running']}/#{host_data['lifetime']} hours"
133
+ metadata = [host_data['template'], duration, *tag_pairs]
134
+ output_target.puts "- #{hostname}.#{host_data['domain']} (#{metadata.join(', ')})".gsub(/^/, ' ' * indent)
135
+ when 'NonstandardPooler'
136
+ line = "- #{host_data['fqdn']} (#{host_data['os_triple']}"
137
+ line += ", #{host_data['hours_left_on_reservation']}h remaining"
138
+ line += ", reason: #{host_data['reserved_for_reason']}" unless host_data['reserved_for_reason'].empty?
139
+ line += ')'
140
+ output_target.puts line
141
+ else
142
+ raise "Invalid service type #{service.type}"
143
+ end
144
+ end
145
+ end
146
+
147
+ def self.get_host_data(verbose, service, hostnames = [])
148
+ result = {}
83
149
  hostnames = [hostnames] unless hostnames.is_a? Array
84
150
  hostnames.each do |hostname|
85
151
  begin
86
152
  response = service.query(verbose, hostname)
87
153
  host_data = response[hostname]
88
-
89
- case service.type
90
- when 'ABS'
91
- # For ABS, 'hostname' variable is the jobID
92
- if host_data['state'] == 'allocated' || host_data['state'] == 'filled'
93
- host_data['allocated_resources'].each do |vm_name, _i|
94
- puts "- [JobID:#{host_data['request']['job']['id']}] #{vm_name['hostname']} (#{vm_name['type']}) <#{host_data['state']}>"
154
+ if block_given?
155
+ yield host_data result
156
+ else
157
+ case service.type
158
+ when 'ABS'
159
+ # For ABS, 'hostname' variable is the jobID
160
+ if host_data['state'] == 'allocated' || host_data['state'] == 'filled'
161
+ result[hostname] = host_data
95
162
  end
163
+ when 'Pooler'
164
+ result[hostname] = host_data
165
+ when 'NonstandardPooler'
166
+ result[hostname] = host_data
167
+ else
168
+ raise "Invalid service type #{service.type}"
96
169
  end
97
- when 'Pooler'
98
- tag_pairs = []
99
- tag_pairs = host_data['tags'].map { |key, value| "#{key}: #{value}" } unless host_data['tags'].nil?
100
- duration = "#{host_data['running']}/#{host_data['lifetime']} hours"
101
- metadata = [host_data['template'], duration, *tag_pairs]
102
- puts "- #{hostname}.#{host_data['domain']} (#{metadata.join(', ')})"
103
- when 'NonstandardPooler'
104
- line = "- #{host_data['fqdn']} (#{host_data['os_triple']}"
105
- line += ", #{host_data['hours_left_on_reservation']}h remaining"
106
- line += ", reason: #{host_data['reserved_for_reason']}" unless host_data['reserved_for_reason'].empty?
107
- line += ')'
108
- puts line
109
- else
110
- raise "Invalid service type #{service.type}"
111
170
  end
112
171
  rescue StandardError => e
113
- STDERR.puts("Something went wrong while trying to gather information on #{hostname}:")
114
- STDERR.puts(e)
172
+ FloatyLogger.error("Something went wrong while trying to gather information on #{hostname}:")
173
+ FloatyLogger.error(e)
115
174
  end
116
175
  end
176
+ result
117
177
  end
118
178
 
119
179
  def self.pretty_print_status(verbose, service)
@@ -135,7 +195,7 @@ class Utils
135
195
  char = 'o'
136
196
  puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}"
137
197
  rescue StandardError => e
138
- puts "#{name.ljust(width)} #{e.red}"
198
+ FloatyLogger.error "#{name.ljust(width)} #{e.red}"
139
199
  end
140
200
  end
141
201
  puts message.colorize(status_response['status']['ok'] ? :default : :red)
@@ -154,11 +214,11 @@ class Utils
154
214
  char = 'o'
155
215
  puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}"
156
216
  rescue StandardError => e
157
- puts "#{name.ljust(width)} #{e.red}"
217
+ FloatyLogger.error "#{name.ljust(width)} #{e.red}"
158
218
  end
159
219
  end
160
220
  when 'ABS'
161
- puts 'ABS Not OK'.red unless status_response
221
+ FloatyLogger.error 'ABS Not OK' unless status_response
162
222
  puts 'ABS is OK'.green if status_response
163
223
  else
164
224
  raise "Invalid service type #{service.type}"
@@ -174,12 +234,15 @@ class Utils
174
234
  end
175
235
 
176
236
  def self.get_service_object(type = '')
177
- nspooler_strings = %w[ns nspooler nonstandard nonstandard_pooler]
178
237
  abs_strings = %w[abs alwaysbescheduling always_be_scheduling]
179
- if nspooler_strings.include? type.downcase
180
- NonstandardPooler
181
- elsif abs_strings.include? type.downcase
238
+ nspooler_strings = %w[ns nspooler nonstandard nonstandard_pooler]
239
+ vmpooler_strings = %w[vmpooler]
240
+ if abs_strings.include? type.downcase
182
241
  ABS
242
+ elsif nspooler_strings.include? type.downcase
243
+ NonstandardPooler
244
+ elsif vmpooler_strings.include? type.downcase
245
+ Pooler
183
246
  else
184
247
  Pooler
185
248
  end
@@ -191,6 +254,7 @@ class Utils
191
254
  'url' => config['url'],
192
255
  'user' => config['user'],
193
256
  'token' => config['token'],
257
+ 'vmpooler_fallback' => config['vmpooler_fallback'],
194
258
  'type' => config['type'] || 'vmpooler',
195
259
  }
196
260
 
@@ -207,6 +271,9 @@ class Utils
207
271
  # If the service is configured but some values are missing, use the top-level defaults to fill them in
208
272
  service_config.merge! config['services'][options.service]
209
273
  end
274
+ # No config file but service is declared on command line
275
+ elsif !config['services'] && options.service
276
+ service_config['type'] = options.service
210
277
  end
211
278
 
212
279
  # Prioritize an explicitly specified url, user, or token if the user provided one
@@ -217,4 +284,30 @@ class Utils
217
284
 
218
285
  service_config
219
286
  end
287
+
288
+ # This method gets the vmpooler service configured in ~/.vmfloaty
289
+ def self.get_vmpooler_service_config(vmpooler_fallback)
290
+ config = Conf.read_config
291
+ # The top-level url, user, and token values in the config file are treated as defaults
292
+ service_config = {
293
+ 'url' => config['url'],
294
+ 'user' => config['user'],
295
+ 'token' => config['token'],
296
+ 'type' => 'vmpooler',
297
+ }
298
+
299
+ # at a minimum, the url needs to be configured
300
+ if config['services'] && config['services'][vmpooler_fallback] && config['services'][vmpooler_fallback]['url']
301
+ # If the service is configured but some values are missing, use the top-level defaults to fill them in
302
+ service_config.merge! config['services'][vmpooler_fallback]
303
+ else
304
+ if vmpooler_fallback.nil?
305
+ raise ArgumentError, "The abs service should have a key named 'vmpooler_fallback' in ~/.vmfloaty.yml with a value that points to a vmpooler service name use this format:\nservices:\n myabs:\n url: 'http://abs.com'\n user: 'superman'\n token: 'kryptonite'\n vmpooler_fallback: 'myvmpooler'\n myvmpooler:\n url: 'http://vmpooler.com'\n user: 'superman'\n token: 'kryptonite'"
306
+ else
307
+ raise ArgumentError, "Could not find a configured service named '#{vmpooler_fallback}' in ~/.vmfloaty.yml use this format:\nservices:\n #{vmpooler_fallback}:\n url: 'http://vmpooler.com'\n user: 'superman'\n token: 'kryptonite'"
308
+ end
309
+ end
310
+
311
+ service_config
312
+ end
220
313
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Vmfloaty
4
- VERSION = '0.10.0'
4
+ VERSION = '1.2.0'
5
5
  end
6
+
@@ -9,15 +9,60 @@ describe ABS do
9
9
  before :each do
10
10
  end
11
11
 
12
+ describe '#list' do
13
+ it 'skips empty platforms and lists aws' do
14
+ stub_request(:get, "http://foo/api/v2/status/platforms/vmpooler").
15
+ to_return(:status => 200, :body => "", :headers => {})
16
+ stub_request(:get, "http://foo/api/v2/status/platforms/ondemand_vmpooler").
17
+ to_return(:status => 200, :body => "", :headers => {})
18
+ stub_request(:get, "http://foo/api/v2/status/platforms/nspooler").
19
+ to_return(:status => 200, :body => "", :headers => {})
20
+ body = '{
21
+ "aws_platforms": [
22
+ "amazon-6-x86_64",
23
+ "amazon-7-x86_64",
24
+ "amazon-7-arm64",
25
+ "centos-7-x86-64-west",
26
+ "redhat-8-arm64"
27
+ ]
28
+ }'
29
+ stub_request(:get, "http://foo/api/v2/status/platforms/aws").
30
+ to_return(:status => 200, :body => body, :headers => {})
31
+
32
+
33
+ results = ABS.list(false, "http://foo")
34
+
35
+ expect(results).to include("amazon-6-x86_64", "amazon-7-x86_64", "amazon-7-arm64", "centos-7-x86-64-west", "redhat-8-arm64")
36
+ end
37
+ it 'legacy JSON string, prior to PR 306' do
38
+ stub_request(:get, "http://foo/api/v2/status/platforms/vmpooler").
39
+ to_return(:status => 200, :body => "", :headers => {})
40
+ stub_request(:get, "http://foo/api/v2/status/platforms/ondemand_vmpooler").
41
+ to_return(:status => 200, :body => "", :headers => {})
42
+ stub_request(:get, "http://foo/api/v2/status/platforms/nspooler").
43
+ to_return(:status => 200, :body => "", :headers => {})
44
+ body = '{
45
+ "aws_platforms": "[\"amazon-6-x86_64\",\"amazon-7-x86_64\",\"amazon-7-arm64\",\"centos-7-x86-64-west\",\"redhat-8-arm64\"]"
46
+ }'
47
+ stub_request(:get, "http://foo/api/v2/status/platforms/aws").
48
+ to_return(:status => 200, :body => body, :headers => {})
49
+
50
+ results = ABS.list(false, "http://foo")
51
+
52
+ expect(results).to include("amazon-6-x86_64", "amazon-7-x86_64", "amazon-7-arm64", "centos-7-x86-64-west", "redhat-8-arm64")
53
+ end
54
+ end
55
+
12
56
  describe '#format' do
13
- it 'returns an hash formatted like a vmpooler return' do
57
+ it 'returns an hash formatted like a vmpooler return, plus the job_id' do
58
+ job_id = "generated_by_floaty_12345"
14
59
  abs_formatted_response = [
15
60
  { 'hostname' => 'aaaaaaaaaaaaaaa.delivery.puppetlabs.net', 'type' => 'centos-7.2-x86_64', 'engine' => 'vmpooler' },
16
61
  { 'hostname' => 'aaaaaaaaaaaaaab.delivery.puppetlabs.net', 'type' => 'centos-7.2-x86_64', 'engine' => 'vmpooler' },
17
62
  { 'hostname' => 'aaaaaaaaaaaaaac.delivery.puppetlabs.net', 'type' => 'ubuntu-7.2-x86_64', 'engine' => 'vmpooler' },
18
63
  ]
19
64
 
20
- vmpooler_formatted_response = ABS.translated(abs_formatted_response)
65
+ vmpooler_formatted_response = ABS.translated(abs_formatted_response, job_id)
21
66
 
22
67
  vmpooler_formatted_compare = {
23
68
  'centos-7.2-x86_64' => {},
@@ -29,6 +74,8 @@ describe ABS do
29
74
 
30
75
  vmpooler_formatted_compare['ok'] = true
31
76
 
77
+ vmpooler_formatted_compare['job_id'] = job_id
78
+
32
79
  expect(vmpooler_formatted_response).to eq(vmpooler_formatted_compare)
33
80
  vmpooler_formatted_response.delete('ok')
34
81
  vmpooler_formatted_compare.delete('ok')
@@ -68,9 +115,9 @@ describe ABS do
68
115
  # rubocop:disable Layout/LineLength
69
116
  @active_requests_response = '
70
117
  [
71
- "{ \"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}}",
118
+ { "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}},
72
119
  "null",
73
- "{\"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}}"
120
+ {"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}}
74
121
  ]'
75
122
  # rubocop:enable Layout/LineLength
76
123
  @token = 'utpg2i2xswor6h8ttjhu3d47z53yy47y'
@@ -78,7 +125,7 @@ describe ABS do
78
125
  end
79
126
 
80
127
  it 'will skip a line with a null value returned from abs' do
81
- stub_request(:get, 'https://abs.example.com/status/queue')
128
+ stub_request(:get, 'https://abs.example.com/api/v2/status/queue')
82
129
  .to_return(:status => 200, :body => @active_requests_response, :headers => {})
83
130
 
84
131
  ret = ABS.get_active_requests(false, @abs_url, @test_user)
@@ -98,7 +145,7 @@ describe ABS do
98
145
  # rubocop:disable Layout/LineLength
99
146
  @active_requests_response = '
100
147
  [
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}}"
148
+ { "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
149
  ]'
103
150
  @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
151
  # rubocop:enable Layout/LineLength
@@ -109,9 +156,9 @@ describe ABS do
109
156
  end
110
157
 
111
158
  it 'will delete the whole job' do
112
- stub_request(:get, 'https://abs.example.com/status/queue')
159
+ stub_request(:get, 'https://abs.example.com/api/v2/status/queue')
113
160
  .to_return(:status => 200, :body => @active_requests_response, :headers => {})
114
- stub_request(:post, 'https://abs.example.com/return')
161
+ stub_request(:post, 'https://abs.example.com/api/v2/return')
115
162
  .with(:body => @return_request)
116
163
  .to_return(:status => 200, :body => 'OK', :headers => {})
117
164