Skip to content

Commit 0114942

Browse files
authored
Merge pull request #15 from stackhpc/upstream/yoga-2022-11-28
Synchronise yoga with upstream
2 parents 4af55d5 + 9381481 commit 0114942

File tree

26 files changed

+669
-331
lines changed

26 files changed

+669
-331
lines changed

doc/source/ovn/dhcp_opts.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ classless-static-route classless_static_route
1717
default-ttl default_ttl
1818
dns-server dns_server
1919
domain-name domain_name
20+
domain-search domain_search_list
2021
ethernet-encap ethernet_encap
2122
ip-forward-enable ip_forward_enable
2223
lease-time lease_time
@@ -67,6 +68,7 @@ wpad wpad
6768
59 T2
6869
66 tftp_server
6970
67 bootfile_name
71+
119 domain_search_list
7072
121 classless_static_route
7173
150 tftp_server_address
7274
210 path_prefix

neutron/agent/ovn/metadata/agent.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from oslo_utils import netutils
2525
from ovsdbapp.backend.ovs_idl import event as row_event
2626
from ovsdbapp.backend.ovs_idl import vlog
27-
import tenacity
2827

2928
from neutron.agent.linux import external_process
3029
from neutron.agent.linux import ip_lib
@@ -280,10 +279,7 @@ def start(self):
280279

281280
self._proxy.wait()
282281

283-
@tenacity.retry(
284-
wait=tenacity.wait_exponential(
285-
max=config.get_ovn_ovsdb_retry_max_interval()),
286-
reraise=True)
282+
@ovn_utils.retry()
287283
def register_metadata_agent(self):
288284
# NOTE(lucasagomes): db_add() will not overwrite the UUID if
289285
# it's already set.

neutron/agent/ovn/metadata/ovsdb.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
from ovsdbapp.backend.ovs_idl import connection
1818
from ovsdbapp.backend.ovs_idl import idlutils
1919
from ovsdbapp.schema.open_vswitch import impl_idl as idl_ovs
20-
import tenacity
2120

21+
from neutron.common.ovn import utils as ovn_utils
2222
from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf as config
2323
from neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb import impl_idl_ovn
2424
from neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb import ovsdb_monitor
@@ -54,16 +54,11 @@ def __init__(self, chassis=None, events=None, tables=None):
5454
if events:
5555
self.notify_handler.watch_events(events)
5656

57-
@tenacity.retry(
58-
wait=tenacity.wait_exponential(max=180),
59-
reraise=True)
57+
@ovn_utils.retry(max_=180)
6058
def _get_ovsdb_helper(self, connection_string):
6159
return idlutils.get_schema_helper(connection_string, self.SCHEMA)
6260

