Skip to content

Commit 6445dd8

Browse files
Merge pull request #550 from h0tw1r3/module-install
Minor install_module improvements
2 parents e0c7202 + 23461d5 commit 6445dd8

File tree

3 files changed

+58
-10
lines changed

3 files changed

+58
-10
lines changed

lib/puppet_litmus/rake_tasks.rb

+4-6
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@
210210
# module_tar = Dir.glob('pkg/*.tar.gz').max_by { |f| File.mtime(f) }
211211
raise "Unable to find package in 'pkg/*.tar.gz'" if module_tar.nil?
212212

213-
install_module(inventory_hash, args[:target_node_name], module_tar, args[:module_repository])
213+
install_module(inventory_hash, target_nodes, module_tar, args[:module_repository])
214214

215-
puts "Installed '#{module_tar}' on #{args[:target_node_name]}"
215+
puts "Installed '#{module_tar}' on #{target_nodes.join(', ')}"
216216
end
217217

218218
# Install the puppet modules from a source directory to nodes. It does not install dependencies.
@@ -241,10 +241,8 @@
241241
include BoltSpec::Run
242242
module_tars.each do |module_tar|
243243
puts "Installing '#{module_tar}'"
244-
target_nodes.each do |target_node_name|
245-
install_module(inventory_hash, target_node_name, module_tar, args[:module_repository], args[:ignore_dependencies])
246-
puts "Installed '#{module_tar}' on #{target_node_name}"
247-
end
244+
install_module(inventory_hash, target_nodes, module_tar, args[:module_repository], args[:ignore_dependencies])
245+
puts "Installed '#{module_tar}' on #{target_nodes.join(', ')}"
248246
end
249247
end
250248

spec/lib/puppet_litmus/rake_tasks_spec.rb

+49
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,55 @@
2626
end
2727
end
2828

29+
context 'with litmus:install_module' do
30+
let(:args) { { target_node_name: nil, module_repository: nil } }
31+
let(:inventory_hash) { { 'groups' => [{ 'name' => 'ssh_nodes', 'nodes' => [{ 'uri' => 'some.host' }, { 'uri' => 'some.otherhost' }] }] } }
32+
let(:target_nodes) { ['some.host', 'some.otherhost'] }
33+
let(:dummy_tar) { 'spec/data/doot.tar.gz' }
34+
35+
before do
36+
Rake::Task['litmus:install_module'].reenable
37+
allow_any_instance_of(PuppetLitmus::InventoryManipulation).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
38+
allow_any_instance_of(PuppetLitmus::InventoryManipulation).to receive(:find_targets).with(inventory_hash, args[:target_node_name]).and_return(target_nodes)
39+
end
40+
41+
it 'installs module' do
42+
expect_any_instance_of(Object).to receive(:build_module).and_return(dummy_tar)
43+
expect($stdout).to receive(:puts).with("Built '#{dummy_tar}'")
44+
45+
expect_any_instance_of(Object).to receive(:install_module).with(inventory_hash, target_nodes, dummy_tar, args[:module_repository])
46+
expect($stdout).to receive(:puts).with("Installed '#{dummy_tar}' on #{target_nodes.join(', ')}")
47+
48+
Rake::Task['litmus:install_module'].invoke(*args.values)
49+
end
50+
51+
context 'with unknown target' do
52+
let(:args) { { target_node_name: 'un.known', module_repository: nil } }
53+
let(:target_nodes) { [] }
54+
55+
it 'exits with No targets found' do
56+
expect do
57+
expect($stdout).to receive(:puts).with('No targets found')
58+
Rake::Task['litmus:install_module'].invoke(*args.values)
59+
end.to raise_error(SystemExit) { |error|
60+
expect(error.status).to eq(0)
61+
}
62+
end
63+
end
64+
65+
context 'when build_module returns nil' do
66+
let(:dummy_tar) { nil }
67+
68+
it 'raises error if build fails' do
69+
expect_any_instance_of(Object).to receive(:build_module).and_return(dummy_tar)
70+
expect($stdout).to receive(:puts).with("Built '#{dummy_tar}'")
71+
72+
expect { Rake::Task['litmus:install_module'].invoke(*args.values) }
73+
.to raise_error(RuntimeError, "Unable to find package in 'pkg/*.tar.gz'")
74+
end
75+
end
76+
end
77+
2978
context 'with litmus:install_modules_from_directory' do
3079
let(:inventory_hash) { { 'groups' => [{ 'name' => 'ssh_nodes', 'nodes' => [{ 'uri' => 'some.host' }] }] } }
3180
let(:target_dir) { File.join(Dir.pwd, 'spec/fixtures/modules') }

spec/lib/puppet_litmus/util_spec.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
RSpec.describe PuppetLitmus::Util do
77
context 'when using interpolate_powershell' do
8+
let(:command) { 'foo' }
9+
let(:encoded) { Base64.strict_encode64(command.encode('UTF-16LE')) }
10+
811
it 'interpolates the command' do
9-
expect(described_class.interpolate_powershell('foo')).to match(/powershell\.exe/)
10-
expect(described_class.interpolate_powershell('foo')).to match(/NoProfile/)
11-
expect(described_class.interpolate_powershell('foo')).to match(/EncodedCommand/)
12-
expect(described_class.interpolate_powershell('foo')).not_to match(/foo/)
12+
expect(described_class.interpolate_powershell(command)).to eql("powershell.exe -NoProfile -EncodedCommand #{encoded}")
13+
expect(described_class.interpolate_powershell(command)).not_to match(/#{command}/)
1314
end
1415
end
1516
end

0 commit comments

Comments
 (0)