Allow for any order of user_roles

Change insync determination of the roles list to be order
agnostic.  The specific order in which the user roles
appear in keystone does not matter.

Closes-Bug: 1372493

Change-Id: Iaee28f45ebb68acbe3ed70e7c45d9397140169f3
This commit is contained in:
Christian Schnidrig
2014-09-22 16:42:02 +02:00
committed by Mike Dorman
parent a7c891b220
commit 93a67d7fd0
2 changed files with 33 additions and 0 deletions

View File

@@ -23,6 +23,11 @@ Puppet::Type.newtype(:keystone_user_role) do
end
newproperty(:roles, :array_matching => :all) do
def insync?(is)
return false unless is.is_a? Array
# order of roles does not matter
is.sort == self.should.sort
end
end
newproperty(:id) do

View File

@@ -0,0 +1,28 @@
require 'spec_helper'
require 'puppet'
require 'puppet/type/keystone_user_role'
describe Puppet::Type.type(:keystone_user_role) do
before :each do
@user_roles = Puppet::Type.type(:keystone_user_role).new(
:name => 'foo@bar',
:roles => ['a', 'b']
)
@roles = @user_roles.parameter('roles')
end
it 'should not be in sync for' do
expect(@roles.insync?(['a', 'b', 'c'])).to be false
expect(@roles.insync?('a')).to be false
expect(@roles.insync?(['a'])).to be false
expect(@roles.insync?(nil)).to be false
end
it 'should be in sync for' do
expect(@roles.insync?(['a', 'b'])).to be true
expect(@roles.insync?(['b', 'a'])).to be true
end
end