Skip to content

Commit

Permalink
Remove absent support from sensu_user
Browse files Browse the repository at this point in the history
Upstream issue: sensu/sensu-go#2540
  • Loading branch information
treydock committed Jan 3, 2019
1 parent 8827d8f commit e08f197
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 37 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ This module does not support adding `sensuctl` resources on a host other than th

The type `sensu_asset` does not at this time support `ensure => absent` due to a limitation with sensuctl, see [sensu-go#988](https://github.com/sensu/sensu-go/issues/988).

The type `sensu_user` does not at this time support `ensure => absent` due to a limitation with sensuctl, see [sensu-go#2540](https://github.com/sensu/sensu-go/issues/2540).

### Notes regarding support

This module is built for use with Puppet versions 5 and 6 and the ruby
Expand Down
10 changes: 9 additions & 1 deletion lib/puppet/type/sensu_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@
extend PuppetX::Sensu::Type
add_autorequires()

ensurable
ensurable do
desc "The basic property that the resource should be in."
defaultvalues
validate do |value|
if value.to_sym == :absent
raise ArgumentError, "sensu_user ensure does not support absent"
end
end
end

newparam(:name, :namevar => true) do
desc "The name of the user."
Expand Down
39 changes: 3 additions & 36 deletions spec/acceptance/sensu_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,46 +109,13 @@
end

context 'ensure => absent' do
it 'should remove without errors' do
it 'should result in error as unsupported' do
pp = <<-EOS
include ::sensu::backend
sensu_user { 'test': ensure => 'absent' }
sensu_config { 'format': ensure => 'absent' }
EOS

# Run it twice and test for idempotency
apply_manifest_on(node, pp, :catch_failures => true)
apply_manifest_on(node, pp, :catch_changes => true)
end

it 'should not have user removed' do
on node, 'sensuctl user list --format json' do
data = JSON.parse(stdout)
d = data.select { |o| o['username'] == 'test' }
expect(d.size).to eq(0)
end
end
end

context 'resources purge' do
it 'should remove without errors' do
pp = <<-EOS
include ::sensu::backend
resources { 'sensu_user':
purge => true,
}
EOS

# Run it twice and test for idempotency
apply_manifest_on(node, pp, :catch_failures => true)
apply_manifest_on(node, pp, :catch_changes => true)
end

it 'should have 1 user' do
on node, 'sensuctl user list --format json' do
data = JSON.parse(stdout)
expect(data.size).to eq(1)
end
apply_manifest_on(node, pp, :expect_failures => true)
end
end
end

5 changes: 5 additions & 0 deletions spec/unit/sensu_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
}.to raise_error(Puppet::Error, 'Title or name must be provided')
end

it 'should not accept ensure => absent' do
config[:ensure] = 'absent'
expect { user[:ensure] = 'absent' }.to raise_error(Puppet::Error, /ensure does not support absent/)
end

defaults = {
'disabled': :false,
'configure': :false,
Expand Down

0 comments on commit e08f197

Please sign in to comment.