vmfloaty 0.9.0 → 0.11.1

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.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Vmfloaty
4
- VERSION = '0.9.0'
4
+ VERSION = '0.11.1'
5
5
  end
@@ -1,5 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'simplecov'
4
+ require 'coveralls'
5
+
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ])
10
+ SimpleCov.start do
11
+ add_filter %r{^/spec/}
12
+ end
13
+
3
14
  require 'vmfloaty'
4
15
  require 'webmock/rspec'
5
16
 
@@ -65,14 +65,14 @@ describe ABS do
65
65
 
66
66
  describe '#test_abs_status_queue_endpoint' do
67
67
  before :each do
68
- # rubocop:disable Metrics/LineLength
68
+ # rubocop:disable Layout/LineLength
69
69
  @active_requests_response = '
70
70
  [
71
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}}",
72
72
  "null",
73
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}}"
74
74
  ]'
75
- # rubocop:enable Metrics/LineLength
75
+ # rubocop:enable Layout/LineLength
76
76
  @token = 'utpg2i2xswor6h8ttjhu3d47z53yy47y'
77
77
  @test_user = 'test-user'
78
78
  end
@@ -92,5 +92,35 @@ describe ABS do
92
92
  )
93
93
  end
94
94
  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
95
125
  end
96
126
  end
@@ -274,7 +274,7 @@ describe NonstandardPooler do
274
274
  .with(:headers => @auth_token_headers)
275
275
  .to_return(:status => 200, :body => @delete_response_success, :headers => {})
276
276
 
277
- request = NonstandardPooler.delete(false, @nspooler_url, 'sol11-7', 'token-value')
277
+ request = NonstandardPooler.delete(false, @nspooler_url, 'sol11-7', 'token-value', nil)
278
278
  expect(request['sol11-7']['ok']).to be true
279
279
  end
280
280
 
@@ -283,7 +283,7 @@ describe NonstandardPooler do
283
283
  .with(:headers => @auth_token_headers)
284
284
  .to_return(:status => 401, :body => @delete_response_failure, :headers => {})
285
285
 
286
- request = NonstandardPooler.delete(false, @nspooler_url, 'fakehost', 'token-value')
286
+ request = NonstandardPooler.delete(false, @nspooler_url, 'fakehost', 'token-value', nil)
287
287
  expect(request['fakehost']['ok']).to be false
288
288
  end
289
289
  end
@@ -84,6 +84,26 @@ describe Pooler do
84
84
  expect(vm_req['debian-7-i386']['hostname']).to eq %w[sc0o4xqtodlul5w 4m4dkhqiufnjmxy]
85
85
  expect(vm_req['centos-7-x86_64']['hostname']).to eq 'zb91y9qbrbf6d3q'
86
86
  end
87
+
88
+ context 'with ondemand provisioning' do
89
+ let(:ondemand_response) { '{"ok":true,"request_id":"1234"}' }
90
+ it 'retreives the vm with a token' do
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 => {})
94
+
95
+ stub_request(:get, "#{@vmpooler_url}/ondemandvm/1234")
96
+ .to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {})
97
+
98
+ vm_hash = {}
99
+ vm_hash['debian-7-i386'] = 1
100
+ Pooler.retrieve(false, vm_hash, 'mytokenfile', @vmpooler_url, 'user', {}, true)
101
+ vm_req = Pooler.check_ondemandvm(false, '1234', @vmpooler_url)
102
+ expect(vm_req).to be_an_instance_of Hash
103
+ expect(vm_req['ok']).to equal true
104
+ expect(vm_req['debian-7-i386']['hostname']).to eq 'fq6qlpjlsskycq6'
105
+ end
106
+ end
87
107
  end
88
108
 
89
109
  describe '#modify' do
@@ -119,11 +139,11 @@ describe Pooler do
119
139
  .with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
120
140
  .to_return(:status => 200, :body => @delete_response_body_success, :headers => {})
121
141
 
122
- expect(Pooler.delete(false, @vmpooler_url, ['fq6qlpjlsskycq6'], 'mytokenfile')).to eq @delete_response
142
+ expect(Pooler.delete(false, @vmpooler_url, ['fq6qlpjlsskycq6'], 'mytokenfile', nil)).to eq @delete_response
123
143
  end
124
144
 
125
145
  it 'raises a token error if no token provided' do
126
- expect { Pooler.delete(false, @vmpooler_url, ['myfakehost'], nil) }.to raise_error(TokenError)
146
+ expect { Pooler.delete(false, @vmpooler_url, ['myfakehost'], nil, nil) }.to raise_error(TokenError)
127
147
  end
128
148
  end
