diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d358fedda..c8ecad6d4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -36,6 +36,7 @@ repos: hooks: - id: mypy additional_dependencies: + - dogpile.cache - keystoneauth1>=5.11.0 - types-decorator - types-PyYAML diff --git a/openstack/config/cloud_config.py b/openstack/config/cloud_config.py index fdb4925b8..3c695a8f5 100644 --- a/openstack/config/cloud_config.py +++ b/openstack/config/cloud_config.py @@ -12,12 +12,84 @@ # License for the specific language governing permissions and limitations # under the License. +import typing as ty +import warnings # TODO(mordred) This is only here to ease the OSC transition from openstack.config import cloud_region +from openstack import warnings as os_warnings + +if ty.TYPE_CHECKING: + from keystoneauth1 import discover + from keystoneauth1 import plugin + from keystoneauth1 import session as ks_session + import prometheus_client + + from openstack.config import loader class CloudConfig(cloud_region.CloudRegion): - def __init__(self, name, region, config, **kwargs): - super().__init__(name, region, config, **kwargs) + def __init__( + self, + name: str | None, + region: str | None, + config: dict[str, ty.Any] | None, + force_ipv4: bool = False, + auth_plugin: ty.Optional['plugin.BaseAuthPlugin'] = None, + openstack_config: ty.Optional['loader.OpenStackConfig'] = None, + session_constructor: type['ks_session.Session'] | None = None, + app_name: str | None = None, + app_version: str | None = None, + session: ty.Optional['ks_session.Session'] = None, + discovery_cache: dict[str, 'discover.Discover'] | None = None, + extra_config: dict[str, ty.Any] | None = None, + cache_expiration_time: int = 0, + cache_expirations: dict[str, int] | None = None, + cache_path: str | None = None, + cache_class: str = 'dogpile.cache.null', + cache_arguments: dict[str, ty.Any] | None = None, + password_callback: cloud_region._PasswordCallback | None = None, + statsd_host: str | None = None, + statsd_port: str | None = None, + statsd_prefix: str | None = None, + # TODO(stephenfin): Add better types + influxdb_config: dict[str, ty.Any] | None = None, + collector_registry: ty.Optional[ + 'prometheus_client.CollectorRegistry' + ] = None, + cache_auth: bool = False, + ) -> None: + warnings.warn( + 'The CloudConfig class has been deprecated in favour of ' + 'CloudRegion. Please update your references.', + os_warnings.RemovedInSDK60Warning, + ) + self.region = region + + super().__init__( + name, + region, + config, + force_ipv4=force_ipv4, + auth_plugin=auth_plugin, + openstack_config=openstack_config, + session_constructor=session_constructor, + app_name=app_name, + app_version=app_version, + session=session, + discovery_cache=discovery_cache, + extra_config=extra_config, + cache_expiration_time=cache_expiration_time, + cache_expirations=cache_expirations, + cache_path=cache_path, + cache_class=cache_class, + cache_arguments=cache_arguments, + password_callback=password_callback, + statsd_host=statsd_host, + statsd_port=statsd_port, + statsd_prefix=statsd_prefix, + influxdb_config=influxdb_config, + collector_registry=collector_registry, + cache_auth=cache_auth, + ) diff --git a/openstack/proxy.py b/openstack/proxy.py index b13786c6c..3c028aabd 100644 --- a/openstack/proxy.py +++ b/openstack/proxy.py @@ -222,6 +222,7 @@ class Proxy(adapter.Adapter): try: if conn.cache_enabled and not skip_cache and method == 'GET': + assert key is not None # type narrow # Get the object expiration time from config # default to 0 to disable caching for this resource type expiration_time = int( diff --git a/openstack/tests/functional/base.py b/openstack/tests/functional/base.py index f42f719ff..c2c0fdab8 100644 --- a/openstack/tests/functional/base.py +++ b/openstack/tests/functional/base.py @@ -245,7 +245,7 @@ class BaseFunctionalTest(base.TestCase): service_type=service_type, **kwargs ) - if not ( + if not data or not ( data.min_microversion and data.max_microversion and discover.version_between( diff --git a/pyproject.toml b/pyproject.toml index e204658e9..7faf07ff8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,6 +35,7 @@ module = [ "openstack.common.*", "openstack.config._util", "openstack.config.defaults", + "openstack.config.cloud_config", "openstack.config.cloud_region", "openstack.config.loader", "openstack.config.vendors",