vmfloaty 0.8.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'json'
3
5
  require 'commander/command'
4
6
  require_relative '../../lib/vmfloaty/utils'
5
7
 
6
8
  describe Utils do
7
-
8
- describe "#format_hosts" do
9
+ describe '#standardize_hostnames' do
9
10
  before :each do
10
- @vmpooler_response_body ='{
11
+ @vmpooler_response_body = '{
11
12
  "ok": true,
12
13
  "domain": "delivery.mycompany.net",
13
14
  "ubuntu-1610-x86_64": {
@@ -26,57 +27,81 @@ describe Utils do
26
27
  "hostname": "power8-ubuntu16.04-6.delivery.mycompany.net"
27
28
  }
28
29
  }'
29
- @vmpooler_output = <<-OUT
30
- - gdoy8q3nckuob0i.delivery.mycompany.net (ubuntu-1610-x86_64)
31
- - ctnktsd0u11p9tm.delivery.mycompany.net (ubuntu-1610-x86_64)
32
- - dlgietfmgeegry2.delivery.mycompany.net (centos-7-x86_64)
30
+ end
31
+
32
+ it 'formats a result from vmpooler into a hash of os to hostnames' do
33
+ result = Utils.standardize_hostnames(JSON.parse(@vmpooler_response_body))
34
+ expect(result).to eq('centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'],
35
+ 'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.delivery.mycompany.net', 'ctnktsd0u11p9tm.delivery.mycompany.net'])
36
+ end
37
+
38
+ it 'formats a result from the nonstandard pooler into a hash of os to hostnames' do
39
+ result = Utils.standardize_hostnames(JSON.parse(@nonstandard_response_body))
40
+ expect(result).to eq('solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'],
41
+ 'ubuntu-16.04-power8' => ['power8-ubuntu16.04-6.delivery.mycompany.net'])
42
+ end
43
+ end
44
+
45
+ describe '#format_host_output' do
46
+ before :each do
47
+ @vmpooler_results = {
48
+ 'centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'],
49
+ 'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.delivery.mycompany.net', 'ctnktsd0u11p9tm.delivery.mycompany.net'],
50
+ }
51
+ @nonstandard_results = {
52
+ 'solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'],
53
+ 'ubuntu-16.04-power8' => ['power8-ubuntu16.04-6.delivery.mycompany.net'],
54
+ }
55
+ @vmpooler_output = <<~OUT.chomp
56
+ - dlgietfmgeegry2.delivery.mycompany.net (centos-7-x86_64)
57
+ - gdoy8q3nckuob0i.delivery.mycompany.net (ubuntu-1610-x86_64)
58
+ - ctnktsd0u11p9tm.delivery.mycompany.net (ubuntu-1610-x86_64)
33
59
  OUT
34
- @nonstandard_output = <<-OUT
35
- - sol10-10.delivery.mycompany.net (solaris-10-sparc)
36
- - sol10-11.delivery.mycompany.net (solaris-10-sparc)
37
- - power8-ubuntu16.04-6.delivery.mycompany.net (ubuntu-16.04-power8)
60
+ @nonstandard_output = <<~OUT.chomp
61
+ - sol10-10.delivery.mycompany.net (solaris-10-sparc)
62
+ - sol10-11.delivery.mycompany.net (solaris-10-sparc)
63
+ - power8-ubuntu16.04-6.delivery.mycompany.net (ubuntu-16.04-power8)
38
64
  OUT
39
65
  end
40
-
41
- it "formats a hostname hash from vmpooler into a list that includes the os" do
42
- expect { Utils.format_hosts(JSON.parse(@vmpooler_response_body)) }.to output( @vmpooler_output).to_stdout_from_any_process
66
+ it 'formats a hostname hash from vmpooler into a list that includes the os' do
67
+ expect(Utils.format_host_output(@vmpooler_results)).to eq(@vmpooler_output)
43
68
  end
44
69
 
