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

Properly handle changes to AdminLevel for users #17

Merged
merged 1 commit into from Jul 29, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/puppet/provider/sacctmgr.rb
Expand Up @@ -77,6 +77,10 @@ def self.fields_name_overrides
{}
end

def property_skip_set_values
[]
end

def self.sacctmgr_resource
case resource_type.to_s
when 'Puppet::Type::Slurm_cluster'
Expand Down Expand Up @@ -242,6 +246,7 @@ def set_values(create) # rubocop:disable Style/AccessorMethodName
@property_flush.keys
end
properties.each do |property|
next if property_skip_set_values.include?(property.to_sym) && !create
value = if create
resource[property]
else
Expand Down Expand Up @@ -310,8 +315,14 @@ def flush
cmd << "cluster=#{@resource[:cluster]}" if @resource[:cluster]
end
cmd << 'set'
cmd << set_values(false)
sacctmgr(cmd.flatten)
values = set_values(false)
cmd << values
unless values.empty?
sacctmgr(cmd.flatten)
end
property_skip_set_values.each do |p|
send("set_#{p}")
end
end
@property_hash = resource.to_hash
end
Expand Down
12 changes: 12 additions & 0 deletions lib/puppet/provider/slurm_user/sacctmgr.rb
Expand Up @@ -24,6 +24,10 @@ def self.array_properties
[:qos]
end

def property_skip_set_values
[:admin_level]
end

def self.instances
users = []
sacctmgr_list(true).each_line do |line|
Expand Down Expand Up @@ -73,6 +77,14 @@ def initialize(value = {})
end
end

def set_admin_level
value = @property_flush[:admin_level]
return if value.nil?
Puppet.notice("Setting SLURM adminlevel=#{value} for user=#{resource[:user]}")
cmd = ['-i', 'modify', 'user', 'where', "user=#{resource[:user]}", 'set', "adminlevel=#{value}"]
sacctmgr(cmd)
end

def destroy
if @resource[:user] == 'root'
Puppet.warning("Slurm_user[#{@resource[:name]}] Not permitted to delete root user. Must define root user or remove cluster")
Expand Down
8 changes: 8 additions & 0 deletions spec/acceptance/05_user_spec.rb
Expand Up @@ -57,6 +57,7 @@
slurm_cluster { 'linux': ensure => 'present' }
slurm_account { 'test on linux': ensure => 'present' }
slurm_user { '#{name} under test on linux': ensure => 'present' }
slurm_user { 'testuser under test on linux': admin_level => 'Administrator' }
EOS

apply_manifest(pp, catch_failures: true)
Expand All @@ -66,6 +67,9 @@
describe command("sacctmgr list user format=#{format_string} withassoc --noheader --parsable2") do
its(:stdout) { is_expected.to include(value) }
end
describe command('sacctmgr list user format=user,adminlevel --noheader --parsable2') do
its(:stdout) { is_expected.to include('testuser|Administrator') }
end
end

context 'update' do
Expand All @@ -76,6 +80,7 @@
slurm_cluster { 'linux': ensure => 'present' }
slurm_account { 'test on linux': ensure => 'present' }
slurm_user { '#{name} under test on linux': ensure => 'present', grp_tres => {'cpu' => 1} }
slurm_user { 'testuser under test on linux': admin_level => 'Operator' }
EOS

apply_manifest(pp, catch_failures: true)
Expand All @@ -85,6 +90,9 @@
describe command("sacctmgr list user format=#{format_string} withassoc --noheader --parsable2") do
its(:stdout) { is_expected.to include(value) }
end
describe command('sacctmgr list user format=user,adminlevel --noheader --parsable2') do
its(:stdout) { is_expected.to include('testuser|Operator') }
end
end

context 'remove' do
Expand Down