Skip to content

Commit 6693f55

Browse files
committed
quota: Allow 'quota set' to function without volume service
Unlike cinderclient, SDK attempts to connect to a service as soon as you create a client. A keystoneauth1.exceptions.catalog.EndpointNotFound exception can be raised if this service does not exist in the service catalog. Avoid this for the quota and limits commands by first checking if the service is enabled. In the process, we rework the 'is_volume_endpoint_enabled' helper we are using to check for the existence of the service to *not* require a volume client, since this was causing a chicken and egg issue for us (and was also pretty much unnecessary). Change-Id: I56e68f00ea221d689eb7f668e9e5ffa7d1a20184 Signed-off-by: Stephen Finucane <stephenfin@redhat.com> Closes-bug: #2076229
1 parent a59262e commit 6693f55

File tree

4 files changed

+39
-54
lines changed

4 files changed

+39
-54
lines changed

openstackclient/common/clientmanager.py

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ def _fallback_load_auth_plugin(self, e):
116116

117117
def is_network_endpoint_enabled(self):
118118
"""Check if the network endpoint is enabled"""
119-
120119
# NOTE(dtroyer): is_service_available() can also return None if
121120
# there is no Service Catalog, callers here are
122121
# not expecting that so fold None into True to
@@ -125,34 +124,16 @@ def is_network_endpoint_enabled(self):
125124

126125
def is_compute_endpoint_enabled(self):
127126
"""Check if Compute endpoint is enabled"""
128-
129127
return self.is_service_available('compute') is not False
130128

131-
def is_volume_endpoint_enabled(self, volume_client):
129+
# TODO(stephenfin): Drop volume_client argument in OSC 8.0 or later.
130+
def is_volume_endpoint_enabled(self, volume_client=None):
132131
"""Check if volume endpoint is enabled"""
133-
# NOTE(jcross): Cinder did some interesting things with their service
134-
# name so we need to figure out which version to look
135-
# for when calling is_service_available()
136-
endpoint_data = volume_client.get_endpoint_data()
137-
# Not sure how endpoint data stores the api version for v2 API,
138-
# for v3 it is a tuple (3, 0)
139-
if endpoint_data.api_version and isinstance(
140-
endpoint_data.api_version, tuple
141-
):
142-
volume_version = endpoint_data.api_version[0]
143-
else:
144-
# Setting volume_version as 2 here if it doesn't satisfy the
145-
# conditions for version 3
146-
volume_version = 2
147-
if (
148-
self.is_service_available("volumev%s" % volume_version)
149-
is not False
150-
):
151-
return True
152-
elif self.is_service_available('volume') is not False:
153-
return True
154-
else:
155-
return False
132+
return (
133+
self.is_service_available('volume') is not False
134+
or self.is_service_available('volumev3') is not False
135+
or self.is_service_available('volumev2') is not False
136+
)
156137

157138

158139
# Plugin Support

openstackclient/common/limits.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ def get_parser(self, prog_name):
101101
return parser
102102

103103
def take_action(self, parsed_args):
104-
compute_client = self.app.client_manager.sdk_connection.compute
105-
volume_client = self.app.client_manager.sdk_connection.volume
106-
107104
project_id = None
108105
if parsed_args.project is not None:
109106
identity_client = self.app.client_manager.identity
@@ -125,11 +122,13 @@ def take_action(self, parsed_args):
125122
volume_limits = None
126123

127124
if self.app.client_manager.is_compute_endpoint_enabled():
125+
compute_client = self.app.client_manager.sdk_connection.compute
128126
compute_limits = compute_client.get_limits(
129127
reserved=parsed_args.is_reserved, tenant_id=project_id
130128
)
131129

132-
if self.app.client_manager.is_volume_endpoint_enabled(volume_client):
130+
if self.app.client_manager.is_volume_endpoint_enabled():
131+
volume_client = self.app.client_manager.sdk_connection.volume
133132
volume_limits = volume_client.get_limits(
134133
project_id=project_id,
135134
)

openstackclient/common/quota.py

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -565,33 +565,42 @@ def take_action(self, parsed_args):
565565
msg = _('--force cannot be used with --class or --default')
566566
raise exceptions.CommandError(msg)
567567

568-
compute_client = self.app.client_manager.sdk_connection.compute
569-
volume_client = self.app.client_manager.sdk_connection.volume
570-
571568
compute_kwargs = {}
572-
for k, v in COMPUTE_QUOTAS.items():
573-
value = getattr(parsed_args, k, None)
574-
if value is not None:
575-
compute_kwargs[k] = value
569+
volume_kwargs = {}
570+
network_kwargs = {}
576571

577-
if compute_kwargs and parsed_args.force is True:
578-
compute_kwargs['force'] = parsed_args.force
572+
if self.app.client_manager.is_compute_endpoint_enabled():
573+
compute_client = self.app.client_manager.sdk_connection.compute
579574

580-
volume_kwargs = {}
581-
for k, v in VOLUME_QUOTAS.items():
582-
value = getattr(parsed_args, k, None)
583-
if value is not None:
584-
if parsed_args.volume_type and k in IMPACT_VOLUME_TYPE_QUOTAS:
585-
k = k + '_%s' % parsed_args.volume_type
586-
volume_kwargs[k] = value
575+
for k, v in COMPUTE_QUOTAS.items():
576+
value = getattr(parsed_args, k, None)
577+
if value is not None:
578+
compute_kwargs[k] = value
579+
580+
if compute_kwargs and parsed_args.force is True:
581+
compute_kwargs['force'] = parsed_args.force
582+
583+
if self.app.client_manager.is_volume_endpoint_enabled():
584+
volume_client = self.app.client_manager.sdk_connection.volume
585+
586+
for k, v in VOLUME_QUOTAS.items():
587+
value = getattr(parsed_args, k, None)
588+
if value is not None:
589+
if (
590+
parsed_args.volume_type
591+
and k in IMPACT_VOLUME_TYPE_QUOTAS
592+
):
593+
k = k + '_%s' % parsed_args.volume_type
594+
volume_kwargs[k] = value
587595

588-
network_kwargs = {}
589596
if self.app.client_manager.is_network_endpoint_enabled():
597+
network_client = self.app.client_manager.network
598+
590599
for k, v in NETWORK_QUOTAS.items():
591600
value = getattr(parsed_args, k, None)
592601
if value is not None:
593602
network_kwargs[k] = value
594-
else:
603+
elif self.app.client_manager.is_compute_endpoint_enabled():
595604
for k, v in NOVA_NETWORK_QUOTAS.items():
596605
value = getattr(parsed_args, k, None)
597606
if value is not None:
@@ -632,11 +641,7 @@ def take_action(self, parsed_args):
632641
compute_client.update_quota_set(project, **compute_kwargs)
633642
if volume_kwargs:
634643
volume_client.update_quota_set(project, **volume_kwargs)
635-
if (
636-
network_kwargs
637-
and self.app.client_manager.is_network_endpoint_enabled()
638-
):
639-
network_client = self.app.client_manager.network
644+
if network_kwargs:
640645
network_client.update_quota(project, **network_kwargs)
641646

642647

openstackclient/tests/unit/fakes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def is_network_endpoint_enabled(self):
154154
def is_compute_endpoint_enabled(self):
155155
return self.compute_endpoint_enabled
156156

157-
def is_volume_endpoint_enabled(self, client):
157+
def is_volume_endpoint_enabled(self, client=None):
158158
return self.volume_endpoint_enabled
159159

160160

0 commit comments

Comments
 (0)