Table name in "add_ip_rule" can be a string

In neutron.agent.linux.ip_lib.add_ip_rule, the "table" argument can be
an integer or a string ("default", "main", "local").

This parameter is incorrectly treated in "_make_pyroute2_args".

Change-Id: I0a50af5fe9b1550700e607eb680bb16e5044e8ef
Closes-Bug: #1807128
This commit is contained in:
Rodolfo Alonso Hernandez 2018-12-06 10:48:51 +00:00
parent 462b510c50
commit 89ba2416f2
2 changed files with 11 additions and 3 deletions

View File

@ -1353,7 +1353,8 @@ def _make_pyroute2_args(ip, iif, table, priority, to):
:param ip: (string) source IP or CIDR address (IPv4, IPv6)
:param iif: (string) input interface name
:param table: (string, int) table number
:param table: (string, int) table number (as an int or a string) or table
name ('default', 'main', 'local')
:param priority: (string, int) rule priority
:param to: (string) destination IP or CIDR address (IPv4, IPv6)
:return: a dictionary with the kwargs needed in pyroute rule commands
@ -1372,7 +1373,7 @@ def _make_pyroute2_args(ip, iif, table, priority, to):
cmd_args['dst'] = common_utils.cidr_to_ip(to)
cmd_args['dst_len'] = common_utils.cidr_mask(to)
if table:
cmd_args['table'] = RULE_TABLES.get(int(table), int(table))
cmd_args['table'] = RULE_TABLES.get(table) or int(table)
if priority:
cmd_args['priority'] = int(priority)
return cmd_args

View File

@ -620,7 +620,8 @@ class TestIpRuleCommand(TestIPCmdBase):
def _test_add_rule(self, ip, iif, table, priority):
ip_version = netaddr.IPNetwork(ip).version
ip_family = common_utils.get_socket_address_family(ip_version)
cmd_args = {'table': table,
table_num = ip_lib.RULE_TABLES.get(table) or int(table)
cmd_args = {'table': table_num,
'priority': priority,
'family': ip_family}
if iif:
@ -694,6 +695,12 @@ class TestIpRuleCommand(TestIPCmdBase):
def test_add_rule_v6(self):
self._test_add_rule('2001:db8::1', None, 3, 200)
def test_add_rule_table_string(self):
self._test_add_rule('2001:db8::1', None, 'default', 200)
self._test_add_rule('2001:db8::1', None, 'main', 200)
self._test_add_rule('2001:db8::1', None, 'local', 200)
self._test_add_rule('2001:db8::1', None, '100', 200)
def test_delete_rule_v4(self):
self._test_delete_rule('192.168.45.100', 2, 100)