Skip to content

Commit

Permalink
Switch sensu_ctl resouce to use archive_file
Browse files Browse the repository at this point in the history
This removes the need for a dependency on the seven_zip cookbook since
archive_file is a builtin chef resources since Chef 15
  • Loading branch information
webframp committed Oct 17, 2020
1 parent 297f7bf commit af63a62
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 27 deletions.
1 change: 0 additions & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@
source_url 'https://github.com/sensu/sensu-go-chef'

depends 'packagecloud'
depends 'seven_zip'
23 changes: 3 additions & 20 deletions resources/ctl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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
Expand Down
8 changes: 2 additions & 6 deletions spec/unit/recipes/sensu_ctl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions test/cookbooks/sensu_test/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit af63a62

Please sign in to comment.