45
- it "formats a hostname hash from the nonstandard pooler into a list that includes the os" do
46
- expect { Utils.format_hosts(JSON.parse(@nonstandard_response_body)) }.to output(@nonstandard_output).to_stdout_from_any_process
70
+ it 'formats a hostname hash from the nonstandard pooler into a list that includes the os' do
71
+ expect(Utils.format_host_output(@nonstandard_results)).to eq(@nonstandard_output)
47
72
  end
48
73
  end
49
74
 
50
- describe "#get_service_object" do
51
- it "assumes vmpooler by default" do
75
+ describe '#get_service_object' do
76
+ it 'assumes vmpooler by default' do
52
77
  expect(Utils.get_service_object).to be Pooler
53
78
  end
54
79
 
55
- it "uses nspooler when told explicitly" do
56
- expect(Utils.get_service_object "nspooler").to be NonstandardPooler
80
+ it 'uses nspooler when told explicitly' do
81
+ expect(Utils.get_service_object('nspooler')).to be NonstandardPooler
57
82
  end
58
83
  end
59
84
 
60
- describe "#get_service_config" do
85
+ describe '#get_service_config' do
61
86
  before :each do
62
87
  @default_config = {
63
- "url" => "http://default.url",
64
- "user" => "first.last.default",
65
- "token" => "default-token",
88
+ 'url' => 'http://default.url',
89
+ 'user' => 'first.last.default',
90
+ 'token' => 'default-token',
66
91
  }
67
92
  @services_config = {
68
- "services" => {
69
- "vm" => {
70
- "url" => "http://vmpooler.url",
71
- "user" => "first.last.vmpooler",
72
- "token" => "vmpooler-token"
73
- },
74
- "ns" => {
75
- "url" => "http://nspooler.url",
76
- "user" => "first.last.nspooler",
77
- "token" => "nspooler-token"
78
- }
79
- }
93
+ 'services' => {
94
+ 'vm' => {
95
+ 'url' => 'http://vmpooler.url',
96
+ 'user' => 'first.last.vmpooler',
97
+ 'token' => 'vmpooler-token',
98
+ },
99
+ 'ns' => {
100
+ 'url' => 'http://nspooler.url',
101
+ 'user' => 'first.last.nspooler',
102
+ 'token' => 'nspooler-token',
103
+ },
104
+ },
80
105
  }
81
106
  end
82
107
 
@@ -86,70 +111,70 @@ describe Utils do
86
111
  expect(Utils.get_service_config(config, options)).to include @services_config['services']['vm']
87
112
  end
88
113
 
89
- it "allows selection by configured service key" do
114
+ it 'allows selection by configured service key' do
90
115
  config = @default_config.merge @services_config
91
- options = MockOptions.new({:service => "ns"})
116
+ options = MockOptions.new(:service => 'ns')
92
117
  expect(Utils.get_service_config(config, options)).to include @services_config['services']['ns']
93
118
  end
94
119
 
95
- it "uses top-level service config values as defaults when configured service values are missing" do
120
+ it 'uses top-level service config values as defaults when configured service values are missing' do
96
121
  config = @default_config.merge @services_config
97
- config["services"]['vm'].delete 'url'
98
- options = MockOptions.new({:service => "vm"})
122
+ config['services']['vm'].delete 'url'
123
+ options = MockOptions.new(:service => 'vm')
99
124
  expect(Utils.get_service_config(config, options)['url']).to eq 'http://default.url'
100
125
  end
101
126
 
102
127
  it "raises an error if passed a service name that hasn't been configured" do
103
128
  config = @default_config.merge @services_config
104
- options = MockOptions.new({:service => "none"})
129
+ options = MockOptions.new(:service => 'none')
105
130
  expect { Utils.get_service_config(config, options) }.to raise_error ArgumentError
106
131
  end
107
132
 
108
- it "prioritizes values passed as command line options over configuration options" do
133
+ it 'prioritizes values passed as command line options over configuration options' do
109
134
  config = @default_config
