puppet_litmus 0.16.0 → 0.18.3
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/README.md +12 -16
- data/lib/puppet_litmus.rb +0 -30
- data/lib/puppet_litmus/inventory_manipulation.rb +10 -1
- data/lib/puppet_litmus/puppet_helpers.rb +200 -137
- data/lib/puppet_litmus/rake_helper.rb +258 -96
- data/lib/puppet_litmus/rake_tasks.rb +96 -100
- data/lib/puppet_litmus/version.rb +1 -1
- data/spec/lib/puppet_litmus/inventory_manipulation_spec.rb +16 -16
- data/spec/lib/puppet_litmus/puppet_helpers_spec.rb +103 -117
- data/spec/lib/puppet_litmus/rake_helper_spec.rb +79 -27
- data/spec/lib/puppet_litmus/rake_tasks_spec.rb +14 -12
- data/spec/spec_helper.rb +7 -6
- metadata +77 -17
@@ -2,27 +2,62 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
+
RSpec.shared_examples 'supported provisioner' do |args|
|
6
|
+
let(:provisioner) { args[:provisioner] }
|
7
|
+
let(:platform) { args[:platform] }
|
8
|
+
let(:inventory_vars) { args[:inventory_vars] }
|
9
|
+
let(:provision_hash) { args[:provision_hash] }
|
10
|
+
let(:results) { args[:results] }
|
11
|
+
let(:params) { args[:params] }
|
12
|
+
|
13
|
+
it 'calls function' do
|
14
|
+
allow(File).to receive(:directory?).and_call_original
|
15
|
+
allow(File).to receive(:directory?)
|
16
|
+
.with(File.join(described_class::DEFAULT_CONFIG_DATA['modulepath'], 'provision'))
|
17
|
+
.and_return(true)
|
18
|
+
allow_any_instance_of(BoltSpec::Run).to receive(:run_task)
|
19
|
+
.with("provision::#{provisioner}", 'localhost', params, config: described_class::DEFAULT_CONFIG_DATA, inventory: nil)
|
20
|
+
.and_return(results)
|
21
|
+
result = provision(provisioner, platform, inventory_vars)
|
22
|
+
expect(result).to eq(results)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
5
26
|
RSpec.describe PuppetLitmus::RakeHelper do
|
6
27
|
context 'with provision_list' do
|
7
28
|
let(:provision_hash) { { 'default' => { 'provisioner' => 'docker', 'images' => ['waffleimage/centos7'] } } }
|
8
29
|
let(:results) { [] }
|
9
30
|
|
10
31
|
it 'calls function' do
|
11
|
-
expect(
|
12
|
-
|
32
|
+
expect(self).to receive(:provision).with('docker', 'waffleimage/centos7', nil).and_return(results)
|
33
|
+
provision_list(provision_hash, 'default')
|
13
34
|
end
|
14
35
|
end
|
15
36
|
|
16
37
|
context 'with provision' do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
38
|
+
examples = [
|
39
|
+
{
|
40
|
+
provisioner: 'docker',
|
41
|
+
platform: 'waffleimage/centos7',
|
42
|
+
inventory_vars: nil,
|
43
|
+
provision_hash: { 'default' => { 'provisioner' => 'docker', 'images' => ['waffleimage/centos7'] } },
|
44
|
+
results: [],
|
45
|
+
params: { 'action' => 'provision', 'platform' => 'waffleimage/centos7', 'inventory' => Dir.pwd },
|
46
|
+
},
|
47
|
+
{
|
48
|
+
provisioner: 'vagrant',
|
49
|
+
platform: 'centos7',
|
50
|
+
inventory_vars: nil,
|
51
|
+
provision_hash: { 'default' => { 'provisioner' => 'vagrant', 'images' => ['centos7'] } },
|
52
|
+
results: [],
|
53
|
+
params: { 'action' => 'provision', 'platform' => 'centos7', 'inventory' => Dir.pwd },
|
54
|
+
},
|
55
|
+
].freeze
|
56
|
+
|
57
|
+
examples.each do |e|
|
58
|
+
describe e[:provisioner] do
|
59
|
+
it_behaves_like 'supported provisioner', e
|
60
|
+
end
|
26
61
|
end
|
27
62
|
end
|
28
63
|
|
@@ -36,9 +71,9 @@ RSpec.describe PuppetLitmus::RakeHelper do
|
|
36
71
|
let(:params) { { 'action' => 'tear_down', 'node_name' => 'some.host', 'inventory' => Dir.pwd } }
|
37
72
|
|
38
73
|
it 'calls function' do
|
39
|
-
allow(File).to receive(:directory?).with(File.join(DEFAULT_CONFIG_DATA['modulepath'], 'provision')).and_return(true)
|
40
|
-
allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with('provision::docker', 'localhost', params, config: DEFAULT_CONFIG_DATA, inventory: nil).and_return([])
|
41
|
-
|
74
|
+
allow(File).to receive(:directory?).with(File.join(described_class::DEFAULT_CONFIG_DATA['modulepath'], 'provision')).and_return(true)
|
75
|
+
allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with('provision::docker', 'localhost', params, config: described_class::DEFAULT_CONFIG_DATA, inventory: nil).and_return([])
|
76
|
+
tear_down_nodes(targets, inventory_hash)
|
42
77
|
end
|
43
78
|
end
|
44
79
|
|
@@ -52,9 +87,9 @@ RSpec.describe PuppetLitmus::RakeHelper do
|
|
52
87
|
let(:params) { { 'collection' => 'puppet6' } }
|
53
88
|
|
54
89
|
it 'calls function' do
|
55
|
-
allow(File).to receive(:directory?).with(File.join(DEFAULT_CONFIG_DATA['modulepath'], 'puppet_agent')).and_return(true)
|
56
|
-
allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with('puppet_agent::install', targets, params, config: DEFAULT_CONFIG_DATA, inventory: inventory_hash).and_return([])
|
57
|
-
|
90
|
+
allow(File).to receive(:directory?).with(File.join(described_class::DEFAULT_CONFIG_DATA['modulepath'], 'puppet_agent')).and_return(true)
|
91
|
+
allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with('puppet_agent::install', targets, params, config: described_class::DEFAULT_CONFIG_DATA, inventory: inventory_hash).and_return([])
|
92
|
+
install_agent('puppet6', targets, inventory_hash)
|
58
93
|
end
|
59
94
|
end
|
60
95
|
|
@@ -65,15 +100,20 @@ RSpec.describe PuppetLitmus::RakeHelper do
|
|
65
100
|
[{ 'name' => 'ssh_nodes', 'targets' =>
|
66
101
|
[{ 'uri' => 'some.host', 'facts' => { 'provisioner' => 'docker', 'container_name' => 'foo', 'platform' => 'some.host' } }] }] }
|
67
102
|
end
|
68
|
-
let(:module_tar) { '
|
103
|
+
let(:module_tar) { 'foo.tar.gz' }
|
69
104
|
let(:targets) { ['some.host'] }
|
70
|
-
let(:
|
105
|
+
let(:uninstall_module_command) { 'puppet module uninstall foo --force' }
|
106
|
+
let(:install_module_command) { "puppet module install --module_repository 'https://forgeapi.example.com' #{module_tar}" }
|
71
107
|
|
72
108
|
it 'calls function' do
|
73
|
-
|
109
|
+
allow_any_instance_of(BoltSpec::Run).to receive(:upload_file).with(module_tar, module_tar, targets, options: {}, config: nil, inventory: inventory_hash).and_return([])
|
110
|
+
allow(File).to receive(:exist?).with(File.join(Dir.pwd, 'metadata.json')).and_return(true)
|
111
|
+
allow(File).to receive(:read).with(File.join(Dir.pwd, 'metadata.json')).and_return(JSON.dump({ name: 'foo' }))
|
112
|
+
allow(Open3).to receive(:capture3).with("bundle exec bolt file upload \"#{module_tar}\" #{File.basename(module_tar)} --targets all --inventoryfile inventory.yaml")
|
74
113
|
.and_return(['success', '', 0])
|
114
|
+
allow_any_instance_of(BoltSpec::Run).to receive(:run_command).with(uninstall_module_command, targets, config: nil, inventory: inventory_hash).and_return([])
|
75
115
|
allow_any_instance_of(BoltSpec::Run).to receive(:run_command).with(install_module_command, targets, config: nil, inventory: inventory_hash).and_return([])
|
76
|
-
|
116
|
+
install_module(inventory_hash, nil, module_tar, 'https://forgeapi.example.com')
|
77
117
|
end
|
78
118
|
end
|
79
119
|
|
@@ -89,12 +129,12 @@ RSpec.describe PuppetLitmus::RakeHelper do
|
|
89
129
|
it 'node available' do
|
90
130
|
allow(Open3).to receive(:capture3).with('cd .').and_return(['success', '', 0])
|
91
131
|
allow_any_instance_of(BoltSpec::Run).to receive(:run_command).with(command, targets, config: nil, inventory: inventory_hash).and_return([{ 'target' => 'some.host', 'status' => 'success' }])
|
92
|
-
|
132
|
+
check_connectivity?(inventory_hash, 'some.host')
|
93
133
|
end
|
94
134
|
|
95
135
|
it 'node unavailable' do
|
96
136
|
allow_any_instance_of(BoltSpec::Run).to receive(:run_command).with(command, targets, config: nil, inventory: inventory_hash).and_return([{ 'target' => 'some.host', 'status' => 'failure' }])
|
97
|
-
expect {
|
137
|
+
expect { check_connectivity?(inventory_hash, 'some.host') }.to raise_error(RuntimeError, %r{Connectivity has failed on:})
|
98
138
|
end
|
99
139
|
end
|
100
140
|
|
@@ -109,13 +149,13 @@ RSpec.describe PuppetLitmus::RakeHelper do
|
|
109
149
|
|
110
150
|
it 'uninstalls module' do
|
111
151
|
allow_any_instance_of(BoltSpec::Run).to receive(:run_command).with(uninstall_module_command, targets, config: nil, inventory: inventory_hash).and_return([])
|
112
|
-
expect(
|
113
|
-
|
152
|
+
expect(self).to receive(:metadata_module_name).and_return('foo-bar')
|
153
|
+
uninstall_module(inventory_hash, nil)
|
114
154
|
end
|
115
155
|
|
116
156
|
it 'and custom name' do
|
117
157
|
allow_any_instance_of(BoltSpec::Run).to receive(:run_command).with(uninstall_module_command, targets, config: nil, inventory: inventory_hash).and_return([])
|
118
|
-
|
158
|
+
uninstall_module(inventory_hash, nil, 'foo-bar')
|
119
159
|
end
|
120
160
|
end
|
121
161
|
|
@@ -125,8 +165,20 @@ RSpec.describe PuppetLitmus::RakeHelper do
|
|
125
165
|
it 'reads module name' do
|
126
166
|
allow(File).to receive(:exist?).with(File.join(Dir.pwd, 'metadata.json')).and_return(true)
|
127
167
|
allow(File).to receive(:read).with(File.join(Dir.pwd, 'metadata.json')).and_return(metadata)
|
128
|
-
name =
|
168
|
+
name = metadata_module_name
|
129
169
|
expect(name).to eq('foo-bar')
|
130
170
|
end
|
131
171
|
end
|
172
|
+
|
173
|
+
context 'with provisioner_task' do
|
174
|
+
described_class::SUPPORTED_PROVISIONERS.each do |supported_provisioner|
|
175
|
+
it "returns supported provisioner task name for #{supported_provisioner}" do
|
176
|
+
expect(provisioner_task(supported_provisioner)).to eq("provision::#{supported_provisioner}")
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'returns an unsupported provisioner name' do
|
181
|
+
expect(provisioner_task('my_org::custom_provisioner')).to eql('my_org::custom_provisioner')
|
182
|
+
end
|
183
|
+
end
|
132
184
|
end
|
@@ -28,19 +28,22 @@ describe 'litmus rake tasks' do
|
|
28
28
|
|
29
29
|
context 'with litmus:install_modules_from_directory' do
|
30
30
|
let(:inventory_hash) { { 'groups' => [{ 'name' => 'ssh_nodes', 'nodes' => [{ 'uri' => 'some.host' }] }] } }
|
31
|
-
let(:
|
32
|
-
let(:dummy_tar) {
|
31
|
+
let(:target_dir) { File.join(Dir.pwd, 'spec/fixtures/modules') }
|
32
|
+
let(:dummy_tar) { 'spec/data/doot.tar.gz' }
|
33
33
|
|
34
34
|
it 'happy path' do
|
35
|
+
allow(File).to receive(:exist?).with(File.join(Dir.pwd, 'metadata.json')).and_return(true)
|
36
|
+
allow(File).to receive(:read).with(File.join(Dir.pwd, 'metadata.json')).and_return(JSON.dump({ name: 'foo' }))
|
37
|
+
|
35
38
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
36
39
|
expect_any_instance_of(PuppetLitmus::InventoryManipulation).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
37
|
-
expect(File).to receive(:directory?).with(
|
38
|
-
expect_any_instance_of(Object).to receive(:
|
39
|
-
expect(STDOUT).to receive(:puts).with('Building')
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
expect(File).to receive(:directory?).with(target_dir).and_return(true)
|
41
|
+
expect_any_instance_of(Object).to receive(:build_modules_in_dir).with(target_dir).and_return([dummy_tar])
|
42
|
+
expect(STDOUT).to receive(:puts).with(start_with('Building all modules in'))
|
43
|
+
expect_any_instance_of(Object).to receive(:upload_file).once.and_return([])
|
44
|
+
expect(STDOUT).to receive(:puts).with(start_with('Installing \'spec/data/doot.tar.gz\''))
|
45
|
+
expect_any_instance_of(Object).to receive(:run_command).twice.and_return([])
|
46
|
+
expect(STDOUT).to receive(:puts).with(start_with('Installed \'spec/data/doot.tar.gz\''))
|
44
47
|
Rake::Task['litmus:install_modules_from_directory'].invoke('./spec/fixtures/modules')
|
45
48
|
end
|
46
49
|
end
|
@@ -57,12 +60,11 @@ describe 'litmus rake tasks' do
|
|
57
60
|
|
58
61
|
context 'with litmus:provision task' do
|
59
62
|
it 'happy path' do
|
60
|
-
results = [{ '
|
61
|
-
'target' => 'localhost',
|
63
|
+
results = [{ 'target' => 'localhost',
|
62
64
|
'action' => 'task',
|
63
65
|
'object' => 'provision::docker',
|
64
66
|
'status' => 'success',
|
65
|
-
'
|
67
|
+
'value' => { 'status' => 'ok', 'node_name' => 'localhost:2222' } }]
|
66
68
|
|
67
69
|
allow(File).to receive(:directory?).with(any_args).and_return(true)
|
68
70
|
allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with(any_args).and_return(results)
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'rspec'
|
4
|
-
require 'puppet_litmus'
|
5
|
-
|
6
|
-
# Unfortunately this needs to be included as this is
|
7
|
-
# how Litmus functions. We only include once here instead
|
8
|
-
# of including for every single spec file.
|
9
|
-
include PuppetLitmus # rubocop:disable Style/MixinUsage
|
10
4
|
|
11
5
|
if ENV['COVERAGE'] == 'yes'
|
12
6
|
require 'simplecov'
|
@@ -37,3 +31,10 @@ if ENV['COVERAGE'] == 'yes'
|
|
37
31
|
end
|
38
32
|
end
|
39
33
|
end
|
34
|
+
|
35
|
+
# This is basically how `configure!` sets up RSpec in tests.
|
36
|
+
require 'puppet_litmus'
|
37
|
+
RSpec.configure do |config|
|
38
|
+
config.include PuppetLitmus
|
39
|
+
config.extend PuppetLitmus
|
40
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet_litmus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.18.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bolt
|
@@ -16,34 +16,40 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.0.1
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 3.0.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 2.0.1
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 3.0.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: puppet-modulebuilder
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- - "
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.2.1
|
40
|
+
- - "<"
|
38
41
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
42
|
+
version: 1.0.0
|
40
43
|
type: :runtime
|
41
44
|
prerelease: false
|
42
45
|
version_requirements: !ruby/object:Gem::Requirement
|
43
46
|
requirements:
|
44
|
-
- - "
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.2.1
|
50
|
+
- - "<"
|
45
51
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
52
|
+
version: 1.0.0
|
47
53
|
- !ruby/object:Gem::Dependency
|
48
54
|
name: tty-spinner
|
49
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,6 +132,60 @@ dependencies:
|
|
126
132
|
- - ">="
|
127
133
|
- !ruby/object:Gem::Version
|
128
134
|
version: '0'
|
135
|
+
- !ruby/object:Gem::Dependency
|
136
|
+
name: rspec_honeycomb_formatter
|
137
|
+
requirement: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
type: :runtime
|
143
|
+
prerelease: false
|
144
|
+
version_requirements: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
- !ruby/object:Gem::Dependency
|
150
|
+
name: ed25519
|
151
|
+
requirement: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '1.2'
|
156
|
+
- - "<"
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '2.0'
|
159
|
+
type: :runtime
|
160
|
+
prerelease: false
|
161
|
+
version_requirements: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '1.2'
|
166
|
+
- - "<"
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '2.0'
|
169
|
+
- !ruby/object:Gem::Dependency
|
170
|
+
name: bcrypt_pbkdf
|
171
|
+
requirement: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '1.0'
|
176
|
+
- - "<"
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '2.0'
|
179
|
+
type: :runtime
|
180
|
+
prerelease: false
|
181
|
+
version_requirements: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - ">="
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '1.0'
|
186
|
+
- - "<"
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '2.0'
|
129
189
|
description: " Providing a simple command line tool for puppet content creators,
|
130
190
|
to enable simple and complex test deployments.\n"
|
131
191
|
email:
|
@@ -179,13 +239,13 @@ specification_version: 4
|
|
179
239
|
summary: Providing a simple command line tool for puppet content creators, to enable
|
180
240
|
simple and complex test deployments.
|
181
241
|
test_files:
|
182
|
-
- spec/
|
183
|
-
- spec/
|
184
|
-
- spec/
|
242
|
+
- spec/data/doot.tar.gz
|
243
|
+
- spec/data/inventory.yaml
|
244
|
+
- spec/data/jim.yaml
|
185
245
|
- spec/lib/puppet_litmus/util_spec.rb
|
246
|
+
- spec/lib/puppet_litmus/version_spec.rb
|
186
247
|
- spec/lib/puppet_litmus/inventory_manipulation_spec.rb
|
187
|
-
- spec/lib/puppet_litmus/rake_helper_spec.rb
|
188
248
|
- spec/lib/puppet_litmus/puppet_helpers_spec.rb
|
189
|
-
- spec/
|
190
|
-
- spec/
|
191
|
-
- spec/
|
249
|
+
- spec/lib/puppet_litmus/rake_helper_spec.rb
|
250
|
+
- spec/lib/puppet_litmus/rake_tasks_spec.rb
|
251
|
+
- spec/spec_helper.rb
|