Skip to content

Commit ef99f44

Browse files
author
Dean Troyer
committed
Improve no-auth path
The commands that do not require authentication sometimes still need to call ClientManager.is_network_endpoint_enabled() to see if Neutron is available. Optimize the paths a bit to skip auth when it is not necessary; the upshot is Neutron will be assumed in these cases now. This gets a LOT cleaner when it appears is a future osc-lib. Change-Id: Ifaddc57dfa192bde04d0482e2cdcce111313a22a
1 parent db6081f commit ef99f44

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

openstackclient/common/clientmanager.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class ClientManager(clientmanager.ClientManager):
4141
# A simple incrementing version for the plugin to know what is available
4242
PLUGIN_INTERFACE_VERSION = "2"
4343

44+
# Let the commands set this
45+
_auth_required = False
46+
4447
def __init__(
4548
self,
4649
cli_options=None,
@@ -72,7 +75,10 @@ def setup_auth(self):
7275
# because openstack_config is an optional argument to
7376
# CloudConfig.__init__() and we'll die if it was not
7477
# passed.
75-
if self._cli_options._openstack_config is not None:
78+
if (
79+
self._auth_required and
80+
self._cli_options._openstack_config is not None
81+
):
7682
self._cli_options._openstack_config._pw_callback = \
7783
shell.prompt_for_password
7884
try:
@@ -85,6 +91,13 @@ def setup_auth(self):
8591

8692
return super(ClientManager, self).setup_auth()
8793

94+
@property
95+
def auth_ref(self):
96+
if not self._auth_required:
97+
return None
98+
else:
99+
return super(ClientManager, self).auth_ref
100+
88101
def _fallback_load_auth_plugin(self, e):
89102
# NOTES(RuiChen): Hack to avoid auth plugins choking on data they don't
90103
# expect, delete fake token and endpoint, then try to

openstackclient/shell.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ def prepare_to_run_command(self, cmd):
182182
# get_one_Cloud()'s validation to avoid loading plugins
183183
validate = cmd.auth_required
184184

185+
# Force skipping auth for commands that do not need it
186+
# NOTE(dtroyer): This is here because ClientManager does not have
187+
# visibility into the Command object to get
188+
# auth_required. It needs to move into osc-lib
189+
self.client_manager._auth_required = cmd.auth_required
190+
185191
# Validate auth options
186192
self.cloud = self.cloud_config.get_one_cloud(
187193
cloud=self.options.cloud,

openstackclient/tests/unit/common/test_clientmanager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,6 @@ def test_client_manager_network_endpoint_disabled(self):
6666
)
6767

6868
self.assertFalse(client_manager.is_service_available('network'))
69-
self.assertFalse(client_manager.is_network_endpoint_enabled())
69+
# This is True because ClientManager.auth_ref returns None in this
70+
# test; "no service catalog" means use Network API by default now
71+
self.assertTrue(client_manager.is_network_endpoint_enabled())

0 commit comments

Comments
 (0)