Merge "[OVN]Any string type dhcp options should be quoted"

This commit is contained in:
Zuul 2022-05-18 17:17:15 +00:00 committed by Gerrit Code Review
commit 68481e625f
5 changed files with 24 additions and 9 deletions

View File

@ -175,6 +175,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'

View File

@ -161,6 +161,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.
@ -194,6 +198,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)

View File

@ -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']],

View File

@ -209,7 +209,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({
@ -256,7 +256,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'],
@ -279,7 +279,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({
@ -340,7 +340,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([
@ -717,7 +717,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}}

View File

@ -386,7 +386,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)