110
- options = MockOptions.new({:url => "http://alternate.url", :token => "alternate-token"})
111
- expected = config.merge({"url" => "http://alternate.url", "token" => "alternate-token"})
135
+ options = MockOptions.new(:url => 'http://alternate.url', :token => 'alternate-token')
136
+ expected = config.merge('url' => 'http://alternate.url', 'token' => 'alternate-token')
112
137
  expect(Utils.get_service_config(config, options)).to include expected
113
138
  end
114
139
  end
115
140
 
116
- describe "#generate_os_hash" do
141
+ describe '#generate_os_hash' do
117
142
  before :each do
118
- @host_hash = {"centos"=>1, "debian"=>5, "windows"=>1}
143
+ @host_hash = { 'centos' => 1, 'debian' => 5, 'windows' => 1 }
119
144
  end
120
145
 
121
- it "takes an array of os arguments and returns a formatted hash" do
122
- host_arg = ["centos", "debian=5", "windows=1"]
146
+ it 'takes an array of os arguments and returns a formatted hash' do
147
+ host_arg = ['centos', 'debian=5', 'windows=1']
123
148
  expect(Utils.generate_os_hash(host_arg)).to eq @host_hash
124
149
  end
125
150
 
126
- it "returns an empty hash if there are no arguments provided" do
151
+ it 'returns an empty hash if there are no arguments provided' do
127
152
  host_arg = []
128
153
  expect(Utils.generate_os_hash(host_arg)).to be_empty
129
154
  end
130
155
  end
131
156
 
132
157
  describe '#pretty_print_hosts' do
133
- let(:url) { 'http://pooler.example.com' }
158
+ let(:url) { 'http://pooler.example.com' }
134
159
 
135
160
  it 'prints a vmpooler output with host fqdn, template and duration info' do
136
161
  hostname = 'mcpy42eqjxli9g2'
137
162
  response_body = { hostname => {
138
- 'template' => 'ubuntu-1604-x86_64',
139
- 'lifetime' => 12,
140
- 'running' => 9.66,
141
- 'state' => 'running',
142
- 'ip' => '127.0.0.1',
143
- 'domain' => 'delivery.mycompany.net'
144
- }}
145
- output = "- mcpy42eqjxli9g2.delivery.mycompany.net (ubuntu-1604-x86_64, 9.66/12 hours)"
163
+ 'template' => 'ubuntu-1604-x86_64',
164
+ 'lifetime' => 12,
165
+ 'running' => 9.66,
166
+ 'state' => 'running',
167
+ 'ip' => '127.0.0.1',
168
+ 'domain' => 'delivery.mycompany.net',
169
+ } }
170
+ output = '- mcpy42eqjxli9g2.delivery.mycompany.net (ubuntu-1604-x86_64, 9.66/12 hours)'
146
171
 
147
172
  expect(Utils).to receive(:puts).with(output)
148
173
 
149
- service = Service.new(MockOptions.new, {'url' => url})
174
+ service = Service.new(MockOptions.new, 'url' => url)
150
175
  allow(service).to receive(:query)
151
- .with(nil, hostname)
152
- .and_return(response_body)
176
+ .with(nil, hostname)
177
+ .and_return(response_body)
153
178
 
154
179
  Utils.pretty_print_hosts(nil, service, hostname)
155
180
  end
@@ -157,46 +182,46 @@ describe Utils do
157
182
  it 'prints a vmpooler output with host fqdn, template, duration info, and tags when supplied' do
158
183
  hostname = 'aiydvzpg23r415q'
159
184
  response_body = { hostname => {
160
- 'template' => 'redhat-7-x86_64',
161
- 'lifetime' => 48,
162
- 'running' => 7.67,
163
- 'state' => 'running',
164
- 'tags' => {
165
- 'user' => 'bob',
166
- 'role' => 'agent'
167
- },
168
- 'ip' => '127.0.0.1',
169
- 'domain' => 'delivery.mycompany.net'
170
- }}
171
- output = "- aiydvzpg23r415q.delivery.mycompany.net (redhat-7-x86_64, 7.67/48 hours, user: bob, role: agent)"
185
+ 'template' => 'redhat-7-x86_64',
186
+ 'lifetime' => 48,
187
+ 'running' => 7.67,
188
+ 'state' => 'running',
189
+ 'tags' => {
190
+ 'user' => 'bob',
191
+ 'role' => 'agent',
192
+ },
193
+ 'ip' => '127.0.0.1',
194
+ 'domain' => 'delivery.mycompany.net',
195
+ } }
196
+ output = '- aiydvzpg23r415q.delivery.mycompany.net (redhat-7-x86_64, 7.67/48 hours, user: bob, role: agent)'
172
197
 
