vmfloaty 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,12 +11,12 @@ describe ABS do
11
11
 
12
12
  describe '#list' do
13
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 => {})
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
20
  body = '{
21
21
  "aws_platforms": [
22
22
  "amazon-6-x86_64",
@@ -26,50 +26,55 @@ describe ABS do
26
26
  "redhat-8-arm64"
27
27
  ]
28
28
  }'
29
- stub_request(:get, "http://foo/api/v2/status/platforms/aws").
30
- to_return(:status => 200, :body => body, :headers => {})
29
+ stub_request(:get, 'http://foo/api/v2/status/platforms/aws')
30
+ .to_return(status: 200, body: body, headers: {})
31
31
 
32
+ results = ABS.list(false, 'http://foo')
32
33
 
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")
34
+ expect(results).to include('amazon-6-x86_64', 'amazon-7-x86_64', 'amazon-7-arm64', 'centos-7-x86-64-west',
35
+ 'redhat-8-arm64')
36
36
  end
37
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 => {})
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
44
  body = '{
45
45
  "aws_platforms": "[\"amazon-6-x86_64\",\"amazon-7-x86_64\",\"amazon-7-arm64\",\"centos-7-x86-64-west\",\"redhat-8-arm64\"]"
46
46
  }'
47
- stub_request(:get, "http://foo/api/v2/status/platforms/aws").
48
- to_return(:status => 200, :body => body, :headers => {})
47
+ stub_request(:get, 'http://foo/api/v2/status/platforms/aws')
48
+ .to_return(status: 200, body: body, headers: {})
49
49
 
50
- results = ABS.list(false, "http://foo")
50
+ results = ABS.list(false, 'http://foo')
51
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")
52
+ expect(results).to include('amazon-6-x86_64', 'amazon-7-x86_64', 'amazon-7-arm64', 'centos-7-x86-64-west',
53
+ 'redhat-8-arm64')
53
54
  end
54
55
  end
55
56
 
56
57
  describe '#format' do
57
58
  it 'returns an hash formatted like a vmpooler return, plus the job_id' do
58
- job_id = "generated_by_floaty_12345"
59
+ job_id = 'generated_by_floaty_12345'
59
60
  abs_formatted_response = [
60
- { 'hostname' => 'aaaaaaaaaaaaaaa.delivery.puppetlabs.net', 'type' => 'centos-7.2-x86_64', 'engine' => 'vmpooler' },
61
- { 'hostname' => 'aaaaaaaaaaaaaab.delivery.puppetlabs.net', 'type' => 'centos-7.2-x86_64', 'engine' => 'vmpooler' },
62
- { 'hostname' => 'aaaaaaaaaaaaaac.delivery.puppetlabs.net', 'type' => 'ubuntu-7.2-x86_64', 'engine' => 'vmpooler' },
61
+ { 'hostname' => 'aaaaaaaaaaaaaaa.delivery.puppetlabs.net', 'type' => 'centos-7.2-x86_64',
62
+ 'engine' => 'vmpooler' },
63
+ { 'hostname' => 'aaaaaaaaaaaaaab.delivery.puppetlabs.net', 'type' => 'centos-7.2-x86_64',
64
+ 'engine' => 'vmpooler' },
65
+ { 'hostname' => 'aaaaaaaaaaaaaac.delivery.puppetlabs.net', 'type' => 'ubuntu-7.2-x86_64',
66
+ 'engine' => 'vmpooler' }
63
67
  ]
64
68
 
65
69
  vmpooler_formatted_response = ABS.translated(abs_formatted_response, job_id)
66
70
 
67
71
  vmpooler_formatted_compare = {
68
72
  'centos-7.2-x86_64' => {},
69
- 'ubuntu-7.2-x86_64' => {},
73
+ 'ubuntu-7.2-x86_64' => {}
70
74
  }
71
75
 
