From 46e59d312a46d96860fc1226ec6024d10ef2b1e0 Mon Sep 17 00:00:00 2001 From: Carl Baldwin Date: Tue, 1 Sep 2015 16:58:22 +0000 Subject: [PATCH] Make ip address optional to add_route and delete_route The add_route and delete_route methods require that the ip (actually "via" in ip route terms) be passed. Some routes don't require this. This patch makes it optional while maintaining the position for those callers who do pass it by position. Change-Id: Ic16408c00c77898d8f7663c92e56aa30427469f3 Partially-Implements: blueprint address-scopes --- neutron/agent/linux/ip_lib.py | 12 ++++++++---- neutron/tests/unit/agent/linux/test_ip_lib.py | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/neutron/agent/linux/ip_lib.py b/neutron/agent/linux/ip_lib.py index 1f26561c7..c7acd047b 100644 --- a/neutron/agent/linux/ip_lib.py +++ b/neutron/agent/linux/ip_lib.py @@ -733,16 +733,20 @@ class IpRouteCommand(IpDeviceCommandBase): 'proto', 'kernel', 'dev', device)) - def add_route(self, cidr, ip, table=None): + def add_route(self, cidr, via=None, table=None): ip_version = get_ip_version(cidr) - args = ['replace', cidr, 'via', ip] + args = ['replace', cidr] + if via: + args += ['via', via] args += self._dev_args() args += self._table_args(table) self._as_root([ip_version], tuple(args)) - def delete_route(self, cidr, ip, table=None): + def delete_route(self, cidr, via=None, table=None): ip_version = get_ip_version(cidr) - args = ['del', cidr, 'via', ip] + args = ['del', cidr] + if via: + args += ['via', via] args += self._dev_args() args += self._table_args(table) self._as_root([ip_version], tuple(args)) diff --git a/neutron/tests/unit/agent/linux/test_ip_lib.py b/neutron/tests/unit/agent/linux/test_ip_lib.py index dfa6d04bc..587601f91 100644 --- a/neutron/tests/unit/agent/linux/test_ip_lib.py +++ b/neutron/tests/unit/agent/linux/test_ip_lib.py @@ -951,6 +951,13 @@ class TestIpRouteCommand(TestIPCmdBase): 'dev', self.parent.name, 'table', self.table)) + def test_add_route_no_via(self): + self.route_cmd.add_route(self.cidr, table=self.table) + self._assert_sudo([self.ip_version], + ('replace', self.cidr, + 'dev', self.parent.name, + 'table', self.table)) + def test_delete_route(self): self.route_cmd.delete_route(self.cidr, self.ip, self.table) self._assert_sudo([self.ip_version], @@ -959,6 +966,13 @@ class TestIpRouteCommand(TestIPCmdBase): 'dev', self.parent.name, 'table', self.table)) + def test_delete_route_no_via(self): + self.route_cmd.delete_route(self.cidr, table=self.table) + self._assert_sudo([self.ip_version], + ('del', self.cidr, + 'dev', self.parent.name, + 'table', self.table)) + def test_list_routes(self): self.parent._run.return_value = ( "default via 172.124.4.1 dev eth0 metric 100\n" -- 2.45.2