From 4fd5087499b0f3dae16b183eba825e642efb0e95 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Fri, 10 Oct 2014 16:02:41 -0700 Subject: [PATCH] unconfigured clients look in the [clients] section for defaults This change enables clients that have no specific settings in the [clients_xxx] sections of the configuration file to get defaults from the [clients] section. Change-Id: I071bd77a2e1f0ad366b80c095917a8debc5cef2b Closes-Bug: 1379958 --- .../heat_keystoneclient_v2/client.py | 17 +++++---- etc/heat/heat.conf.sample | 38 +++++++++---------- heat/common/config.py | 26 ++++++++++++- heat/common/heat_keystoneclient.py | 17 +++++---- heat/engine/clients/client_plugin.py | 14 +++++-- heat/tests/test_clients.py | 6 +++ 6 files changed, 79 insertions(+), 39 deletions(-) diff --git a/contrib/heat_keystoneclient_v2/heat_keystoneclient_v2/client.py b/contrib/heat_keystoneclient_v2/heat_keystoneclient_v2/client.py index 6fd1895221..0193265cec 100644 --- a/contrib/heat_keystoneclient_v2/heat_keystoneclient_v2/client.py +++ b/contrib/heat_keystoneclient_v2/heat_keystoneclient_v2/client.py @@ -131,13 +131,16 @@ class KeystoneClientV2(object): return creds def _get_client_option(self, option): - try: - cfg.CONF.import_opt(option, 'heat.common.config', - group='clients_keystone') - return getattr(cfg.CONF.clients_keystone, option) - except (cfg.NoSuchGroupError, cfg.NoSuchOptError): - cfg.CONF.import_opt(option, 'heat.common.config', group='clients') - return getattr(cfg.CONF.clients, option) + # look for the option in the [clients_keystone] section + # unknown options raise cfg.NoSuchOptError + cfg.CONF.import_opt(option, 'heat.common.config', + group='clients_keystone') + v = getattr(cfg.CONF.clients_keystone, option) + if v is not None: + return v + # look for the option in the generic [clients] section + cfg.CONF.import_opt(option, 'heat.common.config', group='clients') + return getattr(cfg.CONF.clients, option) def create_stack_user(self, username, password=''): """ diff --git a/etc/heat/heat.conf.sample b/etc/heat/heat.conf.sample index 9d723b2177..51d47d2dec 100644 --- a/etc/heat/heat.conf.sample +++ b/etc/heat/heat.conf.sample @@ -585,7 +585,7 @@ # Type of endpoint in Identity service catalog to use for # communication with the OpenStack service. (string value) -#endpoint_type=publicURL +#endpoint_type= # Optional CA cert file to use in SSL connections. (string # value) @@ -601,7 +601,7 @@ # If set, then the server's certificate will not be verified. # (boolean value) -#insecure=false +#insecure= [clients_cinder] @@ -612,7 +612,7 @@ # Type of endpoint in Identity service catalog to use for # communication with the OpenStack service. (string value) -#endpoint_type=publicURL +#endpoint_type= # Optional CA cert file to use in SSL connections. (string # value) @@ -628,7 +628,7 @@ # If set, then the server's certificate will not be verified. # (boolean value) -#insecure=false +#insecure= # @@ -647,7 +647,7 @@ # Type of endpoint in Identity service catalog to use for # communication with the OpenStack service. (string value) -#endpoint_type=publicURL +#endpoint_type= # Optional CA cert file to use in SSL connections. (string # value) @@ -663,7 +663,7 @@ # If set, then the server's certificate will not be verified. # (boolean value) -#insecure=false +#insecure= [clients_heat] @@ -674,7 +674,7 @@ # Type of endpoint in Identity service catalog to use for # communication with the OpenStack service. (string value) -#endpoint_type=publicURL +#endpoint_type= # Optional CA cert file to use in SSL connections. (string # value) @@ -690,7 +690,7 @@ # If set, then the server's certificate will not be verified. # (boolean value) -#insecure=false +#insecure= # @@ -699,7 +699,7 @@ # Optional heat url in format like # http://0.0.0.0:8004/v1/%(tenant_id)s. (string value) -#url= +#url= [clients_keystone] @@ -710,7 +710,7 @@ # Type of endpoint in Identity service catalog to use for # communication with the OpenStack service. (string value) -#endpoint_type=publicURL +#endpoint_type= # Optional CA cert file to use in SSL connections. (string # value) @@ -726,7 +726,7 @@ # If set, then the server's certificate will not be verified. # (boolean value) -#insecure=false +#insecure= [clients_neutron] @@ -737,7 +737,7 @@ # Type of endpoint in Identity service catalog to use for # communication with the OpenStack service. (string value) -#endpoint_type=publicURL +#endpoint_type= # Optional CA cert file to use in SSL connections. (string # value) @@ -753,7 +753,7 @@ # If set, then the server's certificate will not be verified. # (boolean value) -#insecure=false +#insecure= [clients_nova] @@ -764,7 +764,7 @@ # Type of endpoint in Identity service catalog to use for # communication with the OpenStack service. (string value) -#endpoint_type=publicURL +#endpoint_type= # Optional CA cert file to use in SSL connections. (string # value) @@ -780,7 +780,7 @@ # If set, then the server's certificate will not be verified. # (boolean value) -#insecure=false +#insecure= # @@ -799,7 +799,7 @@ # Type of endpoint in Identity service catalog to use for # communication with the OpenStack service. (string value) -#endpoint_type=publicURL +#endpoint_type= # Optional CA cert file to use in SSL connections. (string # value) @@ -815,7 +815,7 @@ # If set, then the server's certificate will not be verified. # (boolean value) -#insecure=false +#insecure= [clients_trove] @@ -826,7 +826,7 @@ # Type of endpoint in Identity service catalog to use for # communication with the OpenStack service. (string value) -#endpoint_type=publicURL +#endpoint_type= # Optional CA cert file to use in SSL connections. (string # value) @@ -842,7 +842,7 @@ # If set, then the server's certificate will not be verified. # (boolean value) -#insecure=false +#insecure= [database] diff --git a/heat/common/config.py b/heat/common/config.py index 42e89e462e..4e22c79d7b 100644 --- a/heat/common/config.py +++ b/heat/common/config.py @@ -174,7 +174,9 @@ auth_password_opts = [ help=_('Allowed keystone endpoints for auth_uri when ' 'multi_cloud is enabled. At least one endpoint needs ' 'to be specified.'))] -clients_opts = [ + +# these options define baseline defaults that apply to all clients +default_clients_opts = [ cfg.StrOpt('endpoint_type', default='publicURL', help=_( @@ -192,8 +194,28 @@ clients_opts = [ help=_("If set, then the server's certificate will not " "be verified."))] +# these options can be defined for each client +# they must not specify defaults, since any options not defined in a client +# specific group is looked up on the generic group above +clients_opts = [ + cfg.StrOpt('endpoint_type', + help=_( + 'Type of endpoint in Identity service catalog to use ' + 'for communication with the OpenStack service.')), + cfg.StrOpt('ca_file', + help=_('Optional CA cert file to use in SSL connections.')), + cfg.StrOpt('cert_file', + help=_('Optional PEM-formatted certificate chain file.')), + cfg.StrOpt('key_file', + help=_('Optional PEM-formatted file that contains the ' + 'private key.')), + cfg.BoolOpt('insecure', + help=_("If set, then the server's certificate will not " + "be verified."))] + heat_client_opts = [ cfg.StrOpt('url', + default='', help=_('Optional heat url in format like' ' http://0.0.0.0:8004/v1/%(tenant_id)s.'))] @@ -220,7 +242,7 @@ def list_opts(): yield auth_password_group.name, auth_password_opts yield revision_group.name, revision_opts yield profiler_group.name, profiler_opts - yield 'clients', clients_opts + yield 'clients', default_clients_opts for client in ('nova', 'swift', 'neutron', 'cinder', 'ceilometer', 'keystone', 'heat', 'glance', 'trove'): diff --git a/heat/common/heat_keystoneclient.py b/heat/common/heat_keystoneclient.py index 378cf7b481..28b7b01b6f 100644 --- a/heat/common/heat_keystoneclient.py +++ b/heat/common/heat_keystoneclient.py @@ -248,13 +248,16 @@ class KeystoneClientV3(object): return opts def _get_client_option(self, option): - try: - cfg.CONF.import_opt(option, 'heat.common.config', - group='clients_keystone') - return getattr(cfg.CONF.clients_keystone, option) - except (cfg.NoSuchGroupError, cfg.NoSuchOptError): - cfg.CONF.import_opt(option, 'heat.common.config', group='clients') - return getattr(cfg.CONF.clients, option) + # look for the option in the [clients_keystone] section + # unknown options raise cfg.NoSuchOptError + cfg.CONF.import_opt(option, 'heat.common.config', + group='clients_keystone') + v = getattr(cfg.CONF.clients_keystone, option) + if v is not None: + return v + # look for the option in the generic [clients] section + cfg.CONF.import_opt(option, 'heat.common.config', group='clients') + return getattr(cfg.CONF.clients, option) def create_trust_context(self): """Create a trust using the trustor identity in the current context. diff --git a/heat/engine/clients/client_plugin.py b/heat/engine/clients/client_plugin.py index 5f3520083d..031e590fe1 100644 --- a/heat/engine/clients/client_plugin.py +++ b/heat/engine/clients/client_plugin.py @@ -50,14 +50,20 @@ class ClientPlugin(object): return self.clients.client('keystone').url_for(**kwargs) def _get_client_option(self, client, option): + # look for the option in the [clients_${client}] section + # unknown options raise cfg.NoSuchOptError try: group_name = 'clients_' + client cfg.CONF.import_opt(option, 'heat.common.config', group=group_name) - return getattr(getattr(cfg.CONF, group_name), option) - except (cfg.NoSuchGroupError, cfg.NoSuchOptError): - cfg.CONF.import_opt(option, 'heat.common.config', group='clients') - return getattr(cfg.CONF.clients, option) + v = getattr(getattr(cfg.CONF, group_name), option) + if v is not None: + return v + except cfg.NoSuchGroupError: + pass # do not error if the client is unknown + # look for the option in the generic [clients] section + cfg.CONF.import_opt(option, 'heat.common.config', group='clients') + return getattr(cfg.CONF.clients, option) def is_client_exception(self, ex): '''Returns True if the current exception comes from the client.''' diff --git a/heat/tests/test_clients.py b/heat/tests/test_clients.py index 3a66dd2066..f7b1813bd0 100644 --- a/heat/tests/test_clients.py +++ b/heat/tests/test_clients.py @@ -145,11 +145,17 @@ class ClientPluginTest(HeatTestCase): group='clients_heat') cfg.CONF.set_override('ca_file', '/tmp/foo', group='clients') + cfg.CONF.set_override('endpoint_type', 'internalURL', + group='clients') # check heat group self.assertEqual('/tmp/bar', plugin._get_client_option('heat', 'ca_file')) + # check fallback clients group for known client + self.assertEqual('internalURL', + plugin._get_client_option('glance', 'endpoint_type')) + # check fallback clients group for unknown client foo self.assertEqual('/tmp/foo', plugin._get_client_option('foo', 'ca_file'))