Skip to content

Commit 4449b2f

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Fix neutron setting overrides" into stable/2023.2
2 parents 71b4155 + a9a3c64 commit 4449b2f

File tree

5 files changed

+91
-11
lines changed

5 files changed

+91
-11
lines changed

octavia/common/config.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -935,24 +935,29 @@ def register_cli_opts():
935935
def handle_neutron_deprecations():
936936
# Apply neutron deprecated options to their new setting if needed
937937

938-
# Basicaly: if the value of the deprecated option is not the default:
938+
# Basically: if the new option is not set and the value of the deprecated
939+
# option is not the default, it means that the deprecated setting is still
940+
# used in the config file:
939941
# * convert it to a valid "new" value if needed
940942
# * set it as the default for the new option
941943
# Thus [neutron].<new_option> has an higher precedence than
942944
# [neutron].<deprecated_option>
943945
loc = cfg.CONF.get_location('endpoint', 'neutron')
944-
if loc and loc.location != cfg.Locations.opt_default:
946+
new_loc = cfg.CONF.get_location('endpoint_override', 'neutron')
947+
if not new_loc and loc and loc.location != cfg.Locations.opt_default:
945948
cfg.CONF.set_default('endpoint_override', cfg.CONF.neutron.endpoint,
946949
'neutron')
947950

948951
loc = cfg.CONF.get_location('endpoint_type', 'neutron')
949-
if loc and loc.location != cfg.Locations.opt_default:
952+
new_loc = cfg.CONF.get_location('valid_interfaces', 'neutron')
953+
if not new_loc and loc and loc.location != cfg.Locations.opt_default:
950954
endpoint_type = cfg.CONF.neutron.endpoint_type.replace('URL', '')
951955
cfg.CONF.set_default('valid_interfaces', [endpoint_type],
952956
'neutron')
953957

954958
loc = cfg.CONF.get_location('ca_certificates_file', 'neutron')
955-
if loc and loc.location != cfg.Locations.opt_default:
959+
new_loc = cfg.CONF.get_location('cafile', 'neutron')
960+
if not new_loc and loc and loc.location != cfg.Locations.opt_default:
956961
cfg.CONF.set_default('cafile', cfg.CONF.neutron.ca_certificates_file,
957962
'neutron')
958963

octavia/common/keystone.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ def get_auth(self):
8080

8181
config = getattr(cfg.CONF, self.section)
8282
for opt in config:
83-
# For each option in the [neutron] section, get its setting
84-
# location, if the location is 'opt_default' or
85-
# 'set_default', it means that the option is not configured
86-
# in the config file, it should be replaced with the one
87-
# from [service_auth]
83+
# For each option in the [section] section, get its setting
84+
# location, if the location is 'opt_default', it means that
85+
# the option is not configured in the config file.
86+
# if the option is also defined in [service_auth], the
87+
# option of the [section] can be replaced by the one from
88+
# [service_auth]
8889
loc = cfg.CONF.get_location(opt, self.section)
89-
if not loc or loc.location in (cfg.Locations.opt_default,
90-
cfg.Locations.set_default):
90+
if not loc or loc.location == cfg.Locations.opt_default:
9191
if hasattr(cfg.CONF.service_auth, opt):
9292
cur_value = getattr(config, opt)
9393
value = getattr(cfg.CONF.service_auth, opt)

octavia/tests/unit/common/test_config.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,38 @@ def test_active_connection_retry_interval(self):
7878
self.assertEqual(
7979
3,
8080
conf.conf.haproxy_amphora.active_connection_retry_interval)
81+
82+
def test_handle_neutron_deprecations(self):
83+
conf = self.useFixture(oslo_fixture.Config(config.cfg.CONF))
84+
85+
# The deprecated settings are copied to the new settings
86+
conf.config(endpoint='my_endpoint',
87+
endpoint_type='internal',
88+
ca_certificates_file='/path/to/certs',
89+
group='neutron')
90+
91+
config.handle_neutron_deprecations()
92+
93+
self.assertEqual('my_endpoint', conf.conf.neutron.endpoint_override)
94+
self.assertEqual(['internal'], conf.conf.neutron.valid_interfaces)
95+
self.assertEqual('/path/to/certs', conf.conf.neutron.cafile)
96+
97+
# Test case for https://bugs.launchpad.net/octavia/+bug/2051604
98+
def test_handle_neutron_deprecations_with_precedence(self):
99+
conf = self.useFixture(oslo_fixture.Config(config.cfg.CONF))
100+
101+
# The deprecated settings should not override the new settings when
102+
# they exist
103+
conf.config(endpoint='my_old_endpoint',
104+
endpoint_type='old_type',
105+
ca_certificates_file='/path/to/old_certs',
106+
endpoint_override='my_endpoint',
107+
valid_interfaces=['internal'],
108+
cafile='/path/to/certs',
109+
group='neutron')
110+
111+
config.handle_neutron_deprecations()
112+
113+
self.assertEqual('my_endpoint', conf.conf.neutron.endpoint_override)
114+
self.assertEqual(['internal'], conf.conf.neutron.valid_interfaces)
115+
self.assertEqual('/path/to/certs', conf.conf.neutron.cafile)

octavia/tests/unit/common/test_keystone.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,35 @@ def test_get_auth_neutron_override(self, mock_log, mock_load_auth,
5252
[call("Overriding [%s].%s with '%s'", 'neutron', 'cafile',
5353
'bar')]
5454
)
55+
56+
# Test case for https://bugs.launchpad.net/octavia/+bug/2051604
57+
@mock.patch("octavia.common.keystone.ks_loading"
58+
".load_auth_from_conf_options")
59+
@mock.patch("octavia.common.keystone.LOG")
60+
def test_get_auth_neutron_override_endpoint(self,
61+
mock_log,
62+
mock_load_auth):
63+
opt_mock = mock.MagicMock()
64+
opt_mock.dest = "foo"
65+
conf = oslo_fixture.Config(cfg.CONF)
66+
conf.conf.set_default('endpoint_override', 'default_endpoint',
67+
'service_auth')
68+
conf.conf.set_default('endpoint_override', 'new_endpoint',
69+
'neutron')
70+
71+
mock_load_auth.side_effect = [
72+
ks_exceptions.auth_plugins.MissingRequiredOptions(
73+
[opt_mock]),
74+
None,
75+
None
76+
]
77+
78+
sess = ks.KeystoneSession("neutron")
79+
sess.get_auth()
80+
81+
# [service_auth].endpoint_override should not override
82+
# [neutron].endpoint_override
83+
self.assertNotIn(
84+
call("Overriding [%s].%s with '%s'", 'neutron',
85+
'endpoint_override', 'default_endpoint'),
86+
mock_log.debug.mock_calls)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
fixes:
3+
- |
4+
Fixed a bug when the deprecated settings (``endpoint``, ``endpoint_type``,
5+
``ca_certificates_file``) are used in the ``[neutron]`` section of the
6+
configuration file. The connection to the neutron service may have used
7+
some settings from the ``[service_auth]`` section or used undefined
8+
settings.

0 commit comments

Comments
 (0)