Rehome ovsfw constants and utils modules
Constants module contains definition of the OF registry numbers used by ovs firewall driver. After [1] some other registries are also used to store information related to QoS bw limit and min bw rules. So it would be good to have list of all used registers in one place and reuse them where it's needed. That's why this patch moves those constants to the neutron_lib. Additionally it also adds utils module with some helper functions which are using those constants and are actually used not only in neutron but also in neutron-fwaas. [1] https://review.opendev.org/c/openstack/neutron/+/832662 Related-Bug: #1959567 Change-Id: I89cc83699770e97bba369f50dd4d9e0ed6563aa4
This commit is contained in:
parent
37ddc2cbae
commit
231067caba
0
neutron_lib/agent/common/__init__.py
Normal file
0
neutron_lib/agent/common/__init__.py
Normal file
28
neutron_lib/agent/common/constants.py
Normal file
28
neutron_lib/agent/common/constants.py
Normal file
@ -0,0 +1,28 @@
|
||||
# Copyright 2022
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
REG_INGRESS_BW_LIMIT = 3
|
||||
REG_MIN_BW = 4
|
||||
REG_PORT = 5
|
||||
REG_NET = 6
|
||||
# for logging remote group rule
|
||||
REG_REMOTE_GROUP = 7
|
||||
|
||||
INGRESS_BW_LIMIT_REG_NAME = "reg_ingress_bw_limit"
|
||||
MIN_BW_REG_NAME = "reg_min_bw"
|
||||
PORT_REG_NAME = "reg_port"
|
||||
NET_REG_NAME = "reg_net"
|
||||
REMOTE_GROUP_REG_NAME = "reg_remote_group"
|
50
neutron_lib/agent/common/utils.py
Normal file
50
neutron_lib/agent/common/utils.py
Normal file
@ -0,0 +1,50 @@
|
||||
# Copyright 2022
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.agent.common import constants
|
||||
|
||||
|
||||
def _replace_register(flow_params, register_number, register_value):
|
||||
"""Replace value from flows to given register number
|
||||
|
||||
'register_value' key in dictionary will be replaced by register number
|
||||
given by 'register_number'
|
||||
|
||||
:param flow_params: Dictionary containing defined flows
|
||||
:param register_number: The number of register where value will be stored
|
||||
:param register_value: Key to be replaced by register number
|
||||
|
||||
"""
|
||||
try:
|
||||
reg_port = flow_params[register_value]
|
||||
del flow_params[register_value]
|
||||
flow_params['reg{:d}'.format(register_number)] = reg_port
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
|
||||
def create_reg_numbers(flow_params):
|
||||
"""Replace reg_(port|net) values with defined register numbers"""
|
||||
_replace_register(flow_params, constants.REG_PORT, constants.PORT_REG_NAME)
|
||||
_replace_register(flow_params, constants.REG_NET, constants.NET_REG_NAME)
|
||||
_replace_register(flow_params,
|
||||
constants.REG_REMOTE_GROUP,
|
||||
constants.REMOTE_GROUP_REG_NAME)
|
||||
_replace_register(flow_params,
|
||||
constants.REG_MIN_BW,
|
||||
constants.MIN_BW_REG_NAME)
|
||||
_replace_register(flow_params,
|
||||
constants.REG_INGRESS_BW_LIMIT,
|
||||
constants.INGRESS_BW_LIMIT_REG_NAME)
|
0
neutron_lib/tests/unit/agent/__init__.py
Normal file
0
neutron_lib/tests/unit/agent/__init__.py
Normal file
0
neutron_lib/tests/unit/agent/common/__init__.py
Normal file
0
neutron_lib/tests/unit/agent/common/__init__.py
Normal file
41
neutron_lib/tests/unit/agent/common/test_utils.py
Normal file
41
neutron_lib/tests/unit/agent/common/test_utils.py
Normal file
@ -0,0 +1,41 @@
|
||||
# Copyright 2022
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.agent.common import constants
|
||||
from neutron_lib.agent.common import utils
|
||||
from neutron_lib.tests import _base
|
||||
|
||||
|
||||
class TestCreateRegNumbers(_base.BaseTestCase):
|
||||
def test_no_registers_defined(self):
|
||||
flow = {'foo': 'bar'}
|
||||
utils.create_reg_numbers(flow)
|
||||
self.assertEqual({'foo': 'bar'}, flow)
|
||||
|
||||
def test_all_registers_defined(self):
|
||||
flow = {'foo': 'bar',
|
||||
constants.PORT_REG_NAME: 1,
|
||||
constants.NET_REG_NAME: 2,
|
||||
constants.REMOTE_GROUP_REG_NAME: 3,
|
||||
constants.INGRESS_BW_LIMIT_REG_NAME: 4,
|
||||
constants.MIN_BW_REG_NAME: 5}
|
||||
expected_flow = {'foo': 'bar',
|
||||
'reg{:d}'.format(constants.REG_PORT): 1,
|
||||
'reg{:d}'.format(constants.REG_NET): 2,
|
||||
'reg{:d}'.format(constants.REG_REMOTE_GROUP): 3,
|
||||
'reg{:d}'.format(constants.REG_INGRESS_BW_LIMIT): 4,
|
||||
'reg{:d}'.format(constants.REG_MIN_BW): 5}
|
||||
utils.create_reg_numbers(flow)
|
||||
self.assertEqual(expected_flow, flow)
|
0
neutron_lib/tests/unit/agent/linux/__init__.py
Normal file
0
neutron_lib/tests/unit/agent/linux/__init__.py
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
The neutron ovs_lib related constantswhich represents used
|
||||
OpenFlow registries are now available in the
|
||||
``neutron_lib.agent.common.constants`` module.
|
||||
The helper function ``create_reg_numbers`` is now available in the
|
||||
``neutron_lib.agent.common.utils`` module.
|
Loading…
Reference in New Issue
Block a user