vmfloaty 1.3.0 → 1.4.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.
- checksums.yaml +4 -4
- data/lib/vmfloaty.rb +50 -56
- data/lib/vmfloaty/abs.rb +50 -51
- data/lib/vmfloaty/http.rb +2 -6
- data/lib/vmfloaty/logger.rb +13 -10
- data/lib/vmfloaty/nonstandard_pooler.rb +3 -2
- data/lib/vmfloaty/pooler.rb +19 -24
- data/lib/vmfloaty/service.rb +3 -3
- data/lib/vmfloaty/utils.rb +60 -61
- data/lib/vmfloaty/version.rb +1 -2
- data/spec/spec_helper.rb +20 -3
- data/spec/vmfloaty/abs/auth_spec.rb +26 -17
- data/spec/vmfloaty/abs_spec.rb +52 -43
- data/spec/vmfloaty/auth_spec.rb +23 -13
- data/spec/vmfloaty/nonstandard_pooler_spec.rb +32 -31
- data/spec/vmfloaty/pooler_spec.rb +29 -26
- data/spec/vmfloaty/service_spec.rb +10 -10
- data/spec/vmfloaty/ssh_spec.rb +3 -3
- data/spec/vmfloaty/utils_spec.rb +170 -164
- metadata +13 -7
data/lib/vmfloaty/logger.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'logger'
|
2
4
|
|
3
5
|
class FloatyLogger < ::Logger
|
@@ -19,22 +21,23 @@ class FloatyLogger < ::Logger
|
|
19
21
|
|
20
22
|
def self.setlevel=(level)
|
21
23
|
level = level.downcase
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
case level
|
25
|
+
when 'debug'
|
26
|
+
logger.level = ::Logger::DEBUG
|
27
|
+
when 'info'
|
28
|
+
logger.level = ::Logger::INFO
|
29
|
+
when 'error'
|
30
|
+
logger.level = ::Logger::ERROR
|
28
31
|
else
|
29
|
-
error(
|
32
|
+
error('set loglevel to debug, info or error')
|
30
33
|
end
|
31
34
|
end
|
32
35
|
|
33
36
|
def initialize
|
34
|
-
super(
|
37
|
+
super($stderr)
|
35
38
|
self.level = ::Logger::INFO
|
36
|
-
self.formatter = proc do |
|
37
|
-
|
39
|
+
self.formatter = proc do |_severity, _datetime, _progname, msg|
|
40
|
+
"#{msg}\n"
|
38
41
|
end
|
39
42
|
end
|
40
43
|
end
|
@@ -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
|
|
@@ -46,7 +46,8 @@ class NonstandardPooler
|
|
46
46
|
raise TokenError, 'Token provided was nil; Request cannot be made to modify VM' if token.nil?
|
47
47
|
|
48
48
|
modify_hash.each do |key, _value|
|
49
|
-
raise ModifyError, "Configured service type does not support modification of #{key}" unless %i[reason
|
49
|
+
raise ModifyError, "Configured service type does not support modification of #{key}" unless %i[reason
|
50
|
+
reserved_for_reason].include? key
|
50
51
|
end
|
51
52
|
|
52
53
|
if modify_hash[:reason]
|
data/lib/vmfloaty/pooler.rb
CHANGED
@@ -12,13 +12,11 @@ class Pooler
|
|
12
12
|
response = conn.get 'vm'
|
13
13
|
response_body = JSON.parse(response.body)
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
hosts
|
15
|
+
if os_filter
|
16
|
+
response_body.select { |i| i[/#{os_filter}/] }
|
17
|
+
else
|
18
|
+
response_body
|
19
|
+
end
|
22
20
|
end
|
23
21
|
|
24
22
|
def self.list_active(verbose, url, token, _user)
|
@@ -50,7 +48,10 @@ class Pooler
|
|
50
48
|
elsif response.status == 403
|
51
49
|
raise "HTTP #{response.status}: Failed to obtain VMs from the pooler at #{url}/vm/#{os_string}. Request exceeds the configured per pool maximum. #{res_body}"
|
52
50
|
else
|
53
|
-
|
51
|
+
unless ondemand
|
52
|
+
raise "HTTP #{response.status}: Failed to obtain VMs from the pooler at #{url}/vm/#{os_string}. #{res_body}"
|
53
|
+
end
|
54
|
+
|
54
55
|
raise "HTTP #{response.status}: Failed to obtain VMs from the pooler at #{url}/ondemandvm/#{os_string}. #{res_body}"
|
55
56
|
end
|
56
57
|
end
|
@@ -63,7 +64,7 @@ class Pooler
|
|
63
64
|
FloatyLogger.info "waiting for request #{request_id} to be fulfilled"
|
64
65
|
sleep 5
|
65
66
|
end
|
66
|
-
FloatyLogger.info
|
67
|
+
FloatyLogger.info 'The request has been fulfilled'
|
67
68
|
check_ondemandvm(verbose, request_id, url)
|
68
69
|
end
|
69
70
|
|
@@ -84,8 +85,9 @@ class Pooler
|
|
84
85
|
def self.modify(verbose, url, hostname, token, modify_hash)
|
85
86
|
raise TokenError, 'Token provided was nil. Request cannot be made to modify vm' if token.nil?
|
86
87
|
|
87
|
-
modify_hash.
|
88
|
-
raise ModifyError, "Configured service type does not support modification of #{key}." unless %i[tags lifetime
|
88
|
+
modify_hash.each_key do |key|
|
89
|
+
raise ModifyError, "Configured service type does not support modification of #{key}." unless %i[tags lifetime
|
90
|
+
disk].include? key
|
89
91
|
end
|
90
92
|
|
91
93
|
conn = Http.get_conn(verbose, url)
|
@@ -120,8 +122,7 @@ class Pooler
|
|
120
122
|
|
121
123
|
response = conn.post "vm/#{hostname}/disk/#{disk}"
|
122
124
|
|
123
|
-
|
124
|
-
res_body
|
125
|
+
JSON.parse(response.body)
|
125
126
|
end
|
126
127
|
|
127
128
|
def self.delete(verbose, url, hosts, token, _user)
|
@@ -146,25 +147,21 @@ class Pooler
|
|
146
147
|
conn = Http.get_conn(verbose, url)
|
147
148
|
|
148
149
|
response = conn.get '/status'
|
149
|
-
|
150
|
-
res_body
|
150
|
+
JSON.parse(response.body)
|
151
151
|
end
|
152
152
|
|
153
153
|
def self.summary(verbose, url)
|
154
154
|
conn = Http.get_conn(verbose, url)
|
155
155
|
|
156
156
|
response = conn.get '/summary'
|
157
|
-
|
158
|
-
res_body
|
157
|
+
JSON.parse(response.body)
|
159
158
|
end
|
160
159
|
|
161
160
|
def self.query(verbose, url, hostname)
|
162
161
|
conn = Http.get_conn(verbose, url)
|
163
162
|
|
164
163
|
response = conn.get "vm/#{hostname}"
|
165
|
-
|
166
|
-
|
167
|
-
res_body
|
164
|
+
JSON.parse(response.body)
|
168
165
|
end
|
169
166
|
|
170
167
|
def self.snapshot(verbose, url, hostname, token)
|
@@ -174,8 +171,7 @@ class Pooler
|
|
174
171
|
conn.headers['X-AUTH-TOKEN'] = token
|
175
172
|
|
176
173
|
response = conn.post "vm/#{hostname}/snapshot"
|
177
|
-
|
178
|
-
res_body
|
174
|
+
JSON.parse(response.body)
|
179
175
|
end
|
180
176
|
|
181
177
|
def self.revert(verbose, url, hostname, token, snapshot_sha)
|
@@ -187,7 +183,6 @@ class Pooler
|
|
187
183
|
raise "Snapshot SHA provided was nil, could not revert #{hostname}" if snapshot_sha.nil?
|
188
184
|
|
189
185
|
response = conn.post "vm/#{hostname}/snapshot/#{snapshot_sha}"
|
190
|
-
|
191
|
-
res_body
|
186
|
+
JSON.parse(response.body)
|
192
187
|
end
|
193
188
|
end
|
data/lib/vmfloaty/service.rb
CHANGED
@@ -39,7 +39,7 @@ class Service
|
|
39
39
|
def user
|
40
40
|
unless @config['user']
|
41
41
|
FloatyLogger.info "Enter your #{@config['url']} service username:"
|
42
|
-
@config['user'] =
|
42
|
+
@config['user'] = $stdin.gets.chomp
|
43
43
|
end
|
44
44
|
@config['user']
|
45
45
|
end
|
@@ -140,8 +140,8 @@ class Service
|
|
140
140
|
# some methods do not exist for ABS, and if possible should target the Pooler service
|
141
141
|
def maybe_use_vmpooler
|
142
142
|
if @service_object == ABS # this is not an instance
|
143
|
-
|
144
|
-
FloatyLogger.info
|
143
|
+
unless 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
145
|
self.silent = true
|
146
146
|
end
|
147
147
|
|
data/lib/vmfloaty/utils.rb
CHANGED
@@ -39,7 +39,10 @@ class Utils
|
|
39
39
|
# "engine"=>"vmpooler"
|
40
40
|
# }
|
41
41
|
|
42
|
-
|
42
|
+
unless response_body.delete('ok')
|
43
|
+
raise ArgumentError,
|
44
|
+
"Bad GET response passed to format_hosts: #{response_body.to_json}"
|
45
|
+
end
|
43
46
|
|
44
47
|
# vmpooler reports the domain separately from the hostname
|
45
48
|
domain = response_body.delete('domain')
|
@@ -50,7 +53,7 @@ class Utils
|
|
50
53
|
abs_job_id = response_body.delete('job_id')
|
51
54
|
result['job_id'] = abs_job_id unless abs_job_id.nil?
|
52
55
|
|
53
|
-
filtered_response_body = response_body.reject { |key, _|
|
56
|
+
filtered_response_body = response_body.reject { |key, _| %w[request_id ready].include?(key) }
|
54
57
|
filtered_response_body.each do |os, value|
|
55
58
|
hostnames = Array(value['hostname'])
|
56
59
|
hostnames.map! { |host| "#{host}.#{domain}" } if domain
|
@@ -106,7 +109,7 @@ class Utils
|
|
106
109
|
def self.pretty_print_hosts(verbose, service, hostnames = [], print_to_stderr = false, indent = 0)
|
107
110
|
output_target = print_to_stderr ? $stderr : $stdout
|
108
111
|
|
109
|
-
fetched_data =
|
112
|
+
fetched_data = get_host_data(verbose, service, hostnames)
|
110
113
|
fetched_data.each do |hostname, host_data|
|
111
114
|
case service.type
|
112
115
|
when 'ABS'
|
@@ -116,13 +119,14 @@ class Utils
|
|
116
119
|
|
117
120
|
output_target.puts "- [JobID:#{host_data['request']['job']['id']}] <#{host_data['state']}>"
|
118
121
|
host_data['allocated_resources'].each do |allocated_resources, _i|
|
119
|
-
if (allocated_resources['engine'] ==
|
122
|
+
if (allocated_resources['engine'] == 'vmpooler' || allocated_resources['engine'] == 'ondemand') && service.config['vmpooler_fallback']
|
120
123
|
vmpooler_service = service.clone
|
121
124
|
vmpooler_service.silent = true
|
122
125
|
vmpooler_service.maybe_use_vmpooler
|
123
|
-
|
126
|
+
pretty_print_hosts(verbose, vmpooler_service, allocated_resources['hostname'].split('.')[0],
|
127
|
+
print_to_stderr, indent + 2)
|
124
128
|
else
|
125
|
-
#TODO we could add more specific metadata for the other services, nspooler and aws
|
129
|
+
# TODO: we could add more specific metadata for the other services, nspooler and aws
|
126
130
|
output_target.puts " - #{allocated_resources['hostname']} (#{allocated_resources['type']})"
|
127
131
|
end
|
128
132
|
end
|
@@ -132,7 +136,7 @@ class Utils
|
|
132
136
|
duration = "#{host_data['running']}/#{host_data['lifetime']} hours"
|
133
137
|
metadata = [host_data['state'], host_data['template'], duration, *tag_pairs]
|
134
138
|
message = "- #{hostname}.#{host_data['domain']} (#{metadata.join(', ')})".gsub(/^/, ' ' * indent)
|
135
|
-
if host_data['state'] && host_data['state'] ==
|
139
|
+
if host_data['state'] && host_data['state'] == 'destroyed'
|
136
140
|
output_target.puts message.colorize(:red)
|
137
141
|
else
|
138
142
|
output_target.puts message
|
@@ -153,30 +157,26 @@ class Utils
|
|
153
157
|
result = {}
|
154
158
|
hostnames = [hostnames] unless hostnames.is_a? Array
|
155
159
|
hostnames.each do |hostname|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
160
|
+
response = service.query(verbose, hostname)
|
161
|
+
host_data = response[hostname]
|
162
|
+
if block_given?
|
163
|
+
yield host_data result
|
164
|
+
else
|
165
|
+
case service.type
|
166
|
+
when 'ABS'
|
167
|
+
# For ABS, 'hostname' variable is the jobID
|
168
|
+
result[hostname] = host_data if host_data['state'] == 'allocated' || host_data['state'] == 'filled'
|
169
|
+
when 'Pooler'
|
170
|
+
result[hostname] = host_data
|
171
|
+
when 'NonstandardPooler'
|
172
|
+
result[hostname] = host_data
|
161
173
|
else
|
162
|
-
|
163
|
-
when 'ABS'
|
164
|
-
# For ABS, 'hostname' variable is the jobID
|
165
|
-
if host_data['state'] == 'allocated' || host_data['state'] == 'filled'
|
166
|
-
result[hostname] = host_data
|
167
|
-
end
|
168
|
-
when 'Pooler'
|
169
|
-
result[hostname] = host_data
|
170
|
-
when 'NonstandardPooler'
|
171
|
-
result[hostname] = host_data
|
172
|
-
else
|
173
|
-
raise "Invalid service type #{service.type}"
|
174
|
-
end
|
174
|
+
raise "Invalid service type #{service.type}"
|
175
175
|
end
|
176
|
-
rescue StandardError => e
|
177
|
-
FloatyLogger.error("Something went wrong while trying to gather information on #{hostname}:")
|
178
|
-
FloatyLogger.error(e)
|
179
176
|
end
|
177
|
+
rescue StandardError => e
|
178
|
+
FloatyLogger.error("Something went wrong while trying to gather information on #{hostname}:")
|
179
|
+
FloatyLogger.error(e)
|
180
180
|
end
|
181
181
|
result
|
182
182
|
end
|
@@ -192,16 +192,14 @@ class Utils
|
|
192
192
|
|
193
193
|
width = pools.keys.map(&:length).max
|
194
194
|
pools.each do |name, pool|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
FloatyLogger.error "#{name.ljust(width)} #{e.red}"
|
204
|
-
end
|
195
|
+
max = pool['max']
|
196
|
+
ready = pool['ready']
|
197
|
+
pending = pool['pending']
|
198
|
+
missing = max - ready - pending
|
199
|
+
char = 'o'
|
200
|
+
puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}"
|
201
|
+
rescue StandardError => e
|
202
|
+
FloatyLogger.error "#{name.ljust(width)} #{e.red}"
|
205
203
|
end
|
206
204
|
puts message.colorize(status_response['status']['ok'] ? :default : :red)
|
207
205
|
when 'NonstandardPooler'
|
@@ -211,16 +209,14 @@ class Utils
|
|
211
209
|
|
212
210
|
width = pools.keys.map(&:length).max
|
213
211
|
pools.each do |name, pool|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
FloatyLogger.error "#{name.ljust(width)} #{e.red}"
|
223
|
-
end
|
212
|
+
max = pool['total_hosts']
|
213
|
+
ready = pool['available_hosts']
|
214
|
+
pending = pool['pending'] || 0 # not available for nspooler
|
215
|
+
missing = max - ready - pending
|
216
|
+
char = 'o'
|
217
|
+
puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}"
|
218
|
+
rescue StandardError => e
|
219
|
+
FloatyLogger.error "#{name.ljust(width)} #{e.red}"
|
224
220
|
end
|
225
221
|
when 'ABS'
|
226
222
|
FloatyLogger.error 'ABS Not OK' unless status_response
|
@@ -256,11 +252,11 @@ class Utils
|
|
256
252
|
def self.get_service_config(config, options)
|
257
253
|
# The top-level url, user, and token values in the config file are treated as defaults
|
258
254
|
service_config = {
|
259
|
-
'url'
|
260
|
-
'user'
|
255
|
+
'url' => config['url'],
|
256
|
+
'user' => config['user'],
|
261
257
|
'token' => config['token'],
|
262
258
|
'vmpooler_fallback' => config['vmpooler_fallback'],
|
263
|
-
'type'
|
259
|
+
'type' => config['type'] || 'vmpooler'
|
264
260
|
}
|
265
261
|
|
266
262
|
if config['services']
|
@@ -271,7 +267,10 @@ class Utils
|
|
271
267
|
service_config.merge! values
|
272
268
|
else
|
273
269
|
# If the user provided a service name at the command line, use that service if posible, or fail
|
274
|
-
|
270
|
+
unless config['services'][options.service]
|
271
|
+
raise ArgumentError,
|
272
|
+
"Could not find a configured service named '#{options.service}' in ~/.vmfloaty.yml"
|
273
|
+
end
|
275
274
|
|
276
275
|
# If the service is configured but some values are missing, use the top-level defaults to fill them in
|
277
276
|
service_config.merge! config['services'][options.service]
|
@@ -295,22 +294,22 @@ class Utils
|
|
295
294
|
config = Conf.read_config
|
296
295
|
# The top-level url, user, and token values in the config file are treated as defaults
|
297
296
|
service_config = {
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
297
|
+
'url' => config['url'],
|
298
|
+
'user' => config['user'],
|
299
|
+
'token' => config['token'],
|
300
|
+
'type' => 'vmpooler'
|
302
301
|
}
|
303
302
|
|
304
303
|
# at a minimum, the url needs to be configured
|
305
304
|
if config['services'] && config['services'][vmpooler_fallback] && config['services'][vmpooler_fallback]['url']
|
306
305
|
# If the service is configured but some values are missing, use the top-level defaults to fill them in
|
307
306
|
service_config.merge! config['services'][vmpooler_fallback]
|
307
|
+
elsif vmpooler_fallback.nil?
|
308
|
+
raise ArgumentError,
|
309
|
+
"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'"
|
308
310
|
else
|
309
|
-
|
310
|
-
|
311
|
-
else
|
312
|
-
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'"
|
313
|
-
end
|
311
|
+
raise ArgumentError,
|
312
|
+
"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'"
|
314
313
|
end
|
315
314
|
|
316
315
|
service_config
|
data/lib/vmfloaty/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -2,11 +2,12 @@
|
|
2
2
|
|
3
3
|
require 'simplecov'
|
4
4
|
require 'coveralls'
|
5
|
+
require 'base64'
|
5
6
|
|
6
7
|
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
7
|
-
|
8
|
-
|
9
|
-
])
|
8
|
+
SimpleCov::Formatter::HTMLFormatter,
|
9
|
+
Coveralls::SimpleCov::Formatter
|
10
|
+
])
|
10
11
|
SimpleCov.start do
|
11
12
|
add_filter %r{^/spec/}
|
12
13
|
end
|
@@ -26,3 +27,19 @@ RSpec.configure do |config|
|
|
26
27
|
config.tty = true
|
27
28
|
config.formatter = :documentation
|
28
29
|
end
|
30
|
+
|
31
|
+
def get_headers(username: nil, password: nil, token: nil, content_type: nil, content_length: nil)
|
32
|
+
headers = {
|
33
|
+
'Accept' => '*/*',
|
34
|
+
'Accept-Encoding' => /gzip/,
|
35
|
+
'User-Agent' => /Faraday/,
|
36
|
+
}
|
37
|
+
if username && password
|
38
|
+
auth = Base64.encode64("#{username}:#{password}").chomp
|
39
|
+
headers['Authorization'] = "Basic #{auth}"
|
40
|
+
end
|
41
|
+
headers['X-Auth-Token'] = token if token
|
42
|
+
headers['Content-Type'] = content_type if content_type
|
43
|
+
headers['Content-Length'] = content_length.to_s if content_length
|
44
|
+
headers
|
45
|
+
end
|
@@ -3,7 +3,11 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
require_relative '../../../lib/vmfloaty/auth'
|
5
5
|
|
6
|
+
user = 'first.last'
|
7
|
+
pass = 'password'
|
8
|
+
|
6
9
|
describe Pooler do
|
10
|
+
|
7
11
|
before :each do
|
8
12
|
@abs_url = 'https://abs.example.com/api/v2'
|
9
13
|
end
|
@@ -15,18 +19,20 @@ describe Pooler do
|
|
15
19
|
end
|
16
20
|
|
17
21
|
it 'returns a token from abs' do
|
18
|
-
stub_request(:post, 'https://
|
19
|
-
.
|
22
|
+
stub_request(:post, 'https://abs.example.com/api/v2/token')
|
23
|
+
.with(headers: get_headers(username: user, password: pass, content_length: 0))
|
24
|
+
.to_return(status: 200, body: @get_token_response, headers: {})
|
20
25
|
|
21
|
-
token = Auth.get_token(false, @abs_url,
|
26
|
+
token = Auth.get_token(false, @abs_url, user, pass)
|
22
27
|
expect(token).to eq @token
|
23
28
|
end
|
24
29
|
|
25
30
|
it 'raises a token error if something goes wrong' do
|
26
|
-
stub_request(:post, 'https://
|
27
|
-
.
|
31
|
+
stub_request(:post, 'https://abs.example.com/api/v2/token')
|
32
|
+
.with(headers: get_headers(username: user, password: pass, content_length: 0))
|
33
|
+
.to_return(status: 500, body: '{"ok":false}', headers: {})
|
28
34
|
|
29
|
-
expect { Auth.get_token(false, @abs_url,
|
35
|
+
expect { Auth.get_token(false, @abs_url, user, pass) }.to raise_error(TokenError)
|
30
36
|
end
|
31
37
|
end
|
32
38
|
|
@@ -37,21 +43,24 @@ describe Pooler do
|
|
37
43
|
end
|
38
44
|
|
39
45
|
it 'deletes the specified token' do
|
40
|
-
stub_request(:delete, 'https://
|
41
|
-
.
|
46
|
+
stub_request(:delete, 'https://abs.example.com/api/v2/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
|
47
|
+
.with(headers: get_headers(username: user, password: pass))
|
48
|
+
.to_return(status: 200, body: @delete_token_response, headers: {})
|
42
49
|
|
43
|
-
expect(Auth.delete_token(false, @abs_url,
|
50
|
+
expect(Auth.delete_token(false, @abs_url, user, pass,
|
51
|
+
@token)).to eq JSON.parse(@delete_token_response)
|
44
52
|
end
|
45
53
|
|
46
54
|
it 'raises a token error if something goes wrong' do
|
47
|
-
stub_request(:delete, 'https://
|
48
|
-
.
|
55
|
+
stub_request(:delete, 'https://abs.example.com/api/v2/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
|
56
|
+
.with(headers: get_headers(username: user, password: pass))
|
57
|
+
.to_return(status: 500, body: '{"ok":false}', headers: {})
|
49
58
|
|
50
|
-
expect { Auth.delete_token(false, @abs_url,
|
59
|
+
expect { Auth.delete_token(false, @abs_url, user, pass, @token) }.to raise_error(TokenError)
|
51
60
|
end
|
52
61
|
|
53
62
|
it 'raises a token error if no token provided' do
|
54
|
-
expect { Auth.delete_token(false, @abs_url,
|
63
|
+
expect { Auth.delete_token(false, @abs_url, user, pass, nil) }.to raise_error(TokenError)
|
55
64
|
end
|
56
65
|
end
|
57
66
|
|
@@ -63,16 +72,16 @@ describe Pooler do
|
|
63
72
|
|
64
73
|
it 'checks the status of a token' do
|
65
74
|
stub_request(:get, "#{@abs_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
|
66
|
-
.with(:
|
67
|
-
.to_return(:
|
75
|
+
.with(headers: get_headers)
|
76
|
+
.to_return(status: 200, body: @token_status_response, headers: {})
|
68
77
|
|
69
78
|
expect(Auth.token_status(false, @abs_url, @token)).to eq JSON.parse(@token_status_response)
|
70
79
|
end
|
71
80
|
|
72
81
|
it 'raises a token error if something goes wrong' do
|
73
82
|
stub_request(:get, "#{@abs_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
|
74
|
-
.with(:
|
75
|
-
.to_return(:
|
83
|
+
.with(headers: get_headers)
|
84
|
+
.to_return(status: 500, body: '{"ok":false}', headers: {})
|
76
85
|
|
77
86
|
expect { Auth.token_status(false, @abs_url, @token) }.to raise_error(TokenError)
|
78
87
|
end
|