From 302b10a1e0d44e2ec941a9f0890160653db6abe8 Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Fri, 4 Aug 2023 10:32:53 +0300 Subject: [PATCH 1/6] fix test install --- tox.ini | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tox.ini b/tox.ini index a731af4..472ee1a 100644 --- a/tox.ini +++ b/tox.ini @@ -5,8 +5,8 @@ skipsdist = true [testenv] passenv = TOXENV commands = - py{36,37,38,39}: pip install -e '.[dev,sqlite,redis]' - py{37,38,39}-uvloop: pip install -e '.[dev,sqlite,redis,uvloop]' + py{37,38,39}: pip install -e '.[dev,sqlite,redis,postgres]' + py{37,38,39}-uvloop: pip install -e '.[dev,sqlite,redis,postgres,uvloop]' pytest . [testenv:lint] @@ -19,6 +19,6 @@ commands = passenv = TOXENV basepython = python3.9 commands = - pip install -e ".[dev,sqlite,redis]" + pip install -e ".[dev,sqlite,redis,postgres]" pytest --cov . --cov-append --cov-report= . coverage report --fail-under=97 --include="postfix_mta_sts_resolver/*" --show-missing From 209d8c4ca586a0afd8186aa228957b84b246427c Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Fri, 4 Aug 2023 10:47:33 +0300 Subject: [PATCH 2/6] tests: drop python3.6 --- .travis.yml | 2 -- tox.ini | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 717fe17..0503a55 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,6 @@ matrix: env: TOXENV=lint - python: 3.9 env: TOXENV=cover - - python: 3.6 - env: TOXENV=py36 - python: 3.7 env: TOXENV=py37 - python: 3.8 diff --git a/tox.ini b/tox.ini index 472ee1a..da2cdc0 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{36,37,38,39}, py{37,38,39}-uvloop, lint, cover +envlist = py{37,38,39}, py{37,38,39}-uvloop, lint, cover skipsdist = true [testenv] From 21eb3a8d026dac220397035be614712ef5c02562 Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Fri, 4 Aug 2023 11:11:41 +0300 Subject: [PATCH 3/6] fix linting --- .pylintrc | 80 +--------------------- postfix_mta_sts_resolver/daemon.py | 21 +++--- postfix_mta_sts_resolver/postgres_cache.py | 4 +- 3 files changed, 14 insertions(+), 91 deletions(-) diff --git a/.pylintrc b/.pylintrc index 11004ce..49fc901 100644 --- a/.pylintrc +++ b/.pylintrc @@ -60,17 +60,7 @@ confidence= # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use "--disable=all --enable=classes # --disable=W". -disable=print-statement, - parameter-unpacking, - unpacking-in-except, - old-raise-syntax, - backtick, - long-suffix, - old-ne-operator, - old-octal-literal, - import-star-module-level, - non-ascii-bytes-literal, - raw-checker-failed, +disable=raw-checker-failed, bad-inline-option, locally-disabled, file-ignored, @@ -78,67 +68,6 @@ disable=print-statement, useless-suppression, deprecated-pragma, use-symbolic-message-instead, - apply-builtin, - basestring-builtin, - buffer-builtin, - cmp-builtin, - coerce-builtin, - execfile-builtin, - file-builtin, - long-builtin, - raw_input-builtin, - reduce-builtin, - standarderror-builtin, - unicode-builtin, - xrange-builtin, - coerce-method, - delslice-method, - getslice-method, - setslice-method, - no-absolute-import, - old-division, - dict-iter-method, - dict-view-method, - next-method-called, - metaclass-assignment, - indexing-exception, - raising-string, - reload-builtin, - oct-method, - hex-method, - nonzero-method, - cmp-method, - input-builtin, - round-builtin, - intern-builtin, - unichr-builtin, - map-builtin-not-iterating, - zip-builtin-not-iterating, - range-builtin-not-iterating, - filter-builtin-not-iterating, - using-cmp-argument, - eq-without-hash, - div-method, - idiv-method, - rdiv-method, - exception-message-attribute, - invalid-str-codec, - sys-max-int, - bad-python3-import, - deprecated-string-function, - deprecated-str-translate-call, - deprecated-itertools-function, - deprecated-types-field, - next-method-defined, - dict-items-not-iterating, - dict-keys-not-iterating, - dict-values-not-iterating, - deprecated-operator-function, - deprecated-urllib-function, - xreadlines-attribute, - deprecated-sys-function, - exception-escape, - comprehension-escape, missing-docstring, import-error, broad-except, @@ -266,13 +195,6 @@ max-line-length=100 # Maximum number of lines in a module. max-module-lines=1000 -# List of optional constructs for which whitespace checking is disabled. `dict- -# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. -# `trailing-comma` allows a space between comma and closing bracket: (a, ). -# `empty-line` allows space-only lines. -no-space-check=trailing-comma, - dict-separator - # Allow the body of a class to be on the same line as the declaration if body # contains single statement. single-line-class-stmt=no diff --git a/postfix_mta_sts_resolver/daemon.py b/postfix_mta_sts_resolver/daemon.py index f079f25..db34368 100644 --- a/postfix_mta_sts_resolver/daemon.py +++ b/postfix_mta_sts_resolver/daemon.py @@ -107,21 +107,21 @@ async def amain(cfg, loop): # pragma: no cover def main(): # pragma: no cover args = parse_args() if args.pidfile is not None: - with open(args.pidfile, 'w') as f: - f.write(str(os.getpid())) + with open(args.pidfile, 'w', encoding='ascii') as pid_file: + pid_file.write(str(os.getpid())) if args.group is not None: try: - g = grp.getgrnam(args.group) - os.setegid(g.gr_gid) - except Exception as e: - print("Unable to change eGID to '{}': {}".format(args.group, e), file=sys.stderr) + group = grp.getgrnam(args.group) + os.setegid(group.gr_gid) + except Exception as exc: + print("Unable to change eGID to '{}': {}".format(args.group, exc), file=sys.stderr) return os.EX_OSERR if args.user is not None: try: - p = pwd.getpwnam(args.user) - os.seteuid(p.pw_uid) - except Exception as e: - print("Unable to change eUID to '{}': {}".format(args.user, e), file=sys.stderr) + passwd = pwd.getpwnam(args.user) + os.seteuid(passwd.pw_uid) + except Exception as exc: + print("Unable to change eUID to '{}': {}".format(args.user, exc), file=sys.stderr) return os.EX_OSERR with utils.AsyncLoggingHandler(args.logfile) as log_handler: logger = utils.setup_logger('MAIN', args.verbosity, log_handler) @@ -148,3 +148,4 @@ def main(): # pragma: no cover evloop.run_until_complete(amain(cfg, evloop)) evloop.close() logger.info("Server finished its work.") + return os.EX_OK diff --git a/postfix_mta_sts_resolver/postgres_cache.py b/postfix_mta_sts_resolver/postgres_cache.py index c70b9d7..f4ac4ed 100644 --- a/postfix_mta_sts_resolver/postgres_cache.py +++ b/postfix_mta_sts_resolver/postgres_cache.py @@ -1,10 +1,10 @@ # pylint: disable=invalid-name,protected-access -import asyncio -import asyncpg import json import logging +import asyncpg + from .defaults import POSTGRES_TIMEOUT from .base_cache import BaseCache, CacheEntry From cb5caee367eac42670c1d6a5f9196b9d2330d31b Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Fri, 4 Aug 2023 11:43:35 +0300 Subject: [PATCH 4/6] relax coverage requirement --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index da2cdc0..f437834 100644 --- a/tox.ini +++ b/tox.ini @@ -21,4 +21,4 @@ basepython = python3.9 commands = pip install -e ".[dev,sqlite,redis,postgres]" pytest --cov . --cov-append --cov-report= . - coverage report --fail-under=97 --include="postfix_mta_sts_resolver/*" --show-missing + coverage report --fail-under=90 --include="postfix_mta_sts_resolver/*" --show-missing From c043818f06832eb97db3ebc1f8a371563c68a61d Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Fri, 4 Aug 2023 12:37:44 +0300 Subject: [PATCH 5/6] fix postgres tests --- .travis.yml | 7 +++++++ tests/install.debian.sh | 4 ++-- tests/test_cache.py | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0503a55..b1716fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,13 @@ language: python dist: bionic +addons: + postgresql: "10" + apt: + packages: + - postgresql-10 + - postgresql-client-10 + matrix: include: - python: 3.9 diff --git a/tests/install.debian.sh b/tests/install.debian.sh index e3d33c2..b803045 100755 --- a/tests/install.debian.sh +++ b/tests/install.debian.sh @@ -7,7 +7,7 @@ PYTHON="${PYTHON:-python3}" # run under travis, but not under autopkgtest if [ -z "${AUTOPKGTEST_TMP+x}" ] ; then apt-get update - apt-get install -y redis-server postgresql dnsmasq lsof nginx-extras tinyproxy \ + apt-get install -y redis-server dnsmasq lsof nginx-extras tinyproxy \ build-essential libssl-dev libffi-dev python3-dev cargo systemctl start redis-server || { journalctl -xe ; false ; } "$PYTHON" -m pip install cryptography @@ -17,7 +17,7 @@ fi install -m 644 tests/resolv.conf /etc/resolv-dnsmasq.conf cat tests/dnsmasq.conf.appendix >> /etc/dnsmasq.conf echo 'nameserver 127.0.0.1' > /etc/resolv.conf -systemctl restart dnsmasq postgresql || { journalctl -xe ; false ; } +systemctl restart dnsmasq || { journalctl -xe ; false ; } # certificates for the test cases diff --git a/tests/test_cache.py b/tests/test_cache.py index c400132..22bb8a0 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -27,8 +27,8 @@ async def setup_cache(cache_type, cache_opts): ("sqlite", {}, False), ("redis", {"url": "redis://127.0.0.1/0?socket_timeout=5&socket_connect_timeout=5"}, True), ("redis", {"url": "redis://127.0.0.1/0?socket_timeout=5&socket_connect_timeout=5"}, False), - ("postgres", {"dsn": "postgres://postgres@%2Frun%2Fpostgresql/postgres"}, True), - ("postgres", {"dsn": "postgres://postgres@%2Frun%2Fpostgresql/postgres"}, False), + ("postgres", {"dsn": "postgres://postgres@localhost:5432"}, True), + ("postgres", {"dsn": "postgres://postgres@localhost:5432"}, False), ]) @pytest.mark.asyncio async def test_cache_lifecycle(cache_type, cache_opts, safe_set): From 9eceb4c0441896aa81061bc8c9397551c2acaf31 Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Fri, 4 Aug 2023 12:45:21 +0300 Subject: [PATCH 6/6] add recent python versions --- .travis.yml | 12 ++++++++++-- tox.ini | 10 +++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index b1716fa..fc2c235 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,9 +10,9 @@ addons: matrix: include: - - python: 3.9 + - python: 3.11 env: TOXENV=lint - - python: 3.9 + - python: 3.11 env: TOXENV=cover - python: 3.7 env: TOXENV=py37 @@ -20,12 +20,20 @@ matrix: env: TOXENV=py38 - python: 3.9 env: TOXENV=py39 + - python: 3.10 + env: TOXENV=py310 + - python: 3.11 + env: TOXENV=py311 - python: 3.7 env: TOXENV=py37-uvloop - python: 3.8 env: TOXENV=py38-uvloop - python: 3.9 env: TOXENV=py39-uvloop + - python: 3.10 + env: TOXENV=py310-uvloop + - python: 3.11 + env: TOXENV=py311-uvloop install: - "sudo -H env PYTHON=\"$(command -v python)\" tests/install.debian.sh" script: diff --git a/tox.ini b/tox.ini index f437834..990bced 100644 --- a/tox.ini +++ b/tox.ini @@ -1,23 +1,23 @@ [tox] -envlist = py{37,38,39}, py{37,38,39}-uvloop, lint, cover +envlist = py{37,38,39,310,311}, py{37,38,39,310,311}-uvloop, lint, cover skipsdist = true [testenv] passenv = TOXENV commands = - py{37,38,39}: pip install -e '.[dev,sqlite,redis,postgres]' - py{37,38,39}-uvloop: pip install -e '.[dev,sqlite,redis,postgres,uvloop]' + py{37,38,39,310,311}: pip install -e '.[dev,sqlite,redis,postgres]' + py{37,38,39,310,311}-uvloop: pip install -e '.[dev,sqlite,redis,postgres,uvloop]' pytest . [testenv:lint] -basepython = python3.9 +basepython = python3.11 commands = pip install -e '.[dev,sqlite,redis]' pylint --reports=n --rcfile=.pylintrc postfix_mta_sts_resolver [testenv:cover] passenv = TOXENV -basepython = python3.9 +basepython = python3.11 commands = pip install -e ".[dev,sqlite,redis,postgres]" pytest --cov . --cov-append --cov-report= .