diff --git a/neutron/agent/linux/ip_lib.py b/neutron/agent/linux/ip_lib.py index 353164b2ac4..f3f80c32ced 100644 --- a/neutron/agent/linux/ip_lib.py +++ b/neutron/agent/linux/ip_lib.py @@ -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 diff --git a/neutron/tests/unit/agent/linux/test_ip_lib.py b/neutron/tests/unit/agent/linux/test_ip_lib.py index adaaac081a0..9bef3c04b56 100644 --- a/neutron/tests/unit/agent/linux/test_ip_lib.py +++ b/neutron/tests/unit/agent/linux/test_ip_lib.py @@ -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)