From eea81cef1ec0c70315a11a9a236cf86e554459dd Mon Sep 17 00:00:00 2001 From: Michal Arbet Date: Thu, 21 Dec 2023 13:30:10 +0100 Subject: [PATCH] Fix skyline-apiserver on python3.11 Bump pydantic version which fixes skyline-apiserver when running under python3.11. Closes-Bug: #2047145 Change-Id: Idb1897f64ffaf0cd0fbee4f7f198935386a5f599 --- requirements.txt | 2 +- setup.cfg | 2 ++ skyline_apiserver/api/v1/extension.py | 6 +++--- skyline_apiserver/api/v1/login.py | 6 +++--- skyline_apiserver/api/v1/policy.py | 6 +++--- .../tests/unit/config/test_base.py | 2 +- tox.ini | 19 ++++++++----------- 7 files changed, 21 insertions(+), 22 deletions(-) diff --git a/requirements.txt b/requirements.txt index af7c09a..f2dbc61 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ pbr>=5.8.0 # Apache-2.0 fastapi<=0.58.1 # MIT -pydantic<=1.8.2 # MIT +pydantic<=1.10.0 # MIT uvicorn<=0.17.6 # BSD License (3 clause) gunicorn>=20.1.0 # MIT python-jose<=3.3.0 # MIT diff --git a/setup.cfg b/setup.cfg index e6ca4ff..dda286f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,6 +19,8 @@ classifier = Programming Language :: Python :: 3 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 project_urls: Source=https://opendev.org/openstack/skyline-apiserver Tracker=https://bugs.launchpad.net/skyline-apiserver diff --git a/skyline_apiserver/api/v1/extension.py b/skyline_apiserver/api/v1/extension.py index ff9e62f..f967a47 100644 --- a/skyline_apiserver/api/v1/extension.py +++ b/skyline_apiserver/api/v1/extension.py @@ -165,7 +165,7 @@ async def list_servers( sort_dirs=[sort_dirs.value] if sort_dirs else None, ) - result = [] + result: List = [] server_ids = [] image_ids = [] root_device_ids = [] @@ -752,13 +752,13 @@ async def list_volume_snapshots( ) except NotFound as ex: LOG.debug(f"Not found volume snapshot with id '{uuid}': {ex}") - return schemas.VolumeSnapshotsResponse(**{"count": 0, "volume_snapshots": []}) + return schemas.VolumeSnapshotsResponse(count=0, volume_snapshots=[]) if volume_snapshot.project_id != profile.project.id: LOG.debug( f"Volume snapshot with id '{uuid}' is in project " f"'{volume_snapshot.project_id}', not in '{profile.project.id}'" ) - return schemas.VolumeSnapshotsResponse(**{"count": 0, "volume_snapshots": []}) + return schemas.VolumeSnapshotsResponse(count=0, volume_snapshots=[]) snapshot_session = get_system_session() search_opts["all_tenants"] = True diff --git a/skyline_apiserver/api/v1/login.py b/skyline_apiserver/api/v1/login.py index 182adab..e4d5941 100644 --- a/skyline_apiserver/api/v1/login.py +++ b/skyline_apiserver/api/v1/login.py @@ -15,7 +15,7 @@ from __future__ import annotations from pathlib import PurePath -from typing import Any, List, Optional, Tuple, Union +from typing import Any, Dict, List, Optional, Tuple, Union from fastapi import APIRouter, Depends, Form, Header, HTTPException, Request, Response, status from fastapi.responses import RedirectResponse @@ -218,12 +218,12 @@ async def login( response_description="OK", ) async def get_sso(request: Request) -> schemas.SSO: - sso = { + sso: Dict = { "enable_sso": False, "protocols": [], } if CONF.openstack.sso_enabled: - protocols = [] + protocols: List = [] ks_url = CONF.openstack.keystone_url.rstrip("/") url_scheme = "https" if CONF.default.ssl_enabled else "http" diff --git a/skyline_apiserver/api/v1/policy.py b/skyline_apiserver/api/v1/policy.py index 9872cca..7f1c136 100644 --- a/skyline_apiserver/api/v1/policy.py +++ b/skyline_apiserver/api/v1/policy.py @@ -14,7 +14,7 @@ from __future__ import annotations -from typing import Dict +from typing import Dict, List from fastapi import APIRouter, Depends, HTTPException, status from keystoneauth1.exceptions.http import ( @@ -113,7 +113,7 @@ async def list_policies( LOG.debug("Keystone is not reachable. No privilege to access system scope.") target = _generate_target(profile) - results = [] + results: List = [] services = constants.SUPPORTED_SERVICE_EPS.keys() for service in services: try: @@ -176,7 +176,7 @@ async def check_policies( target = _generate_target(profile) target.update(policy_rules.target if policy_rules.target else {}) try: - result = [] + result: List = [] for policy_rule in policy_rules.rules: service = policy_rule.split(":", 1)[0] rule = policy_rule.split(":", 1)[1] diff --git a/skyline_apiserver/tests/unit/config/test_base.py b/skyline_apiserver/tests/unit/config/test_base.py index 7b6a8ef..8468610 100644 --- a/skyline_apiserver/tests/unit/config/test_base.py +++ b/skyline_apiserver/tests/unit/config/test_base.py @@ -79,7 +79,7 @@ class TestOpt: { "name": FAKER.text.word(), "description": FAKER.text.word(), - "schema": object, + "schema": RuntimeError, }, RuntimeError, ), diff --git a/tox.ini b/tox.ini index 1c62032..e58c8ff 100644 --- a/tox.ini +++ b/tox.ini @@ -2,21 +2,19 @@ minversion = 3.18.0 requires = virtualenv>=20.4.2 skipsdist = True -# python runtimes: https://governance.openstack.org/tc/reference/project-testing-interface.html#tested-runtimes -envlist = pep8,py38,functional +envlist = pep8,py3,functional # this allows tox to infer the base python from the environment name # and override any basepython configured in this file ignore_basepython_conflict=true [testenv] -basepython = python3 -setenv = VIRTUAL_ENV={envdir} - PYTHONWARNINGS=default::DeprecationWarning - OS_STDOUT_CAPTURE=1 - OS_STDERR_CAPTURE=1 -usedevelop = True +usedevelop = true +setenv = + VIRTUAL_ENV={envdir} + OS_STDOUT_CAPTURE=1 + OS_STDERR_CAPTURE=1 -deps = +deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master} -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt @@ -68,10 +66,9 @@ commands = black --check --diff --color skyline_apiserver --line-length 98 flake8 {posargs} . -[testenv:py38] +[testenv:py{3,38,39,310,311}] description = Run pytest. -envdir = {toxworkdir}/shared deps = {[testenv]deps} extras =