173
198
  expect(Utils).to receive(:puts).with(output)
174
199
 
175
- service = Service.new(MockOptions.new, {'url' => url})
200
+ service = Service.new(MockOptions.new, 'url' => url)
176
201
  allow(service).to receive(:query)
177
- .with(nil, hostname)
178
- .and_return(response_body)
202
+ .with(nil, hostname)
203
+ .and_return(response_body)
179
204
 
180
205
  Utils.pretty_print_hosts(nil, service, hostname)
181
206
  end
182
207
 
183
208
  it 'prints a nonstandard pooler output with host, template, and time remaining' do
184
- hostname = "sol11-9.delivery.mycompany.net"
209
+ hostname = 'sol11-9.delivery.mycompany.net'
185
210
  response_body = { hostname => {
186
- 'fqdn' => hostname,
187
- 'os_triple' => 'solaris-11-sparc',
188
- 'reserved_by_user' => 'first.last',
189
- 'reserved_for_reason' => '',
190
- 'hours_left_on_reservation' => 35.89
191
- }}
192
- output = "- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining)"
211
+ 'fqdn' => hostname,
212
+ 'os_triple' => 'solaris-11-sparc',
213
+ 'reserved_by_user' => 'first.last',
214
+ 'reserved_for_reason' => '',
215
+ 'hours_left_on_reservation' => 35.89,
216
+ } }
217
+ output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining)'
193
218
 
194
219
  expect(Utils).to receive(:puts).with(output)
195
220
 
196
- service = Service.new(MockOptions.new, {'url' => url, 'type' => 'ns'})
221
+ service = Service.new(MockOptions.new, 'url' => url, 'type' => 'ns')
197
222
  allow(service).to receive(:query)
198
- .with(nil, hostname)
199
- .and_return(response_body)
223
+ .with(nil, hostname)
224
+ .and_return(response_body)
200
225
 
201
226
  Utils.pretty_print_hosts(nil, service, hostname)
202
227
  end
@@ -204,20 +229,20 @@ describe Utils do
204
229
  it 'prints a nonstandard pooler output with host, template, time remaining, and reason' do
205
230
  hostname = 'sol11-9.delivery.mycompany.net'
206
231
  response_body = { hostname => {
207
- 'fqdn' => hostname,
208
- 'os_triple' => 'solaris-11-sparc',
209
- 'reserved_by_user' => 'first.last',
210
- 'reserved_for_reason' => 'testing',
211
- 'hours_left_on_reservation' => 35.89
212
- }}
213
- output = "- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining, reason: testing)"
232
+ 'fqdn' => hostname,
233
+ 'os_triple' => 'solaris-11-sparc',
234
+ 'reserved_by_user' => 'first.last',
235
+ 'reserved_for_reason' => 'testing',
236
+ 'hours_left_on_reservation' => 35.89,
237
+ } }
238
+ output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining, reason: testing)'
214
239
 
215
240
  expect(Utils).to receive(:puts).with(output)
216
241
 
217
- service = Service.new(MockOptions.new, {'url' => url, 'type' => 'ns'})
242
+ service = Service.new(MockOptions.new, 'url' => url, 'type' => 'ns')
218
243
  allow(service).to receive(:query)
219
- .with(nil, hostname)
220
- .and_return(response_body)
244
+ .with(nil, hostname)
245
+ .and_return(response_body)
221
246
 
222
247
  Utils.pretty_print_hosts(nil, service, hostname)
223
248
  end
