Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Not all services use microversion (looking at you, Glance), meaning the 'supports_microversion' helper is of no use to them. Add a 'support_version' helper for these services. We will use this shortly in the cloud layer. Change-Id: I02fa4037b8119681379bb3c4b7bb667efff506ee Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
- Loading branch information
1 parent
0b137cf
commit 3cb5bc9
Showing
1 changed file
with
45 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,9 @@ | |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from __future__ import annotations | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ricolin
Contributor
|
||
|
||
from collections.abc import Mapping | ||
import hashlib | ||
import queue | ||
|
@@ -17,6 +20,7 @@ | |
import time | ||
|
||
import keystoneauth1 | ||
from keystoneauth1 import adapter as ks_adapter | ||
from keystoneauth1 import discover | ||
|
||
from openstack import _log | ||
|
@@ -97,25 +101,56 @@ def __getitem__(self, key): | |
return keys | ||
|
||
|
||
def supports_version( | ||
adapter: ks_adapter.Adapter, | ||
version: str, | ||
raise_exception: bool = False, | ||
) -> bool: | ||
"""Determine if the given adapter supports the given version. | ||
Checks the version asserted by the service and ensures this matches the | ||
provided version. ``version`` can be a major version of a major-minor | ||
version | ||
:param adapter: :class:`~keystoneauth1.adapter.Adapter` instance. | ||
:param version: String containing the desired version. | ||
:param raise_exception: Raise exception when requested version | ||
is not supported by the server. | ||
:returns: ``True`` if the service supports the version, else ``False``. | ||
:raises: :class:`~openstack.exceptions.SDKException` when | ||
``raise_exception`` is ``True`` and requested version is not supported. | ||
""" | ||
required = discover.normalize_version_number(version) | ||
|
||
if discover.version_match(required, adapter.get_api_major_version()): | ||
return True | ||
|
||
if raise_exception: | ||
raise exceptions.SDKException( | ||
f'Required version {version} is not supported by the server' | ||
) | ||
|
||
return False | ||
|
||
|
||
def supports_microversion(adapter, microversion, raise_exception=False): | ||
"""Determine if the given adapter supports the given microversion. | ||
Checks the min and max microversion asserted by the service and checks to | ||
make sure that ``min <= microversion <= max``. Current default microversion | ||
is taken into consideration if set and verifies that ``microversion <= | ||
default``. | ||
Checks the min and max microversion asserted by the service and ensures | ||
``min <= microversion <= max``. If set, the current default microversion is | ||
taken into consideration to ensure ``microversion <= default``. | ||
:param adapter: :class:`~keystoneauth1.adapter.Adapter` instance. | ||
:param str microversion: String containing the desired microversion. | ||
:param bool raise_exception: Raise exception when requested microversion | ||
is not supported be the server side or is higher than the current | ||
default microversion. | ||
:returns: True if the service supports the microversion. | ||
is not supported by the server or is higher than the current default | ||
microversion. | ||
:returns: True if the service supports the microversion, else False. | ||
:rtype: bool | ||
:raises: :class:`~openstack.exceptions.SDKException` when requested | ||
microversion is not supported. | ||
:raises: :class:`~openstack.exceptions.SDKException` when | ||
``raise_exception`` is ``True`` and requested microversion is not | ||
supported. | ||
""" | ||
|
||
endpoint_data = adapter.get_endpoint_data() | ||
if ( | ||
endpoint_data.min_microversion | ||
|
This import statement breaks compatibility with Python Version 3.6. This includes RHEL 8.4, which by default uses Python 3.6.8.
According to some stack articles, it sounds like future isn't available until 3.7. Therefore, the openstackSDK isn't useable by Python 3.6 at this point.
Below is from a system with fresh openstacksdk install:
Below is from system with old install:
Steps to reproduce.
Install python 3.6.8
Install pip3
Install with pip3 python-openstackclient
Attempt any openstack command