voxpupuli-acceptance 0.1.1 → 0.2.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/voxpupuli/acceptance/fixtures.rb +143 -0
- data/lib/voxpupuli/acceptance/spec_helper_acceptance.rb +17 -5
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cca558c11482ae56a56730bfb6f7cf338832496721011e9ab0a632925c30ecf
|
4
|
+
data.tar.gz: 9e7d7bb02cea97d8a8e0c76d55f0ae206e63906485816aaaef9714b5ec583482
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a655542ad8013e3d68411fa0acc005be3355c92787ef710a78e0861ae68ade67b7e7cedc13073cb2cc1c0055897e7f5c22edff62bf25dcff7d18694198b81580
|
7
|
+
data.tar.gz: 7d634ac527d99123981ddd1a21be72e5cc588ed55e9445941c1e080aa701eaab845b6524d3fc1c0a097f39f92ba11359520249b84aac999100b64f9a1063c828
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'tmpdir'
|
2
|
+
require 'puppet/modulebuilder'
|
3
|
+
|
4
|
+
module Voxpupupli
|
5
|
+
module Acceptance
|
6
|
+
class Fixtures
|
7
|
+
class << self
|
8
|
+
# Install fixture modules on the given hosts
|
9
|
+
#
|
10
|
+
# @param [Host, Array<Host>, String, Symbol] hosts
|
11
|
+
# The beaker hosts to run on
|
12
|
+
# @param [Array<String>, String] modulepath
|
13
|
+
# A modulepath as Puppet uses it. Typically spec/fixtures/modules
|
14
|
+
# @param [Logger, nil] logger
|
15
|
+
# An optional logger
|
16
|
+
def install_fixture_modules_on(hosts, modulepath, logger = nil)
|
17
|
+
Dir.mktmpdir do |destination|
|
18
|
+
modules = build_modules(modulepath, destination, logger)
|
19
|
+
|
20
|
+
install_modules_on(hosts, modules, logger)
|
21
|
+
end
|
22
|
+
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
# Build modules in the given sources.
|
27
|
+
#
|
28
|
+
# @param [Array<String>, String] modulepath
|
29
|
+
# A modulepath as Puppet uses it
|
30
|
+
# @param [String] destination
|
31
|
+
# The target directory to build modules into
|
32
|
+
# @param [Logger, nil] logger
|
33
|
+
# An optional logger
|
34
|
+
#
|
35
|
+
# @return [Hash<String=>String>]
|
36
|
+
# A mapping of module names and the path to their tarball
|
37
|
+
def build_modules(modulepath, destination, logger = nil)
|
38
|
+
modulepath = [modulepath] if modulepath.is_a?(String)
|
39
|
+
|
40
|
+
modules = {}
|
41
|
+
|
42
|
+
modulepath.each do |dir|
|
43
|
+
Dir[File.join(dir, '*', 'metadata.json')].each do |metadata|
|
44
|
+
path = File.dirname(metadata)
|
45
|
+
name = File.basename(path)
|
46
|
+
next if modules.include?(name)
|
47
|
+
|
48
|
+
builder = Puppet::Modulebuilder::Builder.new(File.realpath(path), destination, logger)
|
49
|
+
|
50
|
+
unless valid_directory_name?(name, builder.metadata['name'])
|
51
|
+
warning = "Directory name of #{path} doesn't match metadata name #{builder.metadata['name']}"
|
52
|
+
if logger
|
53
|
+
logger.warn(warning)
|
54
|
+
else
|
55
|
+
STDERR.puts(warning)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
modules[name] = builder.build
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
modules
|
64
|
+
end
|
65
|
+
|
66
|
+
# Install modules on a number of hosts
|
67
|
+
#
|
68
|
+
# This is done by iterating over every host. On that host a temporary
|
69
|
+
# directory is created. Each module is copied there and installed by
|
70
|
+
# force.
|
71
|
+
#
|
72
|
+
# @param [Host, Array<Host>, String, Symbol] hosts
|
73
|
+
# The beaker hosts to run on
|
74
|
+
# @param [Hash<String=>String>] modules
|
75
|
+
# A mapping between module names and their tarball
|
76
|
+
# @param [Logger, nil] logger
|
77
|
+
# An optional logger
|
78
|
+
def install_modules_on(hosts, modules, logger = nil)
|
79
|
+
hosts.each do |host|
|
80
|
+
logger.debug("Installing modules on #{host}") if logger
|
81
|
+
|
82
|
+
temp_dir_on(host) do |target_dir|
|
83
|
+
modules.each do |name, source_path|
|
84
|
+
target_file = File.join(target_dir, File.basename(source_path))
|
85
|
+
logger.debug("Copying module #{name} from #{source_path} to #{target_file}") if logger
|
86
|
+
|
87
|
+
scp_to(host, source_path, target_file)
|
88
|
+
on host, puppet("module install --force --ignore-dependencies '#{target_file}'")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
nil
|
94
|
+
end
|
95
|
+
|
96
|
+
# Create a temporay directory on the host, similar to Dir.mktmpdir but
|
97
|
+
# on a remote host.
|
98
|
+
#
|
99
|
+
# @example
|
100
|
+
# temp_dir_on(host) { |dir| puts dir }
|
101
|
+
#
|
102
|
+
# @param [Host, String, Symbol] host
|
103
|
+
# The beaker host to run on
|
104
|
+
def temp_dir_on(host, &block)
|
105
|
+
result = on host, "mktemp -d"
|
106
|
+
raise "Could not create directory" unless result.success?
|
107
|
+
|
108
|
+
dir = result.stdout.strip
|
109
|
+
|
110
|
+
begin
|
111
|
+
yield dir
|
112
|
+
ensure
|
113
|
+
on host, "rm -rf #{dir}"
|
114
|
+
end
|
115
|
+
|
116
|
+
nil
|
117
|
+
end
|
118
|
+
|
119
|
+
# Validate a directory name matches its metadata name.
|
120
|
+
#
|
121
|
+
# This is useful to detect misconfigurations in fixture set ups.
|
122
|
+
#
|
123
|
+
# @example
|
124
|
+
# assert valid_directory_name?('tftp', 'theforeman-tftp')
|
125
|
+
# @example
|
126
|
+
# refute valid_directory_name?('puppet-tftp', 'theforeman-tftp')
|
127
|
+
#
|
128
|
+
# @param [String] directory_name
|
129
|
+
# Name of the directory. Not the full path
|
130
|
+
# @param [String] metadata_name
|
131
|
+
# Name as it shows up in the metadata. It is normalized and accepts
|
132
|
+
# both / and - as separators.
|
133
|
+
#
|
134
|
+
# @return [Boolean] Wether the directory name is valid with the given
|
135
|
+
# metadata name
|
136
|
+
def valid_directory_name?(directory_name, metadata_name)
|
137
|
+
normalized = metadata_name.tr('/', '-').split('-').last
|
138
|
+
normalized == directory_name
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
def configure_beaker(&block)
|
1
|
+
def configure_beaker(modules: :metadata, &block)
|
2
2
|
ENV['PUPPET_INSTALL_TYPE'] ||= 'agent'
|
3
3
|
ENV['BEAKER_PUPPET_COLLECTION'] ||= 'puppet6'
|
4
4
|
ENV['BEAKER_debug'] ||= 'true'
|
@@ -7,8 +7,14 @@ def configure_beaker(&block)
|
|
7
7
|
require 'beaker-rspec'
|
8
8
|
require 'beaker-puppet'
|
9
9
|
require 'beaker/puppet_install_helper'
|
10
|
-
|
11
|
-
|
10
|
+
|
11
|
+
case modules
|
12
|
+
when :metadata
|
13
|
+
require 'beaker/module_install_helper'
|
14
|
+
$module_source_dir = get_module_source_directory caller
|
15
|
+
when :fixtures
|
16
|
+
require_relative 'fixtures'
|
17
|
+
end
|
12
18
|
|
13
19
|
run_puppet_install_helper unless ENV['BEAKER_provision'] == 'no'
|
14
20
|
|
@@ -18,8 +24,14 @@ def configure_beaker(&block)
|
|
18
24
|
|
19
25
|
# Configure all nodes in nodeset
|
20
26
|
c.before :suite do
|
21
|
-
|
22
|
-
|
27
|
+
case modules
|
28
|
+
when :metadata
|
29
|
+
install_module
|
30
|
+
install_module_dependencies
|
31
|
+
when :fixtures
|
32
|
+
fixture_modules = File.join(Dir.pwd, 'spec', 'fixtures', 'modules')
|
33
|
+
Voxpupupli::Acceptance::Fixtures.install_fixture_modules_on(hosts, fixture_modules)
|
34
|
+
end
|
23
35
|
|
24
36
|
if block
|
25
37
|
hosts.each do |host|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: voxpupuli-acceptance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vox Pupuli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bcrypt_pbkdf
|
@@ -150,6 +150,20 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: puppet-modulebuilder
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0.1'
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0.1'
|
153
167
|
- !ruby/object:Gem::Dependency
|
154
168
|
name: rbnacl
|
155
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -215,6 +229,7 @@ extensions: []
|
|
215
229
|
extra_rdoc_files: []
|
216
230
|
files:
|
217
231
|
- lib/voxpupuli/acceptance.rb
|
232
|
+
- lib/voxpupuli/acceptance/fixtures.rb
|
218
233
|
- lib/voxpupuli/acceptance/spec_helper_acceptance.rb
|
219
234
|
homepage: http://github.com/voxpupuli/voxpupuli-acceptance
|
220
235
|
licenses:
|
@@ -235,8 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
235
250
|
- !ruby/object:Gem::Version
|
236
251
|
version: '0'
|
237
252
|
requirements: []
|
238
|
-
|
239
|
-
rubygems_version: 2.7.10
|
253
|
+
rubygems_version: 3.0.6
|
240
254
|
signing_key:
|
241
255
|
specification_version: 4
|
242
256
|
summary: Helpers for acceptance testing Vox Pupuli modules
|