72
- vmpooler_formatted_compare['centos-7.2-x86_64']['hostname'] = ['aaaaaaaaaaaaaaa.delivery.puppetlabs.net', 'aaaaaaaaaaaaaab.delivery.puppetlabs.net']
76
+ vmpooler_formatted_compare['centos-7.2-x86_64']['hostname'] =
77
+ ['aaaaaaaaaaaaaaa.delivery.puppetlabs.net', 'aaaaaaaaaaaaaab.delivery.puppetlabs.net']
73
78
  vmpooler_formatted_compare['ubuntu-7.2-x86_64']['hostname'] = ['aaaaaaaaaaaaaac.delivery.puppetlabs.net']
74
79
 
75
80
  vmpooler_formatted_compare['ok'] = true
@@ -86,22 +91,22 @@ describe ABS do
86
91
  hosts = ['host1']
87
92
  allocated_resources = [
88
93
  {
89
- 'hostname' => 'host1',
94
+ 'hostname' => 'host1'
90
95
  },
91
96
  {
92
- 'hostname' => 'host2',
93
- },
97
+ 'hostname' => 'host2'
98
+ }
94
99
  ]
95
100
  expect(ABS.all_job_resources_accounted_for(allocated_resources, hosts)).to eq(false)
96
101
 
97
- hosts = ['host1', 'host2']
102
+ hosts = %w[host1 host2]
98
103
  allocated_resources = [
99
104
  {
100
- 'hostname' => 'host1',
105
+ 'hostname' => 'host1'
101
106
  },
102
107
  {
103
- 'hostname' => 'host2',
104
- },
108
+ 'hostname' => 'host2'
109
+ }
105
110
  ]
106
111
  expect(ABS.all_job_resources_accounted_for(allocated_resources, hosts)).to eq(true)
107
112
  end
@@ -126,16 +131,16 @@ describe ABS do
126
131
 
127
132
  it 'will skip a line with a null value returned from abs' do
128
133
  stub_request(:get, 'https://abs.example.com/api/v2/status/queue')
129
- .to_return(:status => 200, :body => @active_requests_response, :headers => {})
134
+ .to_return(status: 200, body: @active_requests_response, headers: {})
130
135
 
131
136
  ret = ABS.get_active_requests(false, @abs_url, @test_user)
132
137
 
133
138
  expect(ret[0]).to include(
134
139
  'allocated_resources' => [{
135
140
  'hostname' => 'take-this.delivery.puppetlabs.net',
136
- 'type' => 'win-2012r2-x86_64',
137
- 'engine' => 'vmpooler',
138
- }],
141
+ 'type' => 'win-2012r2-x86_64',
142
+ 'engine' => 'vmpooler'
143
+ }]
139
144
  )
140
145
  end
141
146
  end
@@ -147,7 +152,11 @@ describe ABS do
147
152
  [
148
153
  { "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}}
149
154
  ]'
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 }
155
+ @return_request = {
156
+ "job_id" => "1579300120799",
157
+ "hosts" => [{"hostname"=>"craggy-chord.delivery.puppetlabs.net","type"=>"centos-7-x86_64","engine"=>"vmpooler"},
158
+ {"hostname"=>"visible-revival.delivery.puppetlabs.net","type"=>"centos-7-x86_64","engine"=>"vmpooler"}]
159
+ }
151
160
  # rubocop:enable Layout/LineLength
152
161
  @token = 'utpg2i2xswor6h8ttjhu3d47z53yy47y'
153
162
  @test_user = 'test-user'
@@ -157,15 +166,15 @@ describe ABS do
157
166
 
158
167
  it 'will delete the whole job' do
159
168
  stub_request(:get, 'https://abs.example.com/api/v2/status/queue')
160
- .to_return(:status => 200, :body => @active_requests_response, :headers => {})
169
+ .to_return(status: 200, body: @active_requests_response, headers: {})
161
170
  stub_request(:post, 'https://abs.example.com/api/v2/return')
