diff options
author | liushy <liuxie_11@163.com> | 2022-05-11 11:06:50 +0800 |
---|---|---|
committer | yatin <ykarel@redhat.com> | 2022-06-15 13:42:24 +0000 |
commit | 46c359ca4e6ae2858334a6b4182806586b5b26b0 (patch) | |
tree | b6cbd071eb356917ea833c30df9df2d01afc580a /neutron | |
parent | a2dc25a724fd60ba7deaf1b610610325bc767e33 (diff) | |
download | neutron-46c359ca4e6ae2858334a6b4182806586b5b26b0.tar.gz |
[OVN]Any string type dhcp options should be quoted
Any dhcp option[1] which value is string type in ovn
should be added quotes, otherwise it would be regard
as constant.
[1]https://github.com/ovn-org/ovn/blob/main/lib/ovn-l7.h#L116
Closes-Bug: #1946764
Change-Id: Id174cd944c3b883b749046bc49d00e011eb891fe
(cherry picked from commit 18c32e4339cbcb0993d9c162e2715f6fcfa932cc)
Diffstat (limited to 'neutron')
5 files changed, 24 insertions, 9 deletions
diff --git a/neutron/common/ovn/constants.py b/neutron/common/ovn/constants.py index adf9d1a5d1..31abb66335 100644 --- a/neutron/common/ovn/constants.py +++ b/neutron/common/ovn/constants.py @@ -173,6 +173,14 @@ SUPPORTED_DHCP_OPTS_MAPPING = { '23': 'dns_server'}, } +# OVN string type DHCP options +OVN_STR_TYPE_DHCP_OPTS = [ + 'domain_name', + 'bootfile_name', + 'path_prefix', + 'wpad', + 'tftp_server'] + # Special option for disabling DHCP via extra DHCP options DHCP_DISABLED_OPT = 'dhcp_disabled' diff --git a/neutron/common/ovn/utils.py b/neutron/common/ovn/utils.py index ef8e9de221..b7a82f0d72 100644 --- a/neutron/common/ovn/utils.py +++ b/neutron/common/ovn/utils.py @@ -160,6 +160,10 @@ def validate_port_extra_dhcp_opts(port): invalid_ipv6=invalid[const.IP_VERSION_6] if failed else []) +def is_dhcp_option_quoted(opt_value): + return opt_value.startswith('"') and opt_value.endswith('"') + + def get_lsp_dhcp_opts(port, ip_version): # Get dhcp options from Neutron port, for setting DHCP_Options row # in OVN. @@ -193,6 +197,9 @@ def get_lsp_dhcp_opts(port, ip_version): continue opt = mapping[edo['opt_name']] + if (opt in constants.OVN_STR_TYPE_DHCP_OPTS and + not is_dhcp_option_quoted(edo['opt_value'])): + edo['opt_value'] = '"%s"' % edo['opt_value'] lsp_dhcp_opts[opt] = edo['opt_value'] return (lsp_dhcp_disabled, lsp_dhcp_opts) diff --git a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_resources.py b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_resources.py index aeb5c084b2..023a61e6e4 100644 --- a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_resources.py +++ b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_resources.py @@ -376,7 +376,7 @@ class TestNBDbResources(base.TestOVNFunctionalBase): 'mtu': str(n1['network']['mtu']), 'router': subnet['gateway_ip'], 'ip_forward_enable': '1', - 'tftp_server': '10.0.0.100', + 'tftp_server': '"10.0.0.100"', 'domain_name': '"%s"' % cfg.CONF.dns_domain, 'dns_server': '20.20.20.20'}} expected_dhcp_v4_options_rows['v4-' + p2['port']['id']] = \ @@ -440,7 +440,7 @@ class TestNBDbResources(base.TestOVNFunctionalBase): 'dns_server': '{10.10.10.10}', 'mtu': str(n1['network']['mtu']), 'router': subnet['gateway_ip'], - 'tftp_server': '100.0.0.100'}} + 'tftp_server': '"100.0.0.100"'}} expected_dhcp_v4_options_rows['v4-' + p4['port']['id']] = \ expected_dhcp_options_rows['v4-' + p4['port']['id']] expected_dhcp_v6_options_rows['v6-' + p4['port']['id']] = \ @@ -708,7 +708,7 @@ class TestNBDbResources(base.TestOVNFunctionalBase): 'dns_server': '{10.10.10.10}', 'mtu': '1200', 'router': subnet['gateway_ip'], - 'tftp_server': '8.8.8.8'}} + 'tftp_server': '"8.8.8.8"'}} self._verify_dhcp_option_rows(expected_dhcp_options_rows) self._verify_dhcp_option_row_for_port( p1['id'], expected_dhcp_options_rows['v4-' + p1['id']], diff --git a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py index 3b51aafa5f..408e60cf03 100644 --- a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py +++ b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py @@ -208,7 +208,7 @@ class TestOvnNbSync(base.TestOVNFunctionalBase): 'lease_time': str(12 * 60 * 60), 'mtu': str(n1['network']['mtu']), 'router': n1_s1['subnet']['gateway_ip'], - 'tftp_server': '20.0.0.20', + 'tftp_server': '"20.0.0.20"', 'domain_name': '"ovn.test"', 'dns_server': '8.8.8.8'}}) self.expected_dhcp_options_rows.append({ @@ -255,7 +255,7 @@ class TestOvnNbSync(base.TestOVNFunctionalBase): 'lease_time': str(3 * 60 * 60), 'mtu': str(n1['network']['mtu'] / 2), 'router': '10.0.0.254', - 'tftp_server': '20.0.0.234', + 'tftp_server': '"20.0.0.234"', 'domain_name': '"ovn.test"', 'dns_server': '8.8.8.8'}, 'external_ids': {'subnet_id': n1_s1['subnet']['id'], @@ -278,7 +278,7 @@ class TestOvnNbSync(base.TestOVNFunctionalBase): 'lease_time': str(12 * 60 * 60), 'mtu': str(n1['network']['mtu']), 'router': n1_s1['subnet']['gateway_ip'], - 'tftp_server': '20.0.0.20', + 'tftp_server': '"20.0.0.20"', 'domain_name': '"ovn.test"', 'dns_server': '8.8.8.8'}}) self.expected_dhcp_options_rows.append({ @@ -339,7 +339,7 @@ class TestOvnNbSync(base.TestOVNFunctionalBase): 'lease_time': str(12 * 60 * 60), 'mtu': str(n1['network']['mtu']), 'router': n2_s1['subnet']['gateway_ip'], - 'tftp_server': '20.0.0.20', + 'tftp_server': '"20.0.0.20"', 'domain_name': '"ovn.test"', 'dns_server': '8.8.8.8'}}) self.missed_dhcp_options.extend([ @@ -716,7 +716,7 @@ class TestOvnNbSync(base.TestOVNFunctionalBase): 'lease_time': str(3 * 60 * 60), 'mtu': str(n3['network']['mtu'] / 2), 'router': '30.0.0.254', - 'tftp_server': '30.0.0.234', + 'tftp_server': '"30.0.0.234"', 'dns_server': '8.8.8.8'}, 'external_ids': {'subnet_id': n3_s1['subnet']['id'], 'port_id': fake_port_id1}} diff --git a/neutron/tests/unit/common/ovn/test_utils.py b/neutron/tests/unit/common/ovn/test_utils.py index e4cfef3609..af54965a2a 100644 --- a/neutron/tests/unit/common/ovn/test_utils.py +++ b/neutron/tests/unit/common/ovn/test_utils.py @@ -369,7 +369,7 @@ class TestDHCPUtils(base.BaseTestCase): # Assert the names got translated to their OVN names expected_options = {'tftp_server_address': '10.0.0.1', 'ntp_server': '10.0.2.1', - 'bootfile_name': 'homer_simpson.bin'} + 'bootfile_name': '"homer_simpson.bin"'} self.assertEqual(expected_options, options) |