beaker-module_install_helper 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +12 -0
- data/README.md +21 -0
- data/beaker-module_install_helper.gemspec +1 -1
- data/lib/beaker/module_install_helper.rb +49 -10
- data/spec/unit/beaker/module_install_helper_spec.rb +67 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 823c0eb3935f314373fd6a2a69c48a4f00e3cbca
|
4
|
+
data.tar.gz: 7ce9f9efee93bacc80f76247359271992d84bddf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eae59a8d7a8bcd82382ec9d59a93d840b18a6e186199e2b92c7cb135a8b1af7a11460c11886bde8187293000adee2a7c96d355ef6694e307508f5dd80745bb87
|
7
|
+
data.tar.gz: fd2afeff327e32091ac6600c53090edc763f5f73e0b7c81dc7968fbdfea75642e96aab45ab8998c551fb5db70b27140fdd8932f13acc4b163151f41e4c7bedb7
|
data/.rubocop.yml
CHANGED
@@ -3,6 +3,9 @@ require: rubocop-rspec
|
|
3
3
|
AllCops:
|
4
4
|
TargetRubyVersion: 2.1
|
5
5
|
|
6
|
+
Bundler/OrderedGems:
|
7
|
+
Enabled: false
|
8
|
+
|
6
9
|
RSpec/AnyInstance:
|
7
10
|
Enabled: false
|
8
11
|
|
@@ -21,14 +24,23 @@ Style/ClassAndModuleChildren:
|
|
21
24
|
Style/GlobalVars:
|
22
25
|
Enabled: false
|
23
26
|
|
27
|
+
Style/RegexpLiteral:
|
28
|
+
Enabled: false
|
29
|
+
|
24
30
|
Bundler/DuplicatedGem:
|
25
31
|
Enabled: false
|
26
32
|
|
27
33
|
Metrics/AbcSize:
|
28
34
|
Enabled: false
|
29
35
|
|
36
|
+
Metrics/BlockLength:
|
37
|
+
Enabled: false
|
38
|
+
|
30
39
|
Metrics/LineLength:
|
31
40
|
Max: 100
|
32
41
|
|
33
42
|
Metrics/MethodLength:
|
34
43
|
Enabled: false
|
44
|
+
|
45
|
+
Metrics/ModuleLength:
|
46
|
+
Enabled: false
|
data/README.md
CHANGED
@@ -8,6 +8,9 @@ The below example will install the module from source on the host with role 'mas
|
|
8
8
|
require 'beaker/module_install_helper'
|
9
9
|
install_module_dependencies
|
10
10
|
install_module
|
11
|
+
|
12
|
+
# Install a testing only dependency, not specified in metadata
|
13
|
+
install_module_from_forge('puppetlabs-inifile', '>= 1.0.0 <= 50.0.0')
|
11
14
|
```
|
12
15
|
|
13
16
|
The below example will install the module from source on the specified host and install module dependencies specified in metadata.json on the host
|
@@ -32,5 +35,23 @@ This will call `install_module_dependencies_on` on the hosts with role 'master'.
|
|
32
35
|
### `install_module_dependencies_on`
|
33
36
|
This will install a list of dependencies on the specified host from the forge, using the dependencies list specified in the metadata.json file, taking into consideration the version constraints if specified.
|
34
37
|
|
38
|
+
**See: ** [Alternative Forge Instances](#alternative-forge-instances)
|
39
|
+
|
40
|
+
### `install_module_from_forge(module_name, version_requirement)`
|
41
|
+
This will call `install_module_from_forge_on` on the hosts with role 'master'. If there are none, the module will be install on all hosts with the role 'agent', again, if there are none, the module will be installed on all hosts.
|
42
|
+
|
43
|
+
### `install_module_from_forge_on(hosts, module_name, version_requirement)`
|
44
|
+
This will install a module from the forge on the given host(s). Module name must be specified in the {author}-{module_name} or {author}/{module_name} format. Version requirement must be specified to meet [this](https://docs.puppet.com/puppet/latest/modules_metadata.html#version-specifiers) criteria.
|
45
|
+
|
46
|
+
**See: ** [Alternative Forge Instances](#alternative-forge-instances)
|
47
|
+
|
48
|
+
### Alternative Forge Instances
|
49
|
+
It is possible to use alternative forge instances rather than the production forge instance to install module dependencies by specifiying 2 environment variables, `BEAKER_FORGE_HOST` and `BEAKER_FORGE_API`. Both of these are required as the forge API is used under the hood to resolve version requirement boundary strings.
|
50
|
+
|
51
|
+
**Example Using Staging Forge**
|
52
|
+
```
|
53
|
+
BEAKER_FORGE_HOST=https://module-staging.puppetlabs.com BEAKER_FORGE_API=https://api-module-staging.puppetlabs.com BEAKER_debug=true bundle exec rspec spec/acceptance
|
54
|
+
```
|
55
|
+
|
35
56
|
### Support
|
36
57
|
No support is supplied or implied. Use at your own risk.
|
@@ -21,22 +21,45 @@ module Beaker::ModuleInstallHelper
|
|
21
21
|
|
22
22
|
# This method calls the install_module_dependencies_on method for each
|
23
23
|
# host which is a master, or if no master is present, on all agent nodes.
|
24
|
-
def install_module_dependencies
|
25
|
-
install_module_dependencies_on(
|
24
|
+
def install_module_dependencies(deps = nil)
|
25
|
+
install_module_dependencies_on(hosts_to_install_module_on, deps)
|
26
26
|
end
|
27
27
|
|
28
28
|
# This method will install the module under tests module dependencies on the
|
29
|
-
# specified host from the dependencies list in metadata.json
|
30
|
-
def install_module_dependencies_on(
|
31
|
-
|
32
|
-
deps = module_dependencies_from_metadata
|
33
|
-
|
29
|
+
# specified host(s) from the dependencies list in metadata.json
|
30
|
+
def install_module_dependencies_on(hsts, deps = nil)
|
31
|
+
hsts = [hsts] if hsts.is_a?(Hash)
|
32
|
+
deps = deps.nil? ? module_dependencies_from_metadata : deps
|
33
|
+
|
34
|
+
fh = ENV['BEAKER_FORGE_HOST']
|
35
|
+
|
36
|
+
hsts.each do |host|
|
34
37
|
deps.each do |dep|
|
35
|
-
|
38
|
+
if fh.nil?
|
39
|
+
install_puppet_module_via_pmt_on(host, dep)
|
40
|
+
else
|
41
|
+
with_forge_stubbed_on(host) do
|
42
|
+
install_puppet_module_via_pmt_on(host, dep)
|
43
|
+
end
|
44
|
+
end
|
36
45
|
end
|
37
46
|
end
|
38
47
|
end
|
39
48
|
|
49
|
+
def install_module_from_forge(mod_name, ver_req)
|
50
|
+
install_module_from_forge_on(hosts_to_install_module_on, mod_name, ver_req)
|
51
|
+
end
|
52
|
+
|
53
|
+
def install_module_from_forge_on(hsts, mod_name, ver_req)
|
54
|
+
mod_name.sub!('/', '-')
|
55
|
+
dependency = {
|
56
|
+
module_name: mod_name,
|
57
|
+
version: module_version_from_requirement(mod_name, ver_req)
|
58
|
+
}
|
59
|
+
|
60
|
+
install_module_dependencies_on(hsts, [dependency])
|
61
|
+
end
|
62
|
+
|
40
63
|
# This method returns an array of dependencies from the metadata.json file
|
41
64
|
# in the format of an array of hashes, containing :module_name and optionally
|
42
65
|
# :version elements. If no dependencies are specified, empty array is returned
|
@@ -63,7 +86,7 @@ module Beaker::ModuleInstallHelper
|
|
63
86
|
# and upper bounds. The function then uses the forge rest endpoint to find
|
64
87
|
# the most recent release of the given module matching the version requirement
|
65
88
|
def module_version_from_requirement(mod_name, vr_str)
|
66
|
-
uri = URI("
|
89
|
+
uri = URI("#{forge_api}/v3/modules/#{mod_name}")
|
67
90
|
response = Net::HTTP.get(uri)
|
68
91
|
forge_data = JSON.parse(response)
|
69
92
|
|
@@ -75,7 +98,7 @@ module Beaker::ModuleInstallHelper
|
|
75
98
|
return rel['version'] if vrs.all? { |vr| vr.match?('', rel['version']) }
|
76
99
|
end
|
77
100
|
|
78
|
-
raise "No release version found matching '#{
|
101
|
+
raise "No release version found matching '#{vr_str}'"
|
79
102
|
end
|
80
103
|
|
81
104
|
# This method takes a version requirement string as specified in the link
|
@@ -144,6 +167,22 @@ module Beaker::ModuleInstallHelper
|
|
144
167
|
end
|
145
168
|
module_source_dir
|
146
169
|
end
|
170
|
+
|
171
|
+
def forge_host
|
172
|
+
fh = ENV['BEAKER_FORGE_HOST']
|
173
|
+
return fh unless fh.nil?
|
174
|
+
'https://forge.puppet.com/'
|
175
|
+
end
|
176
|
+
|
177
|
+
def forge_api
|
178
|
+
fh = forge_host
|
179
|
+
return 'https://forgeapi.puppetlabs.com' if fh == 'https://forge.puppet.com/'
|
180
|
+
|
181
|
+
fa = ENV['BEAKER_FORGE_API']
|
182
|
+
return fa.gsub(/\/$/, '') unless fa.nil?
|
183
|
+
|
184
|
+
raise 'Must specify BEAKER_FORGE_API env variable when specifying custom forge host'
|
185
|
+
end
|
147
186
|
end
|
148
187
|
|
149
188
|
include Beaker::ModuleInstallHelper
|
@@ -218,6 +218,55 @@ describe Beaker::ModuleInstallHelper do
|
|
218
218
|
end
|
219
219
|
end
|
220
220
|
|
221
|
+
context 'forge_host' do
|
222
|
+
context 'without env variables specified' do
|
223
|
+
it 'returns production forge host' do
|
224
|
+
allow(ENV).to receive(:[]).with('BEAKER_FORGE_HOST').and_return(nil)
|
225
|
+
|
226
|
+
expect(forge_host).to eq('https://forge.puppet.com/')
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
context 'with BEAKER_FORGE_HOST env variable specified' do
|
231
|
+
it 'returns specified forge host' do
|
232
|
+
allow(ENV).to receive(:[]).with('BEAKER_FORGE_HOST').and_return('http://anotherhost1.com')
|
233
|
+
|
234
|
+
expect(forge_host).to eq('http://anotherhost1.com')
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
context 'forge_api' do
|
240
|
+
context 'without env variables specified' do
|
241
|
+
it 'returns production forge api' do
|
242
|
+
allow(ENV).to receive(:[]).with('BEAKER_FORGE_HOST').and_return(nil)
|
243
|
+
allow(ENV).to receive(:[]).with('BEAKER_FORGE_API').and_return(nil)
|
244
|
+
|
245
|
+
expect(forge_api).to eq('https://forgeapi.puppetlabs.com')
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
context 'with BEAKER_FORGE_HOST and BEAKER_FORGE_API env variables specified' do
|
250
|
+
context 'without trailing slash' do
|
251
|
+
it 'returns specified forge api' do
|
252
|
+
allow(ENV).to receive(:[]).with('BEAKER_FORGE_HOST').and_return('custom')
|
253
|
+
allow(ENV).to receive(:[]).with('BEAKER_FORGE_API').and_return('an-api-url')
|
254
|
+
|
255
|
+
expect(forge_api).to eq('an-api-url')
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
context 'with trailing slash' do
|
260
|
+
it 'returns specified forge api without trailing slash' do
|
261
|
+
allow(ENV).to receive(:[]).with('BEAKER_FORGE_HOST').and_return('custom')
|
262
|
+
allow(ENV).to receive(:[]).with('BEAKER_FORGE_API').and_return('an-api-url/')
|
263
|
+
|
264
|
+
expect(forge_api).to eq('an-api-url')
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
221
270
|
context 'install_module_dependencies_on' do
|
222
271
|
before do
|
223
272
|
allow_any_instance_of(described_class)
|
@@ -285,4 +334,22 @@ describe Beaker::ModuleInstallHelper do
|
|
285
334
|
end
|
286
335
|
end
|
287
336
|
end
|
337
|
+
|
338
|
+
context 'install_module_from_forge_on' do
|
339
|
+
let(:a_host) { { name: 'a_host' } }
|
340
|
+
let(:dependency) { { module_name: 'puppetlabs-stdlib', version: '4.14.0' } }
|
341
|
+
let(:input_module_name) { 'puppetlabs/stdlib' }
|
342
|
+
let(:input_module_version_requirement) { '>= 4.13.1 <= 4.14.0' }
|
343
|
+
|
344
|
+
before do
|
345
|
+
expect_any_instance_of(Beaker::DSL::InstallUtils::ModuleUtils)
|
346
|
+
.to receive(:install_puppet_module_via_pmt_on)
|
347
|
+
.with(a_host, dependency)
|
348
|
+
.exactly(1)
|
349
|
+
end
|
350
|
+
|
351
|
+
it 'installs the module' do
|
352
|
+
install_module_from_forge_on(a_host, input_module_name, input_module_version_requirement)
|
353
|
+
end
|
354
|
+
end
|
288
355
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beaker-module_install_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
81
|
rubyforge_project:
|
82
|
-
rubygems_version: 2.
|
82
|
+
rubygems_version: 2.6.8
|
83
83
|
signing_key:
|
84
84
|
specification_version: 4
|
85
85
|
summary: A helper gem for use in a Puppet Modules spec_helper_acceptance.rb file
|