Skip to content

Commit 863f529

Browse files
committed
Validate ovn_nb/sb_connection in config parser
... to detect invalid format early and return explicit error to users. Because these options accept comma-separated strings, use ListOpt to parse multiple items by the common implementation, instead of building own regex. Change-Id: I1546a2826741a0703c0673fcffeddb2356fb10f5
1 parent 91b1258 commit 863f529

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

ovn_octavia_provider/common/config.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from keystoneauth1 import loading as ks_loading
1414
from oslo_config import cfg
15+
from oslo_config import types
1516
from oslo_log import log as logging
1617

1718
from ovn_octavia_provider.i18n import _
@@ -20,14 +21,15 @@
2021

2122

2223
ovn_opts = [
23-
cfg.StrOpt('ovn_nb_connection',
24-
default='tcp:127.0.0.1:6641',
25-
help=_('The connection string for the OVN_Northbound OVSDB.\n'
26-
'Use tcp:IP:PORT for TCP connection.\n'
27-
'Use ssl:IP:PORT for SSL connection. The '
28-
'ovn_nb_private_key, ovn_nb_certificate and '
29-
'ovn_nb_ca_cert are mandatory.\n'
30-
'Use unix:FILE for unix domain socket connection.')),
24+
cfg.ListOpt('ovn_nb_connection',
25+
default=['tcp:127.0.0.1:6641'],
26+
item_type=types.String(regex=r'^(tcp|ssl|unix):.+'),
27+
help=_('The connection string for the OVN_Northbound OVSDB.\n'
28+
'Use tcp:IP:PORT for TCP connection.\n'
29+
'Use ssl:IP:PORT for SSL connection. The '
30+
'ovn_nb_private_key, ovn_nb_certificate and '
31+
'ovn_nb_ca_cert are mandatory.\n'
32+
'Use unix:FILE for unix domain socket connection.')),
3133
cfg.StrOpt('ovn_nb_private_key',
3234
default='',
3335
help=_('The PEM file with private key for SSL connection to '
@@ -40,14 +42,15 @@
4042
default='',
4143
help=_('The PEM file with CA certificate that OVN should use to'
4244
' verify certificates presented to it by SSL peers')),
43-
cfg.StrOpt('ovn_sb_connection',
44-
default='tcp:127.0.0.1:6642',
45-
help=_('The connection string for the OVN_Southbound OVSDB.\n'
46-
'Use tcp:IP:PORT for TCP connection.\n'
47-
'Use ssl:IP:PORT for SSL connection. The '
48-
'ovn_sb_private_key, ovn_sb_certificate and '
49-
'ovn_sb_ca_cert are mandatory.\n'
50-
'Use unix:FILE for unix domain socket connection.')),
45+
cfg.ListOpt('ovn_sb_connection',
46+
default=['tcp:127.0.0.1:6642'],
47+
item_type=types.String(regex=r'^(tcp|ssl|unix):.+'),
48+
help=_('The connection string for the OVN_Southbound OVSDB.\n'
49+
'Use tcp:IP:PORT for TCP connection.\n'
50+
'Use ssl:IP:PORT for SSL connection. The '
51+
'ovn_sb_private_key, ovn_sb_certificate and '
52+
'ovn_sb_ca_cert are mandatory.\n'
53+
'Use unix:FILE for unix domain socket connection.')),
5154
cfg.StrOpt('ovn_sb_private_key',
5255
default='',
5356
help=_('The PEM file with private key for SSL connection to '
@@ -176,7 +179,7 @@ def list_opts():
176179

177180

178181
def get_ovn_nb_connection():
179-
return cfg.CONF.ovn.ovn_nb_connection
182+
return ','.join(cfg.CONF.ovn.ovn_nb_connection)
180183

181184

182185
def get_ovn_nb_private_key():
@@ -192,7 +195,7 @@ def get_ovn_nb_ca_cert():
192195

193196

194197
def get_ovn_sb_connection():
195-
return cfg.CONF.ovn.ovn_sb_connection
198+
return ','.join(cfg.CONF.ovn.ovn_sb_connection)
196199

197200

198201
def get_ovn_sb_private_key():

0 commit comments

Comments
 (0)