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

Fix readonly database property #422

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1386,8 +1386,12 @@ This option puts a replica database into "multiprovider" mode

##### `readonly`

Valid values: `true`, `false`

Puts the database into read-only mode.

Default value: `false`

##### `rootdn`

The distinguished name that is not subject to access control or administrative limit restrictions for operations on this database.
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/openldap_database/olc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def self.instances
when %r{^olcRelay: }
relay = line.split[1]
when %r{^olcReadOnly: }i
readonly = line.split[1]
readonly = line.split[1] == 'TRUE' ? :true : :false
when %r{^olcSizeLimit: }i
sizelimit = line.split[1]
when %r{^olcDbMaxSize: }i
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/type/openldap_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ def should_to_s(_newvalue)

newproperty(:readonly) do
desc 'Puts the database into read-only mode.'
newvalues(:true, :false)
defaultto(:false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the new default value is the reason for the CI failue:

REFERENCE.md is outdated

Please update REFERENCE.md with

$ bundle exec rake strings:generate:reference

Add it to the PR and CI should continue.

end

newproperty(:sizelimit) do
Expand Down
55 changes: 55 additions & 0 deletions spec/unit/puppet/provider/openldap_database/olc_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true

require 'spec_helper'

describe Puppet::Type.type(:openldap_database).provider(:olc) do
let(:params) do
{
suffix: 'dc=example,dc=com',
backend: 'mdb',
readonly: false,
# provider: described_class.name,
}
end

let(:resource) do
Puppet::Type.type(:openldap_database).new(params)
end
let(:provider) do
resource.provider
end

before do
allow(described_class).to receive(:slapcat).with('(|(olcDatabase=monitor)(olcDatabase={0}config)(&(objectClass=olcDatabaseConfig)(|(objectClass=olcBdbConfig)(objectClass=olcHdbConfig)(objectClass=olcMdbConfig)(objectClass=olcMonitorConfig)(objectClass=olcRelayConfig)(objectClass=olcLDAPConfig))))').and_return(<<~SLAPCAT)
dn: olcDatabase={1}mdb,cn=config
olcDatabase: {1}mdb
olcReadOnly: FALSE
SLAPCAT
allow(provider).to receive(:slapcat)
allow(provider).to receive(:ldapmodify)
allow(provider).to receive(:ldapadd)
# allow(described_class).to receive(:slapcat)
# allow(described_class).to receive(:ldapmodify)
# allow(described_class).to receive(:ldapadd)
end

describe 'when creating' do
context 'with readonly set to false' do
it 'parses olcReadOnly as false' do

Check failure on line 38 in spec/unit/puppet/provider/openldap_database/olc_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

Puppet::Type::Openldap_database::ProviderOlc when creating with readonly set to false parses olcReadOnly as false Failure/Error: slapcat("(&(objectClass=olc#{resource[:backend].to_s.capitalize}Config)(olcSuffix=#{resource[:suffix]}))"). split("\n").map do |line| @property_hash[:index] = line.match(%r{^olcDatabase: \{(\d+)\}#{resource[:backend]}$}).captures[0] if line =~ %r{^olcDatabase: } end NoMethodError: undefined method `split' for nil:NilClass

Check failure on line 38 in spec/unit/puppet/provider/openldap_database/olc_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

Puppet::Type::Openldap_database::ProviderOlc when creating with readonly set to false parses olcReadOnly as false Failure/Error: slapcat("(&(objectClass=olc#{resource[:backend].to_s.capitalize}Config)(olcSuffix=#{resource[:suffix]}))"). split("\n").map do |line| @property_hash[:index] = line.match(%r{^olcDatabase: \{(\d+)\}#{resource[:backend]}$}).captures[0] if line =~ %r{^olcDatabase: } end NoMethodError: undefined method `split' for nil:NilClass
provider.create
expect(described_class.instances.first.readonly).to eq :false
# expect(described_class.instances.first.readonly).to eq(:false)
end
end

context 'with readonly set to true' do
let(:params) do
super().merge({ readonly: true })
end

it 'parses olcReadonly' do

Check failure on line 50 in spec/unit/puppet/provider/openldap_database/olc_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

Puppet::Type::Openldap_database::ProviderOlc when creating with readonly set to true parses olcReadonly Failure/Error: expect(described_class.instances.first.readonly).to eq(:true) expected: :true got: :false (compared using ==) Diff: @@ -1 +1 @@ -:true +:false

Check failure on line 50 in spec/unit/puppet/provider/openldap_database/olc_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

Puppet::Type::Openldap_database::ProviderOlc when creating with readonly set to true parses olcReadonly Failure/Error: expect(described_class.instances.first.readonly).to eq(:true) expected: :true got: :false (compared using ==) Diff: @@ -1 +1 @@ -:true +:false
expect(described_class.instances.first.readonly).to eq(:true)
end
end
end
end
Loading