162
- .with(:body => @return_request)
163
- .to_return(:status => 200, :body => 'OK', :headers => {})
171
+ .with(headers: get_headers(content_type: 'application/x-www-form-urlencoded', token: @token), body: @return_request.to_json)
172
+ .to_return(status: 200, body: 'OK', headers: {})
164
173
 
165
174
  ret = ABS.delete(false, @abs_url, @hosts, @token, @test_user)
166
175
 
167
176
  expect(ret).to include(
168
- 'craggy-chord.delivery.puppetlabs.net' => { 'ok'=>true }, 'visible-revival.delivery.puppetlabs.net' => { 'ok'=>true },
177
+ 'craggy-chord.delivery.puppetlabs.net' => { 'ok' => true }, 'visible-revival.delivery.puppetlabs.net' => { 'ok' => true }
169
178
  )
170
179
  end
171
180
  end
@@ -3,6 +3,9 @@
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
7
10
  before :each do
8
11
  @vmpooler_url = 'https://vmpooler.example.com'
@@ -15,18 +18,20 @@ describe Pooler do
15
18
  end
16
19
 
17
20
  it 'returns a token from vmpooler' do
18
- stub_request(:post, 'https://first.last:password@vmpooler.example.com/token')
19
- .to_return(:status => 200, :body => @get_token_response, :headers => {})
21
+ stub_request(:post, 'https://vmpooler.example.com/token')
22
+ .with(headers: get_headers(username: user, password: pass, content_length: 0))
23
+ .to_return(status: 200, body: @get_token_response, headers: {})
20
24
 
21
- token = Auth.get_token(false, @vmpooler_url, 'first.last', 'password')
25
+ token = Auth.get_token(false, @vmpooler_url, user, pass)
22
26
  expect(token).to eq @token
23
27
  end
24
28
 
25
29
  it 'raises a token error if something goes wrong' do
26
- stub_request(:post, 'https://first.last:password@vmpooler.example.com/token')
27
- .to_return(:status => 500, :body => '{"ok":false}', :headers => {})
30
+ stub_request(:post, 'https://vmpooler.example.com/token')
31
+ .with(headers: get_headers(username: user, password: pass, content_length: 0))
32
+ .to_return(status: 500, body: '{"ok":false}', headers: {})
28
33
 
29
- expect { Auth.get_token(false, @vmpooler_url, 'first.last', 'password') }.to raise_error(TokenError)
34
+ expect { Auth.get_token(false, @vmpooler_url, user, pass) }.to raise_error(TokenError)
30
35
  end
31
36
  end
32
37
 
@@ -37,15 +42,18 @@ describe Pooler do
37
42
  end
38
43
 
39
44
  it 'deletes the specified token' do
