From bd005ac60b4485761a99f6b06560426eb5aca059 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Tue, 3 May 2022 16:26:49 +0200 Subject: [PATCH] Use tmpfile extension Having a proper extension, even for temporary files is much cleaner. --- beaker_puppet_helpers.gemspec | 2 +- lib/beaker_puppet_helpers/dsl.rb | 2 +- lib/beaker_puppet_helpers/install_utils.rb | 3 +-- lib/beaker_puppet_helpers/module_utils.rb | 2 +- spec/beaker_puppet_helpers/module_utils_spec.rb | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/beaker_puppet_helpers.gemspec b/beaker_puppet_helpers.gemspec index e19f17d..57db8c8 100644 --- a/beaker_puppet_helpers.gemspec +++ b/beaker_puppet_helpers.gemspec @@ -16,6 +16,6 @@ Gem::Specification.new do |s| s.require_paths = ['lib'] # Run time dependencies - s.add_runtime_dependency 'beaker', '>= 4', '< 6' + s.add_runtime_dependency 'beaker', '>= 5.8.1', '< 6' s.add_runtime_dependency 'puppet-modulebuilder', '>= 0.3', '< 2' end diff --git a/lib/beaker_puppet_helpers/dsl.rb b/lib/beaker_puppet_helpers/dsl.rb index caa239f..ab28b22 100644 --- a/lib/beaker_puppet_helpers/dsl.rb +++ b/lib/beaker_puppet_helpers/dsl.rb @@ -173,7 +173,7 @@ def apply_manifest_on(hosts, manifest, opts = {}, &block) puppet_apply_opts = host[:default_apply_opts].merge(puppet_apply_opts) if host[:default_apply_opts].respond_to? :merge - file_path = host.tmpfile(%(apply_manifest_#{Time.now.strftime('%H%M%S%L')}.pp)) + file_path = host.tmpfile(%(apply_manifest_#{Time.now.strftime('%H%M%S%L')}), '.pp') begin create_remote_file(host, file_path, "#{manifest}\n") diff --git a/lib/beaker_puppet_helpers/install_utils.rb b/lib/beaker_puppet_helpers/install_utils.rb index ab4393a..4e27273 100644 --- a/lib/beaker_puppet_helpers/install_utils.rb +++ b/lib/beaker_puppet_helpers/install_utils.rb @@ -99,8 +99,7 @@ def self.puppet_package_name(host, prefer_aio: true) def self.wget_on(host, url) extension = File.extname(url) name = File.basename(url, extension) - # Can't use host.tmpfile since we need to set an extension - target = host.exec(Beaker::Command.new("mktemp -t '#{name}-XXXXXX#{extension}'")).stdout.strip + target = host.tmpfile(name, extension) begin host.exec(Beaker::Command.new("wget -O '#{target}' '#{url}'")) yield target diff --git a/lib/beaker_puppet_helpers/module_utils.rb b/lib/beaker_puppet_helpers/module_utils.rb index ecd910a..cfc2a8b 100644 --- a/lib/beaker_puppet_helpers/module_utils.rb +++ b/lib/beaker_puppet_helpers/module_utils.rb @@ -44,7 +44,7 @@ def install_local_module_on(hosts, source = '.') source_path = builder.build begin block_on hosts do |host| - target_file = host.tmpfile('puppet_module') + target_file = host.tmpfile('puppet_module', '.tar.gz') begin host.do_scp_to(source_path, target_file, {}) install_puppet_module_via_pmt_on(host, target_file) diff --git a/spec/beaker_puppet_helpers/module_utils_spec.rb b/spec/beaker_puppet_helpers/module_utils_spec.rb index deb5dff..d928811 100644 --- a/spec/beaker_puppet_helpers/module_utils_spec.rb +++ b/spec/beaker_puppet_helpers/module_utils_spec.rb @@ -97,7 +97,7 @@ def logger expect(Puppet::Modulebuilder::Builder).to receive(:new).with('/path/to/module').and_return(builder) expect(builder).to receive(:build).and_return('/path/to/tarball') - expect(host).to receive(:tmpfile).with('puppet_module').and_return('temp') + expect(host).to receive(:tmpfile).with('puppet_module', '.tar.gz').and_return('temp') expect(host).to receive(:do_scp_to).with('/path/to/tarball', 'temp', {}) expect(dsl).to receive(:install_puppet_module_via_pmt_on).with(host, 'temp') expect(host).to receive(:rm_rf).with('temp')