diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 00000000..bd8cc70b --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,71 @@ +--- +name: windows + +"on": + pull_request: + push: + branches: + - master + +jobs: + windows_agent: + runs-on: windows-latest + steps: + - name: Check out code + uses: actions/checkout@master + - name: Install Chef + uses: actionshub/chef-install@master + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true' + - name: Create directory + run: mkdir D:\a\berks-cookbooks\ + - name: Create Link + run: cmd /c mklink /d D:\a\cookbooks\ D:\a\berks-cookbooks\ + - name: Vendor Cookbooks + working-directory: D:\a\ + run: berks vendor -b D:\a\sensu-go-chef\sensu-go-chef\Berksfile + - name: Chef Zero + working-directory: D:\a\cookbooks\sensu-go\ + env: + CHEF_LICENSE: accept-no-persist + run: chef-client -z -o sensu_test::agent + - name: Verify + run: > + chef exec inspec + exec + D:\a\sensu-go-chef\sensu-go-chef\test\integration\agent\agent_spec.rb + env: + CHEF_LICENSE: accept-no-persist + windows_ctl: + runs-on: windows-latest + steps: + - name: Check out code + uses: actions/checkout@master + - name: Install Chef + uses: actionshub/chef-install@master + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true' + - name: Create directory + run: mkdir D:\a\berks-cookbooks\ + - name: Create Link + run: cmd /c mklink /d D:\a\cookbooks\ D:\a\berks-cookbooks\ + - name: Vendor Cookbooks + working-directory: D:\a\ + run: berks vendor -b D:\a\sensu-go-chef\sensu-go-chef\Berksfile + - name: Chef Zero + working-directory: D:\a\cookbooks\sensu-go\ + env: + CHEF_LICENSE: accept-no-persist + run: chef-client -z -o sensu_test::ctl + - name: GitHub Windows Path (Deprecated Add-Path) + run: > + echo "c:\Program Files\Sensu\sensu-cli\bin\sensuctl" + | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true' + - name: Verify + run: > + chef exec inspec + exec D:\a\sensu-go-chef\sensu-go-chef\test\integration\ctl\ctl_spec.rb + env: + CHEF_LICENSE: accept-no-persist diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cb843b1..b827fb7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ This CHANGELOG follows the format located [here](https://github.com/sensu-plugin ## [Unreleased] +- Introduced CI/CD testing for windows for agent and ctl (@derekgroh) + ## [1.3.0] - 2020-10-28 ### Fixed diff --git a/Gemfile b/Gemfile index b5db1163..3a2b96f4 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,6 @@ gem 'berkshelf' gem 'chef-sugar' group :development do - gem 'foodcritic' gem 'chefspec' gem 'cookstyle', '~> 4.0' gem 'guard' diff --git a/Rakefile b/Rakefile index ad2934f3..b4a3a7e3 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,5 @@ require 'rspec/core/rake_task' require 'rubocop/rake_task' -require 'foodcritic' require 'kitchen' require 'chefspec' require 'cookstyle' diff --git a/kitchen.appveyor.yml b/kitchen.appveyor.yml deleted file mode 100644 index b666035f..00000000 --- a/kitchen.appveyor.yml +++ /dev/null @@ -1,48 +0,0 @@ ---- -driver: - name: proxy - host: localhost - reset_command: "exit 0" - port: 5985 - username: <%= ENV["machine_user"] %> - password: <%= ENV["machine_pass"] %> - -provisioner: - name: chef_zero - client_rb: - chef_license: accept - -platforms: - - name: windows-2012r2 - driver: - box: tas50/windows_2012r2 - - name: windows-2016 - driver: - box: tas50/windows_2016 - customize: - memory: 3072 - - name: windows-2019 - driver: - box: tas50/windows_2016 - customize: - memory: 3072 - -verifier: - name: inspec - -suites: - - name: agent - run_list: - - recipe[sensu_test::agent] - verifier: - inspec_tests: - - test/integration/agent - attributes: -# - name: remove -# run_list: -# - recipe[sensu_test::agent] -# - recipe[sensu_test::remove_agent] -# verifier: -# inspec_tests: -# - test/integration/remove_agent -# attributes: diff --git a/resources/ctl.rb b/resources/ctl.rb index 2e527cfd..4285f3d8 100644 --- a/resources/ctl.rb +++ b/resources/ctl.rb @@ -78,12 +78,13 @@ destination sensuctl_bin overwrite true action :nothing + notifies :delete, 'directory[c:\sensutemp]' end windows_path sensuctl_bin directory 'c:\sensutemp' do - action :delete + action :nothing recursive true end end @@ -93,9 +94,17 @@ action :configure do if shell_out('sensuctl user list').error? converge_by 'Reconfiguring sensuctl' do - execute 'configure sensuctl' do - command sensuctl_configure_cmd - sensitive true unless new_resource.debug + unless platform?('windows') + execute 'configure sensuctl' do + command sensuctl_configure_cmd + sensitive true unless new_resource.debug + end + end + if platform?('windows') + powershell_script 'configure sensuctl' do + code sensuctl_configure_cmd + sensitive true unless new_resource.debug + end end end end diff --git a/spec/unit/recipes/sensu_ctl_spec.rb b/spec/unit/recipes/sensu_ctl_spec.rb index fabc0748..1ee00356 100644 --- a/spec/unit/recipes/sensu_ctl_spec.rb +++ b/spec/unit/recipes/sensu_ctl_spec.rb @@ -78,6 +78,8 @@ it 'does nothing for an archive' do expect(chef_run).to nothing_archive_file('Extract Sensuctl') + archive_file_resource = chef_run.archive_file('Extract Sensuctl') + expect(archive_file_resource).to notify('directory[c:\sensutemp]') end it 'notifies to extract the archive' do @@ -90,7 +92,7 @@ end it 'deletes the temporary directory `c:\sensutemp`' do - expect(chef_run).to delete_directory('c:\sensutemp') + expect(chef_run).to nothing_directory('c:\sensutemp') end it 'configures the sensu cli' do diff --git a/test/cookbooks/sensu_test/recipes/agent.rb b/test/cookbooks/sensu_test/recipes/agent.rb index 0d7a2ef9..c65355b9 100644 --- a/test/cookbooks/sensu_test/recipes/agent.rb +++ b/test/cookbooks/sensu_test/recipes/agent.rb @@ -1 +1,3 @@ -sensu_agent 'default' +sensu_agent 'default' do + ignore_failure true +end diff --git a/test/cookbooks/sensu_test/recipes/ctl.rb b/test/cookbooks/sensu_test/recipes/ctl.rb index f977171b..5147581e 100644 --- a/test/cookbooks/sensu_test/recipes/ctl.rb +++ b/test/cookbooks/sensu_test/recipes/ctl.rb @@ -1,4 +1,6 @@ sensu_ctl 'default' do action [:install, :configure] - backend_url 'http://172.128.10.2:8080' + username 'guest' + password 'i<3sensu' + backend_url 'https://caviar.tf.sensu.io:8080/' end diff --git a/test/integration/ctl/ctl_spec.rb b/test/integration/ctl/ctl_spec.rb index 6a84fefb..646bf1fd 100644 --- a/test/integration/ctl/ctl_spec.rb +++ b/test/integration/ctl/ctl_spec.rb @@ -23,6 +23,11 @@ describe package('sensu-go-cli') do it { should be_installed } end + + describe command('sensuctl user list') do + its('stdout') { should match /Username/ } + its('exit_status') { should eq 0 } + end end if os.windows? @@ -33,9 +38,9 @@ describe file('c:\Program Files\Sensu\sensu-cli\bin\sensuctl\sensuctl.exe') do it { should exist } end -end -describe command('sensuctl user list') do - its('stdout') { should match /Username/ } - its('exit_status') { should eq 0 } + describe command('sensuctl entity list') do + its('stdout') { should match /backend/ } + its('exit_status') { should eq 0 } + end end