Skip to content

Commit

Permalink
Merge pull request #550 from h0tw1r3/module-install
Browse files Browse the repository at this point in the history
Minor install_module improvements
  • Loading branch information
jordanbreen28 authored Mar 19, 2024
2 parents e0c7202 + 23461d5 commit 6445dd8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
10 changes: 4 additions & 6 deletions lib/puppet_litmus/rake_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@
# module_tar = Dir.glob('pkg/*.tar.gz').max_by { |f| File.mtime(f) }
raise "Unable to find package in 'pkg/*.tar.gz'" if module_tar.nil?

install_module(inventory_hash, args[:target_node_name], module_tar, args[:module_repository])
install_module(inventory_hash, target_nodes, module_tar, args[:module_repository])

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

# Install the puppet modules from a source directory to nodes. It does not install dependencies.
Expand Down Expand Up @@ -241,10 +241,8 @@
include BoltSpec::Run
module_tars.each do |module_tar|
puts "Installing '#{module_tar}'"
target_nodes.each do |target_node_name|
install_module(inventory_hash, target_node_name, module_tar, args[:module_repository], args[:ignore_dependencies])
puts "Installed '#{module_tar}' on #{target_node_name}"
end
install_module(inventory_hash, target_nodes, module_tar, args[:module_repository], args[:ignore_dependencies])
puts "Installed '#{module_tar}' on #{target_nodes.join(', ')}"
end
end

Expand Down
49 changes: 49 additions & 0 deletions spec/lib/puppet_litmus/rake_tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,55 @@
end
end

context 'with litmus:install_module' do
let(:args) { { target_node_name: nil, module_repository: nil } }
let(:inventory_hash) { { 'groups' => [{ 'name' => 'ssh_nodes', 'nodes' => [{ 'uri' => 'some.host' }, { 'uri' => 'some.otherhost' }] }] } }
let(:target_nodes) { ['some.host', 'some.otherhost'] }
let(:dummy_tar) { 'spec/data/doot.tar.gz' }

before do
Rake::Task['litmus:install_module'].reenable
allow_any_instance_of(PuppetLitmus::InventoryManipulation).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
allow_any_instance_of(PuppetLitmus::InventoryManipulation).to receive(:find_targets).with(inventory_hash, args[:target_node_name]).and_return(target_nodes)
end

it 'installs module' do
expect_any_instance_of(Object).to receive(:build_module).and_return(dummy_tar)
expect($stdout).to receive(:puts).with("Built '#{dummy_tar}'")

expect_any_instance_of(Object).to receive(:install_module).with(inventory_hash, target_nodes, dummy_tar, args[:module_repository])
expect($stdout).to receive(:puts).with("Installed '#{dummy_tar}' on #{target_nodes.join(', ')}")

Rake::Task['litmus:install_module'].invoke(*args.values)
end

context 'with unknown target' do
let(:args) { { target_node_name: 'un.known', module_repository: nil } }
let(:target_nodes) { [] }

it 'exits with No targets found' do
expect do
expect($stdout).to receive(:puts).with('No targets found')
Rake::Task['litmus:install_module'].invoke(*args.values)
end.to raise_error(SystemExit) { |error|
expect(error.status).to eq(0)
}
end
end

context 'when build_module returns nil' do
let(:dummy_tar) { nil }

it 'raises error if build fails' do
expect_any_instance_of(Object).to receive(:build_module).and_return(dummy_tar)
expect($stdout).to receive(:puts).with("Built '#{dummy_tar}'")

expect { Rake::Task['litmus:install_module'].invoke(*args.values) }
.to raise_error(RuntimeError, "Unable to find package in 'pkg/*.tar.gz'")
end
end
end

context 'with litmus:install_modules_from_directory' do
let(:inventory_hash) { { 'groups' => [{ 'name' => 'ssh_nodes', 'nodes' => [{ 'uri' => 'some.host' }] }] } }
let(:target_dir) { File.join(Dir.pwd, 'spec/fixtures/modules') }
Expand Down
9 changes: 5 additions & 4 deletions spec/lib/puppet_litmus/util_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

RSpec.describe PuppetLitmus::Util do
context 'when using interpolate_powershell' do
let(:command) { 'foo' }
let(:encoded) { Base64.strict_encode64(command.encode('UTF-16LE')) }

it 'interpolates the command' do
expect(described_class.interpolate_powershell('foo')).to match(/powershell\.exe/)
expect(described_class.interpolate_powershell('foo')).to match(/NoProfile/)
expect(described_class.interpolate_powershell('foo')).to match(/EncodedCommand/)
expect(described_class.interpolate_powershell('foo')).not_to match(/foo/)
expect(described_class.interpolate_powershell(command)).to eql("powershell.exe -NoProfile -EncodedCommand #{encoded}")
expect(described_class.interpolate_powershell(command)).not_to match(/#{command}/)
end
end
end

0 comments on commit 6445dd8

Please sign in to comment.