puppet_litmus 0.7.3 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE +201 -201
- data/README.md +35 -35
- data/lib/puppet_litmus.rb +15 -15
- data/lib/puppet_litmus/inventory_manipulation.rb +203 -159
- data/lib/puppet_litmus/rake_tasks.rb +460 -445
- data/lib/puppet_litmus/serverspec.rb +224 -214
- data/lib/puppet_litmus/version.rb +6 -6
- data/spec/data/inventory.yaml +16 -16
- data/spec/lib/puppet_litmus/inventory_manipulation_spec.rb +138 -102
- data/spec/lib/puppet_litmus/rake_tasks_spec.rb +55 -55
- data/spec/lib/puppet_litmus/serverspec_spec.rb +194 -196
- data/spec/lib/puppet_litmus/version_spec.rb +10 -10
- data/spec/spec_helper.rb +29 -29
- metadata +7 -7
data/spec/data/inventory.yaml
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
---
|
2
|
-
groups:
|
3
|
-
- name: ssh_nodes
|
4
|
-
nodes:
|
5
|
-
- name: test.delivery.puppetlabs.net
|
6
|
-
config:
|
7
|
-
transport: ssh
|
8
|
-
ssh:
|
9
|
-
user: root
|
10
|
-
password: Qu@lity!
|
11
|
-
host-key-check: false
|
12
|
-
facts:
|
13
|
-
provisioner: vmpooler
|
14
|
-
platform: centos-5-x86_64
|
15
|
-
- name: winrm_nodes
|
16
|
-
nodes: []
|
1
|
+
---
|
2
|
+
groups:
|
3
|
+
- name: ssh_nodes
|
4
|
+
nodes:
|
5
|
+
- name: test.delivery.puppetlabs.net
|
6
|
+
config:
|
7
|
+
transport: ssh
|
8
|
+
ssh:
|
9
|
+
user: root
|
10
|
+
password: Qu@lity!
|
11
|
+
host-key-check: false
|
12
|
+
facts:
|
13
|
+
provisioner: vmpooler
|
14
|
+
platform: centos-5-x86_64
|
15
|
+
- name: winrm_nodes
|
16
|
+
nodes: []
|
@@ -1,102 +1,138 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe PuppetLitmus::InventoryManipulation do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
let(:
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
{ '
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
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
|
+
context 'with config_from_node' do
|
13
|
+
let(:no_config_hash) do
|
14
|
+
{ 'groups' =>
|
15
|
+
[{ 'name' => 'ssh_nodes',
|
16
|
+
'nodes' =>
|
17
|
+
[{ 'name' => 'test.delivery.puppetlabs.net',
|
18
|
+
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' } }] },
|
19
|
+
{ 'name' => 'winrm_nodes', 'nodes' => [] }] }
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:config_hash) do
|
23
|
+
{ 'groups' =>
|
24
|
+
[{ 'name' => 'ssh_nodes',
|
25
|
+
'nodes' =>
|
26
|
+
[{ 'name' => 'test.delivery.puppetlabs.net',
|
27
|
+
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
28
|
+
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' } }] },
|
29
|
+
{ 'name' => 'winrm_nodes', 'nodes' => [] }] }
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:inventory_full_path) { 'spec/data/inventory.yaml' }
|
33
|
+
|
34
|
+
let(:no_feature_hash) do
|
35
|
+
{ 'groups' =>
|
36
|
+
[{ 'name' => 'ssh_nodes',
|
37
|
+
'nodes' =>
|
38
|
+
[{ 'name' => 'test.delivery.puppetlabs.net',
|
39
|
+
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
40
|
+
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' } }] },
|
41
|
+
{ 'name' => 'winrm_nodes', 'nodes' => [] }] }
|
42
|
+
end
|
43
|
+
|
44
|
+
let(:feature_hash_group) do
|
45
|
+
{ 'groups' =>
|
46
|
+
[{ 'name' => 'ssh_nodes',
|
47
|
+
'nodes' =>
|
48
|
+
[{ 'name' => 'test.delivery.puppetlabs.net',
|
49
|
+
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
50
|
+
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' } }],
|
51
|
+
'features' => ['puppet-agent'] },
|
52
|
+
{ 'name' => 'winrm_nodes', 'nodes' => [] }] }
|
53
|
+
end
|
54
|
+
|
55
|
+
let(:empty_feature_hash_group) do
|
56
|
+
{ 'groups' =>
|
57
|
+
[{ 'name' => 'ssh_nodes',
|
58
|
+
'nodes' =>
|
59
|
+
[{ 'name' => 'test.delivery.puppetlabs.net',
|
60
|
+
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
61
|
+
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' } }],
|
62
|
+
'features' => [] },
|
63
|
+
{ 'name' => 'winrm_nodes', 'nodes' => [] }] }
|
64
|
+
end
|
65
|
+
|
66
|
+
let(:feature_hash_node) do
|
67
|
+
{ 'groups' =>
|
68
|
+
[{ 'name' => 'ssh_nodes',
|
69
|
+
'nodes' =>
|
70
|
+
[{ 'name' => 'test.delivery.puppetlabs.net',
|
71
|
+
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
72
|
+
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' },
|
73
|
+
'features' => ['puppet-agent'] }] },
|
74
|
+
{ 'name' => 'winrm_nodes', 'nodes' => [] }] }
|
75
|
+
end
|
76
|
+
|
77
|
+
let(:empty_feature_hash_node) do
|
78
|
+
{ 'groups' =>
|
79
|
+
[{ 'name' => 'ssh_nodes',
|
80
|
+
'nodes' =>
|
81
|
+
[{ 'name' => 'test.delivery.puppetlabs.net',
|
82
|
+
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
83
|
+
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' },
|
84
|
+
'features' => [] }] },
|
85
|
+
{ 'name' => 'winrm_nodes', 'nodes' => [] }] }
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'no matching node, raises' do
|
89
|
+
expect { dummy_class.config_from_node(config_hash, 'not.here') }.to raise_error('No config was found for not.here')
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'no config section, returns nil' do
|
93
|
+
expect(dummy_class.config_from_node(no_config_hash, 'test.delivery.puppetlabs.net')).to eq(nil)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'config exists, and returns' do
|
97
|
+
expect(dummy_class.config_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('transport' => 'ssh', 'ssh' =>
|
98
|
+
{ 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false })
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'no feature exists for the group, and returns hash with feature added' do
|
102
|
+
expect(dummy_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
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'feature exists for the group, and returns hash with feature removed' do
|
106
|
+
expect(dummy_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
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'write from inventory_hash to inventory_yaml file feature_hash_group' do
|
110
|
+
expect { dummy_class.write_to_inventory_file(feature_hash_group, inventory_full_path) }.not_to raise_error
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'empty feature exists for the group, and returns hash with feature added' do
|
114
|
+
expect(dummy_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
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'no feature exists for the node, and returns hash with feature added' do
|
118
|
+
expect(dummy_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
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'feature exists for the node, and returns hash with feature removed' do
|
122
|
+
expect(dummy_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
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'write from inventory_hash to inventory_yaml file feature_hash_node' do
|
126
|
+
expect { dummy_class.write_to_inventory_file(feature_hash_node, inventory_full_path) }.not_to raise_error
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'empty feature exists for the node, and returns hash with feature added' do
|
130
|
+
expect(dummy_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
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'write from inventory_hash to inventory_yaml file no feature_hash' do
|
134
|
+
expect(File).to exist(inventory_full_path)
|
135
|
+
expect { dummy_class.write_to_inventory_file(no_feature_hash, inventory_full_path) }.not_to raise_error
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -1,55 +1,55 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'rake'
|
5
|
-
|
6
|
-
describe 'litmus rake tasks' do
|
7
|
-
before(:all) do # rubocop:disable RSpec/BeforeAfterAll
|
8
|
-
load File.expand_path('../../../lib/puppet_litmus/rake_tasks.rb', __dir__)
|
9
|
-
# the spec_prep task is stubbed, rather than load from another gem.
|
10
|
-
Rake::Task.define_task(:spec_prep)
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'with litmus:metadata task' do
|
14
|
-
it 'happy path' do
|
15
|
-
metadata = { 'name' => 'puppetlabs-postgresql',
|
16
|
-
'version' => '6.0.0',
|
17
|
-
'operatingsystem_support' =>
|
18
|
-
[{ 'operatingsystem' => 'RedHat', 'operatingsystemrelease' => ['5'] },
|
19
|
-
{ 'operatingsystem' => 'Ubuntu', 'operatingsystemrelease' => ['14.04', '18.04'] }],
|
20
|
-
'template-ref' => 'heads/master-0-g7827fc2' }
|
21
|
-
expect(File).to receive(:read).with(any_args).once
|
22
|
-
expect(JSON).to receive(:parse).with(any_args).and_return(metadata)
|
23
|
-
expect(STDOUT).to receive(:puts).with('redhat-5-x86_64')
|
24
|
-
expect(STDOUT).to receive(:puts).with('ubuntu-1404-x86_64')
|
25
|
-
expect(STDOUT).to receive(:puts).with('ubuntu-1804-x86_64')
|
26
|
-
Rake::Task['litmus:metadata'].invoke
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'with litmus:provision_install task' do
|
31
|
-
it 'happy path' do
|
32
|
-
expect(Rake::Task['spec_prep']).to receive(:invoke).and_return('').once
|
33
|
-
expect(Rake::Task['litmus:provision_list']).to receive(:invoke).with('default').once
|
34
|
-
expect(Rake::Task['litmus:install_agent']).to receive(:invoke).with('puppet6').once
|
35
|
-
expect(Rake::Task['litmus:install_module']).to receive(:invoke).once
|
36
|
-
Rake::Task['litmus:provision_install'].invoke('default', 'puppet6')
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'with litmus:provision task' do
|
41
|
-
it 'provisions' do
|
42
|
-
results = [{ 'node' => 'localhost',
|
43
|
-
'target' => 'localhost',
|
44
|
-
'action' => 'task',
|
45
|
-
'object' => 'provision::docker',
|
46
|
-
'status' => 'success',
|
47
|
-
'result' => { 'status' => 'ok', 'node_name' => 'localhost:2222' } }]
|
48
|
-
|
49
|
-
allow(File).to receive(:directory?).with(any_args).and_return(true)
|
50
|
-
allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with(any_args).and_return(results) # rubocop:disable RSpec/AnyInstance
|
51
|
-
expect(STDOUT).to receive(:puts).with('localhost:2222, centos:7')
|
52
|
-
Rake::Task['litmus:provision'].invoke('docker', 'centos:7')
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'rake'
|
5
|
+
|
6
|
+
describe 'litmus rake tasks' do
|
7
|
+
before(:all) do # rubocop:disable RSpec/BeforeAfterAll
|
8
|
+
load File.expand_path('../../../lib/puppet_litmus/rake_tasks.rb', __dir__)
|
9
|
+
# the spec_prep task is stubbed, rather than load from another gem.
|
10
|
+
Rake::Task.define_task(:spec_prep)
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'with litmus:metadata task' do
|
14
|
+
it 'happy path' do
|
15
|
+
metadata = { 'name' => 'puppetlabs-postgresql',
|
16
|
+
'version' => '6.0.0',
|
17
|
+
'operatingsystem_support' =>
|
18
|
+
[{ 'operatingsystem' => 'RedHat', 'operatingsystemrelease' => ['5'] },
|
19
|
+
{ 'operatingsystem' => 'Ubuntu', 'operatingsystemrelease' => ['14.04', '18.04'] }],
|
20
|
+
'template-ref' => 'heads/master-0-g7827fc2' }
|
21
|
+
expect(File).to receive(:read).with(any_args).once
|
22
|
+
expect(JSON).to receive(:parse).with(any_args).and_return(metadata)
|
23
|
+
expect(STDOUT).to receive(:puts).with('redhat-5-x86_64')
|
24
|
+
expect(STDOUT).to receive(:puts).with('ubuntu-1404-x86_64')
|
25
|
+
expect(STDOUT).to receive(:puts).with('ubuntu-1804-x86_64')
|
26
|
+
Rake::Task['litmus:metadata'].invoke
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with litmus:provision_install task' do
|
31
|
+
it 'happy path' do
|
32
|
+
expect(Rake::Task['spec_prep']).to receive(:invoke).and_return('').once
|
33
|
+
expect(Rake::Task['litmus:provision_list']).to receive(:invoke).with('default').once
|
34
|
+
expect(Rake::Task['litmus:install_agent']).to receive(:invoke).with('puppet6').once
|
35
|
+
expect(Rake::Task['litmus:install_module']).to receive(:invoke).once
|
36
|
+
Rake::Task['litmus:provision_install'].invoke('default', 'puppet6')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'with litmus:provision task' do
|
41
|
+
it 'provisions' do
|
42
|
+
results = [{ 'node' => 'localhost',
|
43
|
+
'target' => 'localhost',
|
44
|
+
'action' => 'task',
|
45
|
+
'object' => 'provision::docker',
|
46
|
+
'status' => 'success',
|
47
|
+
'result' => { 'status' => 'ok', 'node_name' => 'localhost:2222' } }]
|
48
|
+
|
49
|
+
allow(File).to receive(:directory?).with(any_args).and_return(true)
|
50
|
+
allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with(any_args).and_return(results) # rubocop:disable RSpec/AnyInstance
|
51
|
+
expect(STDOUT).to receive(:puts).with('localhost:2222, centos:7')
|
52
|
+
Rake::Task['litmus:provision'].invoke('docker', 'centos:7')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -1,196 +1,194 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe PuppetLitmus::Serverspec do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
expect(dummy_class).to receive(:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
let(:
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
expect
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
let(:
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
expect
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
expect(
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
expect(
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
expect(
|
94
|
-
method_result
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
let(:
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
expect(
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
expect(
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
expect(
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
let(:
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
let(:
|
145
|
-
|
146
|
-
let(:
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
expect
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
expect(
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
expect(
|
172
|
-
method_result
|
173
|
-
expect(method_result.
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
expect
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
expect(
|
190
|
-
method_result
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
end
|
196
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe PuppetLitmus::Serverspec do
|
6
|
+
let(:dummy_class) do
|
7
|
+
dummy = Class.new
|
8
|
+
dummy.extend(described_class)
|
9
|
+
dummy
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with idempotent_apply' do
|
13
|
+
let(:manifest) do
|
14
|
+
"include '::doot'"
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'calls all functions' do
|
18
|
+
expect(dummy_class).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
|
19
|
+
expect(dummy_class).to receive(:apply_manifest).with(nil, catch_failures: true, manifest_file_location: '/bla.pp')
|
20
|
+
expect(dummy_class).to receive(:apply_manifest).with(nil, catch_changes: true, manifest_file_location: '/bla.pp')
|
21
|
+
dummy_class.idempotent_apply(manifest)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '.run_shell' do
|
26
|
+
let(:command_to_run) { "puts 'doot'" }
|
27
|
+
let(:result) { ['result' => { 'exit_code' => 0, 'stdout' => nil, 'stderr' => nil }] }
|
28
|
+
let(:inventory_hash) { Hash.new(0) }
|
29
|
+
|
30
|
+
it 'responds to run_shell' do
|
31
|
+
expect(dummy_class).to respond_to(:run_shell).with(1..2).arguments
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when running against localhost and no inventory.yaml file' do
|
35
|
+
it 'does run_shell against localhost without error' do
|
36
|
+
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
|
37
|
+
expect(dummy_class).to receive(:run_command).with(command_to_run, 'localhost', config: nil, inventory: nil).and_return(result)
|
38
|
+
expect { dummy_class.run_shell(command_to_run) }.not_to raise_error
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when running against remote host' do
|
43
|
+
it 'does run_shell against remote host without error' do
|
44
|
+
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
45
|
+
expect(dummy_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
46
|
+
expect(dummy_class).to receive(:run_command).with(command_to_run, 'some.host', config: nil, inventory: inventory_hash).and_return(result)
|
47
|
+
expect { dummy_class.run_shell(command_to_run) }.not_to raise_error
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '.bolt_upload_file' do
|
53
|
+
let(:local) { '/tmp' }
|
54
|
+
let(:remote) { '/remote_tmp' }
|
55
|
+
# Ignore rubocop because these hashes are representative of output from an external method and editing them leads to test failures.
|
56
|
+
# rubocop:disable SpaceInsideHashLiteralBraces, SpaceInsideBlockBraces, SpaceAroundOperators, LineLength, SpaceAfterComma
|
57
|
+
let(:result_success) {[{'node'=>'some.host','target'=>'some.host','action'=>'upload','object'=>'C:\foo\bar.ps1','status'=>'success','result'=>{'_output'=>'Uploaded \'C:\foo\bar.ps1\' to \'some.host:C:\bar\''}}]}
|
58
|
+
let(:result_failure) {[{'node'=>'some.host','target'=>'some.host','action'=>nil,'object'=>nil,'status'=>'failure','result'=>{'_error'=>{'kind'=>'puppetlabs.tasks/task_file_error','msg'=>'No such file or directory @ rb_sysopen - /nonexistant/file/path','details'=>{},'issue_code'=>'WRITE_ERROR'}}}]}
|
59
|
+
# rubocop:enable SpaceInsideHashLiteralBraces, SpaceInsideBlockBraces, SpaceAroundOperators, LineLength, SpaceAfterComma
|
60
|
+
let(:inventory_hash) { Hash.new(0) }
|
61
|
+
|
62
|
+
it 'responds to run_shell' do
|
63
|
+
expect(dummy_class).to respond_to(:bolt_upload_file).with(2..3).arguments
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when upload returns success' do
|
67
|
+
it 'does upload_file against remote host without error' do
|
68
|
+
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
69
|
+
expect(dummy_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
70
|
+
expect(dummy_class).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_success)
|
71
|
+
expect { dummy_class.bolt_upload_file(local, remote) }.not_to raise_error
|
72
|
+
end
|
73
|
+
it 'does upload_file against localhost without error' do
|
74
|
+
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
|
75
|
+
expect(dummy_class).not_to receive(:inventory_hash_from_inventory_file)
|
76
|
+
expect(dummy_class).to receive(:upload_file).with(local, remote, 'localhost', options: {}, config: nil, inventory: nil).and_return(result_success)
|
77
|
+
expect { dummy_class.bolt_upload_file(local, remote) }.not_to raise_error
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when upload returns failure' do
|
82
|
+
it 'does upload_file gives runtime error for failure' do
|
83
|
+
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
84
|
+
expect(dummy_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
85
|
+
expect(dummy_class).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_failure)
|
86
|
+
expect { dummy_class.bolt_upload_file(local, remote) }.to raise_error(RuntimeError, %r{upload file failed})
|
87
|
+
end
|
88
|
+
it 'returns the exit code and error message when expecting failure' do
|
89
|
+
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
90
|
+
expect(dummy_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
91
|
+
expect(dummy_class).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_failure)
|
92
|
+
method_result = dummy_class.bolt_upload_file(local, remote, expect_failures: true)
|
93
|
+
expect(method_result.exit_code).to be(255)
|
94
|
+
expect(method_result.stderr).to be('No such file or directory @ rb_sysopen - /nonexistant/file/path')
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '.bolt_run_script' do
|
100
|
+
let(:script) { '/tmp/script.sh' }
|
101
|
+
let(:result) { ['result' => { 'exit_code' => 0, 'stdout' => nil, 'stderr' => nil }] }
|
102
|
+
let(:inventory_hash) { Hash.new(0) }
|
103
|
+
|
104
|
+
it 'responds to bolt_run_script' do
|
105
|
+
expect(dummy_class).to respond_to(:bolt_run_script).with(1..2).arguments
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'when running against localhost and no inventory.yaml file' do
|
109
|
+
it 'does bolt_run_script against localhost without error' do
|
110
|
+
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
|
111
|
+
expect(dummy_class).not_to receive(:inventory_hash_from_inventory_file)
|
112
|
+
expect(dummy_class).to receive(:run_script).with(script, 'localhost', [], options: {}, config: nil, inventory: nil).and_return(result)
|
113
|
+
expect { dummy_class.bolt_run_script(script) }.not_to raise_error
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'when running against remote host' do
|
118
|
+
it 'does bolt_run_script against remote host without error' do
|
119
|
+
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
120
|
+
expect(dummy_class).to receive(:inventory_hash_from_inventory_file)
|
121
|
+
expect(dummy_class).to receive(:run_script).with(script, 'some.host', [], options: {}, config: nil, inventory: nil).and_return(result)
|
122
|
+
expect { dummy_class.bolt_run_script(script) }.not_to raise_error
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'when running with arguments' do
|
127
|
+
it 'does bolt_run_script with arguments without error' do
|
128
|
+
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
|
129
|
+
expect(dummy_class).not_to receive(:inventory_hash_from_inventory_file)
|
130
|
+
expect(dummy_class).to receive(:run_script).with(script, 'localhost', ['doot'], options: {}, config: nil, inventory: nil).and_return(result)
|
131
|
+
expect { dummy_class.bolt_run_script(script, arguments: ['doot']) }.not_to raise_error
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe '.run_bolt_task' do
|
137
|
+
let(:task_name) { 'testtask' }
|
138
|
+
let(:params) { { 'action' => 'install', 'name' => 'foo' } }
|
139
|
+
let(:config_data) { { 'modulepath' => File.join(Dir.pwd, 'spec', 'fixtures', 'modules') } }
|
140
|
+
# Ignore rubocop because these hashes are representative of output from an external method and editing them leads to test failures.
|
141
|
+
# rubocop:disable SpaceInsideHashLiteralBraces, SpaceBeforeBlockBraces, SpaceInsideBlockBraces, SpaceAroundOperators, LineLength, SpaceAfterComma
|
142
|
+
let(:result_unstructured_task_success){ [{'node'=>'some.host','target'=>'some.host','action'=>'task','object'=>'testtask::unstructured','status'=>'success','result'=>{'_output'=>'SUCCESS!'}}]}
|
143
|
+
let(:result_structured_task_success){ [{'node'=>'some.host','target'=>'some.host','action'=>'task','object'=>'testtask::structured','status'=>'success','result'=>{'key1'=>'foo','key2'=>'bar'}}]}
|
144
|
+
let(:result_failure) {[{'node'=>'some.host','target'=>'some.host','action'=>'task','object'=>'testtask::unstructured','status'=>'failure','result'=>{'_error'=>{'msg'=>'FAILURE!','kind'=>'puppetlabs.tasks/task-error','details'=>{'exitcode'=>123}}}}]}
|
145
|
+
# rubocop:enable SpaceInsideHashLiteralBraces, SpaceBeforeBlockBraces, SpaceInsideBlockBraces, SpaceAroundOperators, LineLength, SpaceAfterComma
|
146
|
+
let(:inventory_hash) { Hash.new(0) }
|
147
|
+
|
148
|
+
it 'responds to bolt_run_task' do
|
149
|
+
expect(dummy_class).to respond_to(:run_bolt_task).with(2..3).arguments
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'when bolt returns success' do
|
153
|
+
it 'does bolt_task_run gives no runtime error for success' do
|
154
|
+
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
155
|
+
expect(dummy_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
156
|
+
expect(dummy_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
|
157
|
+
expect { dummy_class.run_bolt_task(task_name, params, opts: {}) }.not_to raise_error
|
158
|
+
end
|
159
|
+
it 'returns stdout for unstructured-data tasks' do
|
160
|
+
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
161
|
+
expect(dummy_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
162
|
+
expect(dummy_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
|
163
|
+
method_result = dummy_class.run_bolt_task(task_name, params, opts: {})
|
164
|
+
expect(method_result.stdout).to eq('SUCCESS!')
|
165
|
+
end
|
166
|
+
it 'returns structured output for structured-data tasks' do
|
167
|
+
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
168
|
+
expect(dummy_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
169
|
+
expect(dummy_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_structured_task_success)
|
170
|
+
method_result = dummy_class.run_bolt_task(task_name, params, opts: {})
|
171
|
+
expect(method_result.stdout).to eq('{"key1"=>"foo", "key2"=>"bar"}')
|
172
|
+
expect(method_result.result['key1']).to eq('foo')
|
173
|
+
expect(method_result.result['key2']).to eq('bar')
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context 'when bolt returns failure' do
|
178
|
+
it 'does bolt_task_run gives runtime error for failure' do
|
179
|
+
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
180
|
+
expect(dummy_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
181
|
+
expect(dummy_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_failure)
|
182
|
+
expect { dummy_class.run_bolt_task(task_name, params, opts: {}) }.to raise_error(RuntimeError, %r{task failed})
|
183
|
+
end
|
184
|
+
it 'returns the exit code and error message when expecting failure' do
|
185
|
+
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
186
|
+
expect(dummy_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
187
|
+
expect(dummy_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_failure)
|
188
|
+
method_result = dummy_class.run_bolt_task(task_name, params, expect_failures: true)
|
189
|
+
expect(method_result.exit_code).to be(123)
|
190
|
+
expect(method_result.stderr).to be('FAILURE!')
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|