puppet_litmus 0.11.0 → 0.11.1
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/puppet_litmus/inventory_manipulation.rb +12 -5
- data/lib/puppet_litmus/{serverspec.rb → puppet_helpers.rb} +1 -1
- data/lib/puppet_litmus/rake_tasks.rb +2 -0
- data/lib/puppet_litmus/version.rb +1 -1
- data/lib/puppet_litmus.rb +2 -2
- data/spec/lib/puppet_litmus/inventory_manipulation_spec.rb +37 -20
- data/spec/lib/puppet_litmus/{serverspec_spec.rb → puppet_helpers_spec.rb} +96 -99
- data/spec/lib/puppet_litmus/rake_tasks_spec.rb +0 -2
- data/spec/lib/puppet_litmus/version_spec.rb +3 -0
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fcb472feb01cf0ebd62532e0cb58b87fee60285a7c981c416befd43374393c7
|
4
|
+
data.tar.gz: 285b1a3907733f5fc8aa7d29599e257df69ffab3318387ad23952a4947e6b2c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbf13c7c25f17337e7a06c208533c003f5d779e09c31f7363ce228774752e1244a48898174d11728e91744890bd7374a5427b6c66f3c2e9ed97b72cf84ae8e95
|
7
|
+
data.tar.gz: 421817337c42b08ab8bee201e6faf601a6cf65385470db90491c35528815b5578291235b78aa462d860fe9275b3079b3831cad39ae8f7eb5b4115bad771e402e
|
@@ -130,14 +130,21 @@ module PuppetLitmus::InventoryManipulation
|
|
130
130
|
# Adds a node to a group specified, if group_name exists in inventory hash.
|
131
131
|
#
|
132
132
|
# @param inventory_hash [Hash] hash of the inventory.yaml file
|
133
|
-
# @param
|
133
|
+
# @param node [Hash] node to add to the group
|
134
134
|
# group_name [String] group of nodes to limit the search for the node_name in
|
135
135
|
# @return [Hash] inventory_hash with node added to group if group_name exists in inventory hash.
|
136
|
-
def add_node_to_group(inventory_hash,
|
137
|
-
|
138
|
-
|
139
|
-
|
136
|
+
def add_node_to_group(inventory_hash, node, group_name)
|
137
|
+
# check if group exists
|
138
|
+
if inventory_hash['groups'].any? { |g| g['name'] == group_name }
|
139
|
+
inventory_hash['groups'].each do |group|
|
140
|
+
if group['name'] == group_name
|
141
|
+
group['nodes'].push node
|
142
|
+
end
|
140
143
|
end
|
144
|
+
else
|
145
|
+
# add new group
|
146
|
+
group = { 'name' => group_name, 'nodes' => [node] }
|
147
|
+
inventory_hash['groups'].push group
|
141
148
|
end
|
142
149
|
inventory_hash
|
143
150
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# helper functions for running puppet commands. They execute a target system specified by ENV['TARGET_HOST']
|
4
4
|
# heavily uses functions from here https://github.com/puppetlabs/bolt/blob/master/developer-docs/bolt_spec-run.md
|
5
|
-
module PuppetLitmus::
|
5
|
+
module PuppetLitmus::PuppetHelpers
|
6
6
|
# Applies a manifest twice. First checking for errors. Secondly to make sure no changes occur.
|
7
7
|
#
|
8
8
|
# @param manifest [String] puppet manifest code to be applied.
|
@@ -7,6 +7,7 @@ require 'open3'
|
|
7
7
|
require 'pdk'
|
8
8
|
require 'json'
|
9
9
|
require 'parallel'
|
10
|
+
require 'tty-spinner'
|
10
11
|
|
11
12
|
# helper methods for the litmus rake tasks
|
12
13
|
module LitmusRakeHelper
|
@@ -277,6 +278,7 @@ namespace :litmus do
|
|
277
278
|
# stdout, stderr, _status = Open3.capture3(pdk_build_command)
|
278
279
|
# raise "Failed to run 'pdk_build_command',#{stdout} and #{stderr}" if (stderr =~ %r{completed successfully}).nil?
|
279
280
|
require 'pdk/module/build'
|
281
|
+
|
280
282
|
opts = {}
|
281
283
|
opts[:force] = true
|
282
284
|
builder = PDK::Module::Build.new(opts)
|
data/lib/puppet_litmus.rb
CHANGED
@@ -5,11 +5,11 @@ module PuppetLitmus; end
|
|
5
5
|
|
6
6
|
require 'bolt_spec/run'
|
7
7
|
require 'puppet_litmus/inventory_manipulation'
|
8
|
-
require 'puppet_litmus/
|
8
|
+
require 'puppet_litmus/puppet_helpers'
|
9
9
|
|
10
10
|
# Helper methods for testing puppet content
|
11
11
|
module PuppetLitmus
|
12
12
|
include BoltSpec::Run
|
13
13
|
include PuppetLitmus::InventoryManipulation
|
14
|
-
include PuppetLitmus::
|
14
|
+
include PuppetLitmus::PuppetHelpers
|
15
15
|
end
|
@@ -1,14 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
+
load File.expand_path('../../../lib/puppet_litmus/inventory_manipulation.rb', __dir__)
|
5
|
+
include PuppetLitmus::InventoryManipulation # rubocop:disable Style/MixinUsage
|
4
6
|
|
5
7
|
RSpec.describe PuppetLitmus::InventoryManipulation do
|
6
|
-
let(:dummy_class) do
|
7
|
-
dummy = Class.new
|
8
|
-
dummy.extend(described_class)
|
9
|
-
dummy
|
10
|
-
end
|
11
|
-
|
12
8
|
context 'with config_from_node' do
|
13
9
|
let(:no_config_hash) do
|
14
10
|
{ 'groups' =>
|
@@ -19,6 +15,12 @@ RSpec.describe PuppetLitmus::InventoryManipulation do
|
|
19
15
|
{ 'name' => 'winrm_nodes', 'nodes' => [] }] }
|
20
16
|
end
|
21
17
|
|
18
|
+
let(:no_docker_hash) do
|
19
|
+
{ 'groups' =>
|
20
|
+
[{ 'name' => 'ssh_nodes', 'nodes' => [] },
|
21
|
+
{ 'name' => 'winrm_nodes', 'nodes' => [] }] }
|
22
|
+
end
|
23
|
+
|
22
24
|
let(:config_hash) do
|
23
25
|
{ 'groups' =>
|
24
26
|
[{ 'name' => 'ssh_nodes',
|
@@ -86,62 +88,77 @@ RSpec.describe PuppetLitmus::InventoryManipulation do
|
|
86
88
|
{ 'name' => 'winrm_nodes', 'nodes' => [] }] }
|
87
89
|
end
|
88
90
|
|
91
|
+
let(:foo_node) do
|
92
|
+
{ 'name' => 'foo',
|
93
|
+
'facts' => { 'provisioner' => 'bar', 'platform' => 'ubuntu' } }
|
94
|
+
end
|
95
|
+
|
89
96
|
it 'no matching node, raises' do
|
90
|
-
expect {
|
97
|
+
expect { described_class.config_from_node(config_hash, 'not.here') }.to raise_error('No config was found for not.here')
|
91
98
|
end
|
92
99
|
|
93
100
|
it 'no config section, returns nil' do
|
94
|
-
expect(
|
101
|
+
expect(described_class.config_from_node(no_config_hash, 'test.delivery.puppetlabs.net')).to eq(nil)
|
95
102
|
end
|
96
103
|
|
97
104
|
it 'config exists, and returns' do
|
98
|
-
expect(
|
105
|
+
expect(described_class.config_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('transport' => 'ssh', 'ssh' =>
|
99
106
|
{ 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false })
|
100
107
|
end
|
101
108
|
|
102
109
|
it 'facts exists, and returns' do
|
103
|
-
expect(
|
110
|
+
expect(described_class.facts_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64')
|
104
111
|
end
|
105
112
|
|
106
113
|
it 'vars exists, and returns' do
|
107
|
-
expect(
|
114
|
+
expect(described_class.vars_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('role' => 'agent')
|
108
115
|
end
|
109
116
|
|
110
117
|
it 'no feature exists for the group, and returns hash with feature added' do
|
111
|
-
expect(
|
118
|
+
expect(described_class.add_feature_to_group(no_feature_hash, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => ['puppet-agent'], 'name' => 'ssh_nodes', 'nodes' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'name' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'nodes' => [] }]) # rubocop:disable Metrics/LineLength: Line is too long
|
112
119
|
end
|
113
120
|
|
114
121
|
it 'feature exists for the group, and returns hash with feature removed' do
|
115
|
-
expect(
|
122
|
+
expect(described_class.remove_feature_from_group(feature_hash_group, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => [], 'name' => 'ssh_nodes', 'nodes' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'name' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'nodes' => [] }]) # rubocop:disable Metrics/LineLength: Line is too long
|
116
123
|
end
|
117
124
|
|
118
125
|
it 'write from inventory_hash to inventory_yaml file feature_hash_group' do
|
119
|
-
expect {
|
126
|
+
expect { described_class.write_to_inventory_file(feature_hash_group, inventory_full_path) }.not_to raise_error
|
120
127
|
end
|
121
128
|
|
122
129
|
it 'empty feature exists for the group, and returns hash with feature added' do
|
123
|
-
expect(
|
130
|
+
expect(described_class.add_feature_to_group(empty_feature_hash_group, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => ['puppet-agent'], 'name' => 'ssh_nodes', 'nodes' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'name' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'nodes' => [] }]) # rubocop:disable Metrics/LineLength: Line is too long
|
124
131
|
end
|
125
132
|
|
126
133
|
it 'no feature exists for the node, and returns hash with feature added' do
|
127
|
-
expect(
|
134
|
+
expect(described_class.add_feature_to_node(no_feature_hash, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'nodes' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'name' => 'test.delivery.puppetlabs.net', 'features' => ['puppet-agent'] }] }, { 'name' => 'winrm_nodes', 'nodes' => [] }]) # rubocop:disable Metrics/LineLength: Line is too long
|
128
135
|
end
|
129
136
|
|
130
137
|
it 'feature exists for the node, and returns hash with feature removed' do
|
131
|
-
expect(
|
138
|
+
expect(described_class.remove_feature_from_node(feature_hash_node, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'nodes' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'name' => 'test.delivery.puppetlabs.net', 'features' => [] }] }, { 'name' => 'winrm_nodes', 'nodes' => [] }]) # rubocop:disable Metrics/LineLength: Line is too long
|
132
139
|
end
|
133
140
|
|
134
141
|
it 'write from inventory_hash to inventory_yaml file feature_hash_node' do
|
135
|
-
expect {
|
142
|
+
expect { described_class.write_to_inventory_file(feature_hash_node, inventory_full_path) }.not_to raise_error
|
136
143
|
end
|
137
144
|
|
138
145
|
it 'empty feature exists for the node, and returns hash with feature added' do
|
139
|
-
expect(
|
146
|
+
expect(described_class.add_feature_to_node(empty_feature_hash_node, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'nodes' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'name' => 'test.delivery.puppetlabs.net', 'features' => ['puppet-agent'] }] }, { 'name' => 'winrm_nodes', 'nodes' => [] }]) # rubocop:disable Metrics/LineLength: Line is too long
|
140
147
|
end
|
141
148
|
|
142
149
|
it 'write from inventory_hash to inventory_yaml file no feature_hash' do
|
143
150
|
expect(File).to exist(inventory_full_path)
|
144
|
-
expect {
|
151
|
+
expect { described_class.write_to_inventory_file(no_feature_hash, inventory_full_path) }.not_to raise_error
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'group does not exist in inventory, and returns hash with group added' do
|
155
|
+
expect(described_class.add_node_to_group(no_docker_hash, foo_node, 'docker_nodes')).to eq('groups' =>
|
156
|
+
[{ 'name' => 'ssh_nodes', 'nodes' => [] }, { 'name' => 'winrm_nodes', 'nodes' => [] }, { 'name' => 'docker_nodes', 'nodes' => [foo_node] }])
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'group exists in inventory, and returns hash with node added' do
|
160
|
+
expect(described_class.add_node_to_group(no_docker_hash, foo_node, 'ssh_nodes')).to eq('groups' =>
|
161
|
+
[{ 'name' => 'ssh_nodes', 'nodes' => [foo_node] }, { 'name' => 'winrm_nodes', 'nodes' => [] }])
|
145
162
|
end
|
146
163
|
end
|
147
164
|
end
|
@@ -1,24 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
+
load File.expand_path('../../../lib/puppet_litmus/puppet_helpers.rb', __dir__)
|
4
5
|
|
5
|
-
|
6
|
-
let(:dummy_class) do
|
7
|
-
dummy = Class.new
|
8
|
-
dummy.extend(described_class)
|
9
|
-
dummy
|
10
|
-
end
|
6
|
+
include PuppetLitmus::PuppetHelpers # rubocop:disable Style/MixinUsage
|
11
7
|
|
8
|
+
RSpec.describe PuppetLitmus::PuppetHelpers do
|
12
9
|
context 'with idempotent_apply' do
|
13
10
|
let(:manifest) do
|
14
11
|
"include '::doot'"
|
15
12
|
end
|
16
13
|
|
17
14
|
it 'calls all functions' do
|
18
|
-
expect(
|
19
|
-
expect(
|
20
|
-
expect(
|
21
|
-
|
15
|
+
expect(described_class).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
|
16
|
+
expect(described_class).to receive(:apply_manifest).with(nil, expect_failures: false, manifest_file_location: '/bla.pp')
|
17
|
+
expect(described_class).to receive(:apply_manifest).with(nil, catch_changes: true, manifest_file_location: '/bla.pp')
|
18
|
+
described_class.idempotent_apply(manifest)
|
22
19
|
end
|
23
20
|
end
|
24
21
|
|
@@ -31,11 +28,11 @@ RSpec.describe PuppetLitmus::Serverspec do
|
|
31
28
|
|
32
29
|
it 'passes the --hiera_config flag if the :hiera_config opt is specified' do
|
33
30
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
34
|
-
expect(
|
35
|
-
expect(
|
36
|
-
expect(
|
37
|
-
expect(
|
38
|
-
|
31
|
+
expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
|
32
|
+
expect(described_class).to receive(:target_in_inventory?).and_return(true)
|
33
|
+
expect(described_class).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
|
34
|
+
expect(described_class).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
|
35
|
+
described_class.apply_manifest(manifest, hiera_config: '/hiera.yaml')
|
39
36
|
end
|
40
37
|
end
|
41
38
|
|
@@ -47,42 +44,42 @@ RSpec.describe PuppetLitmus::Serverspec do
|
|
47
44
|
|
48
45
|
it 'uses detailed-exitcodes with expect_failures' do
|
49
46
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
50
|
-
expect(
|
51
|
-
expect(
|
52
|
-
expect(
|
53
|
-
expect(
|
54
|
-
expect {
|
47
|
+
expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
|
48
|
+
expect(described_class).to receive(:target_in_inventory?).and_return(true)
|
49
|
+
expect(described_class).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
|
50
|
+
expect(described_class).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
|
51
|
+
expect { described_class.apply_manifest(manifest, expect_failures: true) }.to raise_error(RuntimeError)
|
55
52
|
end
|
56
53
|
|
57
54
|
it 'uses detailed-exitcodes with catch_failures' do
|
58
55
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
59
|
-
expect(
|
60
|
-
expect(
|
61
|
-
expect(
|
62
|
-
expect(
|
63
|
-
|
56
|
+
expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
|
57
|
+
expect(described_class).to receive(:target_in_inventory?).and_return(true)
|
58
|
+
expect(described_class).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
|
59
|
+
expect(described_class).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
|
60
|
+
described_class.apply_manifest(manifest, catch_failures: true)
|
64
61
|
end
|
65
62
|
|
66
63
|
it 'uses detailed-exitcodes with expect_changes' do
|
67
64
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
68
|
-
expect(
|
69
|
-
expect(
|
70
|
-
expect(
|
71
|
-
expect(
|
72
|
-
expect {
|
65
|
+
expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
|
66
|
+
expect(described_class).to receive(:target_in_inventory?).and_return(true)
|
67
|
+
expect(described_class).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
|
68
|
+
expect(described_class).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
|
69
|
+
expect { described_class.apply_manifest(manifest, expect_changes: true) }.to raise_error(RuntimeError)
|
73
70
|
end
|
74
71
|
|
75
72
|
it 'uses detailed-exitcodes with catch_changes' do
|
76
73
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
77
|
-
expect(
|
78
|
-
expect(
|
79
|
-
expect(
|
80
|
-
expect(
|
81
|
-
|
74
|
+
expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
|
75
|
+
expect(described_class).to receive(:target_in_inventory?).and_return(true)
|
76
|
+
expect(described_class).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
|
77
|
+
expect(described_class).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
|
78
|
+
described_class.apply_manifest(manifest, catch_changes: true)
|
82
79
|
end
|
83
80
|
|
84
81
|
it 'uses raises exception for multiple options' do
|
85
|
-
expect {
|
82
|
+
expect { described_class.apply_manifest(manifest, catch_changes: true, expect_failures: true) }
|
86
83
|
.to raise_error(RuntimeError, 'please specify only one of `catch_changes`, `expect_changes`, `catch_failures` or `expect_failures`')
|
87
84
|
end
|
88
85
|
end
|
@@ -95,17 +92,17 @@ RSpec.describe PuppetLitmus::Serverspec do
|
|
95
92
|
let(:localhost_inventory_hash) { { 'groups' => [{ 'name' => 'local', 'nodes' => [{ 'name' => 'litmus_localhost', 'config' => { 'transport' => 'local' } }] }] } }
|
96
93
|
|
97
94
|
it 'responds to run_shell' do
|
98
|
-
expect(
|
95
|
+
expect(described_class).to respond_to(:run_shell).with(1..2).arguments
|
99
96
|
end
|
100
97
|
|
101
98
|
context 'when running against localhost and no inventory.yaml file' do
|
102
99
|
it 'does run_shell against localhost without error' do
|
103
100
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
|
104
101
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
105
|
-
expect(
|
106
|
-
expect(
|
107
|
-
expect(
|
108
|
-
expect {
|
102
|
+
expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
|
103
|
+
expect(described_class).to receive(:target_in_inventory?).and_return(true)
|
104
|
+
expect(described_class).to receive(:run_command).with(command_to_run, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
|
105
|
+
expect { described_class.run_shell(command_to_run) }.not_to raise_error
|
109
106
|
end
|
110
107
|
end
|
111
108
|
|
@@ -113,10 +110,10 @@ RSpec.describe PuppetLitmus::Serverspec do
|
|
113
110
|
it 'does run_shell against remote host without error' do
|
114
111
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
115
112
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
116
|
-
expect(
|
117
|
-
expect(
|
118
|
-
expect(
|
119
|
-
expect {
|
113
|
+
expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
114
|
+
expect(described_class).to receive(:target_in_inventory?).and_return(true)
|
115
|
+
expect(described_class).to receive(:run_command).with(command_to_run, 'some.host', config: nil, inventory: inventory_hash).and_return(result)
|
116
|
+
expect { described_class.run_shell(command_to_run) }.not_to raise_error
|
120
117
|
end
|
121
118
|
end
|
122
119
|
end
|
@@ -133,27 +130,27 @@ RSpec.describe PuppetLitmus::Serverspec do
|
|
133
130
|
let(:localhost_inventory_hash) { { 'groups' => [{ 'name' => 'local', 'nodes' => [{ 'name' => 'litmus_localhost', 'config' => { 'transport' => 'local' } }] }] } }
|
134
131
|
|
135
132
|
it 'responds to run_shell' do
|
136
|
-
expect(
|
133
|
+
expect(described_class).to respond_to(:bolt_upload_file).with(2..3).arguments
|
137
134
|
end
|
138
135
|
|
139
136
|
context 'when upload returns success' do
|
140
137
|
it 'does upload_file against remote host without error' do
|
141
138
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
142
139
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
143
|
-
expect(
|
144
|
-
expect(
|
145
|
-
expect(
|
146
|
-
expect {
|
140
|
+
expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
141
|
+
expect(described_class).to receive(:target_in_inventory?).and_return(true)
|
142
|
+
expect(described_class).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_success)
|
143
|
+
expect { described_class.bolt_upload_file(local, remote) }.not_to raise_error
|
147
144
|
end
|
148
145
|
|
149
146
|
it 'does upload_file against localhost without error' do
|
150
147
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
|
151
148
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
152
|
-
expect(
|
153
|
-
expect(
|
154
|
-
expect(
|
155
|
-
expect(
|
156
|
-
expect {
|
149
|
+
expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
|
150
|
+
expect(described_class).not_to receive(:inventory_hash_from_inventory_file)
|
151
|
+
expect(described_class).to receive(:target_in_inventory?).and_return(true)
|
152
|
+
expect(described_class).to receive(:upload_file).with(local, remote, 'litmus_localhost', options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result_success)
|
153
|
+
expect { described_class.bolt_upload_file(local, remote) }.not_to raise_error
|
157
154
|
end
|
158
155
|
end
|
159
156
|
|
@@ -161,19 +158,19 @@ RSpec.describe PuppetLitmus::Serverspec do
|
|
161
158
|
it 'does upload_file gives runtime error for failure' do
|
162
159
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
163
160
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
164
|
-
expect(
|
165
|
-
expect(
|
166
|
-
expect(
|
167
|
-
expect {
|
161
|
+
expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
162
|
+
expect(described_class).to receive(:target_in_inventory?).and_return(true)
|
163
|
+
expect(described_class).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_failure)
|
164
|
+
expect { described_class.bolt_upload_file(local, remote) }.to raise_error(RuntimeError, %r{upload file failed})
|
168
165
|
end
|
169
166
|
|
170
167
|
it 'returns the exit code and error message when expecting failure' do
|
171
168
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
172
169
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
173
|
-
expect(
|
174
|
-
expect(
|
175
|
-
expect(
|
176
|
-
method_result =
|
170
|
+
expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
171
|
+
expect(described_class).to receive(:target_in_inventory?).and_return(true)
|
172
|
+
expect(described_class).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_failure)
|
173
|
+
method_result = described_class.bolt_upload_file(local, remote, expect_failures: true)
|
177
174
|
expect(method_result.exit_code).to be(255)
|
178
175
|
expect(method_result.stderr).to be('No such file or directory @ rb_sysopen - /nonexistant/file/path')
|
179
176
|
end
|
@@ -187,18 +184,18 @@ RSpec.describe PuppetLitmus::Serverspec do
|
|
187
184
|
let(:localhost_inventory_hash) { { 'groups' => [{ 'name' => 'local', 'nodes' => [{ 'name' => 'litmus_localhost', 'config' => { 'transport' => 'local' } }] }] } }
|
188
185
|
|
189
186
|
it 'responds to bolt_run_script' do
|
190
|
-
expect(
|
187
|
+
expect(described_class).to respond_to(:bolt_run_script).with(1..2).arguments
|
191
188
|
end
|
192
189
|
|
193
190
|
context 'when running against localhost and no inventory.yaml file' do
|
194
191
|
it 'does bolt_run_script against localhost without error' do
|
195
192
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
|
196
193
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
197
|
-
expect(
|
198
|
-
expect(
|
199
|
-
expect(
|
200
|
-
expect(
|
201
|
-
expect {
|
194
|
+
expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
|
195
|
+
expect(described_class).not_to receive(:inventory_hash_from_inventory_file)
|
196
|
+
expect(described_class).to receive(:target_in_inventory?).and_return(true)
|
197
|
+
expect(described_class).to receive(:run_script).with(script, 'litmus_localhost', [], options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result)
|
198
|
+
expect { described_class.bolt_run_script(script) }.not_to raise_error
|
202
199
|
end
|
203
200
|
end
|
204
201
|
|
@@ -206,10 +203,10 @@ RSpec.describe PuppetLitmus::Serverspec do
|
|
206
203
|
it 'does bolt_run_script against remote host without error' do
|
207
204
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
208
205
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
209
|
-
expect(
|
210
|
-
expect(
|
211
|
-
expect(
|
212
|
-
expect {
|
206
|
+
expect(described_class).to receive(:inventory_hash_from_inventory_file)
|
207
|
+
expect(described_class).to receive(:target_in_inventory?).and_return(true)
|
208
|
+
expect(described_class).to receive(:run_script).with(script, 'some.host', [], options: {}, config: nil, inventory: nil).and_return(result)
|
209
|
+
expect { described_class.bolt_run_script(script) }.not_to raise_error
|
213
210
|
end
|
214
211
|
end
|
215
212
|
|
@@ -217,11 +214,11 @@ RSpec.describe PuppetLitmus::Serverspec do
|
|
217
214
|
it 'does bolt_run_script with arguments without error' do
|
218
215
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
|
219
216
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
220
|
-
expect(
|
221
|
-
expect(
|
222
|
-
expect(
|
223
|
-
expect(
|
224
|
-
expect {
|
217
|
+
expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
|
218
|
+
expect(described_class).not_to receive(:inventory_hash_from_inventory_file)
|
219
|
+
expect(described_class).to receive(:target_in_inventory?).and_return(true)
|
220
|
+
expect(described_class).to receive(:run_script).with(script, 'litmus_localhost', ['doot'], options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result)
|
221
|
+
expect { described_class.bolt_run_script(script, arguments: ['doot']) }.not_to raise_error
|
225
222
|
end
|
226
223
|
end
|
227
224
|
end
|
@@ -239,36 +236,36 @@ RSpec.describe PuppetLitmus::Serverspec do
|
|
239
236
|
let(:inventory_hash) { { 'groups' => [{ 'name' => 'local', 'nodes' => [{ 'name' => 'some.host', 'config' => { 'transport' => 'local' } }] }] } }
|
240
237
|
|
241
238
|
it 'responds to bolt_run_task' do
|
242
|
-
expect(
|
239
|
+
expect(described_class).to respond_to(:run_bolt_task).with(2..3).arguments
|
243
240
|
end
|
244
241
|
|
245
242
|
context 'when bolt returns success' do
|
246
243
|
it 'does bolt_task_run gives no runtime error for success' do
|
247
244
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
248
245
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
249
|
-
expect(
|
250
|
-
expect(
|
251
|
-
expect(
|
252
|
-
expect {
|
246
|
+
expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
247
|
+
expect(described_class).to receive(:target_in_inventory?).and_return(true)
|
248
|
+
expect(described_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
|
249
|
+
expect { described_class.run_bolt_task(task_name, params, opts: {}) }.not_to raise_error
|
253
250
|
end
|
254
251
|
|
255
252
|
it 'returns stdout for unstructured-data tasks' do
|
256
253
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
257
254
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
258
|
-
expect(
|
259
|
-
expect(
|
260
|
-
expect(
|
261
|
-
method_result =
|
255
|
+
expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
256
|
+
expect(described_class).to receive(:target_in_inventory?).and_return(true)
|
257
|
+
expect(described_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
|
258
|
+
method_result = described_class.run_bolt_task(task_name, params, opts: {})
|
262
259
|
expect(method_result.stdout).to eq('SUCCESS!')
|
263
260
|
end
|
264
261
|
|
265
262
|
it 'returns structured output for structured-data tasks' do
|
266
263
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
267
264
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
268
|
-
expect(
|
269
|
-
expect(
|
270
|
-
expect(
|
271
|
-
method_result =
|
265
|
+
expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
266
|
+
expect(described_class).to receive(:target_in_inventory?).and_return(true)
|
267
|
+
expect(described_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_structured_task_success)
|
268
|
+
method_result = described_class.run_bolt_task(task_name, params, opts: {})
|
272
269
|
expect(method_result.stdout).to eq('{"key1"=>"foo", "key2"=>"bar"}')
|
273
270
|
expect(method_result.result['key1']).to eq('foo')
|
274
271
|
expect(method_result.result['key2']).to eq('bar')
|
@@ -279,19 +276,19 @@ RSpec.describe PuppetLitmus::Serverspec do
|
|
279
276
|
it 'does bolt_task_run gives runtime error for failure' do
|
280
277
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
281
278
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
282
|
-
expect(
|
283
|
-
expect(
|
284
|
-
expect(
|
285
|
-
expect {
|
279
|
+
expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
280
|
+
expect(described_class).to receive(:target_in_inventory?).and_return(true)
|
281
|
+
expect(described_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_failure)
|
282
|
+
expect { described_class.run_bolt_task(task_name, params, opts: {}) }.to raise_error(RuntimeError, %r{task failed})
|
286
283
|
end
|
287
284
|
|
288
285
|
it 'returns the exit code and error message when expecting failure' do
|
289
286
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
290
287
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
291
|
-
expect(
|
292
|
-
expect(
|
293
|
-
expect(
|
294
|
-
method_result =
|
288
|
+
expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
289
|
+
expect(described_class).to receive(:target_in_inventory?).and_return(true)
|
290
|
+
expect(described_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_failure)
|
291
|
+
method_result = described_class.run_bolt_task(task_name, params, expect_failures: true)
|
295
292
|
expect(method_result.exit_code).to be(123)
|
296
293
|
expect(method_result.stderr).to be('FAILURE!')
|
297
294
|
end
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
require 'rake'
|
5
|
-
# rubocop:disable RSpec/AnyInstance
|
6
5
|
describe 'litmus rake tasks' do
|
7
6
|
before(:all) do # rubocop:disable RSpec/BeforeAfterAll
|
8
7
|
load File.expand_path('../../../lib/puppet_litmus/rake_tasks.rb', __dir__)
|
@@ -83,4 +82,3 @@ describe 'litmus rake tasks' do
|
|
83
82
|
end
|
84
83
|
end
|
85
84
|
end
|
86
|
-
# rubocop:enable RSpec/AnyInstance
|
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.11.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bolt
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
version: 1.10.0
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version:
|
42
|
+
version: 1.13.0
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,7 +49,7 @@ dependencies:
|
|
49
49
|
version: 1.10.0
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
52
|
+
version: 1.13.0
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: tty-spinner
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,14 +102,14 @@ files:
|
|
102
102
|
- README.md
|
103
103
|
- lib/puppet_litmus.rb
|
104
104
|
- lib/puppet_litmus/inventory_manipulation.rb
|
105
|
+
- lib/puppet_litmus/puppet_helpers.rb
|
105
106
|
- lib/puppet_litmus/rake_tasks.rb
|
106
|
-
- lib/puppet_litmus/serverspec.rb
|
107
107
|
- lib/puppet_litmus/version.rb
|
108
108
|
- spec/data/doot.tar.gz
|
109
109
|
- spec/data/inventory.yaml
|
110
110
|
- spec/lib/puppet_litmus/inventory_manipulation_spec.rb
|
111
|
+
- spec/lib/puppet_litmus/puppet_helpers_spec.rb
|
111
112
|
- spec/lib/puppet_litmus/rake_tasks_spec.rb
|
112
|
-
- spec/lib/puppet_litmus/serverspec_spec.rb
|
113
113
|
- spec/lib/puppet_litmus/version_spec.rb
|
114
114
|
- spec/spec_helper.rb
|
115
115
|
homepage: https://github.com/puppetlabs/puppet_litmus
|
@@ -142,6 +142,6 @@ test_files:
|
|
142
142
|
- spec/lib/puppet_litmus/rake_tasks_spec.rb
|
143
143
|
- spec/lib/puppet_litmus/version_spec.rb
|
144
144
|
- spec/lib/puppet_litmus/inventory_manipulation_spec.rb
|
145
|
-
- spec/lib/puppet_litmus/
|
145
|
+
- spec/lib/puppet_litmus/puppet_helpers_spec.rb
|
146
146
|
- spec/data/doot.tar.gz
|
147
147
|
- spec/data/inventory.yaml
|