Coverage for nova/conf/utils.py: 97%
22 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-17 15:08 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-17 15:08 +0000
1# Copyright 2017 OpenStack Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14"""Common utilities for conf providers.
16This module does not provide any actual conf options.
17"""
18from keystoneauth1 import loading as ks_loading
19from oslo_config import cfg
22_ADAPTER_VERSION_OPTS = ('version', 'min_version', 'max_version')
25def get_ksa_adapter_opts(default_service_type, deprecated_opts=None):
26 """Get auth, Session, and Adapter conf options from keystonauth1.loading.
28 :param default_service_type: Default for the service_type conf option on
29 the Adapter.
30 :param deprecated_opts: dict of deprecated opts to register with the ksa
31 Adapter opts. Works the same as the
32 deprecated_opts kwarg to:
33 keystoneauth1.loading.session.Session.register_conf_options
34 :return: List of cfg.Opts.
35 """
36 opts = ks_loading.get_adapter_conf_options(include_deprecated=False,
37 deprecated_opts=deprecated_opts)
39 for opt in opts[:]:
40 # Remove version-related opts. Required/supported versions are
41 # something the code knows about, not the operator.
42 if opt.dest in _ADAPTER_VERSION_OPTS:
43 opts.remove(opt)
45 # Override defaults that make sense for nova
46 cfg.set_defaults(opts,
47 valid_interfaces=['internal', 'public'],
48 service_type=default_service_type)
49 return opts
52def _dummy_opt(name):
53 # A config option that can't be set by the user, so it behaves as if it's
54 # ignored; but consuming code may expect it to be present in a conf group.
55 return cfg.Opt(name, type=lambda x: None)
58def register_ksa_opts(conf, group, default_service_type, include_auth=True,
59 deprecated_opts=None):
60 """Register keystoneauth auth, Session, and Adapter opts.
62 :param conf: oslo_config.cfg.CONF in which to register the options
63 :param group: Conf group, or string name thereof, in which to register the
64 options.
65 :param default_service_type: Default for the service_type conf option on
66 the Adapter.
67 :param include_auth: For service types where Nova is acting on behalf of
68 the user, auth should come from the user context.
69 In those cases, set this arg to False to avoid
70 registering ksa auth options.
71 :param deprecated_opts: dict of deprecated opts to register with the ksa
72 Session or Adapter opts. See docstring for
73 the deprecated_opts param of:
74 keystoneauth1.loading.session.Session.register_conf_options
75 """
76 # ksa register methods need the group name as a string. oslo doesn't care.
77 group = getattr(group, 'name', group)
78 ks_loading.register_session_conf_options(
79 conf, group, deprecated_opts=deprecated_opts)
80 if include_auth:
81 ks_loading.register_auth_conf_options(conf, group)
82 conf.register_opts(get_ksa_adapter_opts(
83 default_service_type, deprecated_opts=deprecated_opts), group=group)
84 # Have to register dummies for the version-related opts we removed
85 for name in _ADAPTER_VERSION_OPTS:
86 conf.register_opt(_dummy_opt(name), group=group)
89# NOTE(efried): Required for docs build.
90def list_opts():
91 return {}