129
149
 
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'vmfloaty/ssh'
5
+
6
+ class ServiceStub
7
+ def retrieve(_verbose, os_types, _use_token)
8
+ if os_types.keys[0] == 'abs_host_string'
9
+ return {
10
+ os_types.keys[0] => { 'hostname' => ['abs-hostname.delivery.puppetlabs.net'] },
11
+ 'ok' => true,
12
+ }
13
+ end
14
+
15
+ {
16
+ os_types.keys[0] => { 'hostname' => 'vmpooler-hostname' },
17
+ 'domain' => 'delivery.puppetlabs.net',
18
+ 'ok' => true,
19
+ }
20
+ end
21
+
22
+ def type
23
+ return 'abs' if os_types == 'abs_host_string'
24
+ return 'vmpooler' if os_types == 'vmpooler_host_string'
25
+ end
26
+ end
27
+
28
+ describe Ssh do
29
+ before :each do
30
+ end
31
+
32
+ it 'gets a hostname string for abs' do
33
+ verbose = false
34
+ service = ServiceStub.new
35
+ host_os = 'abs_host_string'
36
+ use_token = false
37
+ cmd = Ssh.command_string(verbose, service, host_os, use_token)
38
+ expect(cmd).to match(/ssh root@abs-hostname.delivery.puppetlabs.net/)
39
+ end
40
+
41
+ it 'gets a hostname string for vmpooler' do
42
+ verbose = false
43
+ service = ServiceStub.new
44
+ host_os = 'vmpooler_host_string'
45
+ use_token = false
46
+ cmd = Ssh.command_string(verbose, service, host_os, use_token)
47
+ expect(cmd).to match(/ssh root@vmpooler-hostname.delivery.puppetlabs.net/)
48
+ end
49
+ end
@@ -169,7 +169,7 @@ describe Utils do
169
169
  } }
170
170
  output = '- mcpy42eqjxli9g2.delivery.mycompany.net (ubuntu-1604-x86_64, 9.66/12 hours)'
171
171
 
172
- expect(Utils).to receive(:puts).with(output)
172
+ expect(STDOUT).to receive(:puts).with(output)
173
173
 
174
174
  service = Service.new(MockOptions.new, 'url' => url)
175
175
  allow(service).to receive(:query)
@@ -195,7 +195,7 @@ describe Utils do
195
195
  } }
196
196
  output = '- aiydvzpg23r415q.delivery.mycompany.net (redhat-7-x86_64, 7.67/48 hours, user: bob, role: agent)'
197
197
 
198
- expect(Utils).to receive(:puts).with(output)
198
+ expect(STDOUT).to receive(:puts).with(output)
199
199
 
200
200
  service = Service.new(MockOptions.new, 'url' => url)
201
201
  allow(service).to receive(:query)
@@ -216,7 +216,7 @@ describe Utils do
216
216
  } }
217
217
  output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining)'
218
218
 
219
- expect(Utils).to receive(:puts).with(output)
219
+ expect(STDOUT).to receive(:puts).with(output)
220
220
 
221
221
  service = Service.new(MockOptions.new, 'url' => url, 'type' => 'ns')
222
222
  allow(service).to receive(:query)
@@ -237,7 +237,7 @@ describe Utils do
237
237
  } }
238
238
  output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining, reason: testing)'
239
239
 
240
- expect(Utils).to receive(:puts).with(output)
240
+ expect(STDOUT).to receive(:puts).with(output)
241
241
 
242
242
  service = Service.new(MockOptions.new, 'url' => url, 'type' => 'ns')
243
243
  allow(service).to receive(:query)
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ # All of the interfaces for the different services must be the
4
+ # same, otherwise there will be errors when you change the caller
5
+ # for the services from services.rb.
6
+ #
7
+
8
+ require_relative '../../lib/vmfloaty/pooler'
9
+ require_relative '../../lib/vmfloaty/abs'
10
+ require_relative '../../lib/vmfloaty/nonstandard_pooler'
11
+
12
+ shared_examples 'a vmfloaty service' do
13
+ it { is_expected.to respond_to(:delete).with(5).arguments }
14
+ it { is_expected.to respond_to(:disk).with(5).arguments }
15
+ it { is_expected.to respond_to(:list).with(3).arguments }
16
+ it { is_expected.to respond_to(:list_active).with(4).arguments }
17
+ it { is_expected.to respond_to(:modify).with(5).arguments }
18
+ it { is_expected.to respond_to(:retrieve).with(6).arguments }
19
+ it { is_expected.to respond_to(:revert).with(5).arguments }
20
+ it { is_expected.to respond_to(:query).with(3).arguments }
21
+ it { is_expected.to respond_to(:snapshot).with(4).arguments }
22
+ it { is_expected.to respond_to(:status).with(2).arguments }
23
+ it { is_expected.to respond_to(:summary).with(2).arguments }
24
+ end
25
+
26
+ describe Pooler do
27
+ subject { Pooler }
28
+ it_behaves_like 'a vmfloaty service'
29
+ end
30
+
31
+ describe ABS do
32
+ subject { ABS }
33
+ it_behaves_like 'a vmfloaty service'
34
+ end
35
+
36
+ describe NonstandardPooler do
37
+ subject { NonstandardPooler }
38
+ it_behaves_like 'a vmfloaty service'
39
+ end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmfloaty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Cain
8
- autorequire:
8
+ - Puppet
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2019-12-17 00:00:00.000000000 Z
12
+ date: 2020-08-20 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: colorize
@@ -28,33 +29,40 @@ dependencies:
28
29
  name: commander
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - "~>"
32
+ - - ">="
32
33
  - !ruby/object:Gem::Version
