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

postgresql_pg_hba: Exception when two lines with same weight are compared #59198

Merged
merged 1 commit into from
Jul 18, 2019
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
8 changes: 4 additions & 4 deletions lib/ansible/modules/database/postgresql/postgresql_pg_hba.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,11 @@ def __lt__(self, other):
return myweight < hisweight
try:
return self['src'] < other['src']
except (TypeError, KeyError):
except TypeError:
return self.source_type_weight() < other.source_type_weight()
errormessage = 'We have two rules ({1}, {2})'.format(self, other)
errormessage += ' with exact same weight. Please file a bug.'
raise PgHbaValueError(errormessage)
except Exception:
# When all else fails, just compare the exact line.
return self.line() < other.line()

def source_weight(self):
"""Report the weight of this source net.
Expand Down
2 changes: 1 addition & 1 deletion test/integration/targets/postgresql/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ db_session_role2: 'session_role2'

pg_hba_test_ips:
- contype: local
users: 'all,postgres'
users: 'all,postgres,test'
- source: '0000:ffff::'
netmask: 'ffff:fff0::'
- source: '192.168.0.0/24'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@
- assert:
that:
- 'pg_hba.pg_hba == [
{ "db": "all", "method": "md5", "type": "local", "usr": "postgres" },
{ "db": "all", "method": "ldap", "type": "local", "usr": "+some", "options": "ldapserver=example.com ldapport=389 ldapprefix=\"cn=\"" },
{ "db": "all", "method": "md5", "type": "local", "usr": "postgres" },
{ "db": "all", "method": "md5", "type": "local", "usr": "test" },
{ "db": "all", "method": "md5", "type": "local", "usr": "all" },
{ "db": "all", "method": "cert", "src": "blue", "type": "hostssl", "usr": "+some", "options": "clientcert=1 map=mymap" },
{ "db": "all", "method": "cert", "src": "red", "type": "hostssl", "usr": "+some", "options": "clientcert=1 map=mymap" },
Expand Down