Subject: patroni debian bullseye package file inconsistency

From: Kirill <[email-masked]>
Date: Wed, 27 Apr 2022 14:37:34 +0300

Hello, community!
 
First of all, thanks for fast version releases of patroni package.
 
I am using that package:
 
$ apt-cache policy patroni
patroni:
  Installed: 2.1.3-2.pgdg110+1
  Candidate: 2.1.3-2.pgdg110+1
  Version table:
 *** 2.1.3-2.pgdg110+1 500
        500 http://apt.postgresql.org/pub/repos/apt bullseye-pgdg/main amd64 Packages
        100 /var/lib/dpkg/status

During the usage of patroni I got an error:
 
$ patroni --version
patroni 2.1.3
 
$ patroni --validate-config /etc/patroni-server/config.yaml
...
Traceback (most recent call last):
  File "/usr/bin/patroni", line 33, in <module>
    sys.exit(load_entry_point('patroni==2.1.3', 'console_scripts', 'patroni')())
  File "/usr/lib/python3/dist-packages/patroni/__main__.py", line 143, in main
    return patroni_main()
  File "/usr/lib/python3/dist-packages/patroni/__main__.py", line 135, in patroni_main
    abstract_main(Patroni, schema)
  File "/usr/lib/python3/dist-packages/patroni/daemon.py", line 88, in abstract_main
    Config(args.configfile, validator=validator)
  File "/usr/lib/python3/dist-packages/patroni/config.py", line 105, in __init__
    error = validator(self._local_configuration)
  File "/usr/lib/python3/dist-packages/patroni/validator.py", line 177, in __call__
    for i in self.validate(data):
  File "/usr/lib/python3/dist-packages/patroni/validator.py", line 209, in validate
    for i in self.iter():
  File "/usr/lib/python3/dist-packages/patroni/validator.py", line 217, in iter
    for i in self.iter_dict():
  File "/usr/lib/python3/dist-packages/patroni/validator.py", line 244, in iter_dict
    validator = self.validator[key]._schema[d]
KeyError: 'etcd3'

I started to investigate and found that actual file:
 
$ dpkg -S  /usr/lib/python3/dist-packages/patroni/validator.py
patroni: /usr/lib/python3/dist-packages/patroni/validator.py

is different from source file:
 
$ git clone https://github.com/zalando/patroni.git
$ cd patroni/
$ git checkout v2.1.3
 
$ diff patroni/validator.py /usr/lib/python3/dist-packages/patroni/validator.py
 
56,60d55
< def validate_host_port_list(value):
<     assert all([validate_host_port(v) for v in value]), "didn't pass the validation"
<     return True
< 
< 
62c57,58
<     return validate_host_port_list([s.strip() for s in string.split(",")])
---
>     assert all([validate_host_port(s.strip()) for s in string.split(",")]), "didn't pass the validation"
>     return True
298d293
< validate_host_port_list.expected_type = list
304,312d298
< validate_etcd = {
<     Or("host", "hosts", "srv", "srv_suffix", "url", "proxy"): Case({
<         "host": validate_host_port,
<         "hosts": Or(comma_separated_host_port, [validate_host_port]),
<         "srv": str,
<         "srv_suffix": str,
<         "url": str,
<         "proxy": str})
< }
337,338c323,330
<       "etcd": validate_etcd,
<       "etcd3": validate_etcd,
---
>       "etcd": {
>           Or("host", "hosts", "srv", "url", "proxy"): Case({
>               "host": validate_host_port,
>               "hosts": Or(comma_separated_host_port, [validate_host_port]),
>               "srv": str,
>               "url": str,
>               "proxy": str})
 
So my question — is it intended inconsistency or just a bug?
 
i will appreciate to any feedback. Thanks! 
 
---
Kirill Petrov
https://github.com/chobostar

---

From: Michael Banck <[email-masked]>
Date: Fri, 29 Apr 2022 18:05:20 +0200

Hi,

(I'm not on pgsql-pkg-debian, somebody forwarded me your mail)

> $ patroni --validate-config /etc/patroni-server/config.yaml

[...]

> Traceback (most recent call last):
[...]
>     validator = self.validator[key]._schema[d]

Apparently, running --validate-config on a config using etc3 has been
broken for quite a long time, and nobody noticed.
  
> is different from source file:

This is because there is a Debian patch that reverts an upstream change
that adds some RAFT tests which (as Debian does not ship RAFT yet) when
run would make the testsuite fail:
https://salsa.debian.org/postgresql/patroni/-/blob/debian/2.1.3-2/debian/patches/regression_tests_disable_raft_tests.py

However, that upstream change we reverted also added etcd3 validation,
which is what is now missing for you.

I've reworked the patch[1] so that only the RAFT-specifc changes remain,
and in my testing the above traceback is gone.

I will upload it once CI passes.

Michael

[1] https://salsa.debian.org/postgresql/patroni/-/commit/538cc5f0f9d6bd1704513f7280a0fd35cd193edf