From 96fa3ea6e428e1f74815321236f4bd832f4f6f47 Mon Sep 17 00:00:00 2001 From: Dale Smith Date: Wed, 10 Jul 2024 12:51:55 +1200 Subject: [PATCH] Upgrade to Django4 * Now supports py10, py11. Drop py8 * Update unit test template as per https://review.opendev.org/c/openstack/adjutant/+/904651 Change-Id: I1209cf9b35c42262396bbc0e00898110e3111255 --- .zuul.yaml | 2 +- .../migrations/0002_action_auto_approve.py | 2 +- adjutant/api/urls.py | 10 +++--- adjutant/api/v1/urls.py | 18 +++++----- adjutant/feature_set.py | 6 ++-- adjutant/middleware.py | 34 +++++++++---------- adjutant/settings.py | 4 +-- adjutant/startup/__init__.py | 1 - adjutant/urls.py | 4 +-- bindep.txt | 2 +- requirements.txt | 2 +- setup.cfg | 3 +- 12 files changed, 42 insertions(+), 46 deletions(-) diff --git a/.zuul.yaml b/.zuul.yaml index 20c69b2..c166104 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -16,7 +16,7 @@ - publish-openstack-docs-pti - build-release-notes-jobs-python3 - openstack-cover-jobs - - openstack-python3-zed-jobs + - openstack-python3-jobs check: jobs: - adjutant-black-style-check diff --git a/adjutant/actions/migrations/0002_action_auto_approve.py b/adjutant/actions/migrations/0002_action_auto_approve.py index 3c6f1a1..d591d8d 100644 --- a/adjutant/actions/migrations/0002_action_auto_approve.py +++ b/adjutant/actions/migrations/0002_action_auto_approve.py @@ -12,6 +12,6 @@ class Migration(migrations.Migration): migrations.AddField( model_name="action", name="auto_approve", - field=models.NullBooleanField(default=None), + field=models.BooleanField(null=True, default=None), ), ] diff --git a/adjutant/api/urls.py b/adjutant/api/urls.py index 16f060b..feb00b0 100644 --- a/adjutant/api/urls.py +++ b/adjutant/api/urls.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -from django.conf.urls import url, include +from django.urls import include, re_path from django.conf import settings from rest_framework_swagger.views import get_swagger_view @@ -22,15 +22,15 @@ from adjutant.api.views import build_version_details from adjutant.api.v1 import views as views_v1 urlpatterns = [ - url(r"^$", views.VersionView.as_view()), + re_path(r"^$", views.VersionView.as_view()), ] # NOTE(adriant): make this conditional once we have a v2. build_version_details("1.0", "CURRENT", relative_endpoint="v1/") -urlpatterns.append(url(r"^v1/?$", views_v1.V1VersionEndpoint.as_view())) -urlpatterns.append(url(r"^v1/", include("adjutant.api.v1.urls"))) +urlpatterns.append(re_path(r"^v1/?$", views_v1.V1VersionEndpoint.as_view())) +urlpatterns.append(re_path(r"^v1/", include("adjutant.api.v1.urls"))) if settings.DEBUG: schema_view = get_swagger_view(title="Adjutant API") - urlpatterns.append(url(r"^docs/", schema_view)) + urlpatterns.append(re_path(r"^docs/", schema_view)) diff --git a/adjutant/api/v1/urls.py b/adjutant/api/v1/urls.py index 63a5385..c3de350 100644 --- a/adjutant/api/v1/urls.py +++ b/adjutant/api/v1/urls.py @@ -12,23 +12,23 @@ # License for the specific language governing permissions and limitations # under the License. -from django.conf.urls import url +from django.urls import re_path from adjutant.api.v1 import views from adjutant import api from adjutant.config import CONF urlpatterns = [ - url(r"^status/?$", views.StatusView.as_view()), - url(r"^tasks/(?P\w+)/?$", views.TaskDetail.as_view()), - url(r"^tasks/?$", views.TaskList.as_view()), - url(r"^tokens/(?P\w+)", views.TokenDetail.as_view()), - url(r"^tokens/?$", views.TokenList.as_view()), - url(r"^notifications/(?P\w+)/?$", views.NotificationDetail.as_view()), - url(r"^notifications/?$", views.NotificationList.as_view()), + re_path(r"^status/?$", views.StatusView.as_view()), + re_path(r"^tasks/(?P\w+)/?$", views.TaskDetail.as_view()), + re_path(r"^tasks/?$", views.TaskList.as_view()), + re_path(r"^tokens/(?P\w+)", views.TokenDetail.as_view()), + re_path(r"^tokens/?$", views.TokenList.as_view()), + re_path(r"^notifications/(?P\w+)/?$", views.NotificationDetail.as_view()), + re_path(r"^notifications/?$", views.NotificationList.as_view()), ] for active_view in CONF.api.active_delegate_apis: delegate_api = api.DELEGATE_API_CLASSES[active_view] - urlpatterns.append(url(delegate_api.url, delegate_api.as_view())) + urlpatterns.append(re_path(delegate_api.url, delegate_api.as_view())) diff --git a/adjutant/feature_set.py b/adjutant/feature_set.py index e019a2b..738e9e5 100644 --- a/adjutant/feature_set.py +++ b/adjutant/feature_set.py @@ -101,9 +101,9 @@ def register_notification_handler(notification_handler): "'%s' is not a built off the BaseNotificationHandler class." % notification_handler.__name__ ) - notifications.NOTIFICATION_HANDLERS[ - notification_handler.__name__ - ] = notification_handler + notifications.NOTIFICATION_HANDLERS[notification_handler.__name__] = ( + notification_handler + ) if notification_handler.config_group: # NOTE(adriant): We copy the config_group before naming it # to avoid cases where a subclass inherits but doesn't extend it diff --git a/adjutant/middleware.py b/adjutant/middleware.py index ca4d70a..e9df0aa 100644 --- a/adjutant/middleware.py +++ b/adjutant/middleware.py @@ -29,14 +29,14 @@ class KeystoneHeaderUnwrapper: def __call__(self, request): try: token_data = { - "project_domain_id": request.META["HTTP_X_PROJECT_DOMAIN_ID"], - "project_name": request.META["HTTP_X_PROJECT_NAME"], - "project_id": request.META["HTTP_X_PROJECT_ID"], - "roles": request.META["HTTP_X_ROLES"].split(","), - "user_domain_id": request.META["HTTP_X_USER_DOMAIN_ID"], - "username": request.META["HTTP_X_USER_NAME"], - "user_id": request.META["HTTP_X_USER_ID"], - "authenticated": request.META["HTTP_X_IDENTITY_STATUS"], + "project_domain_id": request.headers["x-project-domain-id"], + "project_name": request.headers["x-project-name"], + "project_id": request.headers["x-project-id"], + "roles": request.headers["x-roles"].split(","), + "user_domain_id": request.headers["x-user-domain-id"], + "username": request.headers["x-user-name"], + "user_id": request.headers["x-user-id"], + "authenticated": request.headers["x-identity-status"], } except KeyError: token_data = {} @@ -60,18 +60,16 @@ class TestingHeaderUnwrapper: # TODO(adriant): follow up patch to update all the test # headers to provide domain values. # Default here is just a temporary measure. - "project_domain_id": request.META["headers"].get( + "project_domain_id": request.headers.get( "project_domain_id", "default" ), - "project_name": request.META["headers"]["project_name"], - "project_id": request.META["headers"]["project_id"], - "roles": request.META["headers"]["roles"].split(","), - "user_domain_id": request.META["headers"].get( - "user_domain_id", "default" - ), - "username": request.META["headers"]["username"], - "user_id": request.META["headers"]["user_id"], - "authenticated": request.META["headers"]["authenticated"], + "project_name": request.headers["project_name"], + "project_id": request.headers["project_id"], + "roles": request.headers["roles"].split(","), + "user_domain_id": request.headers.get("user_domain_id", "default"), + "username": request.headers["username"], + "user_id": request.headers["user_id"], + "authenticated": request.headers["authenticated"], } except KeyError: token_data = {} diff --git a/adjutant/settings.py b/adjutant/settings.py index d0bbbfc..92c34b3 100644 --- a/adjutant/settings.py +++ b/adjutant/settings.py @@ -45,7 +45,7 @@ INSTALLED_APPS = ( "adjutant.api", "adjutant.notifications", "adjutant.tasks", - "adjutant.startup", + "adjutant.startup.config.StartUpConfig", ) MIDDLEWARE = ( @@ -70,8 +70,6 @@ TIME_ZONE = "UTC" USE_I18N = True -USE_L10N = True - USE_TZ = True STATIC_URL = "/static/" diff --git a/adjutant/startup/__init__.py b/adjutant/startup/__init__.py index 6868ddd..e69de29 100644 --- a/adjutant/startup/__init__.py +++ b/adjutant/startup/__init__.py @@ -1 +0,0 @@ -default_app_config = "adjutant.startup.config.StartUpConfig" diff --git a/adjutant/urls.py b/adjutant/urls.py index 4dbd978..d452a4e 100644 --- a/adjutant/urls.py +++ b/adjutant/urls.py @@ -12,8 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -from django.conf.urls import include, url +from django.urls import include, re_path urlpatterns = [ - url(r"^", include("adjutant.api.urls")), + re_path(r"^", include("adjutant.api.urls")), ] diff --git a/bindep.txt b/bindep.txt index 8b49c76..8ec5e46 100644 --- a/bindep.txt +++ b/bindep.txt @@ -8,7 +8,7 @@ virtual/libffi [platform:gentoo] libssl-dev [platform:dpkg] openssl-devel [platform:rpm] -libmysqlclient-dev [platform:dpkg] +default-libmysqlclient-dev [platform:dpkg] mariadb-devel [platform:redhat] libmariadb-devel [platform:suse] dev-db/mariadb [platform:gentoo] diff --git a/requirements.txt b/requirements.txt index bae8366..9463a94 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ pbr>=5.2.0 -Django>=3.2.12 +Django>=4.2 Babel>=2.6.0 decorator>=4.4.0 django-rest-swagger>=2.2.0 diff --git a/setup.cfg b/setup.cfg index a7b70ce..a509652 100644 --- a/setup.cfg +++ b/setup.cfg @@ -18,8 +18,9 @@ classifier = License :: OSI Approved :: Apache Software License Framework :: Django :: 3.2 Programming Language :: Python :: 3 - Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 Environment :: OpenStack keywords =