40
- stub_request(:delete, 'https://first.last:password@vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
41
- .to_return(:status => 200, :body => @delete_token_response, :headers => {})
45
+ stub_request(:delete, 'https://vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
46
+ .with(headers: get_headers(username: user, password: pass))
47
+ .to_return(status: 200, body: @delete_token_response, headers: {})
42
48
 
43
- expect(Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', @token)).to eq JSON.parse(@delete_token_response)
49
+ expect(Auth.delete_token(false, @vmpooler_url, user, pass,
50
+ @token)).to eq JSON.parse(@delete_token_response)
44
51
  end
45
52
 
46
53
  it 'raises a token error if something goes wrong' do
47
- stub_request(:delete, 'https://first.last:password@vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
48
- .to_return(:status => 500, :body => '{"ok":false}', :headers => {})
54
+ stub_request(:delete, 'https://vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
55
+ .with(headers: get_headers(username: user, password: pass))
56
+ .to_return(status: 500, body: '{"ok":false}', headers: {})
49
57
 
50
58
  expect { Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', @token) }.to raise_error(TokenError)
51
59
  end
@@ -63,14 +71,16 @@ describe Pooler do
63
71
 
64
72
  it 'checks the status of a token' do
65
73
  stub_request(:get, "#{@vmpooler_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
66
- .to_return(:status => 200, :body => @token_status_response, :headers => {})
74
+ .with(headers: get_headers)
75
+ .to_return(status: 200, body: @token_status_response, headers: {})
67
76
 
68
77
  expect(Auth.token_status(false, @vmpooler_url, @token)).to eq JSON.parse(@token_status_response)
69
78
  end
70
79
 
71
80
  it 'raises a token error if something goes wrong' do
72
81
  stub_request(:get, "#{@vmpooler_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
73
- .to_return(:status => 500, :body => '{"ok":false}', :headers => {})
82
+ .with(headers: get_headers)
83
+ .to_return(status: 500, body: '{"ok":false}', headers: {})
74
84
 
75
85
  expect { Auth.token_status(false, @vmpooler_url, @token) }.to raise_error(TokenError)
76
86
  end
@@ -8,9 +8,7 @@ require 'vmfloaty/nonstandard_pooler'
8
8
  describe NonstandardPooler do
9
9
  before :each do
10
10
  @nspooler_url = 'https://nspooler.example.com'
11
- @auth_token_headers = {
12
- 'X-Auth-Token' => 'token-value',
13
- }
11
+ @auth_token_headers = get_headers(token: 'token-value')
14
12
  end
15
13
 
16
14
  describe '#list' do
@@ -36,7 +34,7 @@ describe NonstandardPooler do
36
34
 
37
35
  it 'returns an array with operating systems from the pooler' do
38
36
  stub_request(:get, "#{@nspooler_url}/status")
39
- .to_return(:status => 200, :body => @status_response_body, :headers => {})
37
+ .to_return(status: 200, body: @status_response_body, headers: {})
40
38
 
41
39
  list = NonstandardPooler.list(false, @nspooler_url, nil)
42
40
  expect(list).to be_an_instance_of Array
@@ -44,7 +42,7 @@ describe NonstandardPooler do
44
42
 
45
43
  it 'filters operating systems based on the filter param' do
46
44
  stub_request(:get, "#{@nspooler_url}/status")
47
- .to_return(:status => 200, :body => @status_response_body, :headers => {})
45
+ .to_return(status: 200, body: @status_response_body, headers: {})
48
46
 
49
47
  list = NonstandardPooler.list(false, @nspooler_url, 'aix')
50
48
  expect(list).to be_an_instance_of Array
@@ -53,7 +51,7 @@ describe NonstandardPooler do
53
51
 
54
52
  it 'returns nothing if the filter does not match' do
55
53
  stub_request(:get, "#{@nspooler_url}/status")
56
- .to_return(:status => 199, :body => @status_response_body, :headers => {})
54
+ .to_return(status: 199, body: @status_response_body, headers: {})
57
55
 
58
56
  list = NonstandardPooler.list(false, @nspooler_url, 'windows')
59
57
  expect(list).to be_an_instance_of Array
@@ -89,7 +87,7 @@ describe NonstandardPooler do
89
87
  .and_return(JSON.parse(@token_status_body_active))
90
88
 
91
89
  list = NonstandardPooler.list_active(false, @nspooler_url, 'token-value', 'user')
92
- expect(list).to eql ['sol10-9', 'sol10-11']
90
+ expect(list).to eql %w[sol10-9 sol10-11]
93
91
  end
94
92
  end
95
93
 
@@ -121,17 +119,19 @@ describe NonstandardPooler do
121
119
 
122
120
  it 'raises an AuthError if the token is invalid' do
123
121
  stub_request(:post, "#{@nspooler_url}/host/solaris-11-sparc")
124
- .with(:headers => @auth_token_headers)
125
- .to_return(:status => 401, :body => '{"ok":false,"reason": "token: token-value does not exist"}', :headers => {})
122
+ .with(headers: get_headers(token: 'token-value'))
123
+ .to_return(status: 401, body: '{"ok":false,"reason": "token: token-value does not exist"}', headers: {})
126
124
 
127
125
  vm_hash = { 'solaris-11-sparc' => 1 }
128
- expect { NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url, 'first.last', {}) }.to raise_error(AuthError)
126
+ expect do
127
+ NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url, 'first.last', {})
128
+ end.to raise_error(AuthError)
129
129
  end
130
130
 
131
131
  it 'retrieves a single vm with a token' do
132
132
  stub_request(:post, "#{@nspooler_url}/host/solaris-11-sparc")
133
- .with(:headers => @auth_token_headers)
134
- .to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {})
133
+ .with(headers: @auth_token_headers)
134
+ .to_return(status: 200, body: @retrieve_response_body_single, headers: {})
135
135
 
136
136
  vm_hash = { 'solaris-11-sparc' => 1 }
137
137
  vm_req = NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url, 'first.last', {})
@@ -142,15 +142,16 @@ describe NonstandardPooler do
142
142
 
143
143
  it 'retrieves a multiple vms with a token' do
144
144
  stub_request(:post, "#{@nspooler_url}/host/aix-7.1-power+solaris-10-sparc+solaris-10-sparc")
145
- .with(:headers => @auth_token_headers)
146
- .to_return(:status => 200, :body => @retrieve_response_body_many, :headers => {})
145
+ .with(headers: @auth_token_headers)
146
+ .to_return(status: 200, body: @retrieve_response_body_many, headers: {})
147
147
 
148
148
  vm_hash = { 'aix-7.1-power' => 1, 'solaris-10-sparc' => 2 }
149
149
  vm_req = NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url, 'first.last', {})
150
150
  expect(vm_req).to be_an_instance_of Hash
151
151
  expect(vm_req['ok']).to equal true
152
152
  expect(vm_req['solaris-10-sparc']['hostname']).to be_an_instance_of Array
153
- expect(vm_req['solaris-10-sparc']['hostname']).to eq ['sol10-9.delivery.puppetlabs.net', 'sol10-10.delivery.puppetlabs.net']
153
+ expect(vm_req['solaris-10-sparc']['hostname']).to eq ['sol10-9.delivery.puppetlabs.net',
154
+ 'sol10-10.delivery.puppetlabs.net']
154
155
  expect(vm_req['aix-7.1-power']['hostname']).to eq 'pe-aix-71-ci-acceptance.delivery.puppetlabs.net'
155
156
  end
156
157
  end
@@ -162,22 +163,22 @@ describe NonstandardPooler do
162
163
 
163
164
  it 'raises an error if the user tries to modify an unsupported attribute' do
164
165
  stub_request(:put, 'https://nspooler.example.com/host/myfakehost')
165
- .with(:body => { '{}' => true },
166
- :headers => @auth_token_headers)
167
- .to_return(:status => 200, :body => '', :headers => {})
168
- details = { :lifetime => 12 }
166
+ .with(body: { '{}' => true },
167
+ headers: @auth_token_headers)
168
+ .to_return(status: 200, body: '', headers: {})
169
+ details = { lifetime: 12 }
169
170
  expect { NonstandardPooler.modify(false, @nspooler_url, 'myfakehost', 'token-value', details) }
170
171
  .to raise_error(ModifyError)
171
172
  end
172
173
 
173
174
  it 'modifies the reason of a vm' do
174
- modify_request_body = { '{"reserved_for_reason":"testing"}' => true }
175
+ modify_request_body = { '{"reserved_for_reason":"testing"}' => nil }
175
176
  stub_request(:put, "#{@nspooler_url}/host/myfakehost")
176
- .with(:body => modify_request_body,
177
- :headers => @auth_token_headers)
178
- .to_return(:status => 200, :body => '{"ok": true}', :headers => {})
177
+ .with(body: modify_request_body,
178
+ headers: @auth_token_headers)
179
+ .to_return(status: 200, body: '{"ok": true}', headers: {})
179
180
 
180
- modify_hash = { :reason => 'testing' }
181
+ modify_hash = { reason: 'testing' }
181
182
  modify_req = NonstandardPooler.modify(false, @nspooler_url, 'myfakehost', 'token-value', modify_hash)
182
183
  expect(modify_req['ok']).to be true
183
184
  end
@@ -208,7 +209,7 @@ describe NonstandardPooler do
208
209
 
209
210
  it 'prints the status' do
210
211
  stub_request(:get, "#{@nspooler_url}/status")
211
- .to_return(:status => 200, :body => @status_response_body, :headers => {})
212
+ .to_return(status: 200, body: @status_response_body, headers: {})
212
213
 
213
214
  status = NonstandardPooler.status(false, @nspooler_url)
214
215
  expect(status).to be_an_instance_of Hash
@@ -231,7 +232,7 @@ describe NonstandardPooler do
231
232
 
232
233
  it 'prints the summary' do
233
234
  stub_request(:get, "#{@nspooler_url}/summary")
234
- .to_return(:status => 200, :body => @status_response_body, :headers => {})
235
+ .to_return(status: 200, body: @status_response_body, headers: {})
235
236
 
236
237
  summary = NonstandardPooler.summary(false, @nspooler_url)
237
238
  expect(summary).to be_an_instance_of Hash
@@ -256,7 +257,7 @@ describe NonstandardPooler do
256
257
 
257
258
  it 'makes a query about a vm' do
258
259
  stub_request(:get, "#{@nspooler_url}/host/sol10-11")
259
- .to_return(:status => 200, :body => @query_response_body, :headers => {})
260
+ .to_return(status: 200, body: @query_response_body, headers: {})
260
261
 
261
262
  query_req = NonstandardPooler.query(false, @nspooler_url, 'sol10-11')
262
263
  expect(query_req).to be_an_instance_of Hash
@@ -271,8 +272,8 @@ describe NonstandardPooler do
271
272
 
272
273
  it 'deletes a single existing vm' do
273
274
  stub_request(:delete, "#{@nspooler_url}/host/sol11-7")
274
- .with(:headers => @auth_token_headers)
275
- .to_return(:status => 200, :body => @delete_response_success, :headers => {})
275
+ .with(headers: @auth_token_headers)
276
+ .to_return(status: 200, body: @delete_response_success, headers: {})
276
277
 
277
278
  request = NonstandardPooler.delete(false, @nspooler_url, 'sol11-7', 'token-value', nil)
278
279
  expect(request['sol11-7']['ok']).to be true
@@ -280,8 +281,8 @@ describe NonstandardPooler do
280
281
 
281
282
  it 'does not delete a nonexistant vm' do
282
283
  stub_request(:delete, "#{@nspooler_url}/host/fakehost")
283
- .with(:headers => @auth_token_headers)
284
- .to_return(:status => 401, :body => @delete_response_failure, :headers => {})
284
+ .with(headers: @auth_token_headers)
285
+ .to_return(status: 401, body: @delete_response_failure, headers: {})
285
286
 
286
287
  request = NonstandardPooler.delete(false, @nspooler_url, 'fakehost', 'token-value', nil)
287
288
  expect(request['fakehost']['ok']).to be false
@@ -15,7 +15,7 @@ describe Pooler do
15
15
 
16
16
  it 'returns a hash with operating systems from the pooler' do
17
17
  stub_request(:get, "#{@vmpooler_url}/vm")
18
- .to_return(:status => 200, :body => @list_response_body, :headers => {})
18
+ .to_return(status: 200, body: @list_response_body, headers: {})
19
19
 
20
20
  list = Pooler.list(false, @vmpooler_url, nil)
21
21
  expect(list).to be_an_instance_of Array
@@ -23,7 +23,7 @@ describe Pooler do
23
23
 
24
24
  it 'filters operating systems based on the filter param' do
25
25
  stub_request(:get, "#{@vmpooler_url}/vm")
26
- .to_return(:status => 200, :body => @list_response_body, :headers => {})
26
+ .to_return(status: 200, body: @list_response_body, headers: {})
27
27
 
28
28
  list = Pooler.list(false, @vmpooler_url, 'deb')
29
29
  expect(list).to be_an_instance_of Array
@@ -32,7 +32,7 @@ describe Pooler do
32
32
 
33
33
  it 'returns nothing if the filter does not match' do
34
34
  stub_request(:get, "#{@vmpooler_url}/vm")
35
- .to_return(:status => 200, :body => @list_response_body, :headers => {})
35
+ .to_return(status: 200, body: @list_response_body, headers: {})
36
36
 
37
37
  list = Pooler.list(false, @vmpooler_url, 'windows')
38
38
  expect(list).to be_an_instance_of Array
@@ -48,8 +48,8 @@ describe Pooler do
48
48
 
49
49
  it 'raises an AuthError if the token is invalid' do
50
50
  stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386")
51
- .with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
52
- .to_return(:status => 401, :body => '{"ok":false}', :headers => {})
51
+ .with(headers: { 'X-Auth-Token' => 'mytokenfile' })
52
+ .to_return(status: 401, body: '{"ok":false}', headers: {})
53
53
 
54
54
  vm_hash = {}
55
55
  vm_hash['debian-7-i386'] = 1
@@ -58,8 +58,8 @@ describe Pooler do
58
58
 
59
59
  it 'retrieves a single vm with a token' do
60
60
  stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386")
61
- .with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
62
- .to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {})
61
+ .with(headers: { 'X-Auth-Token' => 'mytokenfile' })
62
+ .to_return(status: 200, body: @retrieve_response_body_single, headers: {})
63
63
 
64
64
  vm_hash = {}
65
65
  vm_hash['debian-7-i386'] = 1
@@ -71,8 +71,8 @@ describe Pooler do
71
71
 
72
72
  it 'retrieves a multiple vms with a token' do
73
73
  stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386+debian-7-i386+centos-7-x86_64")
74
- .with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
75
- .to_return(:status => 200, :body => @retrieve_response_body_double, :headers => {})
74
+ .with(headers: { 'X-Auth-Token' => 'mytokenfile' })
75
+ .to_return(status: 200, body: @retrieve_response_body_double, headers: {})
76
76
 
77
77
  vm_hash = {}
78
78
  vm_hash['debian-7-i386'] = 2
@@ -89,11 +89,11 @@ describe Pooler do
89
89
  let(:ondemand_response) { '{"ok":true,"request_id":"1234"}' }
90
90
  it 'retreives the vm with a token' do
91
91
  stub_request(:post, "#{@vmpooler_url}/ondemandvm/debian-7-i386")
92
- .with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
93
- .to_return(:status => 200, :body => ondemand_response, :headers => {})
92
+ .with(headers: { 'X-Auth-Token' => 'mytokenfile' })
93
+ .to_return(status: 200, body: ondemand_response, headers: {})
94
94
 
95
95
  stub_request(:get, "#{@vmpooler_url}/ondemandvm/1234")
96
- .to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {})
96
+ .to_return(status: 200, body: @retrieve_response_body_single, headers: {})
97
97
 
98
98
  vm_hash = {}
99
99
  vm_hash['debian-7-i386'] = 1
@@ -117,11 +117,11 @@ describe Pooler do
117
117
  end
118
118
 
119
119
  it 'modifies the TTL of a vm' do
120
- modify_hash = { :lifetime => 12 }
120
+ modify_hash = { lifetime: 12 }
121
121
  stub_request(:put, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6")
122
- .with(:body => { '{"lifetime":12}' => true },
123
- :headers => { 'Content-Type' => 'application/x-www-form-urlencoded', 'X-Auth-Token' => 'mytokenfile' })
124
- .to_return(:status => 200, :body => @modify_response_body_success, :headers => {})
122
+ .with(body: { '{"lifetime":12}' => nil },
123
+ headers: get_headers(content_type: 'application/x-www-form-urlencoded', token: 'mytokenfile'))
124
+ .to_return(status: 200, body: @modify_response_body_success, headers: {})
125
125
 
126
126
  modify_req = Pooler.modify(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', modify_hash)
127
127
  expect(modify_req['ok']).to be true
@@ -136,8 +136,8 @@ describe Pooler do
136
136
 
137
137
  it 'deletes a specified vm' do
138
138
  stub_request(:delete, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6")
139
- .with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
140
- .to_return(:status => 200, :body => @delete_response_body_success, :headers => {})
139
+ .with(headers: { 'X-Auth-Token' => 'mytokenfile' })
140
+ .to_return(status: 200, body: @delete_response_body_success, headers: {})
141
141
 
142
142
  expect(Pooler.delete(false, @vmpooler_url, ['fq6qlpjlsskycq6'], 'mytokenfile', nil)).to eq @delete_response
143
143
  end
@@ -155,7 +155,7 @@ describe Pooler do
155
155
 
156
156
  it 'prints the status' do
157
157
  stub_request(:get, "#{@vmpooler_url}/status")
158
- .to_return(:status => 200, :body => @status_response_body, :headers => {})
158
+ .to_return(status: 200, body: @status_response_body, headers: {})
159
159
 
160
160
  status = Pooler.status(false, @vmpooler_url)
161
161
  expect(status).to be_an_instance_of Hash
@@ -178,7 +178,7 @@ describe Pooler do
178
178
 
179
179
  it 'makes a query about a vm' do
180
180
  stub_request(:get, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6")
181
- .to_return(:status => 200, :body => @query_response_body, :headers => {})
181
+ .to_return(status: 200, body: @query_response_body, headers: {})
182
182
 
183
183
  query_req = Pooler.query(false, @vmpooler_url, 'fq6qlpjlsskycq6')
184
184
  expect(query_req).to be_an_instance_of Hash
@@ -192,8 +192,8 @@ describe Pooler do
192
192
 
193
193
  it 'makes a snapshot for a single vm' do
194
194
  stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/snapshot")
195
- .with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
196
- .to_return(:status => 200, :body => @snapshot_response_body, :headers => {})
195
+ .with(headers: { 'X-Auth-Token' => 'mytokenfile' })
196
+ .to_return(status: 200, body: @snapshot_response_body, headers: {})
197
197
 
198
198
  snapshot_req = Pooler.snapshot(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile')
199
199
  expect(snapshot_req['ok']).to be true
@@ -207,15 +207,18 @@ describe Pooler do
207
207
 
208
208
  it 'makes a request to revert a vm from a snapshot' do
209
209
  stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/snapshot/dAfewKNfaweLKNve")
210
- .with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
211
- .to_return(:status => 200, :body => @revert_response_body, :headers => {})
210
+ .with(headers: { 'X-Auth-Token' => 'mytokenfile' })
211
+ .to_return(status: 200, body: @revert_response_body, headers: {})
212
212
 
213
213
  revert_req = Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 'dAfewKNfaweLKNve')
214
214
  expect(revert_req['ok']).to be true
215
215
  end
216
216
 
217
217
  it "doesn't make a request to revert a vm if snapshot is not provided" do
218
- expect { Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', nil) }.to raise_error(RuntimeError, 'Snapshot SHA provided was nil, could not revert fq6qlpjlsskycq6')
218
+ expect do
219
+ Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile',
220
+ nil)
221
+ end.to raise_error(RuntimeError, 'Snapshot SHA provided was nil, could not revert fq6qlpjlsskycq6')
219
222
  end
220
223
 
221
224
  it 'raises a TokenError if no token was provided' do
@@ -231,7 +234,7 @@ describe Pooler do
231
234
 
232
235
  it 'makes a request to extend disk space of a vm' do
233
236
  stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/disk/12")
234
- .with(:headers => { 'X-Auth-Token' => 'mytokenfile' }). to_return(:status => 200, :body => @disk_response_body_success, :headers => {})
237
+ .with(headers: { 'X-Auth-Token' => 'mytokenfile' }).to_return(status: 200, body: @disk_response_body_success, headers: {})
235
238
 
236
239
  disk_req = Pooler.disk(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 12)
237
240
  expect(disk_req['ok']).to be true