puppet_litmus 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +201 -0
- data/README.md +44 -0
- data/lib/puppet_litmus/rake_tasks.rb +269 -0
- data/lib/puppet_litmus/version.rb +6 -0
- data/lib/puppet_litmus.rb +161 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 418acded5bb7ca19c9a011892b89b805aaedd642be7e94d004f038640d144c28
|
4
|
+
data.tar.gz: 20082a2cba1921b73cfb1a0324709253b6f74318916c8c302c8eb917cf7ad2f3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d55ceaa23d4df5e1aed93363f2d3ecd725817064003630728887fb5f10262f079e89e60dc69b86e05f22e560d98f9b9ea1dcf5cad4fc419ad2d56766b538e499
|
7
|
+
data.tar.gz: d27be055768592ccdbc603b374787a2f4ce555f6c8649bcee071a5beaece65e699bd4cc2b7b22ece8706cb1ecc3ffa26752afd6d61477b9dd443866d20c50e68
|
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Litmus
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
Litmus provides a simple command line tool for Puppet content creators, to enable both simple and complex test deployments against specifically configured target systems. It is available as a gem, and can be installed by running ```gem install puppet-litmus```.
|
5
|
+
|
6
|
+
Litmus allows Puppet module developers to:
|
7
|
+
* provision targets to test against,
|
8
|
+
* install the Puppet Agent,
|
9
|
+
* install a module,
|
10
|
+
* run tests, and
|
11
|
+
* tear down the infrastructure.
|
12
|
+
|
13
|
+
The tool facilitates parallel test runs, running tests in isolation, and each step is standalone, allowing other operations between test runs, such as debugging, or configuration updates on the test targets.
|
14
|
+
|
15
|
+
## Documentation
|
16
|
+
|
17
|
+
All our documentation is currently available in the [Wiki](https://github.com/puppetlabs/puppet_litmus/wiki).
|
18
|
+
|
19
|
+
* [Overview](https://github.com/puppetlabs/puppet_litmus/wiki/Overview-of-Litmus) of the main functions
|
20
|
+
* [Architecture](https://github.com/puppetlabs/puppet_litmus/wiki/Architecture-of-puppet-litmus) with an explanation of what's going on under the hood
|
21
|
+
* [Step-by-step guide](https://github.com/puppetlabs/puppet_litmus/wiki/Tutorial:-use-Litmus-to-execute-acceptance-tests-with-a-sample-module-(MoTD)) of how to use Litmus with the popular and simple [MoTD Puppet module](https://forge.puppet.com/puppetlabs/motd).
|
22
|
+
* [How to guide](https://github.com/puppetlabs/puppet_litmus/wiki/Converting-a-module-to-use-Litmus) walking through how to use Litmus in a module
|
23
|
+
|
24
|
+
## Known issues
|
25
|
+
|
26
|
+
### PDK and Bolt dependencies infers support on Ruby and Puppet versions
|
27
|
+
|
28
|
+
We are actively working towards the point that where we declare our gem dependencies for PDK and Bolt gems in the puppet_litmus gemspec file [here](https://github.com/puppetlabs/puppet_litmus/blame/master/puppet_litmus.gemspec#L23)
|
29
|
+
|
30
|
+
Bolt has a hard dependency on Puppet 6, and CRI 2.15.1 which is ruby version specific
|
31
|
+
|
32
|
+
PDK depends on CRI 2.10.0 which is ruby version specific
|
33
|
+
|
34
|
+
We have work in progress to create a pathway through this. A fix is up for PDK, which allows CRI 2.15 and 2.10 to be used (here)[https://github.com/puppetlabs/pdk/pull/638]. This also allows the use of multiple ruby versions.
|
35
|
+
|
36
|
+
A PR (here)[https://github.com/puppetlabs/puppetlabs-motd/pull/200] shows what needs to happen within a module, to use litmus for puppet 5 unit tests, and puppet 6 unit tests. Also for running acceptance tests against puppet 5 and puppet 6 with litmus.
|
37
|
+
|
38
|
+
(Gem changes for a module)[https://github.com/puppetlabs/puppetlabs-motd/blob/29d8c9b0ceceb4b0114a66077ce0f473a49481a5/Gemfile#L34-L39] it only installs litmus if your are running puppet 6 and system tests. Also to use a version of the pdk that has the CRI fixes. You can still test against puppet 5 targets in acceptance tests. IF you want to run unit tests against the puppet 5 gem you will have to run something like (this)[https://github.com/puppetlabs/puppetlabs-motd/blob/29d8c9b0ceceb4b0114a66077ce0f473a49481a5/.travis.yml#L107]
|
39
|
+
|
40
|
+
Thank you for your patience.
|
41
|
+
|
42
|
+
## Other Resources
|
43
|
+
|
44
|
+
* [Is it Worth the Time?](https://xkcd.com/1205/)
|
@@ -0,0 +1,269 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
require 'puppet_litmus'
|
5
|
+
require 'bolt_spec/run'
|
6
|
+
require 'open3'
|
7
|
+
require 'pdk'
|
8
|
+
require 'json'
|
9
|
+
require 'parallel'
|
10
|
+
|
11
|
+
def get_metadata_operating_systems(metadata)
|
12
|
+
return unless metadata.is_a?(Hash)
|
13
|
+
return unless metadata['operatingsystem_support'].is_a?(Array)
|
14
|
+
|
15
|
+
metadata['operatingsystem_support'].each do |os_info|
|
16
|
+
next unless os_info['operatingsystem'] && os_info['operatingsystemrelease']
|
17
|
+
|
18
|
+
os_name = case os_info['operatingsystem']
|
19
|
+
when 'Amazon', 'Archlinux', 'AIX', 'OSX'
|
20
|
+
next
|
21
|
+
when 'OracleLinux'
|
22
|
+
'oracle'
|
23
|
+
when 'Windows'
|
24
|
+
'win'
|
25
|
+
else
|
26
|
+
os_info['operatingsystem'].downcase
|
27
|
+
end
|
28
|
+
|
29
|
+
os_info['operatingsystemrelease'].each do |release|
|
30
|
+
version = case os_name
|
31
|
+
when 'ubuntu', 'osx'
|
32
|
+
release.sub('.', '')
|
33
|
+
when 'sles'
|
34
|
+
release.gsub(%r{ SP[14]}, '')
|
35
|
+
when 'win'
|
36
|
+
release = release.delete('.') if release.include? '8.1'
|
37
|
+
release.sub('Server', '').sub('10', '10-pro')
|
38
|
+
else
|
39
|
+
release
|
40
|
+
end
|
41
|
+
|
42
|
+
yield "#{os_name}-#{version.downcase}-x86_64".delete(' ')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def run_local_command(command)
|
48
|
+
stdout, stderr, status = Open3.capture3(command)
|
49
|
+
error_message = "Attempted to run\ncommand:'#{command}'\nstdout:#{stdout}\nstderr:#{stderr}"
|
50
|
+
raise error_message unless status.to_i.zero?
|
51
|
+
|
52
|
+
stdout
|
53
|
+
end
|
54
|
+
|
55
|
+
namespace :litmus do
|
56
|
+
desc 'print all supported OSes from metadata'
|
57
|
+
task :metadata do
|
58
|
+
metadata = JSON.parse(File.read('metadata.json'))
|
59
|
+
get_metadata_operating_systems(metadata) do |os_and_version|
|
60
|
+
puts os_and_version
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "provision all supported OSes on with abs eg 'bundle exec rake 'litmus:provision_from_metadata'"
|
65
|
+
task :provision_from_metadata, [:provisioner] do |_task, args|
|
66
|
+
metadata = JSON.parse(File.read('metadata.json'))
|
67
|
+
get_metadata_operating_systems(metadata) do |os_and_version|
|
68
|
+
puts os_and_version
|
69
|
+
include PuppetLitmus
|
70
|
+
Rake::Task['spec_prep'].invoke
|
71
|
+
config_data = { 'modulepath' => File.join(Dir.pwd, 'spec', 'fixtures', 'modules') }
|
72
|
+
raise "the provision module was not found in #{config_data['modulepath']}, please amend the .fixtures.yml file" unless File.directory?(File.join(config_data['modulepath'], 'provision'))
|
73
|
+
|
74
|
+
params = { 'action' => 'provision', 'platform' => os_and_version, 'inventory' => Dir.pwd }
|
75
|
+
results = run_task("provision::#{args[:provisioner]}", 'localhost', params, config: config_data, inventory: nil)
|
76
|
+
results.each do |result|
|
77
|
+
if result['status'] != 'success'
|
78
|
+
puts "Failed on #{result['node']}\n#{result}"
|
79
|
+
else
|
80
|
+
puts "Provisioned #{result['result']['node_name']}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
desc "provision list of machines from provision.yaml file. 'bundle exec rake 'litmus:provision_list[default]'"
|
87
|
+
task :provision_list, [:key] do |_task, args|
|
88
|
+
provision_hash = YAML.load_file('./provision.yaml')
|
89
|
+
provisioner = provision_hash[args[:key]]['provisioner']
|
90
|
+
provision_hash[args[:key]]['images'].each do |image|
|
91
|
+
Rake::Task['litmus:provision'].invoke(provisioner, image)
|
92
|
+
Rake::Task['litmus:provision'].reenable
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
desc "provision container/VM - abs/docker/vmpooler eg 'bundle exec rake 'litmus:provision[vmpooler, ubuntu-1604-x86_64]'"
|
97
|
+
task :provision, [:provisioner, :platform] do |_task, args|
|
98
|
+
include PuppetLitmus
|
99
|
+
Rake::Task['spec_prep'].invoke
|
100
|
+
config_data = { 'modulepath' => File.join(Dir.pwd, 'spec', 'fixtures', 'modules') }
|
101
|
+
raise "the provision module was not found in #{config_data['modulepath']}, please amend the .fixtures.yml file" unless File.directory?(File.join(config_data['modulepath'], 'provision'))
|
102
|
+
|
103
|
+
if %w[abs vmpooler].include?(args[:provisioner])
|
104
|
+
params = { 'action' => 'provision', 'platform' => args[:platform], 'inventory' => Dir.pwd }
|
105
|
+
results = run_task("provision::#{args[:provisioner]}", 'localhost', params, config: config_data, inventory: nil)
|
106
|
+
results.each do |result|
|
107
|
+
if result['status'] != 'success'
|
108
|
+
puts "Failed #{result['node']}\n#{result}"
|
109
|
+
else
|
110
|
+
puts "#{result['result']['node_name']}, #{args[:platform]}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
elsif args[:provisioner] == 'docker'
|
114
|
+
params = { 'action' => 'provision', 'platform' => args[:platform], 'inventory' => Dir.pwd }
|
115
|
+
results = run_task('provision::docker', 'localhost', params, config: config_data, inventory: nil)
|
116
|
+
results.each do |result|
|
117
|
+
if result['status'] != 'success'
|
118
|
+
puts "Failed #{result['node']}\n#{result}"
|
119
|
+
else
|
120
|
+
puts "#{result['result']['node_name']}, #{args[:platform]}"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
else
|
124
|
+
raise "Unknown provisioner '#{args[:provisioner]}', try abs/docker/vmpooler"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
desc 'install puppet agent, [:collection, :target_node_name]'
|
129
|
+
task :install_agent, [:collection, :target_node_name] do |_task, args|
|
130
|
+
puts 'install_agent'
|
131
|
+
include BoltSpec::Run
|
132
|
+
inventory_hash = inventory_hash_from_inventory_file
|
133
|
+
targets = find_targets(inventory_hash, args[:target_node_name])
|
134
|
+
Rake::Task['spec_prep'].invoke
|
135
|
+
config_data = { 'modulepath' => File.join(Dir.pwd, 'spec', 'fixtures', 'modules') }
|
136
|
+
params = if args[:collection].nil?
|
137
|
+
{}
|
138
|
+
else
|
139
|
+
{ 'collection' => args[:collection] }
|
140
|
+
end
|
141
|
+
raise "puppet_agent was not found in #{config_data['modulepath']}, please amend the .fixtures.yml file" unless File.directory?(File.join(config_data['modulepath'], 'puppet_agent'))
|
142
|
+
|
143
|
+
results = run_task('puppet_agent::install', targets, params, config: config_data, inventory: inventory_hash)
|
144
|
+
results.each do |result|
|
145
|
+
if result['status'] != 'success'
|
146
|
+
puts "Failed on #{result['node']}\n#{result}"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# fix the path on ssh_nodes
|
151
|
+
results = run_command('echo PATH="$PATH:/opt/puppetlabs/puppet/bin" > /etc/environment', 'ssh_nodes', config: nil, inventory: inventory_hash) unless inventory_hash['groups'].select { |group| group['name'] == 'ssh_nodes' }.size.zero? # rubocop:disable Metrics/LineLength
|
152
|
+
results.each do |result|
|
153
|
+
if result['status'] != 'success'
|
154
|
+
puts "Failed on #{result['node']}\n#{result}"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
desc 'install_module - build and install module'
|
160
|
+
task :install_module, [:target_node_name] do |_task, args|
|
161
|
+
include BoltSpec::Run
|
162
|
+
# old cli_way
|
163
|
+
# pdk_build_command = 'bundle exec pdk build --force'
|
164
|
+
# stdout, stderr, _status = Open3.capture3(pdk_build_command)
|
165
|
+
# raise "Failed to run 'pdk_build_command',#{stdout} and #{stderr}" if (stderr =~ %r{completed successfully}).nil?
|
166
|
+
require 'pdk/module/build'
|
167
|
+
opts = {}
|
168
|
+
opts[:force] = true
|
169
|
+
builder = PDK::Module::Build.new(opts)
|
170
|
+
module_tar = builder.build
|
171
|
+
puts 'Built'
|
172
|
+
|
173
|
+
inventory_hash = inventory_hash_from_inventory_file
|
174
|
+
target_nodes = find_targets(inventory_hash, args[:target_node_name])
|
175
|
+
# module_tar = Dir.glob('pkg/*.tar.gz').max_by { |f| File.mtime(f) }
|
176
|
+
raise "Unable to find package in 'pkg/*.tar.gz'" if module_tar.nil?
|
177
|
+
|
178
|
+
target_string = if args[:target_node_name].nil?
|
179
|
+
'all'
|
180
|
+
else
|
181
|
+
args[:target_node_name]
|
182
|
+
end
|
183
|
+
run_local_command("bundle exec bolt file upload #{module_tar} /tmp/#{File.basename(module_tar)} --nodes #{target_string} --inventoryfile inventory.yaml")
|
184
|
+
install_module_command = "puppet module install /tmp/#{File.basename(module_tar)}"
|
185
|
+
result = run_command(install_module_command, target_nodes, config: nil, inventory: inventory_hash)
|
186
|
+
# rubocop:disable Style/GuardClause
|
187
|
+
if result.is_a?(Array)
|
188
|
+
result.each do |node|
|
189
|
+
puts "#{node['node']} failed #{node['result']}" if node['status'] != 'success'
|
190
|
+
end
|
191
|
+
else
|
192
|
+
raise "Failed trying to run '#{install_module_command}' against inventory."
|
193
|
+
end
|
194
|
+
# rubocop:enable Style/GuardClause
|
195
|
+
puts 'Installed'
|
196
|
+
end
|
197
|
+
|
198
|
+
desc 'tear-down - decommission machines'
|
199
|
+
task :tear_down, [:target] do |_task, args|
|
200
|
+
Rake::Task['spec_prep'].invoke
|
201
|
+
config_data = { 'modulepath' => File.join(Dir.pwd, 'spec', 'fixtures', 'modules') }
|
202
|
+
raise "the provision module was not found in #{config_data['modulepath']}, please amend the .fixtures.yml file" unless File.directory?(File.join(config_data['modulepath'], 'provision'))
|
203
|
+
|
204
|
+
inventory_hash = inventory_hash_from_inventory_file
|
205
|
+
targets = find_targets(inventory_hash, args[:target])
|
206
|
+
bad_results = []
|
207
|
+
targets.each do |node_name|
|
208
|
+
# how do we know what provisioner to use
|
209
|
+
node_facts = facts_from_node(inventory_hash, node_name)
|
210
|
+
next unless %w[abs docker vmpooler].include?(node_facts['provisioner'])
|
211
|
+
|
212
|
+
params = { 'action' => 'tear_down', 'node_name' => node_name, 'inventory' => Dir.pwd }
|
213
|
+
result = run_task("provision::#{node_facts['provisioner']}", 'localhost', params, config: config_data, inventory: nil)
|
214
|
+
if result.first['status'] != 'success'
|
215
|
+
bad_results << "#{node_name}, #{result.first['result']['_error']['msg']}"
|
216
|
+
else
|
217
|
+
print "#{node_name}, "
|
218
|
+
end
|
219
|
+
end
|
220
|
+
puts ''
|
221
|
+
# output the things that went wrong, after the successes
|
222
|
+
puts 'something went wrong:' unless bad_results.size.zero?
|
223
|
+
bad_results.each do |result|
|
224
|
+
puts result
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
namespace :acceptance do
|
229
|
+
include PuppetLitmus
|
230
|
+
if File.file?('inventory.yaml')
|
231
|
+
inventory_hash = inventory_hash_from_inventory_file
|
232
|
+
hosts = find_targets(inventory_hash, nil)
|
233
|
+
|
234
|
+
desc 'Run tests in parallel against all machines in the inventory file'
|
235
|
+
task :parallel do
|
236
|
+
args = []
|
237
|
+
hosts.each do |host|
|
238
|
+
args << ["TARGET_HOST=#{host} bundle exec rspec ./spec/acceptance --format progress --format html --out html/#{host}.html", host]
|
239
|
+
end
|
240
|
+
results = Parallel.map(args, progress: "Running against #{hosts.size} machines") do |test, host|
|
241
|
+
stdout, stderr, status = Open3.capture3(test)
|
242
|
+
["================\n#{host}\n", stdout, stderr, status]
|
243
|
+
end
|
244
|
+
# if any result is nonzero, there were test failures
|
245
|
+
failures = false
|
246
|
+
results.each do |result|
|
247
|
+
failures = true unless result.last.exitstatus.zero?
|
248
|
+
puts result
|
249
|
+
end
|
250
|
+
exit 1 if failures
|
251
|
+
end
|
252
|
+
|
253
|
+
hosts.each do |host|
|
254
|
+
desc "Run serverspec against #{host}"
|
255
|
+
RSpec::Core::RakeTask.new(host.to_sym) do |t|
|
256
|
+
t.pattern = 'spec/acceptance/**{,/*/**}/*_spec.rb'
|
257
|
+
ENV['TARGET_HOST'] = host
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
# add localhost separately
|
262
|
+
desc 'Run serverspec against localhost, USE WITH CAUTION, this action can be potentially dangerous.'
|
263
|
+
host = 'localhost'
|
264
|
+
RSpec::Core::RakeTask.new(host.to_sym) do |t|
|
265
|
+
t.pattern = 'spec/acceptance/**{,/*/**}/*_spec.rb'
|
266
|
+
ENV['TARGET_HOST'] = host
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bolt_spec/run'
|
4
|
+
|
5
|
+
# Helper methods for testing puppet content
|
6
|
+
module PuppetLitmus
|
7
|
+
include BoltSpec::Run
|
8
|
+
def apply_manifest(manifest, opts = {})
|
9
|
+
target_node_name = ENV['TARGET_HOST']
|
10
|
+
raise 'manifest and manifest_file_location in the opts hash are mutually exclusive arguments, pick one' if !manifest.nil? && !opts[:manifest_file_location].nil?
|
11
|
+
raise 'please pass a manifest or the manifest_file_location in the opts hash' if (manifest.nil? || manifest == '') && opts[:manifest_file_location].nil?
|
12
|
+
|
13
|
+
manifest_file_location = opts[:manifest_file_location] || create_manifest_file(manifest)
|
14
|
+
inventory_hash = if target_node_name.nil? || target_node_name == 'localhost'
|
15
|
+
nil
|
16
|
+
else
|
17
|
+
inventory_hash_from_inventory_file
|
18
|
+
end
|
19
|
+
command_to_run = "puppet apply #{manifest_file_location}"
|
20
|
+
command_to_run += " --modulepath #{Dir.pwd}/spec/fixtures/modules" if target_node_name.nil? || target_node_name == 'localhost'
|
21
|
+
command_to_run += ' --detailed-exitcodes' if !opts[:catch_changes].nil? && (opts[:catch_changes] == true)
|
22
|
+
# BOLT-608
|
23
|
+
if Gem.win_platform?
|
24
|
+
stdout, stderr, status = Open3.capture3(command_to_run)
|
25
|
+
status_text = if status.to_i.zero?
|
26
|
+
'success'
|
27
|
+
else
|
28
|
+
'failure'
|
29
|
+
end
|
30
|
+
result = [{ 'node' => 'localhost', 'status' => status_text, 'result' => { 'exit_code' => status.to_i, 'stderr' => stderr, 'stdout' => stdout } }]
|
31
|
+
else
|
32
|
+
result = run_command(command_to_run, target_node_name, config: nil, inventory: inventory_hash)
|
33
|
+
end
|
34
|
+
|
35
|
+
raise "apply mainfest failed\n`#{command_to_run}`\n======\n#{result}" if result.first['result']['exit_code'] != 0 && opts[:expect_failures] != true
|
36
|
+
|
37
|
+
result
|
38
|
+
end
|
39
|
+
|
40
|
+
# creates a temp manifest file locally & remote depending on target
|
41
|
+
def create_manifest_file(manifest)
|
42
|
+
target_node_name = ENV['TARGET_HOST']
|
43
|
+
manifest_file = Tempfile.new(['manifest_', '.pp'])
|
44
|
+
manifest_file.write(manifest)
|
45
|
+
manifest_file.close
|
46
|
+
if target_node_name.nil? || target_node_name == 'localhost'
|
47
|
+
# no need to transfer
|
48
|
+
manifest_file_location = manifest_file.path
|
49
|
+
else
|
50
|
+
# transfer to TARGET_HOST
|
51
|
+
command = "bundle exec bolt file upload #{manifest_file.path} /tmp/#{File.basename(manifest_file)} --nodes #{target_node_name} --inventoryfile inventory.yaml"
|
52
|
+
stdout, stderr, status = Open3.capture3(command)
|
53
|
+
error_message = "Attempted to run\ncommand:'#{command}'\nstdout:#{stdout}\nstderr:#{stderr}"
|
54
|
+
raise error_message unless status.to_i.zero?
|
55
|
+
|
56
|
+
manifest_file_location = "/tmp/#{File.basename(manifest_file)}"
|
57
|
+
end
|
58
|
+
manifest_file_location
|
59
|
+
end
|
60
|
+
|
61
|
+
def apply_manifest_and_idempotent(manifest)
|
62
|
+
manifest_file_location = create_manifest_file(manifest)
|
63
|
+
apply_manifest(nil, catch_failures: true, manifest_file_location: manifest_file_location)
|
64
|
+
apply_manifest(nil, catch_changes: true, manifest_file_location: manifest_file_location)
|
65
|
+
end
|
66
|
+
|
67
|
+
def run_shell(command_to_run, opts = {})
|
68
|
+
inventory_hash = inventory_hash_from_inventory_file
|
69
|
+
target_node_name = ENV['TARGET_HOST']
|
70
|
+
result = run_command(command_to_run, target_node_name, config: nil, inventory: inventory_hash)
|
71
|
+
|
72
|
+
raise "shell failed\n`#{command_to_run}`\n======\n#{result}" if result.first['result']['exit_code'] != 0 && opts[:expect_failures] != true
|
73
|
+
|
74
|
+
result
|
75
|
+
end
|
76
|
+
|
77
|
+
def inventory_hash_from_inventory_file(inventory_full_path = nil)
|
78
|
+
inventory_full_path = if inventory_full_path.nil?
|
79
|
+
'inventory.yaml'
|
80
|
+
else
|
81
|
+
inventory_full_path
|
82
|
+
end
|
83
|
+
raise "There is no inventory file at '#{inventory_full_path}'" unless File.exist?(inventory_full_path)
|
84
|
+
|
85
|
+
inventory_hash = YAML.load_file(inventory_full_path)
|
86
|
+
inventory_hash
|
87
|
+
end
|
88
|
+
|
89
|
+
def find_targets(inventory_hash, targets)
|
90
|
+
if targets.nil?
|
91
|
+
inventory = Bolt::Inventory.new(inventory_hash, nil)
|
92
|
+
targets = inventory.node_names.to_a
|
93
|
+
else
|
94
|
+
targets = [targets]
|
95
|
+
end
|
96
|
+
targets
|
97
|
+
end
|
98
|
+
|
99
|
+
def target_in_group(inventory_hash, node_name, group_name)
|
100
|
+
exists = false
|
101
|
+
inventory_hash['groups'].each do |group|
|
102
|
+
next unless group['name'] == group_name
|
103
|
+
|
104
|
+
group['nodes'].each do |node|
|
105
|
+
exists = true if node['name'] == node_name
|
106
|
+
end
|
107
|
+
end
|
108
|
+
exists
|
109
|
+
end
|
110
|
+
|
111
|
+
def config_from_node(inventory_hash, node_name)
|
112
|
+
inventory_hash['groups'].each do |group|
|
113
|
+
group['nodes'].each do |node|
|
114
|
+
if node['name'] == node_name
|
115
|
+
return node['config']
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
raise "No config was found for #{node_name}"
|
120
|
+
end
|
121
|
+
|
122
|
+
def facts_from_node(inventory_hash, node_name)
|
123
|
+
inventory_hash['groups'].each do |group|
|
124
|
+
group['nodes'].each do |node|
|
125
|
+
if node['name'] == node_name
|
126
|
+
return node['facts']
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
raise "No config was found for #{node_name}"
|
131
|
+
end
|
132
|
+
|
133
|
+
def add_node_to_group(inventory_hash, node_name, group_name)
|
134
|
+
inventory_hash['groups'].each do |group|
|
135
|
+
if group['name'] == group_name
|
136
|
+
group['nodes'].push node_name
|
137
|
+
end
|
138
|
+
end
|
139
|
+
inventory_hash
|
140
|
+
end
|
141
|
+
|
142
|
+
def remove_node(inventory_hash, node_name)
|
143
|
+
inventory_hash['groups'].each do |group|
|
144
|
+
group['nodes'].delete_if { |i| i['name'] == node_name }
|
145
|
+
end
|
146
|
+
inventory_hash
|
147
|
+
end
|
148
|
+
|
149
|
+
# Runs a selected task against the target host. Parameters should be passed in with a hash format.
|
150
|
+
def task_run(task_name, params)
|
151
|
+
config_data = { 'modulepath' => File.join(Dir.pwd, 'spec', 'fixtures', 'modules') }
|
152
|
+
inventory_hash = inventory_hash_from_inventory_file
|
153
|
+
target_node_name = ENV['TARGET_HOST'] if target_node_name.nil?
|
154
|
+
|
155
|
+
result = run_task(task_name, target_node_name, params, config: config_data, inventory: inventory_hash)
|
156
|
+
|
157
|
+
raise "task failed\n`#{task_name}`\n======\n#{result}" if result.first['status'] != 'success'
|
158
|
+
|
159
|
+
result
|
160
|
+
end
|
161
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: puppet_litmus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Puppet, Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bolt
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.13.1
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.13.1
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: pdk
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 1.10.0
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 2.0.0
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.10.0
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.0.0
|
53
|
+
description: " Providing a simple command line tool for puppet content creators,
|
54
|
+
to enable simple and complex test deployments.\n"
|
55
|
+
email:
|
56
|
+
- info@puppet.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- LICENSE
|
62
|
+
- README.md
|
63
|
+
- lib/puppet_litmus.rb
|
64
|
+
- lib/puppet_litmus/rake_tasks.rb
|
65
|
+
- lib/puppet_litmus/version.rb
|
66
|
+
homepage: https://github.com/puppetlabs/puppet_litmus
|
67
|
+
licenses:
|
68
|
+
- Apache-2.0
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 2.7.6
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: Providing a simple command line tool for puppet content creators, to enable
|
90
|
+
simple and complex test deployments.
|
91
|
+
test_files: []
|