From 1944c65ff5f96ad8f85278a590255573b816be50 Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Fri, 23 Feb 2024 16:20:28 -0600 Subject: [PATCH 1/4] (bugfix) show target nodes in output if target_node_name option is not given, the default is all targets, but the confirmation output is blank --- lib/puppet_litmus/rake_tasks.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet_litmus/rake_tasks.rb b/lib/puppet_litmus/rake_tasks.rb index 62c4547a..44a7d945 100644 --- a/lib/puppet_litmus/rake_tasks.rb +++ b/lib/puppet_litmus/rake_tasks.rb @@ -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. From fcdf73869c5d080b392f72f4c2d972e77e0391b0 Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Fri, 23 Feb 2024 16:23:52 -0600 Subject: [PATCH 2/4] (maint) improve install_modules_from_directory performance install each module to nodes in parallel --- lib/puppet_litmus/rake_tasks.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/puppet_litmus/rake_tasks.rb b/lib/puppet_litmus/rake_tasks.rb index 44a7d945..dcb2fe6a 100644 --- a/lib/puppet_litmus/rake_tasks.rb +++ b/lib/puppet_litmus/rake_tasks.rb @@ -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 From e9ca7b822fcf0882c839fedd32f76be8d4f47a87 Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Thu, 14 Mar 2024 22:36:52 -0500 Subject: [PATCH 3/4] (maint) improve interpolate_powershell spec test --- spec/lib/puppet_litmus/util_spec.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/spec/lib/puppet_litmus/util_spec.rb b/spec/lib/puppet_litmus/util_spec.rb index dfefc28b..964303e5 100644 --- a/spec/lib/puppet_litmus/util_spec.rb +++ b/spec/lib/puppet_litmus/util_spec.rb @@ -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 From 23461d5c66a2742e580d3243be058b141c02e67f Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Thu, 14 Mar 2024 23:55:37 -0500 Subject: [PATCH 4/4] (maint) add tests for litmus:install_module task --- spec/lib/puppet_litmus/rake_tasks_spec.rb | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/spec/lib/puppet_litmus/rake_tasks_spec.rb b/spec/lib/puppet_litmus/rake_tasks_spec.rb index cad91179..313ad48e 100644 --- a/spec/lib/puppet_litmus/rake_tasks_spec.rb +++ b/spec/lib/puppet_litmus/rake_tasks_spec.rb @@ -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') }