Skip to content

Commit

Permalink
unconfigured clients look in the [clients] section for defaults
Browse files Browse the repository at this point in the history
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
  • Loading branch information
miguelgrinberg committed Nov 4, 2014
1 parent 5725b0e commit 4fd5087
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 39 deletions.
17 changes: 10 additions & 7 deletions contrib/heat_keystoneclient_v2/heat_keystoneclient_v2/client.py
Expand Up @@ -131,13 +131,16 @@ def _service_admin_creds():
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=''):
"""
Expand Down
38 changes: 19 additions & 19 deletions etc/heat/heat.conf.sample
Expand Up @@ -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=<None>

# Optional CA cert file to use in SSL connections. (string
# value)
Expand All @@ -601,7 +601,7 @@

# If set, then the server's certificate will not be verified.
# (boolean value)
#insecure=false
#insecure=<None>


[clients_cinder]
Expand All @@ -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=<None>

# Optional CA cert file to use in SSL connections. (string
# value)
Expand All @@ -628,7 +628,7 @@

# If set, then the server's certificate will not be verified.
# (boolean value)
#insecure=false
#insecure=<None>


#
Expand All @@ -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=<None>

# Optional CA cert file to use in SSL connections. (string
# value)
Expand All @@ -663,7 +663,7 @@

# If set, then the server's certificate will not be verified.
# (boolean value)
#insecure=false
#insecure=<None>


[clients_heat]
Expand All @@ -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=<None>

# Optional CA cert file to use in SSL connections. (string
# value)
Expand All @@ -690,7 +690,7 @@

# If set, then the server's certificate will not be verified.
# (boolean value)
#insecure=false
#insecure=<None>


#
Expand All @@ -699,7 +699,7 @@

# Optional heat url in format like
# http://0.0.0.0:8004/v1/%(tenant_id)s. (string value)
#url=<None>
#url=


[clients_keystone]
Expand All @@ -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=<None>

# Optional CA cert file to use in SSL connections. (string
# value)
Expand All @@ -726,7 +726,7 @@

# If set, then the server's certificate will not be verified.
# (boolean value)
#insecure=false
#insecure=<None>


[clients_neutron]
Expand All @@ -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=<None>

# Optional CA cert file to use in SSL connections. (string
# value)
Expand All @@ -753,7 +753,7 @@

# If set, then the server's certificate will not be verified.
# (boolean value)
#insecure=false
#insecure=<None>


[clients_nova]
Expand All @@ -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=<None>

# Optional CA cert file to use in SSL connections. (string
# value)
Expand All @@ -780,7 +780,7 @@

# If set, then the server's certificate will not be verified.
# (boolean value)
#insecure=false
#insecure=<None>


#
Expand All @@ -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=<None>

# Optional CA cert file to use in SSL connections. (string
# value)
Expand All @@ -815,7 +815,7 @@

# If set, then the server's certificate will not be verified.
# (boolean value)
#insecure=false
#insecure=<None>


[clients_trove]
Expand All @@ -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=<None>

# Optional CA cert file to use in SSL connections. (string
# value)
Expand All @@ -842,7 +842,7 @@

# If set, then the server's certificate will not be verified.
# (boolean value)
#insecure=false
#insecure=<None>


[database]
Expand Down
26 changes: 24 additions & 2 deletions heat/common/config.py
Expand Up @@ -174,7 +174,9 @@
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=_(
Expand All @@ -192,8 +194,28 @@
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.'))]

Expand All @@ -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'):
Expand Down
17 changes: 10 additions & 7 deletions heat/common/heat_keystoneclient.py
Expand Up @@ -248,13 +248,16 @@ def _ssl_options(self):
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.
Expand Down
14 changes: 10 additions & 4 deletions heat/engine/clients/client_plugin.py
Expand Up @@ -50,14 +50,20 @@ def url_for(self, **kwargs):
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.'''
Expand Down
6 changes: 6 additions & 0 deletions heat/tests/test_clients.py
Expand Up @@ -145,11 +145,17 @@ def test_get_client_option(self):
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'))
Expand Down

0 comments on commit 4fd5087

Please sign in to comment.