puppet_litmus 0.17.0 → 0.18.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -16
- data/lib/puppet_litmus/inventory_manipulation.rb +10 -2
- data/lib/puppet_litmus/puppet_helpers.rb +44 -40
- data/lib/puppet_litmus/rake_helper.rb +146 -71
- data/lib/puppet_litmus/rake_tasks.rb +95 -101
- data/lib/puppet_litmus/spec_helper_acceptance.rb +1 -1
- 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 +99 -108
- data/spec/lib/puppet_litmus/rake_helper_spec.rb +28 -23
- data/spec/lib/puppet_litmus/rake_tasks_spec.rb +14 -12
- data/spec/spec_helper.rb +7 -6
- metadata +27 -22
@@ -13,12 +13,12 @@ RSpec.shared_examples 'supported provisioner' do |args|
|
|
13
13
|
it 'calls function' do
|
14
14
|
allow(File).to receive(:directory?).and_call_original
|
15
15
|
allow(File).to receive(:directory?)
|
16
|
-
.with(File.join(DEFAULT_CONFIG_DATA['modulepath'], 'provision'))
|
16
|
+
.with(File.join(described_class::DEFAULT_CONFIG_DATA['modulepath'], 'provision'))
|
17
17
|
.and_return(true)
|
18
18
|
allow_any_instance_of(BoltSpec::Run).to receive(:run_task)
|
19
|
-
.with("provision::#{provisioner}", 'localhost', params, config: DEFAULT_CONFIG_DATA, inventory: nil)
|
19
|
+
.with("provision::#{provisioner}", 'localhost', params, config: described_class::DEFAULT_CONFIG_DATA, inventory: nil)
|
20
20
|
.and_return(results)
|
21
|
-
result =
|
21
|
+
result = provision(provisioner, platform, inventory_vars)
|
22
22
|
expect(result).to eq(results)
|
23
23
|
end
|
24
24
|
end
|
@@ -29,8 +29,8 @@ RSpec.describe PuppetLitmus::RakeHelper do
|
|
29
29
|
let(:results) { [] }
|
30
30
|
|
31
31
|
it 'calls function' do
|
32
|
-
expect(
|
33
|
-
|
32
|
+
expect(self).to receive(:provision).with('docker', 'waffleimage/centos7', nil).and_return(results)
|
33
|
+
provision_list(provision_hash, 'default')
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -71,9 +71,9 @@ RSpec.describe PuppetLitmus::RakeHelper do
|
|
71
71
|
let(:params) { { 'action' => 'tear_down', 'node_name' => 'some.host', 'inventory' => Dir.pwd } }
|
72
72
|
|
73
73
|
it 'calls function' do
|
74
|
-
allow(File).to receive(:directory?).with(File.join(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: DEFAULT_CONFIG_DATA, inventory: nil).and_return([])
|
76
|
-
|
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)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -87,9 +87,9 @@ RSpec.describe PuppetLitmus::RakeHelper do
|
|
87
87
|
let(:params) { { 'collection' => 'puppet6' } }
|
88
88
|
|
89
89
|
it 'calls function' do
|
90
|
-
allow(File).to receive(:directory?).with(File.join(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: DEFAULT_CONFIG_DATA, inventory: inventory_hash).and_return([])
|
92
|
-
|
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)
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
@@ -100,15 +100,20 @@ RSpec.describe PuppetLitmus::RakeHelper do
|
|
100
100
|
[{ 'name' => 'ssh_nodes', 'targets' =>
|
101
101
|
[{ 'uri' => 'some.host', 'facts' => { 'provisioner' => 'docker', 'container_name' => 'foo', 'platform' => 'some.host' } }] }] }
|
102
102
|
end
|
103
|
-
let(:module_tar) { '
|
103
|
+
let(:module_tar) { 'foo.tar.gz' }
|
104
104
|
let(:targets) { ['some.host'] }
|
105
|
-
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}" }
|
106
107
|
|
107
108
|
it 'calls function' do
|
108
|
-
|
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")
|
109
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([])
|
110
115
|
allow_any_instance_of(BoltSpec::Run).to receive(:run_command).with(install_module_command, targets, config: nil, inventory: inventory_hash).and_return([])
|
111
|
-
|
116
|
+
install_module(inventory_hash, nil, module_tar, 'https://forgeapi.example.com')
|
112
117
|
end
|
113
118
|
end
|
114
119
|
|
@@ -124,12 +129,12 @@ RSpec.describe PuppetLitmus::RakeHelper do
|
|
124
129
|
it 'node available' do
|
125
130
|
allow(Open3).to receive(:capture3).with('cd .').and_return(['success', '', 0])
|
126
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' }])
|
127
|
-
|
132
|
+
check_connectivity?(inventory_hash, 'some.host')
|
128
133
|
end
|
129
134
|
|
130
135
|
it 'node unavailable' do
|
131
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' }])
|
132
|
-
expect {
|
137
|
+
expect { check_connectivity?(inventory_hash, 'some.host') }.to raise_error(RuntimeError, %r{Connectivity has failed on:})
|
133
138
|
end
|
134
139
|
end
|
135
140
|
|
@@ -144,13 +149,13 @@ RSpec.describe PuppetLitmus::RakeHelper do
|
|
144
149
|
|
145
150
|
it 'uninstalls module' do
|
146
151
|
allow_any_instance_of(BoltSpec::Run).to receive(:run_command).with(uninstall_module_command, targets, config: nil, inventory: inventory_hash).and_return([])
|
147
|
-
expect(
|
148
|
-
|
152
|
+
expect(self).to receive(:metadata_module_name).and_return('foo-bar')
|
153
|
+
uninstall_module(inventory_hash, nil)
|
149
154
|
end
|
150
155
|
|
151
156
|
it 'and custom name' do
|
152
157
|
allow_any_instance_of(BoltSpec::Run).to receive(:run_command).with(uninstall_module_command, targets, config: nil, inventory: inventory_hash).and_return([])
|
153
|
-
|
158
|
+
uninstall_module(inventory_hash, nil, 'foo-bar')
|
154
159
|
end
|
155
160
|
end
|
156
161
|
|
@@ -160,7 +165,7 @@ RSpec.describe PuppetLitmus::RakeHelper do
|
|
160
165
|
it 'reads module name' do
|
161
166
|
allow(File).to receive(:exist?).with(File.join(Dir.pwd, 'metadata.json')).and_return(true)
|
162
167
|
allow(File).to receive(:read).with(File.join(Dir.pwd, 'metadata.json')).and_return(metadata)
|
163
|
-
name =
|
168
|
+
name = metadata_module_name
|
164
169
|
expect(name).to eq('foo-bar')
|
165
170
|
end
|
166
171
|
end
|
@@ -168,12 +173,12 @@ RSpec.describe PuppetLitmus::RakeHelper do
|
|
168
173
|
context 'with provisioner_task' do
|
169
174
|
described_class::SUPPORTED_PROVISIONERS.each do |supported_provisioner|
|
170
175
|
it "returns supported provisioner task name for #{supported_provisioner}" do
|
171
|
-
expect(
|
176
|
+
expect(provisioner_task(supported_provisioner)).to eq("provision::#{supported_provisioner}")
|
172
177
|
end
|
173
178
|
end
|
174
179
|
|
175
180
|
it 'returns an unsupported provisioner name' do
|
176
|
-
expect(
|
181
|
+
expect(provisioner_task('my_org::custom_provisioner')).to eql('my_org::custom_provisioner')
|
177
182
|
end
|
178
183
|
end
|
179
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet, Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-01 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
38
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
39
|
+
version: 0.2.1
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::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
|
@@ -172,7 +178,7 @@ homepage: https://github.com/puppetlabs/puppet_litmus
|
|
172
178
|
licenses:
|
173
179
|
- Apache-2.0
|
174
180
|
metadata: {}
|
175
|
-
post_install_message:
|
181
|
+
post_install_message:
|
176
182
|
rdoc_options: []
|
177
183
|
require_paths:
|
178
184
|
- lib
|
@@ -187,20 +193,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
193
|
- !ruby/object:Gem::Version
|
188
194
|
version: '0'
|
189
195
|
requirements: []
|
190
|
-
|
191
|
-
|
192
|
-
signing_key:
|
196
|
+
rubygems_version: 3.1.2
|
197
|
+
signing_key:
|
193
198
|
specification_version: 4
|
194
199
|
summary: Providing a simple command line tool for puppet content creators, to enable
|
195
200
|
simple and complex test deployments.
|
196
201
|
test_files:
|
197
|
-
- spec/
|
198
|
-
- spec/data/inventory.yaml
|
199
|
-
- spec/data/jim.yaml
|
200
|
-
- spec/lib/puppet_litmus/inventory_manipulation_spec.rb
|
202
|
+
- spec/spec_helper.rb
|
201
203
|
- spec/lib/puppet_litmus/rake_tasks_spec.rb
|
202
|
-
- spec/lib/puppet_litmus/util_spec.rb
|
203
204
|
- spec/lib/puppet_litmus/version_spec.rb
|
204
|
-
- spec/lib/puppet_litmus/
|
205
|
+
- spec/lib/puppet_litmus/util_spec.rb
|
206
|
+
- spec/lib/puppet_litmus/inventory_manipulation_spec.rb
|
205
207
|
- spec/lib/puppet_litmus/rake_helper_spec.rb
|
206
|
-
- spec/
|
208
|
+
- spec/lib/puppet_litmus/puppet_helpers_spec.rb
|
209
|
+
- spec/data/doot.tar.gz
|
210
|
+
- spec/data/jim.yaml
|
211
|
+
- spec/data/inventory.yaml
|