@@ -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,60 +1,68 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmfloaty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.10.0
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: 2017-10-24 00:00:00.000000000 Z
12
+ date: 2020-08-04 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
- name: commander
15
+ name: colorize
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
18
  - - "~>"
18
19
  - !ruby/object:Gem::Version
19
- version: 4.4.3
20
+ version: 0.8.1
20
21
  type: :runtime
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
25
  - - "~>"
25
26
  - !ruby/object:Gem::Version
26
- version: 4.4.3
27
+ version: 0.8.1
27
28
  - !ruby/object:Gem::Dependency
28
- name: faraday
29
+ name: commander
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - "~>"
32
+ - - ">="
32
33
  - !ruby/object:Gem::Version
33
- version: 0.9.0
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
- version: 0.9.0
44
+ version: 4.4.3
45
+ - - "<"
46
+ - !ruby/object:Gem::Version
47
+ version: 4.6.0
41
48
  - !ruby/object:Gem::Dependency
42
- name: colorize
49
+ name: faraday
43
50
  requirement: !ruby/object:Gem::Requirement
44
51
  requirements:
45
52
  - - "~>"
46
53
  - !ruby/object:Gem::Version
47
- version: 0.8.1
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.8.1
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: []
@@ -65,6 +73,7 @@ files:
65
73
  - bin/floaty
66
74
  - extras/completions/floaty.bash
67
75
  - lib/vmfloaty.rb
76
+ - lib/vmfloaty/abs.rb
68
77
  - lib/vmfloaty/auth.rb
69
78
  - lib/vmfloaty/conf.rb
70
79
  - lib/vmfloaty/errors.rb
@@ -76,16 +85,20 @@ files:
76
85
  - lib/vmfloaty/utils.rb
77
86
  - lib/vmfloaty/version.rb
78
87
  - spec/spec_helper.rb
88
+ - spec/vmfloaty/abs/auth_spec.rb
89
+ - spec/vmfloaty/abs_spec.rb
79
90
  - spec/vmfloaty/auth_spec.rb
80
91
  - spec/vmfloaty/nonstandard_pooler_spec.rb
81
92
  - spec/vmfloaty/pooler_spec.rb
82
93
  - spec/vmfloaty/service_spec.rb
94
+ - spec/vmfloaty/ssh_spec.rb
83
95
  - spec/vmfloaty/utils_spec.rb
84
- homepage: https://github.com/briancain/vmfloaty
96
+ - spec/vmfloaty/vmfloaty_services_spec.rb
97
+ homepage: https://github.com/puppetlabs/vmfloaty
85
98
  licenses:
86
99
  - Apache-2.0
87
100
  metadata: {}
88
- post_install_message:
101
+ post_install_message:
89
102
  rdoc_options: []
90
103
  require_paths:
91
104
  - lib
@@ -100,15 +113,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
113
  - !ruby/object:Gem::Version
101
114
  version: '0'
102
115
  requirements: []
103
- rubyforge_project:
104
- rubygems_version: 2.6.14
105
- signing_key:
116
+ rubygems_version: 3.0.3
117
+ signing_key:
106
118
  specification_version: 4
107
119
  summary: CLI application to interface with vmpooler
108
120
  test_files:
109
121
  - spec/spec_helper.rb
110
- - spec/vmfloaty/auth_spec.rb
111
- - spec/vmfloaty/nonstandard_pooler_spec.rb
112
- - spec/vmfloaty/pooler_spec.rb
122
+ - spec/vmfloaty/vmfloaty_services_spec.rb
113
123
  - spec/vmfloaty/service_spec.rb
124
+ - spec/vmfloaty/abs/auth_spec.rb
125
+ - spec/vmfloaty/nonstandard_pooler_spec.rb
126
+ - spec/vmfloaty/ssh_spec.rb
114
127
  - spec/vmfloaty/utils_spec.rb
128
+ - spec/vmfloaty/abs_spec.rb
129
+ - spec/vmfloaty/auth_spec.rb
130
+ - spec/vmfloaty/pooler_spec.rb