33
34
  version: 4.4.3
35
+ - - "<"
36
+ - !ruby/object:Gem::Version
37
+ version: 4.6.0
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
37
41
  requirements:
38
- - - "~>"
42
+ - - ">="
39
43
  - !ruby/object:Gem::Version
40
44
  version: 4.4.3
45
+ - - "<"
46
+ - !ruby/object:Gem::Version
47
+ version: 4.6.0
41
48
  - !ruby/object:Gem::Dependency
42
49
  name: faraday
43
50
  requirement: !ruby/object:Gem::Requirement
44
51
  requirements:
45
52
  - - "~>"
46
53
  - !ruby/object:Gem::Version
47
- version: 0.15.0
54
+ version: 0.17.0
48
55
  type: :runtime
49
56
  prerelease: false
50
57
  version_requirements: !ruby/object:Gem::Requirement
51
58
  requirements:
52
59
  - - "~>"
53
60
  - !ruby/object:Gem::Version
54
- version: 0.15.0
61
+ version: 0.17.0
55
62
  description: A helper tool for vmpooler to help you stay afloat
56
63
  email:
57
64
  - brianccain@gmail.com
65
+ - dio-gems@puppet.com
58
66
  executables:
59
67
  - floaty
60
68
  extensions: []
@@ -70,6 +78,7 @@ files:
70
78
  - lib/vmfloaty/conf.rb
71
79
  - lib/vmfloaty/errors.rb
72
80
  - lib/vmfloaty/http.rb
81
+ - lib/vmfloaty/logger.rb
73
82
  - lib/vmfloaty/nonstandard_pooler.rb
74
83
  - lib/vmfloaty/pooler.rb
75
84
  - lib/vmfloaty/service.rb
@@ -83,12 +92,14 @@ files:
83
92
  - spec/vmfloaty/nonstandard_pooler_spec.rb
84
93
  - spec/vmfloaty/pooler_spec.rb
85
94
  - spec/vmfloaty/service_spec.rb
95
+ - spec/vmfloaty/ssh_spec.rb
86
96
  - spec/vmfloaty/utils_spec.rb
87
- homepage: https://github.com/briancain/vmfloaty
97
+ - spec/vmfloaty/vmfloaty_services_spec.rb
98
+ homepage: https://github.com/puppetlabs/vmfloaty
88
99
  licenses:
89
100
  - Apache-2.0
90
101
  metadata: {}
91
- post_install_message:
102
+ post_install_message:
92
103
  rdoc_options: []
93
104
  require_paths:
94
105
  - lib
@@ -103,17 +114,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
114
  - !ruby/object:Gem::Version
104
115
  version: '0'
105
116
  requirements: []
106
- rubyforge_project:
107
- rubygems_version: 2.7.7
108
- signing_key:
117
+ rubygems_version: 3.0.3
118
+ signing_key:
109
119
  specification_version: 4
110
120
  summary: CLI application to interface with vmpooler
111
121
  test_files:
112
122
  - spec/spec_helper.rb
123
+ - spec/vmfloaty/vmfloaty_services_spec.rb
113
124
  - spec/vmfloaty/service_spec.rb
114
- - spec/vmfloaty/utils_spec.rb
115
- - spec/vmfloaty/auth_spec.rb
125
+ - spec/vmfloaty/abs/auth_spec.rb
116
126
  - spec/vmfloaty/nonstandard_pooler_spec.rb
127
+ - spec/vmfloaty/ssh_spec.rb
128
+ - spec/vmfloaty/utils_spec.rb
117
129
  - spec/vmfloaty/abs_spec.rb
130
+ - spec/vmfloaty/auth_spec.rb
118
131
  - spec/vmfloaty/pooler_spec.rb
119
- - spec/vmfloaty/abs/auth_spec.rb