Skip to content

Commit b2eccdc

Browse files
committed
Permit use of tuple API_VERSIONS
The values of these dictionaries are not used when SDK is in use, which should soon account for all use cases. Eventually we should probably look for plugins to return a proper class or typeddict but that's a job for another day. This began as a fix for in openstackclient/object/client.py which referenced a non-existent class and quickly snowballed. Change-Id: I7b807ec3a97124b35828ffdecbb36f6fde11e7b5 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent 7380fbe commit b2eccdc

File tree

6 files changed

+32
-27
lines changed

6 files changed

+32
-27
lines changed

openstackclient/compute/client.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
#
1514

1615
import logging
1716

@@ -21,13 +20,11 @@
2120

2221
LOG = logging.getLogger(__name__)
2322

23+
# global variables used when building the shell
2424
DEFAULT_API_VERSION = '2.1'
2525
API_VERSION_OPTION = 'os_compute_api_version'
2626
API_NAME = 'compute'
27-
API_VERSIONS = {
28-
'2': 'openstack.connection.Connection',
29-
'2.1': 'openstack.connection.Connection',
30-
}
27+
API_VERSIONS = ('2', '2.1')
3128

3229

3330
def make_client(instance):

openstackclient/identity/client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
#
1514

1615
import logging
1716

@@ -20,9 +19,9 @@
2019

2120
from openstackclient.i18n import _
2221

23-
2422
LOG = logging.getLogger(__name__)
2523

24+
# global variables used when building the shell
2625
DEFAULT_API_VERSION = '3'
2726
API_VERSION_OPTION = 'os_identity_api_version'
2827
API_NAME = 'identity'

openstackclient/image/client.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
#
1514

1615
import logging
1716

@@ -21,13 +20,11 @@
2120

2221
LOG = logging.getLogger(__name__)
2322

23+
# global variables used when building the shell
2424
DEFAULT_API_VERSION = '2'
2525
API_VERSION_OPTION = 'os_image_api_version'
2626
API_NAME = 'image'
27-
API_VERSIONS = {
28-
'1': 'openstack.connection.Connection',
29-
'2': 'openstack.connection.Connection',
30-
}
27+
API_VERSIONS = ('1', '2')
3128

3229

3330
def make_client(instance):

openstackclient/network/client.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,20 @@
99
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
12-
#
1312

1413
import logging
1514

1615
from osc_lib import utils
1716

1817
from openstackclient.i18n import _
1918

20-
2119
LOG = logging.getLogger(__name__)
2220

21+
# global variables used when building the shell
2322
DEFAULT_API_VERSION = '2.0'
2423
API_VERSION_OPTION = 'os_network_api_version'
25-
API_NAME = "network"
26-
API_VERSIONS = {
27-
"2.0": "openstack.connection.Connection",
28-
"2": "openstack.connection.Connection",
29-
}
24+
API_NAME = 'network'
25+
API_VERSIONS = ('2.0', '2')
3026

3127

3228
def make_client(instance):

openstackclient/object/client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919

2020
from openstackclient.api import object_store_v1
2121

22+
# global variables used when building the shell
2223
DEFAULT_API_VERSION = '1'
2324
API_VERSION_OPTION = 'os_object_api_version'
2425
API_NAME = 'object_store'
25-
API_VERSIONS = {
26-
'1': 'openstackclient.object.client.ObjectClientv1',
27-
}
26+
API_VERSIONS = ('1',)
2827

2928

3029
def make_client(instance):

openstackclient/shell.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,34 @@ def _load_plugins(self):
8888
# this throws an exception if invalid
8989
skip_old_check = mod_check_api_version(version_opt)
9090

91+
# NOTE(stephenfin): API_VERSIONS has traditionally been a
92+
# dictionary but the values are only used internally and are
93+
# ignored for the modules using SDK. So we now support tuples
94+
# instead.
9195
mod_versions = getattr(mod, 'API_VERSIONS', None)
92-
if not skip_old_check and mod_versions:
96+
if mod_versions is not None and not isinstance(
97+
mod_versions, (dict, tuple)
98+
):
99+
raise TypeError(
100+
f'Plugin {mod} has incompatible API_VERSIONS. '
101+
f'Expected: tuple, dict. Got: {type(mod_versions)}. '
102+
f'Please report this to your package maintainer.'
103+
)
104+
105+
if mod_versions and not skip_old_check:
93106
if version_opt not in mod_versions:
94107
sorted_versions = sorted(
95-
mod.API_VERSIONS.keys(),
108+
list(mod.API_VERSIONS),
96109
key=lambda s: list(map(int, s.split('.'))),
97110
)
98111
self.log.warning(
99-
"{} version {} is not in supported versions: {}".format(
100-
api, version_opt, ', '.join(sorted_versions)
101-
)
112+
"%(name)s API version %(version)s is not in "
113+
"supported versions: %(supported)s",
114+
{
115+
'name': api,
116+
'version': version_opt,
117+
'supported': ', '.join(sorted_versions),
118+
},
102119
)
103120

104121
# Command groups deal only with major versions

0 commit comments

Comments
 (0)