From: Carl Baldwin Date: Tue, 1 Sep 2015 16:58:22 +0000 (+0000) Subject: Make ip address optional to add_route and delete_route X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=46e59d312a46d96860fc1226ec6024d10ef2b1e0;p=openstack-build%2Fneutron-build.git 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 --- 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"