63-
@tenacity.retry(
64-
wait=tenacity.wait_exponential(
65-
max=config.get_ovn_ovsdb_retry_max_interval()),
66-
reraise=True)
61+
@ovn_utils.retry()
6762
def start(self):
6863
LOG.info('Getting OvsdbSbOvnIdl for MetadataAgent with retry')
6964
conn = connection.Connection(

neutron/agent/ovn/metadata_agent.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
from neutron.agent.ovn.metadata import agent
2222
from neutron.conf.agent.metadata import config as meta
2323
from neutron.conf.agent.ovn.metadata import config as ovn_meta
24+
from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf
2425

2526
LOG = logging.getLogger(__name__)
2627

2728

2829
def main():
30+
ovn_conf.register_opts()
2931
ovn_meta.register_meta_conf_opts(meta.SHARED_OPTS)
3032
ovn_meta.register_meta_conf_opts(meta.UNIX_DOMAIN_METADATA_PROXY_OPTS)
3133
ovn_meta.register_meta_conf_opts(meta.METADATA_PROXY_HANDLER_OPTS)

neutron/cmd/ovn/neutron_ovn_db_sync_util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def security_groups_provider_updated(self, context,
137137

138138
def setup_conf():
139139
conf = cfg.CONF
140+
ovn_conf.register_opts()
140141
ml2_group, ml2_opts = neutron_options.list_ml2_conf_opts()[0]
141142
cfg.CONF.register_cli_opts(ml2_opts, ml2_group)
142143
cfg.CONF.register_cli_opts(securitygroups_rpc.security_group_opts,

neutron/common/ovn/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
'log-server': 'log_server',
112112
'lpr-server': 'lpr_server',
113113
'domain-name': 'domain_name',
114+
'domain-search': 'domain_search_list',
114115
'swap-server': 'swap_server',
115116
'policy-filter': 'policy_filter',
116117
'router-solicitation': 'router_solicitation',
@@ -162,6 +163,7 @@
162163
'58': 'T1',
163164
'59': 'T2',
164165
'67': 'bootfile_name',
166+
'119': 'domain_search_list',
165167
'252': 'wpad',
166168
'210': 'path_prefix',
167169
'150': 'tftp_server_address'},
@@ -187,6 +189,7 @@
187189
# OVN string type DHCP options
188190
OVN_STR_TYPE_DHCP_OPTS = [
189191
'domain_name',
192+
'domain_search_list',
190193
'bootfile_name',
191194
'bootfile_name_alt',
192195
'path_prefix',

neutron/common/ovn/utils.py

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
2727
from neutron_lib import exceptions as n_exc
2828
from neutron_lib.plugins import directory
2929
from neutron_lib.utils import net as n_utils
30+
from oslo_concurrency import processutils
3031
from oslo_config import cfg
3132
from oslo_log import log
3233
from oslo_serialization import jsonutils
3334
from oslo_utils import netutils
3435
from oslo_utils import strutils
3536
from ovsdbapp import constants as ovsdbapp_const
37+
import tenacity
3638

3739
from neutron._i18n import _
3840
from neutron.common.ovn import constants
@@ -55,6 +57,70 @@
5557
'PortExtraDHCPValidation', ['failed', 'invalid_ipv4', 'invalid_ipv6'])
5658

5759

60+
class OvsdbClientCommand(object):
61+
_CONNECTION = 0
62+
_PRIVATE_KEY = 1
63+
_CERTIFICATE = 2
64+
_CA_AUTHORITY = 3
65+
66+
OVN_Northbound = "OVN_Northbound"
67+
OVN_Southbound = "OVN_Southbound"
68+
69+
_db_settings = {
70+
OVN_Northbound: {
71+
_CONNECTION: ovn_conf.get_ovn_nb_connection,
72+
_PRIVATE_KEY: ovn_conf.get_ovn_nb_private_key,
73+
_CERTIFICATE: ovn_conf.get_ovn_nb_certificate,
74+
_CA_AUTHORITY: ovn_conf.get_ovn_nb_ca_cert,
75+
},
76+
OVN_Southbound: {
77+
_CONNECTION: ovn_conf.get_ovn_sb_connection,
78+
_PRIVATE_KEY: ovn_conf.get_ovn_sb_private_key,
79+
_CERTIFICATE: ovn_conf.get_ovn_sb_certificate,
80+
_CA_AUTHORITY: ovn_conf.get_ovn_sb_ca_cert,
81+
},
82+
}
83+
84+
@classmethod
85+
def run(cls, command):
86+
"""Run custom ovsdb protocol command.
87+
88+
:param command: JSON object of ovsdb protocol command
89+
"""
90+
try:
91+
db = command[0]
92+
except IndexError:
93+
raise KeyError(
94+
_("%s or %s schema must be specified in the command %s" % (
95+
cls.OVN_Northbound, cls.OVN_Southbound, command)))
96+
97+
if db not in (cls.OVN_Northbound, cls.OVN_Southbound):
98+
raise KeyError(
99+
_("%s or %s schema must be specified in the command %s" % (
100+
cls.OVN_Northbound, cls.OVN_Southbound, command)))
101+
102+
cmd = ['ovsdb-client',
103+
cls.COMMAND,
104+
cls._db_settings[db][cls._CONNECTION](),
105+
'--timeout',
106+
str(ovn_conf.get_ovn_ovsdb_timeout())]
107+
108+
if cls._db_settings[db][cls._PRIVATE_KEY]():
109+
cmd += ['-p', cls._db_settings[db][cls._PRIVATE_KEY](),
110+
'-c', cls._db_settings[db][cls._CERTIFICATE](),
111+
'-C', cls._db_settings[db][cls._CA_AUTHORITY]()]
112+
113+
cmd.append(jsonutils.dumps(command))
114+
115+
return processutils.execute(
116+
*cmd,
117+
log_errors=processutils.LOG_FINAL_ERROR)
118+
119+
120+
class OvsdbClientTransactCommand(OvsdbClientCommand):
121+
COMMAND = 'transact'
122+
123+
58124
def ovn_name(id):
59125
# The name of the OVN entry will be neutron-<UUID>
60126
# This is due to the fact that the OVN application checks if the name
@@ -693,3 +759,67 @@ def is_port_external(port):
693759

694760
return (vnic_type in constants.EXTERNAL_PORT_TYPES and
695761
constants.PORT_CAP_SWITCHDEV not in capabilities)
762+
763+
764+
def retry(max_=None):
765+
def inner(func):
766+
def wrapper(*args, **kwargs):
767+
local_max = max_ or ovn_conf.get_ovn_ovsdb_retry_max_interval()
768+
return tenacity.retry(
769+
wait=tenacity.wait_exponential(max=local_max),
770+
reraise=True)(func)(*args, **kwargs)
771+
return wrapper
772+
return inner
773+
774+
775+
def create_neutron_pg_drop():
776+
"""Create neutron_pg_drop Port Group.
777+
778+
It uses ovsdb-client to send to server transact command using ovsdb
779+
protocol that checks if the neutron_pg_drop row exists. If it exists
780+
it times out immediatelly. If it doesn't exist then it creates the
781+
Port_Group and default ACLs to drop all ingress and egress traffic.
782+
"""
783+
command = [
784+
"OVN_Northbound", {
785+
"op": "wait",
786+
"timeout": 0,
787+
"table": "Port_Group",
788+
"where": [
789+
["name", "==", constants.OVN_DROP_PORT_GROUP_NAME]
790+
],
791+
"until": "==",
792+
"rows": []
793+
}, {
794+
"op": "insert",
795+
"table": "ACL",
796+
"row": {
797+
"action": "drop",
798+
"direction": "to-lport",
799+
"match": "outport == @neutron_pg_drop && ip",
800+
"priority": 1001
801+
},
802+
"uuid-name": "droptoport"
803+
}, {
804+
"op": "insert",
805+
"table": "ACL",
806+
"row": {
807+
"action": "drop",
808+
"direction": "from-lport",
809+
"match": "inport == @neutron_pg_drop && ip",
810+
"priority": 1001
811+
},
812+
"uuid-name": "dropfromport"
813+
}, {
814+
"op": "insert",
815+
"table": "Port_Group",
816+
"row": {
817+
"name": constants.OVN_DROP_PORT_GROUP_NAME,
818+
"acls": ["set", [
819+
["named-uuid", "droptoport"],
820+
["named-uuid", "dropfromport"]
821+
]]
822+
}
823+
}]
824+
825+
OvsdbClientTransactCommand.run(command)

neutron/conf/plugins/ml2/drivers/ovn/ovn_conf.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,10 @@
205205
'baremetal nodes. Defaults to False.')),
206206
]
207207

208-
cfg.CONF.register_opts(ovn_opts, group='ovn')
209-
ovs_conf.register_ovs_agent_opts()
208+
209+
def register_opts():
210+
cfg.CONF.register_opts(ovn_opts, group='ovn')
211+
ovs_conf.register_ovs_agent_opts()
210212

211213

212214
def list_opts():

0 commit comments

Comments
 (0)