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 handling #358

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from
Draft

Conversation

towo
Copy link
Member

@towo towo commented Aug 25, 2022

Pull Request (PR) description

The database readonly properly expects a boolean, but the olc
provider doesn't take care to parse the existing value into a boolean,
thus leading to issues.

Simply applies the same logic applied to olcMirrorMode for
olcReadOnly.

This Pull Request (PR) fixes the following issues

n/a

Copy link
Member

@smortex smortex left a comment

Choose a reason for hiding this comment

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

This also lacks unit tests. Can you add some? Here is a starter spec/unit/puppet/provider/openldap_database/olc_spec.rb:

# frozen_string_literal: true

require 'spec_helper'

describe Puppet::Type.type(:openldap_database).provider(:olc) do
  describe '::instances' do
    context 'with all parameters' do
      before do
        expect(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
      end

      it 'parses olcReadOnly' do
        expect(described_class.instances.first.readonly).to be_falsey
      end
    end
  end
end

@@ -49,7 +49,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
Copy link
Member

Choose a reason for hiding this comment

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

I think we can use native types here:

Suggested change
readonly = line.split[1] == 'TRUE' ? :true : :false
readonly = line.split[1] == 'TRUE'

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, I'm a bit confused at this, to be quite honest; the mirrormode setting defined the :true and :false values, which appears to be an accepted way as it's used all throughout various modules, including modules by @puppetlabs. So I just tried to mirror (hah) that, and also pushed f2e809d since the symbol approach needed that.

I could just drop it and go down to ruby booleans, but then there'd be a certain inconsistency, and one that the overall codebase, including @voxpupuli, seems split on. Or have I overlooked a style guide somewhere that defines the way to go?

Copy link
Member

Choose a reason for hiding this comment

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

this won't help you, but: This is an ongoing problem since types and provider exists and everytime I don't know how to handle it properly :(

Copy link
Member

Choose a reason for hiding this comment

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

Deprecation of :true / :false in favor of true / false is quite vague for me. I feel like it was needed with older parser and Puppet 4 fixed that. As you say, there are inconsistencies in the various modules around. Some module even mix both ways: https://github.com/puppetlabs/puppetlabs-vcsrepo/blob/bcae373622364f3088fd6d0c89c4d499c05b3e5d/lib/puppet/type/vcsrepo.rb#L290-L321

This makes me think we can switch to pure true / false but if it cause trouble that's not a major issue.

@bastelfreak bastelfreak added the bug Something isn't working label Aug 30, 2022
@towo towo force-pushed the fix/readonly-boolean branch 2 times, most recently from 30d627a to 6486301 Compare August 31, 2022 07:09
@towo towo marked this pull request as draft August 31, 2022 07:29
smortex and others added 5 commits August 31, 2022 09:56
FreeBSD ports are now build against OpenLDAP 2.6 by default.  Update the
package names accordingly.
The database `readonly` properly expecteds a boolean, but the olc
provider doesn't take care to parse the existing value into a boolean,
thus leading to issues.

Simply applies the same logic applied to `olcMirrorMode` for
`olcReadOnly`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants