Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch sensu_ctl resouce to use archive_file #112

Merged
merged 5 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ This CHANGELOG follows the format located [here](https://github.com/sensu-plugin
### Fixed

- Fixed outfile for sensuctl install for Windows, as well as preventing unnecessary downloads for install. Fixed configure action for Windows that was unable to parse array. (@kovukono)
- Fixed `sensu_ctl` resource to only extract downloads on new versions, not every chef run (@webframp)

### Added

- `sensu_auth_oidc` resource added (@webframp)
- `sensu_auth_ldap` resource for ldap integration. (@webframp)
- `sensu_auth_oidc` resource added (@webframp)
- `sensu_etcd_replicator` resource for managing cluster RBAC federation (@webframp)
- `sensu_search` resource added (@webframp)
- `sensu_global_config` resource to manage web ui configuration (@webframp)
Expand All @@ -24,6 +24,7 @@ This CHANGELOG follows the format located [here](https://github.com/sensu-plugin
### Changed

- Rename `:ad_servers` property of `sensu_active_diretory` resource to `:auth_servers`. For consistency with `sensu_auth_ldap` resource this property was renamed and will be removed in a future cookbook version. (@webframp)
- Refactored `sensu_ctl` to use builtin (Chef 15+) `archive_file` resource and remove 3rd party `seven_zip` cookbook dependency. (@webframp)

## [1.2.0] - 2020-10-17

Expand Down
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'
25 changes: 5 additions & 20 deletions resources/ctl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,36 +63,21 @@

if platform?('windows')
# This is awaiting a packaged method to be delivered, but provides a resource currently.
include_recipe 'seven_zip'

unless shell_out('sensuctl version').stdout.match?("sensuctl version #{node['sensu-go']['ctl_version']}")
directory 'c:\sensutemp'

powershell_script 'Download Sensuctl' do
code "Invoke-WebRequest https://s3-us-west-2.amazonaws.com/sensu.io/sensu-go/#{node['sensu-go']['ctl_version']}/sensu-go_#{node['sensu-go']['ctl_version']}_windows_amd64.tar.gz -OutFile c:/sensutemp/sensu-go_#{node['sensu-go']['ctl_version']}_windows_amd64.tar.gz"
not_if "Test-Path c:/sensutemp/sensu-go_#{node['sensu-go']['ctl_version']}_windows_amd64.tar.gz"
notifies :extract, 'archive_file[Extract Sensuctl]'
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"
action :nothing
end

windows_path sensuctl_bin
Expand Down
25 changes: 5 additions & 20 deletions spec/unit/recipes/sensu_ctl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,13 @@
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')
it 'does nothing for an archive' do
expect(chef_run).to nothing_archive_file('Extract Sensuctl')
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')
end

it 'extracts the archive' do
expect(chef_run).to extract_seven_zip_archive('Extract Sensuctl Tar')
end

it 'creates a directory `c:\Program Files\Sensu\sensu-cli\bin\sensuctl`' do
expect(chef_run).to create_directory('c:\Program Files\Sensu\sensu-cli\bin\sensuctl')
end

it 'creates a remote_file `c:\Program Files\Sensu\sensu-cli\bin\sensuctl\sensuctl.exe`' do
expect(chef_run).to create_remote_file('c:\Program Files\Sensu\sensu-cli\bin\sensuctl\sensuctl.exe')
it 'notifies to extract the archive' do
ps_resource = chef_run.powershell_script('Download Sensuctl')
expect(ps_resource).to notify('archive_file[Extract Sensuctl]')
end

it 'adds `c:\Program Files\Sensu\sensu-cli\bin\sensuctl` to windows path' do
Expand Down