freeipa / freeipa-healthcheck

Check the health of a freeIPA installation
GNU General Public License v3.0
50 stars 28 forks source link

Use timezone.utc instead of datetime.UTC for backwards compatibility #303

Closed rcritten closed 1 year ago

rcritten commented 1 year ago

We switched to datetime.UTC because datetime.utcnow() was deprecated. This is only available in python 3.11+. Use datetime.timezone.utc instead which is available from python 3.2+

Fixes: https://github.com/freeipa/freeipa-healthcheck/issues/302

flo-renaud commented 1 year ago

Hi @rcritten thanks for the patch, works well for me. I tested on fedora 38 with python 3.11 and on RHEL 9.3 with python 3.9.

The patch is missing an update for tests/test_ipa_certfile_expiration.py though, which contains a few occurrences of UTC:

# pytest
============================= test session starts ==============================
platform linux -- Python 3.9.18, pytest-7.4.2, pluggy-1.3.0
rootdir: /root/freeipa-healthcheck
collected 188 items / 1 error                                                  

==================================== ERRORS ====================================
____________ ERROR collecting tests/test_ipa_certfile_expiration.py ____________
ImportError while importing test module '/root/freeipa-healthcheck/tests/test_ipa_certfile_expiration.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib64/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_ipa_certfile_expiration.py:18: in <module>
    from datetime import datetime, timedelta, UTC
E   ImportError: cannot import name 'UTC' from 'datetime' (/usr/lib64/python3.9/datetime.py)
=========================== short test summary info ============================
ERROR tests/test_ipa_certfile_expiration.py
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.60s ===============================
rcritten commented 1 year ago

Hi @rcritten thanks for the patch, works well for me. I tested on fedora 38 with python 3.11 and on RHEL 9.3 with python 3.9.

The patch is missing an update for tests/test_ipa_certfile_expiration.py though, which contains a few occurrences of UTC:

Can't believe I missed those. Fixed now.