From af63a62b6c3eef0b0a7898ce703ec321ebe212a9 Mon Sep 17 00:00:00 2001 From: Sean Escriva <sean.escriva@gmail.com> Date: Sat, 17 Oct 2020 16:01:29 -0400 Subject: [PATCH] Switch sensu_ctl resouce to use archive_file This removes the need for a dependency on the seven_zip cookbook since archive_file is a builtin chef resources since Chef 15 --- metadata.rb | 1 - resources/ctl.rb | 23 +++----------------- spec/unit/recipes/sensu_ctl_spec.rb | 8 ++----- test/cookbooks/sensu_test/recipes/default.rb | 14 ++++++++++++ 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/metadata.rb b/metadata.rb index 0558eedd..76b25e20 100644 --- a/metadata.rb +++ b/metadata.rb @@ -27,4 +27,3 @@ source_url 'https://github.com/sensu/sensu-go-chef' depends 'packagecloud' -depends 'seven_zip' diff --git a/resources/ctl.rb b/resources/ctl.rb index 15a63b93..e5bd64b7 100644 --- a/resources/ctl.rb +++ b/resources/ctl.rb @@ -63,7 +63,6 @@ if platform?('windows') # This is awaiting a packaged method to be delivered, but provides a resource currently. - include_recipe 'seven_zip' directory 'c:\sensutemp' @@ -72,26 +71,10 @@ not_if "Test-Path c:/sensutemp/sensu-go_#{node['sensu-go']['ctl_version']}_windows_amd64.tar.gz" end - seven_zip_archive 'Extract Sensuctl Gz' do - path "c:/sensutemp/sensu-go_#{node['sensu-go']['ctl_version']}_windows_amd64.tar" - source "c:/sensutemp/sensu-go_#{node['sensu-go']['ctl_version']}_windows_amd64.tar.gz" + archive_file 'Extract Sensuctl' do + path "c:/sensutemp/sensu-go_#{node['sensu-go']['ctl_version']}_windows_amd64.tar.gz" + destination sensuctl_bin overwrite true - timeout 30 - end - - seven_zip_archive 'Extract Sensuctl Tar' do - path "c:/sensutemp/sensu-go_#{node['sensu-go']['ctl_version']}_windows_amd64" - source "c:/sensutemp/sensu-go_#{node['sensu-go']['ctl_version']}_windows_amd64.tar" - overwrite true - timeout 30 - end - - directory sensuctl_bin do - recursive true - end - - remote_file "#{sensuctl_bin}\\sensuctl.exe" do - source "file:///c:/sensutemp/sensu-go_#{node['sensu-go']['ctl_version']}_windows_amd64/sensuctl.exe" end windows_path sensuctl_bin diff --git a/spec/unit/recipes/sensu_ctl_spec.rb b/spec/unit/recipes/sensu_ctl_spec.rb index 0160d02f..6db1d168 100644 --- a/spec/unit/recipes/sensu_ctl_spec.rb +++ b/spec/unit/recipes/sensu_ctl_spec.rb @@ -76,20 +76,16 @@ expect { chef_run }.to_not raise_error end - it 'includes the `seven_zip::default` recipe' do - expect(chef_run).to include_recipe('seven_zip::default') - end - it 'creates a directory `c:\sensutemp`' do expect(chef_run).to create_directory('c:\sensutemp') end it 'extracts an archive' do - expect(chef_run).to extract_seven_zip_archive('Extract Sensuctl Gz') + expect(chef_run).to extract_archive_file('Extract Sensuctl Gz') end it 'extracts the archive' do - expect(chef_run).to extract_seven_zip_archive('Extract Sensuctl Tar') + expect(chef_run).to extract_archive_file('Extract Sensuctl Tar') end it 'creates a directory `c:\Program Files\Sensu\sensu-cli\bin\sensuctl`' do diff --git a/test/cookbooks/sensu_test/recipes/default.rb b/test/cookbooks/sensu_test/recipes/default.rb index aa4120c8..5265df68 100644 --- a/test/cookbooks/sensu_test/recipes/default.rb +++ b/test/cookbooks/sensu_test/recipes/default.rb @@ -330,3 +330,17 @@ id 'CONSUL_TOKEN' secrets_provider 'env' end + + +directory '/tmp/sensutmp1' + +remote_file '/tmp/sensutmp1/windows.tar.gz' do + source 'https://s3-us-west-2.amazonaws.com/sensu.io/sensu-go/6.1.0/sensu-go_6.1.0_windows_amd64.tar.gz' + checksum 'bf4324e1e00f46022323c14d650234a73e238727bec59fdecbc46154bdd5448f' + mode '0644' +end + +archive_file '/tmp/sensutmp1/windows.tar.gz' do + destination '/tmp/sensutmp2' + overwrite true +end