Merge "Table name in "add_ip_rule" can be a string"
This commit is contained in:
commit
75ad37d91c
@ -1353,7 +1353,8 @@ def _make_pyroute2_args(ip, iif, table, priority, to):
|
|||||||
|
|
||||||
:param ip: (string) source IP or CIDR address (IPv4, IPv6)
|
:param ip: (string) source IP or CIDR address (IPv4, IPv6)
|
||||||
:param iif: (string) input interface name
|
: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 priority: (string, int) rule priority
|
||||||
:param to: (string) destination IP or CIDR address (IPv4, IPv6)
|
:param to: (string) destination IP or CIDR address (IPv4, IPv6)
|
||||||
:return: a dictionary with the kwargs needed in pyroute rule commands
|
: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'] = common_utils.cidr_to_ip(to)
|
||||||
cmd_args['dst_len'] = common_utils.cidr_mask(to)
|
cmd_args['dst_len'] = common_utils.cidr_mask(to)
|
||||||
if table:
|
if table:
|
||||||
cmd_args['table'] = RULE_TABLES.get(int(table), int(table))
|
cmd_args['table'] = RULE_TABLES.get(table) or int(table)
|
||||||
if priority:
|
if priority:
|
||||||
cmd_args['priority'] = int(priority)
|
cmd_args['priority'] = int(priority)
|
||||||
return cmd_args
|
return cmd_args
|
||||||
|
@ -620,7 +620,8 @@ class TestIpRuleCommand(TestIPCmdBase):
|
|||||||
def _test_add_rule(self, ip, iif, table, priority):
|
def _test_add_rule(self, ip, iif, table, priority):
|
||||||
ip_version = netaddr.IPNetwork(ip).version
|
ip_version = netaddr.IPNetwork(ip).version
|
||||||
ip_family = common_utils.get_socket_address_family(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,
|
'priority': priority,
|
||||||
'family': ip_family}
|
'family': ip_family}
|
||||||
if iif:
|
if iif:
|
||||||
@ -694,6 +695,12 @@ class TestIpRuleCommand(TestIPCmdBase):
|
|||||||
def test_add_rule_v6(self):
|
def test_add_rule_v6(self):
|
||||||
self._test_add_rule('2001:db8::1', None, 3, 200)
|
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):
|
def test_delete_rule_v4(self):
|
||||||
self._test_delete_rule('192.168.45.100', 2, 100)
|
self._test_delete_rule('192.168.45.100', 2, 100)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user