diff --git a/osism/tasks/ansible.py b/osism/tasks/ansible.py index ec8f1d89..ae8a5165 100644 --- a/osism/tasks/ansible.py +++ b/osism/tasks/ansible.py @@ -1,10 +1,25 @@ # SPDX-License-Identifier: Apache-2.0 +import functools +from threading import RLock + from celery import Celery +import kombu.utils from osism import settings from osism.tasks import Config, run_ansible_in_environment +# https://github.com/celery/kombu/issues/1804 +if not getattr(kombu.utils.cached_property, "lock", None): + setattr( + kombu.utils.cached_property, + "lock", + functools.cached_property(lambda _: RLock()), + ) + # Must call __set_name__ here since this cached property is not defined in the context of a class + # Refer to https://docs.python.org/3/reference/datamodel.html#object.__set_name__ + kombu.utils.cached_property.lock.__set_name__(kombu.utils.cached_property, "lock") + app = Celery("ansible") app.config_from_object(Config) diff --git a/osism/tasks/openstack.py b/osism/tasks/openstack.py index 6bc8c88e..e6c8aec9 100644 --- a/osism/tasks/openstack.py +++ b/osism/tasks/openstack.py @@ -1,19 +1,34 @@ # SPDX-License-Identifier: Apache-2.0 +import functools import copy import ipaddress +from threading import RLock from celery import Celery from celery.signals import worker_process_init import jinja2 import keystoneauth1 +import kombu.utils import openstack from pottery import Redlock from redis import Redis + from osism import settings from osism.tasks import Config, conductor, netbox from osism import utils +# https://github.com/celery/kombu/issues/1804 +if not getattr(kombu.utils.cached_property, "lock", None): + setattr( + kombu.utils.cached_property, + "lock", + functools.cached_property(lambda _: RLock()), + ) + # Must call __set_name__ here since this cached property is not defined in the context of a class + # Refer to https://docs.python.org/3/reference/datamodel.html#object.__set_name__ + kombu.utils.cached_property.lock.__set_name__(kombu.utils.cached_property, "lock") + app = Celery("openstack") app.config_from_object(Config) diff --git a/osism/tasks/reconciler.py b/osism/tasks/reconciler.py index de3884ee..38a917d1 100644 --- a/osism/tasks/reconciler.py +++ b/osism/tasks/reconciler.py @@ -1,15 +1,31 @@ # SPDX-License-Identifier: Apache-2.0 +import functools import io import subprocess +from threading import RLock from celery import Celery from celery.signals import worker_process_init +import kombu.utils from pottery import Redlock from redis import Redis + from osism import settings from osism.tasks import Config + +# https://github.com/celery/kombu/issues/1804 +if not getattr(kombu.utils.cached_property, "lock", None): + setattr( + kombu.utils.cached_property, + "lock", + functools.cached_property(lambda _: RLock()), + ) + # Must call __set_name__ here since this cached property is not defined in the context of a class + # Refer to https://docs.python.org/3/reference/datamodel.html#object.__set_name__ + kombu.utils.cached_property.lock.__set_name__(kombu.utils.cached_property, "lock") + app = Celery("reconciler") app.config_from_object(Config) diff --git a/releasenotes/notes/workaround-celery-kombu-gh1804-e0f1b3d38691d561.yaml b/releasenotes/notes/workaround-celery-kombu-gh1804-e0f1b3d38691d561.yaml new file mode 100644 index 00000000..5491d863 --- /dev/null +++ b/releasenotes/notes/workaround-celery-kombu-gh1804-e0f1b3d38691d561.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Add workaround for https://github.com/celery/kombu/issues/1804 to solve the + `after fork raised exception: AttributeError("'cached_property' object has no attribute 'lock'")` + issue for services already using Python 3.12.